How to fix FATAL: password authentication failed for user in PostgreSQL
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- Verify the password is correct
- Check the pg_hba.conf authentication method
- Reload or restart PostgreSQL after pg_hba.conf changes
- Reset the password for the user
psql -U postgres -W -h localhostFATAL: 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
- 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
- pg_hba.conf changes made but PostgreSQL service not reloaded or restarted
- Connecting to wrong host or port where authentication rules differ
- User account lacks LOGIN privilege or was created with NOLOGIN flag
- PostgreSQL version mismatch in authentication method (e.g., SCRAM not compatible with old clients)
How to fix "FATAL: password authentication failed for user"
Double-check that you are typing the correct password. Test with a known-good password or reset it if you are unsure.
psql -U postgres -W -h localhostWhen prompted, carefully enter the password. If you forgot the password, proceed to Step 3.
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:
# TYPE DATABASE USER ADDRESS METHOD
host all all 127.0.0.1/32 scram-sha-256Ensure 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:
# 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-256Changes to pg_hba.conf do not take effect until the PostgreSQL service reloads the configuration.
On Linux:
# Reload without restarting (preferred)
sudo systemctl reload postgresql
# Or: restart the service
sudo systemctl restart postgresql
# Or: use pg_ctl if installed
pg_ctl reloadOn macOS (with Homebrew):
brew services reload postgresqlOn Windows:
1. Open Services (services.msc)
2. Find "postgresql-x64-<version>" service
3. Right-click → Restart
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:
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:
sudo -u postgres psql
psql (14.7, server 14.7)
Type "help" for help.
postgres=# ALTER USER postgres PASSWORD 'new_password';
ALTER ROLE
postgres=# \qThen update pg_hba.conf to use password-based authentication.
If the user was created without the LOGIN privilege, grant it:
ALTER ROLE username LOGIN;
ALTER ROLE username PASSWORD 'new_password';Check if a user was created with NOLOGIN by querying the system:
SELECT usename, usesuper, usecreatedb, usecreaterole, usecanlogin
FROM pg_user
WHERE usename = 'username';The usecanlogin column must be true.
After making changes, test the connection:
psql -U postgres -W -h localhostEnter the new password when prompted. If successful, you will see the psql prompt:
psql (14.7, server 14.7)
Type "help" for help.
postgres=# \qIf 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
- 📚PostgreSQL Official Documentation
- 📖PostgreSQL Docs - Authentication Problems(Official Docs)
- 📖PostgreSQL Docs - The pg_hba.conf File(Official Docs)