Authentication Failed
Error message
password authentication failed
Quick summary
The database server refused your login because the username, password, or authentication method does not match.
Why this happens
Wrong password (typo or changed password)
Wrong username
The user does not have permission to connect to this database
Authentication method mismatch (e.g., md5 vs scram-sha-256)
The user does not exist in the database
Minimal example
# Wrong password
psql -U postgres -h localhost
# → password authentication failed for user "postgres"# Correct password
PGPASSWORD=correct_password psql -U postgres -h localhostThe password was wrong. Providing the correct password (via PGPASSWORD env var) fixes the error.
How to diagnose
Verify the username and password are correct
Check if the user exists:
\duin psql orSELECT * FROM pg_userVerify the user has permission to connect to the database
Check the authentication method in the server configuration
How to fix
Correct the username and password in your connection string
Create the user if it does not exist:
CREATE USER name WITH PASSWORD 'pass'Grant connect permission:
GRANT CONNECT ON DATABASE db TO userUpdate the authentication method in pg_hba.conf if needed
How to prevent
Store credentials in environment variables or a secrets manager
Use connection pooling with validated credentials
Document database access requirements for new team members
Related Resources
Related Glossary
Related Lessons
- Database Security
Learn about database authentication.