Why Does PostgreSQL Show “FATAL: password authentication failed for user ‘postgres’” and How to Fix It?
This guide explains why a PostgreSQL connection attempt fails with “FATAL: password authentication failed for user ‘postgres’”, outlines common causes such as wrong passwords and misconfigured postgresql.conf or pg_hba.conf, and provides step‑by‑step solutions including password reset, config correction, trust authentication and environment rebuild.
PostgreSQL database connection error: psql: error: FATAL: password authentication failed for user “postgres”
Environment: CentOS 7.6 host jeven, IP 192.168.3.166, PostgreSQL 13.10 installed via yum.
1. PostgreSQL overview
PostgreSQL (Postgres) is an open‑source relational DBMS supporting transactions, concurrency, complex queries, extensions, and advanced features such as foreign keys, triggers, and stored procedures.
2. Error scenario
[root@jeven ~]# psql -h192.168.3.166 -Upostgres -W
Password:
psql: error: FATAL: password authentication failed for user "postgres"3. Possible causes
Wrong password entered.
Incorrect settings in postgresql.conf.
Incorrect settings in pg_hba.conf.
Password not set correctly for the user.
4. Configuration checks
Verify listen_addresses = '*' in postgresql.conf.
Typical pg_hba.conf entries:
host all all 127.0.0.1/32 ident
host all all 0.0.0.0/0 md55. Solutions
5.1 Reset forgotten password
su - postgres
psql -c "ALTER USER postgres WITH PASSWORD 'postgres';"5.2 Correct password setting
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'postgres';"5.3 Fix configuration files
Ensure listen_addresses and pg_hba.conf entries are correct, then restart PostgreSQL.
5.4 Temporary trust authentication
vim /var/lib/pgsql/13/data/pg_hba.conf
# change to:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 trust5.5 Re‑install in a clean environment
If configuration issues persist, consider redeploying PostgreSQL on a fresh system.
6. Summary of common causes
Incorrect connection parameters (host, port, user, password).
Database service not started.
Insufficient user privileges.
Firewall or network blockage.
Misconfigured postgresql.conf or pg_hba.conf.
Client‑server version incompatibility.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
