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.
postgres=# 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:
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?
2 Answers
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
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