Cannot connect to DB

2 years ago

Building a Next.js app with IS_BUILD=true pnpm db:migrate && pnpm build gives me this error in the deployment: #13 3.900 [22:36:03] ERROR: Error: cannot connect to Postgres. Details: getaddrinfo ENOTFOUND postgres.railway.internal

Is this some Railway quirk? Looked around and couldn't find a fix for it. I'm connecting from the same region on staging.

Solved

20 Replies

2 years ago

project ID: e8eef74a-59dc-42cf-9b57-69bcb2f3f816


2 years ago

hello, the private network is not available during build, you would want to run your migrations during runtime before starting the app


2 years ago

hmm wouldn't that result in downtime for the app? if you run the migrations and then have to wait for the deployment to finish before your frontend references the new db schema?


2 years ago

it won't as long as you use a healthcheck


2 years ago

damn, seems like a lot of hassle to implement a healthcheck


2 years ago

means on each migration, you'd have to modify the healthcheck endpoint to verify the new schema?


2 years ago

no, just return 200 after pinging your database


2 years ago

alright I added an endpoint that returns 200 after connecting to the db, set the healthcheck path on Railway to /api/health, but it still fails with the same unable to connect to internal db error 😦


2 years ago

@Brody


2 years ago

have you stopped running migrations during build?


2 years ago

ah I think that fixes it, so is the workflow on Railway to run the migrations in Github Acitons on CI, and then check the "wait for CI" option on Railway service?


2 years ago

seems kind of dangerous if the build fails but migration succeeds


2 years ago

or if you run it locally, there would be downtime


2 years ago

trying to see if it's possible to have the deploy fail if the migration fails


2 years ago

right so as previously suggested, you run your migrations during runtime before starting your app, then use a healthcheck, this way if the migration fails the app never gets deployed


2 years ago

ok ok gotcha, I'll do the migrations in the start script then


2 years ago

thanks!


2 years ago

let me know if you have any troubles


2 years ago

have things worked out for you?


2 years ago

!s


Status changed to Solved brody over 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...