Why PostgreSQL Returns ‘FATAL: password authentication failed’ and How to Fix It
This guide explains why a remote PostgreSQL connection may fail with a password authentication error, analyzes common causes such as wrong credentials or misconfigured files, and provides step‑by‑step solutions including password reset, configuration checks, and trust authentication setup.
PostgreSQL Database Connection Error: “FATAL: password authentication failed for user “postgres””
1. Environment Overview
1.1 Practice Environment
The environment uses yum to install PostgreSQL on a CentOS 7.6 host (IP 192.168.3.166) with PostgreSQL 13.10.
1.2 PostgreSQL Overview
PostgreSQL (Postgres) is an open‑source relational database management system that implements all mainstream SQL features, supports transactions, concurrency control, complex queries, foreign keys, triggers, stored procedures, and offers high extensibility, stability, and security, making it a popular choice for enterprise applications.
1.3 PostgreSQL Features
Open‑source and free.
Highly extensible for large data and high concurrency.
Supports many data types such as JSON, arrays, ranges, XML, UUID.
Provides various backup and recovery methods.
Security mechanisms including SSL/TLS, access control, authentication, and authorization.
Extensible with extensions like spatial data and full‑text search.
2. Error Scenario
Remote connection to PostgreSQL fails with a password authentication error.
[root@jeven ~]# psql -h192.168.3.166 -Upostgres -W
Password:
psql: error: FATAL: password authentication failed for user "postgres"3. Cause Analysis
Incorrect password entered.
Misconfiguration in /var/lib/pgsql/13/data/postgresql.conf.
Misconfiguration in /var/lib/pgsql/13/data/pg_hba.conf.
Error when setting the database user password.
4. Check Configuration
Verify listen_addresses = '*' in postgresql.conf.
listen_addresses = '*' # what IP address(es) to listen on;Verify authentication lines in pg_hba.conf.
host all all 127.0.0.1/32 ident
host all all 0.0.0.0/0 md5After confirming the settings, restart the PostgreSQL service and test again.
5. Solutions for Common Scenarios
5.1 Forgot Login Password
Log in locally as the postgres user and reset the password.
su - postgres psql -c "ALTER USER postgres WITH PASSWORD 'postgres';"5.2 Incorrect or Missing Password Setting
The password was typed incorrectly; reset it.
sudo -u postgres
psql -c "ALTER USER postgres WITH PASSWORD 'postgres';"5.3 Configuration File Errors
Check and correct postgresql.conf and pg_hba.conf as shown above.
Verify listen_addresses = '*' in postgresql.conf.
listen_addresses = '*' # what IP address(es) to listen on;Verify authentication lines in pg_hba.conf.
host all all 127.0.0.1/32 ident
host all all 0.0.0.0/0 md5Restart the service after corrections.
5.4 Set Trust Authentication (Password‑less Login)
Temporarily change pg_hba.conf to trust authentication, reset the password, then revert the file.
vim /var/lib/pgsql/13/data/pg_hba.conf host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 trust5.5 Environment Issues
Deploy PostgreSQL on a clean or new environment if the current setup is corrupted.
6. Summary of PostgreSQL Connection Errors
Incorrect connection parameters (address, port, username, password).
Database service not started.
Insufficient user privileges.
Firewall or network blockage.
Misconfigured configuration files.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
