PostgreSQL InvalidPasswordError despite correct password - cannot connect from backend service
cyj801109-commits
HOBBYOP

a month ago

My backend service (backend_automanual) cannot connect to PostgreSQL (Postgres_automanual) in the same Railway project. Getting InvalidPasswordError on every connection attempt despite the password being verified correct.

What I've tried:

- Private network URL (postgres.railway.internal) → InvalidPasswordError

- Public network URL (hopper.proxy.rlwy.net:10453) → InvalidPasswordError

- With ssl=require, ssl=disable, sslmode=require, no SSL param → all fail

- Regenerated password multiple times → same error

- Deleted and recreated PostgreSQL service multiple times → same error

- Variable Reference (${{ Postgres_automanual.DATABASE_URL }}) → DATABASE_URL not being injected into backend

Error: asyncpg.exceptions.InvalidPasswordError: password authentication failed for user "postgres"

The password shown in Database > Config tab matches the password in DATABASE_URL exactly, but connection still fails.

GitHub repo: cyj801109-commits/automanual

PostgreSQL image: ghcr.io/railwayapp-templates/postgres-ssl:18

$10 Bounty

2 Replies

Railway
BOT

a month ago

Your backend service is currently in a CRASHED state while your Postgres service is running. Since you mentioned deleting and recreating the PostgreSQL service multiple times, the most likely cause of the InvalidPasswordError is that your volume retained the old PostgreSQL data directory with the original password baked in, so newly generated credentials in the environment variables no longer match what PostgreSQL actually expects. To resolve this, you would need to delete both the Postgres service and its attached volume, then redeploy fresh so the new password initializes in the data directory. For the variable reference not being injected, ensure you are adding DATABASE_URL=${{Postgres_automanual.DATABASE_URL}} in your backend service's Variables tab in the dashboard, not in your application code or a .env file. The easiest path overall would be to remove everything (service + volume), then add PostgreSQL using the + New button on the project canvas, which auto-generates all connection variables like DATABASE_URL and handles the wiring for you.


Status changed to Awaiting User Response Railway about 1 month ago


Status changed to Awaiting Railway Response Railway about 1 month ago


Status changed to Open Railway about 1 month ago


ilyass012
FREE

a month ago

hey,

ur volume has the old password baked in so regenerating credentials never fixes it , but you dont need to delete everything and lose your data. theres a way to resync the password in place using ssh

first disable public domains on your postgres service just to be safe then install the railway cli, right click your postgres service and copy the ssh command. once youre in run this exactly:

sed -i 's/host all all all scram-sha-256/host all all ::/0 trust/' /var/lib/postgresql/data/pgdata/pg_hba.conf

then redeploy your postgres service. ssh back in, type psql, then run:

ALTER USER postgres WITH PASSWORD 'your_actual_password';

where the password is whatever shows in your PGPASSWORD variable in the variables tab. type exit, then run:

sed -i 's/host all all ::/0 trust/host all all all scram-sha-256/' /var/lib/postgresql/data/pgdata/pg_hba.conf

and redeploy one more time

for the database_url not injecting, go to your backend service variables tab in the dashboard and add DATABASE_URL=${{Postgres_automanual.DATABASE_URL}} manually there, not in your code or .env file


Welcome!

Sign in to your Railway account to join the conversation.

Loading...