2 months ago
Guys,
I'm receiving: Failed to connect to database: password authentication failed for user "postgres"
The database was working ok and started doing this errors.
I cannot login using internal and external database credentials.
Please help.
Pinned Solution
2 months ago
Try this:
Note: If you have any public access domains for your Postgres service, remove them for now just in case as this process involves disabling password authentication.
⠀
Install Railway CLI (https://docs.railway.com/guides/cli)
Copy the SSH command by right clicking the PostgreSQL service
Once you're in, type in the following command: (Copy paste this EXACTLY as written)
sed -i 's/host all all all scram-sha-256/host all all ::\/0 trust/' /var/lib/postgresql/data/pgdata/pg_hba.confRedeploy your database
Use the SSH command again, and once you're in, type
psqlType the following SQL command.
my_passwordshould be replaced with whatever it actually says in your variables tab for your password (Probably under thePGPASSWORDvariable)ALTER USER postgres with password 'my_password';Type
exitReset your authentication settings with the following command:
sed -i 's/host all all ::\/0 trust/host all all all scram-sha-256/' /var/lib/postgresql/data/pgdata/pg_hba.confRedeploy your database and your other services that depend on your database.
3 Replies
2 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open Railway • 2 months ago
2 months ago
Did you by any chance change the password? Are you using docker?
2 months ago
Try this:
Note: If you have any public access domains for your Postgres service, remove them for now just in case as this process involves disabling password authentication.
⠀
Install Railway CLI (https://docs.railway.com/guides/cli)
Copy the SSH command by right clicking the PostgreSQL service
Once you're in, type in the following command: (Copy paste this EXACTLY as written)
sed -i 's/host all all all scram-sha-256/host all all ::\/0 trust/' /var/lib/postgresql/data/pgdata/pg_hba.confRedeploy your database
Use the SSH command again, and once you're in, type
psqlType the following SQL command.
my_passwordshould be replaced with whatever it actually says in your variables tab for your password (Probably under thePGPASSWORDvariable)ALTER USER postgres with password 'my_password';Type
exitReset your authentication settings with the following command:
sed -i 's/host all all ::\/0 trust/host all all all scram-sha-256/' /var/lib/postgresql/data/pgdata/pg_hba.confRedeploy your database and your other services that depend on your database.
0x5b62656e5d
Try this:Note: If you have any public access domains for your Postgres service, remove them for now just in case as this process involves disabling password authentication.⠀Install Railway CLI (https://docs.railway.com/guides/cli)Copy the SSH command by right clicking the PostgreSQL serviceOnce you're in, type in the following command: (Copy paste this EXACTLY as written)sed -i 's/host all all all scram-sha-256/host all all ::\/0 trust/' /var/lib/postgresql/data/pgdata/pg_hba.confRedeploy your databaseUse the SSH command again, and once you're in, type psqlType the following SQL command. my_password should be replaced with whatever it actually says in your variables tab for your password (Probably under the PGPASSWORD variable)ALTER USER postgres with password 'my_password';Type exitReset your authentication settings with the following command:sed -i 's/host all all ::\/0 trust/host all all all scram-sha-256/' /var/lib/postgresql/data/pgdata/pg_hba.confRedeploy your database and your other services that depend on your database.
2 months ago
it worked! Thank you very much!
Status changed to Solved 0x5b62656e5d • about 1 month ago

