PostgreSQL 28P01: password authentication failed
PostgreSQL rejected the password for this user. A wrong password, a role without a password, or a password hashed in a format the server no longer accepts.
- SQLSTATE
28P01- Name
invalid_password
What it means
The server found a pg_hba.conf rule that asks for a password (scram-sha-256, md5 or password) for this connection, and the password the client sent didn't match the role's stored password.
For security the client is only told the password failed. The server log has the reason, for example User "app" has no password assigned or Role "app" does not exist.
Common causes
- Wrong password, or a password with special characters mangled in a connection URL (they must be percent-encoded).
- The role doesn't exist or has no password set; the client still sees
password authentication failed. - The role's password is stored as an MD5 hash but
pg_hba.confrequiresscram-sha-256, after an upgrade to a default of SCRAM. - The client picked up a different password from
PGPASSWORDor a.pgpassfile.
How to fix it
-
Read the server log entry for the failed login; it states the real reason.
-
Set a new password as a superuser (in psql,
\password appprompts without echoing it).ALTER ROLE app WITH LOGIN PASSWORD 'new-strong-password';
-
Check how the password is stored. A value starting with
md5must be reset after switchingpassword_encryptiontoscram-sha-256.SHOW password_encryption; SELECT rolname, left(rolpassword, 14) AS hash_type FROM pg_authid WHERE rolname = 'app';
-
Check which
pg_hba.confline matched; the view shows the file as the server loaded it.SELECT line_number, type, database, user_name, address, auth_method FROM pg_hba_file_rules;
-
Percent-encode special characters in connection URLs, for example
@as%40:postgresql://app:p%40ss@db:5432/shop.
Related errors
28000invalid authorization specification3D000database does not exist53300too many connections18456SQL Server: Login failed for user1045MySQL: Access denied for userORA-01017Oracle: invalid username/password; logon denied
The code and message text are from the PostgreSQL documentation, Appendix A: PostgreSQL Error Codes. Browse the full PostgreSQL error list or search every database error.
Work on PostgreSQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for PostgreSQL and the other databases you use.