【Linux】psql: FATAL: Ident authentication failed for user “username” Error and Solution

Question:I have installed Postgresql.x server under Red Hat Enterprise Linux 5. I have created username/password and database. But when I try to connect it via PHP or psql use the following syntax:

psql -d myDb -U username -W
It gives me an error that reads as follows:

psql:Fatal: Ident authentication failed for user “username”.
How do I fix this error?

A. To fix this error, open the PostgreSQL client authentication configuration file /var/lib/pgsql/data/pg_hba.conf:
# vi /var/lib/pgsql/data/pg_hba.conf:
# vi /var/lib/pgsql/data/pg_hba.conf: # vi /var/lib/pgsql/data/pg_hba.conf: # vi /var/lib/pgsql/data/pg_hba.conf.

    Which hosts are allowed to connect, which clients are authenticated, which PostgreSQL usernames are available to which users, and which databases are accessible

By default, Postgresql uses identity-based authentication. All you have to do is allow authentication to your network or web server based on username and password.IDENT will never allow you to log in via the -U and -W options. Add the following to allow logins through local hosts only:

local all all trust
host all 127.0.0.1/32 trust

Save and close the file. Restart the Postgresql server:
# service Postgresql Restart
Now you should be able to log in using the following command:
$ psql -d myDb -U username -W

Read More: