Reputation: 131
Hi I'm getting the following and the other solutions I've seen for this don't seem to be working... Within the ubuntu server terminal (a virtualbox vm): Error FATAL: Peer authentication failed for user "a4apps"
My Ubuntu server os user name is the same. I have restarted my postgres. I have tried changing my pg_hba.conf file by: changing the IPv4 host method from md5 to "trust" and by adding a line under it "host all all myubuntuserverip/32 trust"
I am trying to access it via a python script. I am using psycopg
con = psycopg2.connect(database='fieldtest2', user='a4apps')
I created the user: sudo -u postgres create user a4apps superuser no, create databases yes, create other users no. Created database: sudo -u postgres createdb fieldtest2 -O a4apps
I was following this tutorial: here
I'm running out of ideas. Any guidance would be appreciated. Thanks Mike
Upvotes: 1
Views: 641
Reputation: 61696
This specific error message:
Peer authentication failed for user "a4apps"
means that the peer
authentication method was selected per pg_hba.conf
and that the connection attempt was not made by the OS user a4apps
, contrary to what this auth method requires.
The default Ubuntu pg_hba.conf
has these lines:
# Database administrative login by Unix domain socket local all postgres peer # TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all peer
To allow local passwordless connections for any user except postgres
, you may replace peer
by trust
in the last line.
The IPv4-related changes you tried in pg_hba.conf
had no effect on your script because it doesn't connect through TCP/IP. If the connection string mentioned a hostname, it would then use TCP/IP and trigger the corresponding rules in pg_hba.conf
.
Upvotes: 3