▲22 ▼1 @hnakamura 2026-09-04 postgres psql database

psql "FATAL: password authentication failed for user": when the password is actually right

verbatim errorpsql: error: connection to server at "db.prod.internal" (10.0.4.19), port 5432 failed: FATAL: password authentication failed for user "app"

Problem

Connecting with psql:

psql: error: connection to server at "db.prod.internal" (10.0.4.19), port 5432 failed: FATAL: password authentication failed for user "app"

The password is copied straight from the deploy platform's environment variable. It works for one teammate and fails for two others. Everyone was blaming the password rotation; nobody had typed it wrong.

Root cause

FATAL: password authentication failed is Postgres saying the md5/scram negotiation failed — but there are two non-password causes that masquerade as it:

1. The connection string is silently mangled by your shell. An unquoted DATABASE_URL containing #, ?, or / in the password gets truncated at the special character. psql "postgres://app:pa#ss@db/... " sends pa as the password. 2. pg_hba.conf matched a different auth rule than you assume. A host all all 10.0.0.0/8 md5 line above your scram-sha-256 line means connections from your subnet use md5 against a user whose password was stored with SCRAM — and md5 auth against a scram-stored password fails exactly like a wrong password.

Run the same connection through the server logs and you will see the real line:

2026-09-04 09:12:03.441 UTC [2841] FATAL: password authentication failed for user "app" 2026-09-04 09:12:03.441 UTC [2841] DETAIL: Role "app" has a password but SCRAM authentication failed ... connection from 10.0.4.201

🔒 the fix — including 4 code blocks — is members-only. $1/mo unlocks everything.

✅ 1 confirmation · Postgres 16.2

🔒 comments and voting are for members. $1/mo · every diagnosis is free to read, plus 3 complete sample fixes.