Prisma deployment fails using internal Postgres URI
ddkfej29
HOBBYOP

3 months ago

When a docker container I run is started (evolution-api), it attempts to run prisma migration but fails to communicate with my Postgres server on the internal network. It does succeed through the external network (but incurs charges so I don't want to use that). I specify the connection path through an environment variable, and it is successfully loaded by the container, but fails upon connection. I do manage to communicate with Postgres internally through other containers.

The container in question used to communicate with Postgres internally and successfully, but when I redeployed the container it has since failed.

I tried to append to my connection some URL parameters (separately and jointly) such as:

connect_timeout=500

pgbouncer=true

connection_limit=1

pool_timeout=10

but to no avail.

The logs I get specifically:

Starting Container

Deploying migrations for postgresql

Database URL: postgresql://postgres:<pwd>@postgres.railway.internal:5432/railway

> evolution-api@2.3.6 db:deploy

> node runWithProvider.js "rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate deploy --schema ./prisma/DATABASE_PROVIDER-schema.prisma"

Environment variables loaded from .env

Prisma schema loaded from prisma/postgresql-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.

Error executing command: rm -rf ./prisma/migrations && cp -r ./prisma/postgresql-migrations ./prisma/migrations && npx prisma migrate deploy --schema ./prisma/postgresql-schema.prisma

npm notice

npm notice New patch version of npm available! 11.6.1 -> 11.6.4

npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.6.4

npm notice To update run: npm install -g npm@11.6.4

npm notice

Migration failed

I've seen this error in previous threads but nothing helped.

I read somewhere that the internal network is unavailable during the build process, but this happens when I run the container, not build it. I also tried to run the new builder, no difference.

I don't know what I'm doing wrong or is it a server fault. Any advice?

Thanks.

Solved$10 Bounty

8 Replies

Railway
BOT

3 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


bytekeim
PRO

3 months ago

hyy;

that P1001 thing is basically your container not being able to find the database hostname which happens a lot with Alpine images if ur using those.

first thing I'd try is checking what base image you're running in your Dockerfile. If it says something like FROM node:alpine then you prob need to flip on Alpine private networking. Just go into your evolution-api service settings and throw in a new environment variable called ENABLE_ALPINE_PRIVATE_NETWORKING and set it to true. Redeploy after that and see if it helps since Alpine handles DNS kinda weirdly in Railway's network.

If that doesn't do it maybe try adding a little pause before your migrations run. like in whatever startup script you got (runWithProvider.js or wherever) just stick a sleep 5 && before the npx prisma migrate deploy command. Sometimes the network just needs a sec to actually be ready before Prisma tries connecting.

also worth checking when your Railway project was created. If it's from before like mid October 2025 it might be on their old IPv6 only setup which Prisma really doesn't like. If that's the case you'd need to spin up a fresh environment in Railway and move everything over to get IPv4 support.

I'd start with that environment variable since that's usually the culprit. But if ur not on Alpine (like if you're using node:bookworm or something) then skip that and try the sleep thing instead. Lmk how it goes or if you're still stuck

bytekeim


hornta
PRO

3 months ago

I have this same problem. I've created my service this november. I didn't know about ENABLE_ALPINE_PRIVATE_NETWORKING but it did not help me. I did however manage to get it to work by providing an absurd high connect_timeout. I remember this being a problem since a long time ago. Unsure if this is a prisma-specific problem or just a pg problem.


hornta

I have this same problem. I've created my service this november. I didn't know about ENABLE_ALPINE_PRIVATE_NETWORKING but it did not help me. I did however manage to get it to work by providing an absurd high connect_timeout. I remember this being a problem since a long time ago. Unsure if this is a prisma-specific problem or just a pg problem.

bytekeim
PRO

3 months ago

yes combine with other Params, Add &pool_timeout=30&socket_timeout=30 for better handling of pooling delays in prisma, this addresses intermittent networking or wake-up latencies in hosted Postgres setups , if that doesn't fix it, consider adding a startup delay in your script (e.g., sleep 5) before migrations


hornta
PRO

3 months ago

Hmm, just tried to use the normal base image for node(bookworm) and then it worked like a charm. No more ugly connect_timeout, custom scripts or ENABLE_ALPINE_PRIVATE_NETWORKING!

FROM node:24 AS base

bytekeim
PRO

3 months ago

that's awesome, bookworm's got proper glibc and better networking support out of the box so it just works. trade-off is a slightly bigger image but honestly worth it for not having to deal with those weird timeouts and hacks.

glad you got it sorted!

bytekeim


bytekeim

hyy;that P1001 thing is basically your container not being able to find the database hostname which happens a lot with Alpine images if ur using those.first thing I'd try is checking what base image you're running in your Dockerfile. If it says something like FROM node:alpine then you prob need to flip on Alpine private networking. Just go into your evolution-api service settings and throw in a new environment variable called ENABLE_ALPINE_PRIVATE_NETWORKING and set it to true. Redeploy after that and see if it helps since Alpine handles DNS kinda weirdly in Railway's network.If that doesn't do it maybe try adding a little pause before your migrations run. like in whatever startup script you got (runWithProvider.js or wherever) just stick a sleep 5 && before the npx prisma migrate deploy command. Sometimes the network just needs a sec to actually be ready before Prisma tries connecting.also worth checking when your Railway project was created. If it's from before like mid October 2025 it might be on their old IPv6 only setup which Prisma really doesn't like. If that's the case you'd need to spin up a fresh environment in Railway and move everything over to get IPv4 support.I'd start with that environment variable since that's usually the culprit. But if ur not on Alpine (like if you're using node:bookworm or something) then skip that and try the sleep thing instead. Lmk how it goes or if you're still stuckbytekeim

ddkfej29
HOBBYOP

3 months ago

Thank you for your response. I too created my environment this November. Adding sleep didn't help, nor adding the ALPINE variable. But I spun up a fresh environment and it seemed to do the trick. So thanks!


ddkfej29

Thank you for your response. I too created my environment this November. Adding sleep didn't help, nor adding the ALPINE variable. But I spun up a fresh environment and it seemed to do the trick. So thanks!

hornta
PRO

3 months ago

I've also spun up new environments and they worked for 2-3 days and only after that time, the problem began to occur again so keep that in mind if it starts happening again.


Status changed to Open brody 3 months ago


Status changed to Solved brody 3 months ago


Loading...