Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-11-30 · container image postgres:17
SQLSTATE 28P01 is invalid_password. The client always sees the same line: password authentication failed for user "app_user". PostgreSQL hides the real reason from the client on purpose and writes it to the server log as a DETAIL line.
We reproduced five different causes on PostgreSQL 17 by connecting with psql -h 127.0.0.1 (pg_hba method scram-sha-256). Each scenario shows the psql output and the server log line written at the same moment. Check the DETAIL first; it tells you which case you are in.
01The password is simply wrong (case typo in the app config)
The role exists and has a password, but the app sends shop2026 instead of Shop2026. Passwords are case-sensitive. The server log has no special DETAIL here, only the pg_hba.conf line that was used (scram-sha-256), which means the password itself did not match.
Setup
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026';CREATE ROLE$ PGPASSWORD='shop2026' psql -h 127.0.0.1 -U app_user -d labSELECT current_user, current_database();psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL: password authentication failed for user "app_user"FATAL: 28P01: password authentication failed for user "app_user"
DETAIL: Connection matched file "/var/lib/postgresql/data/pg_hba.conf" line 119: "host all all 127.0.0.1/32 scram-sha-256"ALTER ROLE app_user PASSWORD 'Reset2026';ALTER ROLEIf nobody knows the correct password, reset it as a superuser (or a role with CREATEROLE) with ALTER ROLE app_user PASSWORD '...', then put the same value in the app config. The connection with the new password succeeds.
$ PGPASSWORD='Reset2026' psql -h 127.0.0.1 -U app_user -d labSELECT current_user, current_database(); current_user | current_database
--------------+------------------
app_user | lab
(1 row)02The role was created without a password
CREATE ROLE app_user LOGIN; makes a role that can log in, but it has no password. With a password method in pg_hba.conf, any password fails. The server log says User "app_user" has no password assigned.
Setup
CREATE ROLE app_user LOGIN;CREATE ROLE$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d labSELECT current_user, current_database();psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL: password authentication failed for user "app_user"FATAL: 28P01: password authentication failed for user "app_user"
DETAIL: User "app_user" has no password assigned.SELECT rolname, rolcanlogin, rolpassword IS NULL AS no_password FROM pg_authid WHERE rolname = 'app_user'; rolname | rolcanlogin | no_password
----------+-------------+-------------
app_user | t | t
(1 row)ALTER ROLE app_user PASSWORD 'Shop2026';ALTER ROLEpg_authid shows no_password = t. Set one with ALTER ROLE app_user PASSWORD '...' and the same login works. Reading pg_authid needs a superuser.
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d labSELECT current_user, current_database(); current_user | current_database
--------------+------------------
app_user | lab
(1 row)03Role name case does not match (AppUser vs appuser)
CREATE ROLE AppUser without double quotes creates the role appuser (lowercase). The app connects as AppUser, and login names are not folded, so the role is not found. The client still sees password authentication failed; the server log says Role "AppUser" does not exist.
Setup
CREATE ROLE AppUser LOGIN PASSWORD 'Shop2026';CREATE ROLE$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U AppUser -d labSELECT current_user, current_database();psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL: password authentication failed for user "AppUser"FATAL: 28P01: password authentication failed for user "AppUser"
DETAIL: Role "AppUser" does not exist.SELECT rolname FROM pg_roles WHERE lower(rolname) = 'appuser'; rolname
---------
appuser
(1 row)Check the real name in pg_roles (here appuser) and use exactly that name in the connection settings.
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U appuser -d labSELECT current_user, current_database(); current_user | current_database
--------------+------------------
appuser | lab
(1 row)04The password has expired (VALID UNTIL in the past)
The password is correct, but the role has VALID UNTIL '2025-12-31'. After that date, login fails with the same 28P01 message. The server log says User "app_user" has an expired password.
Setup
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026' VALID UNTIL '2025-12-31';CREATE ROLE$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d labSELECT current_user, current_database();psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL: password authentication failed for user "app_user"FATAL: 28P01: password authentication failed for user "app_user"
DETAIL: User "app_user" has an expired password.SELECT rolname, rolvaliduntil FROM pg_roles WHERE rolname = 'app_user'; rolname | rolvaliduntil
----------+------------------------
app_user | 2025-12-31 00:00:00+00
(1 row)ALTER ROLE app_user VALID UNTIL 'infinity';ALTER ROLEpg_roles.rolvaliduntil shows the expiry date. Extend it with ALTER ROLE app_user VALID UNTIL 'infinity' (or a new date). The same password works again.
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d labSELECT current_user, current_database(); current_user | current_database
--------------+------------------
app_user | lab
(1 row)05The password is stored as md5 but pg_hba.conf uses scram-sha-256
Roles carried over from old servers (or created while password_encryption = 'md5') store an md5 hash. A scram-sha-256 line in pg_hba.conf cannot use it, so even the correct password fails. The server log says User "app_user" does not have a valid SCRAM secret.
Setup
SET password_encryption = 'md5';
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026';SET
CREATE ROLE$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d labSELECT current_user, current_database();psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL: password authentication failed for user "app_user"FATAL: 28P01: password authentication failed for user "app_user"
DETAIL: User "app_user" does not have a valid SCRAM secret.SELECT rolname, left(rolpassword, 5) AS hash_type FROM pg_authid WHERE rolname = 'app_user';
SHOW password_encryption; rolname | hash_type
----------+-----------
app_user | md5d4
(1 row)
password_encryption
---------------------
scram-sha-256
(1 row)ALTER ROLE app_user PASSWORD 'Shop2026';
SELECT left(rolpassword, 13) AS hash_type FROM pg_authid WHERE rolname = 'app_user';ALTER ROLE
hash_type
---------------
SCRAM-SHA-256
(1 row)pg_authid.rolpassword starts with md5 while password_encryption is now scram-sha-256. Set the same password again with ALTER ROLE ... PASSWORD; it is stored as SCRAM-SHA-256 and login succeeds.
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d labSELECT current_user, current_database(); current_user | current_database
--------------+------------------
app_user | lab
(1 row)FAQ
How do I find why password authentication failed in PostgreSQL?
Look at the server log at the same time. The client only gets the generic message, but the server writes a DETAIL line: no password assigned, role does not exist, expired password, no valid SCRAM secret, or just the pg_hba.conf line (wrong password).
How do I reset a PostgreSQL user's password?
Connect as a superuser or a role with CREATEROLE and run ALTER ROLE app_user PASSWORD 'new_password';. With the default password_encryption = scram-sha-256 it is stored as a SCRAM hash.
Why does the correct password fail after upgrading PostgreSQL?
The role probably still has an md5 hash while pg_hba.conf now says scram-sha-256. The log shows does not have a valid SCRAM secret. Setting the password again stores a SCRAM hash.
Does 28P01 mean the user does not exist?
It can. For a missing role PostgreSQL also reports password authentication failed, so attackers cannot tell. The server log shows Role "..." does not exist. Check the exact name and case in pg_roles.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12