Tuesday, November 20, 2018

psql: FATAL: Ident authentication failed for user (Centos 7)

What's up?

In this article you will know how to fix this error:
psql: FATAL:  Ident authentication failed for user "username"
which happens when you try to connect as follows:
psql -U username -h 127.0.0.1 -d postgres



To fix it, you need to edit pg_hba.conf file. But its location depends on postgresql server version. I will show you for 9.2 and 9.6.

Location of pg_hba.conf for postgresql-server (9.2 - from centos repo)

/var/lib/pgsql/data/pg_hba.conf

Location of pg_hba.conf for postgresql96-server (9.6 - from postgres repo)

/var/lib/pgsql/9.6/data/pg_hba.conf

Fix


1. Open pg_hba.conf and replace these lines:
host    all             all             127.0.0.1/32            ident
host    all             all             ::1/128                 ident

to these lines:
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5

2. Restart postgresql server (depending on your version):
sudo systemctl restart postgresql
# or
sudo systemctl restart postgresql-9.6

3. Now try to connect again, it should allow you to enter password:
psql -U username -h 127.0.0.1 -d postgres

That's it!

No comments:

Post a Comment