How to fix FATAL: password authentication failed for user in PostgreSQL

PostgreSQLINTERMEDIATEMEDIUMUpdated Dec 26, 2025· 320 views

This error occurs when PostgreSQL rejects a login attempt due to incorrect credentials, misconfigured authentication settings, or a missing password. Common causes include wrong password, incorrect pg_hba.conf authentication method, or users created without passwords.

Quick fix

Fixes FATAL: password authentication failed for user

psql -U postgres -W -h localhost
  1. Verify the password is correct
  2. Check the pg_hba.conf authentication method
  3. Reload or restart PostgreSQL after pg_hba.conf changes
  4. Reset the password for the user
postgresql — error
psql -U postgres -W -h localhost
FATAL: password authentication failed for user

What this error means

PostgreSQL uses host-based authentication (pg_hba.conf) to control which users can connect to which databases from which locations. When the server receives a connection attempt, it checks the authentication rules in order and applies the first matching rule. This error means the authentication step failed—either the password was incorrect, the user has no password set, or the authentication method in pg_hba.conf doesn't support password-based login. The error typically appears when connecting via psql, pgAdmin, DBeaver, or application connection strings. It blocks all database access for the affected user until the authentication issue is resolved.

Typical symptoms

  • psql: FATAL: password authentication failed for user "postgres" (or other username)
  • Connection refused when attempting to connect via GUI tools (pgAdmin, DBeaver, etc.)
  • Application unable to connect to PostgreSQL with correct credentials in connection string
  • Error occurs immediately during login attempt without querying any data
  • Only affects remote or TCP/IP connections, not local peer connections

Common causes

  1. Incorrect or mistyped password during login attempt
  2. User or role created without a password set (CREATE USER without PASSWORD clause)
  3. pg_hba.conf configured with "trust", "peer", or "ident" method instead of password-based method
  4. pg_hba.conf changes made but PostgreSQL service not reloaded or restarted
  5. Connecting to wrong host or port where authentication rules differ
  6. User account lacks LOGIN privilege or was created with NOLOGIN flag
  7. PostgreSQL version mismatch in authentication method (e.g., SCRAM not compatible with old clients)

How to fix "FATAL: password authentication failed for user"

1Verify the password is correct

Double-check that you are typing the correct password. Test with a known-good password or reset it if you are unsure.

bash
psql -U postgres -W -h localhost

When prompted, carefully enter the password. If you forgot the password, proceed to Step 3.

2Check the pg_hba.conf authentication method

Locate your pg_hba.conf file (usually at /etc/postgresql/<version>/main/pg_hba.conf on Linux, $PGDATA/pg_hba.conf, or C:\Program Files\PostgreSQL\<version>\data\pg_hba.conf on Windows).

Open it and find the line matching your connection type. For example, for local TCP/IP connections from localhost:

bash
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             127.0.0.1/32            scram-sha-256

Ensure the METHOD column uses a password-based method like scram-sha-256, md5, or password. Do NOT use trust, peer, or ident for remote connections that require passwords.

If you need to change it:

bash
# Before: trust (no password required)
host    all             all             127.0.0.1/32            trust

# After: scram-sha-256 (password required)
host    all             all             127.0.0.1/32            scram-sha-256
3Reload or restart PostgreSQL after pg_hba.conf changes

Changes to pg_hba.conf do not take effect until the PostgreSQL service reloads the configuration.

On Linux:

bash
# Reload without restarting (preferred)
sudo systemctl reload postgresql

# Or: restart the service
sudo systemctl restart postgresql

# Or: use pg_ctl if installed
pg_ctl reload

On macOS (with Homebrew):

bash
brew services reload postgresql

On Windows:

1. Open Services (services.msc)
2. Find "postgresql-x64-<version>" service
3. Right-click → Restart

4Reset the password for the user

If the user has no password or you need to set a new one, log in as a superuser first (using sudo -u postgres on Linux or trusted connection) and run:

sql
ALTER USER postgres PASSWORD 'new_password';

Replace postgres with the actual username and new_password with a secure password.

If you cannot log in at all (e.g., on a fresh installation):

On Linux, use the peer authentication method:

bash
sudo -u postgres psql
psql (14.7, server 14.7)
Type "help" for help.

postgres=# ALTER USER postgres PASSWORD 'new_password';
ALTER ROLE
postgres=# \q

Then update pg_hba.conf to use password-based authentication.

5Ensure the user has LOGIN privilege

If the user was created without the LOGIN privilege, grant it:

sql
ALTER ROLE username LOGIN;
ALTER ROLE username PASSWORD 'new_password';

Check if a user was created with NOLOGIN by querying the system:

sql
SELECT usename, usesuper, usecreatedb, usecreaterole, usecanlogin
FROM pg_user
WHERE usename = 'username';

The usecanlogin column must be true.

6Test the connection

After making changes, test the connection:

bash
psql -U postgres -W -h localhost

Enter the new password when prompted. If successful, you will see the psql prompt:

bash
psql (14.7, server 14.7)
Type "help" for help.

postgres=# \q

If using an application or connection string, update the connection details and retry.

Advanced notes

PostgreSQL 13.3+ defaults to SCRAM-SHA-256 authentication, which is more secure than MD5 but may not be compatible with very old clients. If you need backward compatibility, you can use the MD5 method in pg_hba.conf, but SCRAM is preferred for security.

On local Linux systems, PostgreSQL uses "peer" authentication for the postgres user, which trusts the OS user identity and does not require a password. This is why sudo -u postgres psql works without entering a password—it uses peer authentication, not password authentication.

For Docker or containerized PostgreSQL, if you set the POSTGRES_PASSWORD environment variable, it creates the postgres user with that password during initialization. If you run the container without setting the password, the user may not have a password set, leading to authentication failures.

For production systems, always use strong passwords, enable SSL/TLS encryption for connections, and restrict pg_hba.conf rules to only allow connections from trusted IP ranges. Avoid using "trust" authentication except for local development on secure machines.

Frequently asked questions

What does "FATAL: password authentication failed for user" mean?
conf) to control which users can connect to which databases from which locations. When the server receives a connection attempt, it checks the authentication rules in order and applies the first matching rule. conf doesn't support password-based login.
How do I fix "FATAL: password authentication failed for user"?
This error occurs when PostgreSQL rejects a login attempt due to incorrect credentials, misconfigured authentication settings, or a missing password. Common causes include wrong password, incorrect pg_hba.conf authentication method, or users created without passwords.
What causes "FATAL: password authentication failed for user"?
Incorrect or mistyped password during login attempt User or role created without a password set (CREATE USER without PASSWORD clause) pg_hba.conf configured with "trust", "peer", or "ident" method instead of password-based method
Is the "FATAL: password authentication failed for user" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading