pg_connect(): Unable to connect to PostgreSQL server
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.
Related videos on Youtube
Mysteri0n
Updated on September 18, 2022Comments
-
Mysteri0n almost 2 years
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 172.16.1.64] 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!
Thanks!
-
prophecy201 over 11 yearsIt seems, that only postgresql is allowd to login. Is it correct or do you use another user in you php script?
-
Mysteri0n over 11 yearsI 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
-