1

I am following a tutorial on how to create a to do app with PERN stack. (working on ubuntu 18.4, postgres version 12.3) I did install the PostrgreSQL, server is running on 5000 and I am able to enter to the database from the command line with "psql -U postgres" but when I try to connect database with the server I am getting this error: password authentication failed for user "postgres". I was not asked to give any password to the user "postgres" while instalation so I left the password in the db file empty.

My db file looks like this:

const Pool = require("pg").Pool;

const pool = new Pool({
  user: "postgres",
  password: "",
  host: "localhost",
  port: 5432,
  database: "perntodo",
});

module.exports = pool;

what can I co? I did set the postrgres authentication in pg_hba.conf file from peer to trust as I found in another issue on stockoverflow, but the error keeps appearing.

4
  • Look at the messages in the PostgreSQL log file. Commented Aug 20, 2020 at 14:07
  • server is running on 5000 ? port 5000 ? so why u use port: 5432, Commented Aug 20, 2020 at 14:23
  • Does this answer your question? Postgresql: password authentication failed for user "postgres" Commented Aug 20, 2020 at 15:25
  • thanks for the link, I have seen this post but it did not helped me to run my application. Commented Aug 24, 2020 at 10:11

3 Answers 3

1

The immediate fix would be to eliminate:

host: "localhost"

from your connection settings. This would force the connection to be made on local which would be equivalent to what you are doing with psql -U postgres.

The longer term fix would be to use psql -U postgres to connect and then ALTER ROLE postgres WITH PASSWORD '<some_pwd>'. This would give this ROLE a password. You can do this with other roles that already exist by using ALTER or when you CREATE a new role in the create statement.

The connection authentication methods are controlled by the pg_hba.conf file. A full explanation of what it does is available here:

https://www.postgresql.org/docs/current/auth-pg-hba-conf.html

If the above does not answer all your questions then come back with specific concerns.

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

2 Comments

thanks! unfortunatelly removing the host: "localhost" did not helped, I have created a new user and put this user to the db.js file and now it works.
Did you connect using psql -U postgres? Did you do the ALTER ROLE for the postgres user?
0

Don't use user postgres to connect your application to PostgreSQL.

  1. Create separate user for application.
  2. Grant to application user strict permissions only for schemes and tables what it need access.
  3. Add pg_hba.conf record for application user
  4. Enjoy

4 Comments

Unfortunately the above is not an answer to the issue @PaulinaL is having and will only lead to more of the same errors. The problem is authentication type and mode of connection.
You could do both. However, providing an answer that only leads to the same problem is not an answer.
I did create a new user, gave him rights almost like the postgres user and changed in the db.js file the user from postgres to my new user and to the new user's password and it works now.
@PaulinaL Good Luck!
0

If I go as per your error message, then you need to reset postgres password. And I believe the default isnt working or you might have forgotten after resetting it.

Please follow below tutorial for resetting password:-

https://docs.bitnami.com/aws/infrastructure/postgresql/administration/change-reset-password/

or refer the answer for below:-

What is the default password for Postgres

Comments

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.