Error
Error Code:
28P01
PostgreSQL Error 28P01: Invalid Password or User
Description
This error indicates that the authentication credentials provided for connecting to the PostgreSQL database are incorrect. It typically occurs when a client application or user attempts to establish a connection with an invalid password for the specified username.
Error Message
invalid password
Known Causes
4 known causesIncorrect Password Input
The user or application provided a password that does not match the one stored for the specified database user.
Wrong Username
The username provided during the connection attempt does not exist or is not recognized by the PostgreSQL server.
Outdated Credentials
The password for the database user was recently updated, but the client application is still using an old, incorrect password.
Authentication Method Mismatch
The client is trying to authenticate using a method (e.g., MD5, SCRAM) that the PostgreSQL server is not configured to accept for that user or connection.
Solutions
4 solutions available1. Verify Password easy
Check password is correct
1
Test connection with psql
psql -U username -h localhost -d database
2
Reset password if forgotten
-- As superuser:
ALTER USER username WITH PASSWORD 'new_password';
2. Check pg_hba.conf Authentication medium
Verify authentication method settings
1
Find pg_hba.conf location
SHOW hba_file;
2
Check authentication method
# In pg_hba.conf:
# TYPE DATABASE USER ADDRESS METHOD
local all all md5
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
3
Reload configuration
SELECT pg_reload_conf();
-- or from command line:
pg_ctl reload
3. Fix Password in Connection String easy
Ensure password is correctly formatted
1
Check connection string format
# Standard format:
postgresql://username:password@hostname:5432/database
# URL-encode special characters in password:
# @ → %40
# : → %3A
# / → %2F
# # → %23
2
Or use environment variables
export PGPASSWORD='your_password'
psql -U username -h localhost -d database
4. Check Password Encryption medium
Ensure client and server use same encryption
1
Check password encryption setting
SHOW password_encryption;
2
Reset password with correct encryption
-- For scram-sha-256 (PostgreSQL 10+):
SET password_encryption = 'scram-sha-256';
ALTER USER username WITH PASSWORD 'password';
-- For md5 (older):
SET password_encryption = 'md5';
ALTER USER username WITH PASSWORD 'password';