22 days ago
We have a Railway Postgres service with live data intact, but the Postgres user password and Railway environment variables are out of sync after a failed manual credential rotation attempt.
Postgres starts successfully and logs show:
database system is ready to accept connections
But app connections fail with:
FATAL: password authentication failed for user "postgres"
The Railway Database tab stays stuck on:
Attempting to connect to the database...
The Console/WebSocket also fails, so we cannot run ALTER USER manually.
We need Railway to safely resynchronise or regenerate the Postgres credentials without deleting the database, deleting the volume, or restoring over current data.
Project: RedPoint Social Hub
Postgres service: Postgres
Please help reset/sync:
DATABASE_URL
DATABASE_PUBLIC_URL
PGPASSWORD
POSTGRES_PASSWORD
with the actual postgres user password.
Pinned Solution
19 days ago
Try this then:
- Disable all public networking on the database if you have any, as the following steps will disable user authentication
- SSH into your database service (right click your service and select
Copy SSH Command) - 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) - Redeploy your database
- SSH again, and run the command
psql - Run
ALTER USER postgres with password '<PASSWORD>';where<PASSWORD>is the value of the variablePGPASSWORDin your Railway dashboard - Type
exit - 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) - Redeploy your database
12 Replies
22 days ago
Your Postgres service's Credentials tab (open the Postgres service, go to the Database view, then Credentials) lets you safely regenerate the password while keeping the environment variables in sync, which is exactly the fix for a manual rotation that went out of sync. After regenerating, redeploy any service that references the password variables.
Status changed to Awaiting User Response Railway • 22 days ago
Railway
Your Postgres service's [Credentials tab](https://docs.railway.com/databases/database-view#credentials-tab) (open the Postgres service, go to the Database view, then Credentials) lets you safely regenerate the password while keeping the environment variables in sync, which is exactly the fix for a manual rotation that went out of sync. After regenerating, redeploy any service that references the password variables.
22 days ago
my Postgres Database connection keeps having wheel of death and not connecting so I can not regerate password
Status changed to Awaiting Railway Response Railway • 22 days ago
22 days ago
This thread has been opened as a public bounty so the community can help solve it. The thread and any further activity are now visible to everyone.
Status changed to Open Railway • 22 days ago
22 days ago
You're not able to access the console tab of your database?
Is it online?
22 days ago
yes shows online but the database connection just spins
22 days ago
Are you able to access the console tab when you click on your service?
22 days ago
Try this:
- Click into your database service and go to the console tab
- 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) - Redeploy your database
- SSH again, and run the command
psql - Run
ALTER USER postgres with password '<PASSWORD>';where<PASSWORD>is the value of the variablePGPASSWORDin your Railway dashboard - Type
exit - 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) - Redeploy your database
22 days ago
If the console tab isn't accessible, you can try setting your start command to sleep infinity, and then follow the steps 0x5b62656e5d provided.
20 days ago
I Still Need Help
20 days ago
Thanks. The Credentials tab is not visible for me.
Current situation:
- Postgres service is online.
- Postgres logs show: database system is ready to accept connections.
- The app logs show: FATAL: password authentication failed for user "postgres".
- The Database tab just spins at “Attempting to connect to the database…”.
- The Console tab fails with WebSocket connection failed.
- I cannot access psql through the Railway UI.
- I do not want to delete the database, delete the volume, or restore over current data.
Please either:
- Regenerate/resynchronise the Postgres credentials from Railway’s side, or
- Provide exact step-by-step instructions for this specific UI/service to access the Credentials tab, or
- Confirm the safe recovery procedure using the pg_hba.conf trust method, including how to proceed when the Console tab is inaccessible.
Project: RedPoint Social Hub
Service: Postgres
Please confirm the safest non-destructive recovery path.
19 days ago
Try setting your start command to sleep infinity then see if you're able to access the console from the dashboard.
19 days ago
I followed the suggested workaround.
I set the Postgres Custom Start Command to:
sleep infinity
Then I redeployed the Postgres service.
However, the Console still fails with:
WebSocket connection failed
Connection lost
Disconnected
I cannot access a shell to run the pg_hba.conf command.
I have reverted the Postgres Custom Start Command back to blank/default and redeployed the database so it is running normally again.
Please provide the next recovery step, or reset/resynchronise the Postgres credentials from Railway’s side.
We need to fix:
FATAL: password authentication failed for user "postgres"
without deleting the database, deleting the volume, or restoring over current data.
19 days ago
Try this then:
- Disable all public networking on the database if you have any, as the following steps will disable user authentication
- SSH into your database service (right click your service and select
Copy SSH Command) - 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) - Redeploy your database
- SSH again, and run the command
psql - Run
ALTER USER postgres with password '<PASSWORD>';where<PASSWORD>is the value of the variablePGPASSWORDin your Railway dashboard - Type
exit - 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) - Redeploy your database
Status changed to Solved 0x5b62656e5d • 17 days ago