1

I have user and password in a PostgreSQL server that I can log in with using SQL Console, but when I develop the application with Spring, I get the error message, "password authentication failed for user postgres".

Why the happening? Is authentication from database and application different? What are the possible causes of this? Can give me reference for this.

I searched Google for answers but I'm still not clear what's causing this. Thanks

1 Answer 1

0

The cause is pretty clear: you are trying to log in with the user "postgres" and the wrong password (or no password) is being sent.

postgres is the default/superuser account for Postgres databases. Make sure this is the user you want to connect with.

A convenient and frequently used approach is to have a ~/.pgpass file store the credentials of the Postgres servers you (or your application) are logging into. This is described in detail here. Each line of the file specifies the credentials for a given Postgres server you want to connect to. For example:

localhost:5432:*:postgres:password
devpostgresserver:5432:*:postgres:password123
legitpostgresserver:5432:appdbname:legitpguser:averysecurepassword456

Postgres will check this file when attempting to connect, and if it finds a match for the server it's connecting to, it will use the credentials on that line to log in.

I'm not sure how the connection details are specified in Spring, but this Spring Boot configuration guide might have some helpful information on that. It mentions:

To use the embedded databases, you don’t need any special configuration, not even any connection URL.

Sign up to request clarification or add additional context in comments.

1 Comment

I trying connect the db server with username: postgres and password: postgres and I succesfully log in with SQL console but in my configuration in spring, with the same detail, I found the problem like that.. must I add my IP address my computer for postgre configuration? thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.