Databases 7 min read

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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Why PostgreSQL Returns ‘FATAL: password authentication failed’ and How to Fix It

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         md5

After 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         md5

Restart 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        trust

5.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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

SQLPostgreSQLdatabase troubleshootingpassword-authenticationConnection Error
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.