Monday, April 16, 2012

psql: FATAL: Peer authentication failed for user "xxx"

Authentication :

$ psql simpledb test
psql: FATAL:  Peer authentication failed for user "test"

The authentication service op postgresql has to be configured.

Example of configuration :

$ cd /etc/postgresql/9.1/main

$ diff pg_hba.conf pg_hba.conf.orig
85,87c85
< local   all    postgres                peer
< local   all    energycomm              md5
< #local  all    test                    md5
---
> local   all    postgres                peer
94,96c92
< #host   all    all    127.0.0.1/32     md5
< #host   all    all    10.1.1.104/32    trust
< host    all    all    samenet          md5
---
> host    all    all    127.0.0.1/32     md5


Restart postgresql :
$ service postgresql restart
 * Restarting PostgreSQL 9.1 database server  

postgres@vsolutions:/etc/postgresql/9.1/main$ psql simpledb test
Password for user test:
psql (9.1.3)
Type "help" for help.

simpledb=>