Postgres password mismatch after data-loss incident — new connections fail, old connection works
aitradestocks
HOBBYOP

a month ago

Project ID: c4778036-48e2-4b03-be21-419ec6a0403d

Service ID: 280c6978-5a84-4c7b-8bd0-f9a89c881770

Issue: New connections to my Postgres service fail with "password authentication failed for user postgres" when using the exact POSTGRES_PASSWORD value shown in the Variables tab. My app's existing long-lived connection (established before this issue started) continues to work fine without re-authenticating.

Timeline: This started around 12:12 UTC on 2026-07-22. It was preceded by an earlier incident where my "railway" database was found completely empty (only default postgres/template0/template1 databases remained), which I had to recreate manually.

What I believe happened: The POSTGRES_PASSWORD variable was regenerated/reset at some point, but the password hash stored on the persistent volume's data directory was not updated to match, so Postgres is still authenticating against the old hash.

Request: Please update the password hash on the volume's Postgres data directory to match the current POSTGRES_PASSWORD variable value, or let me know the correct current password if it differs from what's shown in the dashboard.

I have NOT restarted the Postgres service or my app since discovering this, to avoid losing the one working connection. Please advise before I take any action.

$10 Bounty

1 Replies

Railway
BOT

a month ago

This thread has been opened as a bounty so the community can help solve it.

Status changed to Open Railway about 1 month ago


Try this:

  1. Click into your database service and go to the console tab
  2. Run this command: sed -i 's/host all all all scram-sha-256/host all all ::\/0 trust/' /var/lib/postgresql/data/pgdata/pg_hba.conf (This will bypass user authentication)
  3. Redeploy your database
  4. Console again, and run the command psql
  5. Run ALTER USER postgres with password '<PASSWORD>'; where <PASSWORD> is the value of the variable PGPASSWORD in your Railway dashboard
  6. Type exit
  7. Run sed -i 's/host all all ::\/0 trust/host all all all scram-sha-256/' /var/lib/postgresql/data/pgdata/pg_hba.conf (This will re-enable user authentication)
  8. Redeploy your database

Welcome!

Sign in to your Railway account to join the conversation.

Loading...