Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


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?

share|improve this question

migrated from Nov 16 '12 at 12:17

This question came from our site for professional and enthusiast programmers.

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. – Craig Ringer Nov 15 '12 at 22:44
up vote 4 down vote accepted

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
share|improve this answer
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 '12 at 4:13

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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