psql: FATAL: Ident authentication failed for user "username" Error and Solution

by Vivek Gite · 7 comments

Q. I've installed Postgresql under Red Hat Enterprise Linux 5.x server. I've created username / password and database. But when I try to connect it via PHP or psql using following syntax:

psql -d myDb -U username -W

It gives me an error that read as follows:

psql: FATAL: Ident authentication failed for user "username"

How do I fix this error?

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

  1. Which hosts are allowed to connect
  2. How clients are authenticated
  3. Which PostgreSQL user names they can use
  4. Which databases they can access

By default Postgresql uses IDENT-based authentication. All you have to do is allow username and password based authentication for your network or webserver. IDENT will never allow you to login via -U and -W options. Append following to allow login via localhost only:

local	all	all	trust
host	all	127.0.0.1/32	trust

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

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 7 comments… read them below or add one }

1 andrew toth 01.22.09 at 9:36 pm

I did the modifications, and get an error message (pg version 8.3):
psql: FATAL: missing or erroneous pg_hba.conf file
HINT: See server log for details.

2 himanshu 03.01.09 at 12:18 pm

Hi, its very urgent.
I m continuously getting below error, while running JSP file in jakarta-tomcat.
PSQLException: FATAL: Ident authentication failed for user “root”

I am trying to connect to a database ‘bedrock’. I am able to login & see the DB by ‘psql -d bedrock -U root’ from cmd-prompt. But the same does not happen from JSP file. Why is it so?? Please help me, its been 5 days struggling like mads……….

3 Camitux 03.04.09 at 3:04 am

Hey
Tanks

4 Wladek 04.22.09 at 7:50 pm

Hi, I have the same problem. I’ve created a program in perl, which contains connector to database DBI, and driver DBD::Pg. But I have still the same answer Fatal: Ident Authetification failed for user postgres…
this is the connector:
my $dbh = DBI->connect(“DBI:Pg:dbname=test;host=localhost”, “postgres”, “”, {‘RaiseError’ => 1});

please help…

5 Anibal Leite 08.31.09 at 3:55 pm

Tank you!

6 Saeed 11.16.09 at 8:05 am

Thank You! saved me once :-)

7 kangu 02.05.10 at 4:49 pm

Thanks saved one life here!

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All