PostgreSQL: FATAL: password authentication failed for user

PostgreSQL rejected the password for that role, or pg_hba.conf requires a different auth method.

Seen on: PostgreSQL Docker

Meaning

PostgreSQL checks pg_hba.conf to choose the auth method per connection type/host/user, then validates the password. A mismatch between md5 and scram-sha-256 password storage is a common cause after upgrades.

Common causes

  • Wrong password or role name
  • Role has no password set (peer auth works locally, password doesn’t)
  • pg_hba.conf method/host line doesn’t match the connection
  • Password stored as md5 but pg_hba requires scram-sha-256
  • Docker POSTGRES_PASSWORD changed after volume initialized

⚡ Quick fix

  1. Reset the password: ALTER ROLE app WITH PASSWORD '…';
  2. Check pg_hba.conf lines and reload Postgres
  3. Re-set passwords after switching to scram-sha-256

Detailed fix by platform

PostgreSQL

  1. Reset password as postgres superuser:
    bash
    sudo -u postgres psql -c "ALTER ROLE app WITH LOGIN PASSWORD 'NewStrongPass';"
    sudo -u postgres psql -c "SHOW hba_file;"
    sudo systemctl reload postgresql

How to diagnose

  1. Role — Exists with LOGIN?
  2. pg_hba — Which line matches this connection?
  3. Method — md5 vs scram-sha-256?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.