In this article, we will see the solution for below error:
psql error could not connect to server FATAL Peer authentication failed for user
Reason: This is due to authentication method configured in the pg_hba.conf file.
Solution: We have to change the authentication method from peer to md5 in pg_hda.conf file.
Open the file pg_hba.conf file.
If you dont know the pg_hba.conf file location, then use the below command.
find / -name pg_hba.conf 2>/dev/null
Replace peer with md5
Before modification of pg_hba.conf file.
After modification:
We have to reload after changes done in pg_hba.conf file by using below command.
sudo service postgresql reload
or
SELECT pg_reload_conf();