LMSouq
server-admin Open

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: Peer authentication failed for user "postgres" (Ubuntu)

JI
JimmyTheCode
1 month ago
3 views
Problem Description
When I try to open ```psql``` with this command: ``` psql -U postgres ``` I get this error: ``` psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: Peer authentication failed for user "postgres" ``` But it connects successfully when I use: ``` sudo -u postgres psql ``` Can someone please explain what is happening and how to diagnose/fix this problem? My ```pg_hba.conf``` contains the following: ``` # 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 md5 # IPv4 local connections: host all all 127.0.0.1/32 scram-sha-256 # IPv6 local connections: host all all ::1/128 scram-sha-256 # Allow replication connections from localhost, by a user with the # replication privilege. local replication all peer ```

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base