I have read multiple articles detailing this fix for this exact issue. I have tried all kinds of variations of editing the pg_hba.conf file but no luck I still get the following error in my Apache log when I attempt to run the php program I'm trying to use.

Thu Mar 28 08:20:21 2013] [error] [client] PHP Warning: pg_connect(): >Unable to connect to PostgreSQL server: FATAL: Peer authentication failed for user

This is my current pg_hba.conf file:


I don't know what else to try, any help is greatly appreciated!


  • It seems, that only postgresql is allowd to login. Is it correct or do you use another user in you php script? – prophecy201 Mar 28 '13 at 13:44
  • I have a user that is called focus that has all rights to all tables. I built a basic connection and query script that queries the top 10 results from a table in the database. So I know it works like that. But yes I would like to allow the focus user to login from php with the app I'm using. (custom app, not a standard Wordpress or anything) How would I go about editing the config file to add focus to the allow? Thanks – Mysteri0n Mar 28 '13 at 14:08

Consider the first rule in the pg_hba.conf:

local all all peer

It means that for all local connections, the Unix user should be the same as the db user. Obviously this is not the case for you php code, hence the failure Peer authentication failed for user....

The second rule would let your script connect, but it's ignored because the first rule takes precedence:

local all all trust

This rule means that all local connections are allowed without requiring password and without checking any identity.

If that's OK with you, just delete the first rule, and reload the postgresql service for the change to take effect.

The other rules should not be relevant to the problem since they're related to TCP connections, and according to the error message, that's not that the method used by your script, it's trying to connect through the default Unix domain socket.

| improve this answer | |

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.