postgres.railway.internal:5432
2 months ago
Have tried this with 2 new projects now and can't connect to the database over internal network. My application works fine if I use DATABASE_PUBLIC_URL to connect. But is not able to connect over DATABASE_URL.
I get the following error on every deploy:
```bash
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "railway", schema "public" at "postgres.railway.internal:5432"
Error: P1001: Can't reach database server at postgres.railway.internal:5432
Please make sure your database server is running at postgres.railway.internal:5432.
```
I've looked through all the threads on the subject. A lot of the recent ones seem to have been closed prematurely. I've tried setting a timeout parameter recommended in one of the threads, as well as setting the APLINE networking variable. Nothing seems to help.
I have one application deployed on railway already with the same setup NextJS, Prisma, Postgres. Everything connects fine over internal network. I refuse to use DATABASE_PUBLIC_URL and pay fees.
I've spoken with someone else recently who ran into the same issue setting up their application and they just used the PUBLIC URL to get around it. That's not a solution.
Please advise.
Pinned Solution
2 months ago
internal network (*.railway.internal )is only available at runtime, NOT during the build phase.
When Prisma runs "prisma migrate deploy" during your build, it tries to connect to the database — but the internal network isn't accessible yet, causing the error.
Move your migration from the build command to the start command:
# Build command (doesn't need DB connection):
npx prisma generate && npm run build
# Start command (runs at runtime when internal network is available):
npx prisma migrate deploy && npm run start"prisma generate" only generates the Prisma client locally and doesn't require a database connection.
"prisma migrate deploy" needs the database, so it must run at runtime.
3 Replies
2 months ago
internal network (*.railway.internal )is only available at runtime, NOT during the build phase.
When Prisma runs "prisma migrate deploy" during your build, it tries to connect to the database — but the internal network isn't accessible yet, causing the error.
Move your migration from the build command to the start command:
# Build command (doesn't need DB connection):
npx prisma generate && npm run build
# Start command (runs at runtime when internal network is available):
npx prisma migrate deploy && npm run start"prisma generate" only generates the Prisma client locally and doesn't require a database connection.
"prisma migrate deploy" needs the database, so it must run at runtime.
2 months ago
I suggest migrating your DB in a pre-deploy command instead of concatenating it together with your start script as the user above suggested.
https://docs.railway.com/guides/pre-deploy-command
2 months ago
That did the trick. Thanks, folks
Status changed to Solved brody • 2 months ago
