Search code examples
postgresqlpostgresql-15

psql: error: connection to server at "localhost" (::1), port 5432 failed: FATAL: password authentication failed for user "postgres"


After installing and opening the psql shell, it throws this error BEFORE even asking the password I had set during install:

psql: error: connection to server at "localhost" (::1), port 5432 failed: FATAL:  password authentication failed for user "postgres"

I enter the default user ("postgres") and it immediately throws the error before prompting me to enter the password as everyone else's shell.

Tried to look at the pg_hba.conf file and changing the METHOD from scram-sha-256 (the one that was originally set) to md5 and password, but no good.

I know I can just set it to trust but that doesn't seem right. Why is this happening? How can it be an installing mistake if it doesn't even wait for me to the enter the password?


Solution

  • First of all, check did you set up a password for the 'postgres' user. Then try to change in the file /var/lib/pgsql/data/pg_hba.conf all values 'ident' to 'scram-sha-256' And then restart server: sudo systemctl restart postgresql.service