PostgreSQL 17.12Lab-verified · 2026-11-30

PostgreSQL 28P01: password authentication failed for user

The server rejected the login. The real reason is only in the server log DETAIL line, not in the client message.

PostgreSQL 17.12
28P01: password authentication failed for user "app_user"

Jump to a cause

  1. 01The password is simply wrong (case typo in the app config)
  2. 02The role was created without a password
  3. 03Role name case does not match (AppUser vs appuser)
  4. 04The password has expired (VALID UNTIL in the past)
  5. 05The password is stored as md5 but pg_hba.conf uses scram-sha-256

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
Setuprun as postgres
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026';
OUTPUT
CREATE ROLE
Reproducerun as app_user
$ PGPASSWORD='shop2026' psql -h 127.0.0.1 -U app_user -d lab
SELECT current_user, current_database();
✕ ERROR
psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL:  password authentication failed for user "app_user"
SERVER LOG (same moment)
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"
Fixrun as postgres
ALTER ROLE app_user PASSWORD 'Reset2026';
OUTPUT
ALTER ROLE

If 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.

After the fixrun as app_user
$ PGPASSWORD='Reset2026' psql -h 127.0.0.1 -U app_user -d lab
SELECT current_user, current_database();
✓ SUCCESS
 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
Setuprun as postgres
CREATE ROLE app_user LOGIN;
OUTPUT
CREATE ROLE
Reproducerun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d lab
SELECT current_user, current_database();
✕ ERROR
psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL:  password authentication failed for user "app_user"
SERVER LOG (same moment)
FATAL:  28P01: password authentication failed for user "app_user"
DETAIL:  User "app_user" has no password assigned.
Checkrun as postgres
SELECT rolname, rolcanlogin, rolpassword IS NULL AS no_password FROM pg_authid WHERE rolname = 'app_user';
OUTPUT
 rolname  | rolcanlogin | no_password
----------+-------------+-------------
 app_user | t           | t
(1 row)
Fixrun as postgres
ALTER ROLE app_user PASSWORD 'Shop2026';
OUTPUT
ALTER ROLE

pg_authid shows no_password = t. Set one with ALTER ROLE app_user PASSWORD '...' and the same login works. Reading pg_authid needs a superuser.

After the fixrun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d lab
SELECT current_user, current_database();
✓ SUCCESS
 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
Setuprun as postgres
CREATE ROLE AppUser LOGIN PASSWORD 'Shop2026';
OUTPUT
CREATE ROLE
Reproducerun as AppUser
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U AppUser -d lab
SELECT current_user, current_database();
✕ ERROR
psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL:  password authentication failed for user "AppUser"
SERVER LOG (same moment)
FATAL:  28P01: password authentication failed for user "AppUser"
DETAIL:  Role "AppUser" does not exist.
Checkrun as postgres
SELECT rolname FROM pg_roles WHERE lower(rolname) = 'appuser';
OUTPUT
 rolname
---------
 appuser
(1 row)

Check the real name in pg_roles (here appuser) and use exactly that name in the connection settings.

After the fixrun as appuser
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U appuser -d lab
SELECT current_user, current_database();
✓ SUCCESS
 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
Setuprun as postgres
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026' VALID UNTIL '2025-12-31';
OUTPUT
CREATE ROLE
Reproducerun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d lab
SELECT current_user, current_database();
✕ ERROR
psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL:  password authentication failed for user "app_user"
SERVER LOG (same moment)
FATAL:  28P01: password authentication failed for user "app_user"
DETAIL:  User "app_user" has an expired password.
Checkrun as postgres
SELECT rolname, rolvaliduntil FROM pg_roles WHERE rolname = 'app_user';
OUTPUT
 rolname  |     rolvaliduntil
----------+------------------------
 app_user | 2025-12-31 00:00:00+00
(1 row)
Fixrun as postgres
ALTER ROLE app_user VALID UNTIL 'infinity';
OUTPUT
ALTER ROLE

pg_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.

After the fixrun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d lab
SELECT current_user, current_database();
✓ SUCCESS
 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
Setuprun as postgres
SET password_encryption = 'md5';
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026';
OUTPUT
SET
CREATE ROLE
Reproducerun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d lab
SELECT current_user, current_database();
✕ ERROR
psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL:  password authentication failed for user "app_user"
SERVER LOG (same moment)
FATAL:  28P01: password authentication failed for user "app_user"
DETAIL:  User "app_user" does not have a valid SCRAM secret.
Checkrun as postgres
SELECT rolname, left(rolpassword, 5) AS hash_type FROM pg_authid WHERE rolname = 'app_user';
SHOW password_encryption;
OUTPUT
 rolname  | hash_type
----------+-----------
 app_user | md5d4
(1 row)

 password_encryption
---------------------
 scram-sha-256
(1 row)
Fixrun as postgres
ALTER ROLE app_user PASSWORD 'Shop2026';
SELECT left(rolpassword, 13) AS hash_type FROM pg_authid WHERE rolname = 'app_user';
OUTPUT
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.

After the fixrun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d lab
SELECT current_user, current_database();
✓ SUCCESS
 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