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
<code>[root@jeven ~]# psql -h192.168.3.166 -Upostgres -W
Password:
psql: error: FATAL: password authentication failed for user "postgres"
</code>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.confentries:
<code>host all all 127.0.0.1/32 ident
host all all 0.0.0.0/0 md5
</code>5. Solutions
5.1 Reset forgotten password
<code>su - postgres
psql -c "ALTER USER postgres WITH PASSWORD 'postgres';"
</code>5.2 Correct password setting
<code>sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'postgres';"
</code>5.3 Fix configuration files
Ensure
listen_addressesand
pg_hba.confentries are correct, then restart PostgreSQL.
5.4 Temporary trust authentication
<code>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 trust
</code>5.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.confor
pg_hba.conf.
Client‑server version incompatibility.
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.