3 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
3 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.conf - Redeploy your database
- Use the SSH command again, and once you're in, type
psql - Type 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
exit - Reset 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.conf - Redeploy your database and your other services that depend on your database.
3 Replies
3 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 • 3 months ago
3 months ago
Did you by any chance change the password? Are you using docker?
3 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.conf - Redeploy your database
- Use the SSH command again, and once you're in, type
psql - Type 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
exit - Reset 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.conf - Redeploy 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. ⠀ 1. Install Railway CLI (<https://docs.railway.com/guides/cli>) 2. Copy the SSH command by right clicking the PostgreSQL service 3. 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.conf` 4. Redeploy your database 5. Use the SSH command again, and once you're in, type `psql` 6. Type 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';` 7. Type `exit` 8. Reset 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.conf` 9. Redeploy your database and your other services that depend on your database.
3 months ago
it worked! Thank you very much!
Status changed to Solved 0x5b62656e5d • about 1 month ago

