R
Railway11mo ago
Kezi

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
#12 63.39 Can't reach database server at `postgres.railway.internal`:`5432`
#12 63.39
#12 63.39 Please make sure your database server is running at `postgres.railway.internal`:`5432`.
#12 63.39 at fn.handleRequestError (/app/node_modules/@prisma/client/runtime/library.js:174:6750)
#12 63.39 Can't reach database server at `postgres.railway.internal`:`5432`
#12 63.39
#12 63.39 Please make sure your database server is running at `postgres.railway.internal`:`5432`.
#12 63.39 at fn.handleRequestError (/app/node_modules/@prisma/client/runtime/library.js:174:6750)
This is how I initialize my prisma instance (cf. image)
No description
36 Replies
Percy
Percy11mo ago
Project ID: fc6d4521-a7e5-4e44-a082-858f2cba1470
Percy
Percy11mo ago
Project ID: fc6d4521-a7e5-4e44-a082-858f2cba1470
Kezi
KeziOP11mo ago
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
macwilko
macwilko11mo ago
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
Kezi
KeziOP11mo ago
Interesting... so I could add a sleep 3; to the build command? I can try that
macwilko
macwilko11mo ago
Somewhere before you do the prisma connect, yeah
Kezi
KeziOP11mo ago
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
macwilko
macwilko11mo ago
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.
Kezi
KeziOP11mo ago
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
macwilko
macwilko11mo ago
i see, interesting
Kezi
KeziOP11mo ago
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 :'(
macwilko
macwilko11mo ago
yeah I'm not sure honestly myself when Brody comes online i'm sure he'll have a suggestion
Kezi
KeziOP11mo ago
🙏 Thank you for your help!
Brody
Brody11mo ago
the private network is not available during build
Kezi
KeziOP11mo ago
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?
Brody
Brody11mo ago
you can defer till runtime and then use the private network
Kezi
KeziOP11mo ago
I can't defer it's statically built I need to get the data on the build step :/
Brody
Brody11mo ago
build during runtime?
Kezi
KeziOP11mo ago
that works??
Adam
Adam11mo ago
that may be more expensive than egress charges
Kezi
KeziOP11mo ago
so like a custom start command that does sleep 3 / npm run build / npm run start ?
Adam
Adam11mo ago
worth a shot though
Kezi
KeziOP11mo ago
What do you mean? sorry
Brody
Brody11mo ago
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
Kezi
KeziOP11mo ago
Yeah that's a good idea, I didn't think it was possible idk why lol i'll try that in a sec
Brody
Brody11mo ago
Adam speaks to trading egress costs for cpu/memory costs, since the builder doesn't charge for cpu/memory
Kezi
KeziOP11mo ago
oh right...
Brody
Brody11mo ago
well on that note, I'm not sure you can be charged for egress on the builder either
Adam
Adam11mo ago
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
Kezi
KeziOP11mo ago
I'll try for a day and see but indeed I'll need to rebuild the site at least 2 times a day
Adam
Adam11mo ago
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
Kezi
KeziOP11mo ago
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
Adam
Adam11mo ago
my ram was stuck at 5GB for a few hours before I noticed Up to you
Kezi
KeziOP11mo ago
Yeah i'll still try but I'm still expecting high egress fees anyway so :/ Thanks both of you!
Adam
Adam11mo ago
no prob, good luck
Want results from more Discord servers?
Add your server