PostgreSQL FATAL: Peer authentication failed for user "postgres"
Local Unix-socket connection requires OS username to match DB role under `peer` auth.
Runs locally in browser
Free · No login
Independently Verified 2026-11-25
v4.1.0
Identifier: PostgreSQL FATAL
Platform: PostgreSQL
Common Root Causes:
- Local Unix-socket connection requires OS username to match DB role under `peer` auth.
Interactive Diagnostic Checklist
Verified Solutions:
- Connect via `-h 127.0.0.1` (TCP scram-sha-256) or run as `sudo -u postgres psql`.
Safe Diagnostic Command:
grep -v "^#" /etc/postgresql/*/main/pg_hba.conf
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.
Technical Explanation
Local Unix-socket connection requires OS username to match DB role under `peer` auth. Recommended diagnostic: `grep -v "^#" /etc/postgresql/*/main/pg_hba.conf`. Remediation: Connect via `-h 127.0.0.1` (TCP scram-sha-256) or run as `sudo -u postgres psql`.
Worked Examples
- Run `grep -v "^#" /etc/postgresql/*/main/pg_hba.conf` to verify root cause before applying the remediation.
Limitations & Assumptions
- Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.
Source References & Verification
Resource ID: err-pg-fatal-peer-auth-failed · Independently verified: 2026-11-25