Postgres not connecting
slikc
HOBBYOP

a month ago

My Postgres service was crashing on repeat, so I deleted the service and created a new one.

I updated the variables on my web server to use the new local URL, but I get this issue:

[error] failed to initialize database, got error failed to connect to `user=postgres database=railway`: [fd12:228:e210:0:4000:101:b427:c1a3]:5432 (postgres.railway.internal): failed SASL auth: FATAL: password authentication failed for user "postgres" (SQLSTATE 28P01)
panic: Error connecting to database, failed to connect to `user=postgres database=railway`: [fd12:228:e210:0:4000:101:b427:c1a3]:5432 (postgres.railway.internal): failed SASL auth: FATAL: password authentication failed for user "postgres" (SQLSTATE 28P01)
goroutine 1 [running]:
vise/backend/initializers.ConnectDatabase()
    /app/initializers/ConnectDatabase.go:27 +0x314
main.init.0()
    /app/main.go:19 +0x25
main.init.0()
    /app/main.go:19 +0x25

even though the database seems to be fine, and viewing it through the database tab works fine.

I've redeployed my Postgres and web server several times and nothing seems to fix it.

1 Replies

Try this:

  1. Disable all public networking on the database if you have any, as the following steps will disable user authentication
  2. SSH into your database service (right click your service and select Copy SSH Command)
  3. 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)
  4. Redeploy your database
  5. SSH again, and run the command psql
  6. Run ALTER USER postgres with password ''; where `` is the value of the variable PGPASSWORD in your Railway dashboard
  7. Type exit
  8. 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)
  9. Redeploy your database

Welcome!

Sign in to your Railway account to join the conversation.

Loading...