0

Postgres password authentication fails

I've installed PostgreSQL 9.1
after that I tried to connect to the default PostgreSQL template database:
sudo -u postgres psql template1
but login failed with this error message:
psql: FATAL: password authentication failed for user "postgres"

PostgreSQL Authentication Add a comment
michael
asked Nov 03 2021

Answer

0

You've locked yourself out, because you enabled md5 authentication for database user postgres without setting a password for the database user postgres.

Open the file
vim /etc/postgresql/10/main/pg_hba.conf

Add a new line to the top of pg_hba.conf:
local postgres postgres peer

Then restart/reload PostgreSQL:
/etc/init.d/postgresql reload\

and run:
sudo -u postgres psql

From the resulting prompt:
ALTER USER postgres PASSWORD 'my_postgres_password';

Remove the line you added to pg_hba.conf and restart Pg again. You can now use the password you set above to connect to
PostgreSQL as the postgres user.

Add a comment
linuxhelp
asked Nov 03 2021
Post your Answer