I have the following scenario:

saji@geeklap:~$ psql -U postgres
psql: FATAL:  Ident authentication failed for user "postgres"

saji@geeklap:~$ psql -h localhost -U postgres
Password for user postgres: 
psql (8.4.14)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.


I'm trying to log into the postgresql server installed in my system as user postgres. I'm able to login only if I specify -h localhost. Whereas psql documentation says that:

If you omit the host name, psql will connect via a Unix-domain socket to a server on the local host, or via TCP/IP to localhost on machines that don't have Unix-domain sockets.

Ref: http://www.postgresql.org/docs/current/static/app-psql.html#R2-APP-PSQL-CON

Why am I unable to login without specifying the host, is there some configuration file that needs any change for things to occur as told in the psql documentation?

  • Create a .psqlrc that specifies the defaults - or just edit pg_hba.conf to use md5 authentication for local (unix socket) connections. See the documentation for pg_hba.conf and psql. Nov 15, 2012 at 22:44

2 Answers 2


If you don't like the default of connecting via a unix socket, you can set the environment variable PGHOST. I have

export PGHOST="db"

in my ~/.bashrc, to connect to the server with that name. A few more handy environment variables are documented at http://www.postgresql.org/docs/9.5/static/libpq-envars.html


In fact, it works as documented.

When the host name is omitted, psql connects to the Unix-domain socket whose path is compiled in. That part works in your case, otherwise it would output a different error message than what the question shows.

The error message in the question:

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

relates to the fact that only the Unix user postgres has the permission to connect as the database user postgres when using a Unix-domain socket. This is configured in the pg_hba.conf file.

what you should typically do in Ubuntu when you're logged in as a normal user, but you're the administrator of the system:

$ sudo -u postgres psql
  • 1
    Thanks.. Please change sudo -u postgresql psql to sudo -u postgres psql. I tried to edit. But couldn't, as the edit has only <6 characters.
    – saji89
    Nov 16, 2012 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.