Private Network + Prisma + Next.js: "Can't reach database server"
Hello, i'm having this issue with prisma but I searched the forum and the solutions didn't apply for me
This is how I initialize my prisma instance (cf. image)
36 Replies
Project ID:
fc6d4521-a7e5-4e44-a082-858f2cba1470
Project ID:
fc6d4521-a7e5-4e44-a082-858f2cba1470
fc6d4521-a7e5-4e44-a082-858f2cba1470
I tried to set the variable with the ${{}} syntax and also copy/pasted the url
Public URL works fine
I can connect to the db with external tool
(it fails at build step btw)
so I can't try the sleep 3 option
not an expert, but I've run into PN issues. The solution is to wait for the connection to be available (it takes a moment for the connection to be ready).
I expect you'll need to add some pause to the attempt to connect, or simply retry the connection until its ready
Interesting...
so I could add a sleep 3; to the build command? I can try that
Somewhere before you do the prisma connect, yeah
Okay, will try! thank you 🙏
so I did try with a sleep 3 in the custom build command but it still errors, I don't know how I can delay the prisma initialization globally since it's a Next.js app and the requests are everywhere
not entirely sure but why is the prisma connect happening during the build step?
can't you defer those til runtime?
the only time I connect to the database is either during a migration, outside of runtime. And you don't want to run migrations on every build.
The website is 80% built statically
and then it refreshes every so often in runtime
so I "hydrate" the website's data in the build step to have mostly static files to serve
Data Fetching: Incremental Static Regeneration (ISR) | Next.js
Learn how to create or update static pages at runtime with Incremental Static Regeneration.
i see, interesting
I'm using either ISR or pure static
so yeah I don't know how to deal with that delay if it's all over the place
:'(
yeah I'm not sure honestly myself
when Brody comes online i'm sure he'll have a suggestion
🙏
Thank you for your help!
the private network is not available during build
Well, that's a big issue because I'm paying more than $150 of egress fees because of it
would be nice if it was available
otherwise i'm just gonna need to migrate away from Railway... that's unfortunate
I'm basically forced to use public network now that the egress pricing is a thing?
you can defer till runtime and then use the private network
I can't defer
it's statically built
I need to get the data on the build step :/
build during runtime?
that works??
that may be more expensive than egress charges
so like a custom start command that does sleep 3 / npm run build / npm run start ?
worth a shot though
What do you mean? sorry
why wouldn't it, as long as you are using a healthcheck railway won't switch in the new deployment until it's built and accepting connections
Yeah that's a good idea, I didn't think it was possible idk why lol
i'll try that in a sec
Adam speaks to trading egress costs for cpu/memory costs, since the builder doesn't charge for cpu/memory
oh right...
well on that note, I'm not sure you can be charged for egress on the builder either
Railway stops the runtime for the service between build and run. When I was new to the platform I ran my build command as my start command and racked up a huge bill
I'll try for a day and see but indeed I'll need to rebuild the site at least 2 times a day
since the resources aren’t shoveled away between the steps
it’s worth a shot though
the initial build isn’t what I would be worried about, it’s having the used resources not get properly cleared out
I'm more tempted to migrate away from Railway and use Netlify and move to an entire static website
That's probably a looooot cheaper
my ram was stuck at 5GB for a few hours before I noticed
Up to you
Yeah i'll still try but I'm still expecting high egress fees anyway so :/
Thanks both of you!
no prob, good luck