Can not reach the private network database

I am facing and error that i can not reach the database from project and database are on same service and i am using perivate network url for database connection and out of sudden it is showing me databsae can not be reached can u please help me i have checked the stats and they are completely fine . 9/100 connections

image.png

$20 Bounty

20 Replies

Railway
BOT

22 days ago

Having looked into this, the issue appears to be in your application code or configuration rather than the Railway platform itself, which puts it outside what Railway support can resolve directly.

This is exactly the kind of problem the Railway community is good at, so we'd like to open your thread as a community bounty. Railway pays a bounty to the community member who solves it, and threads like this usually get picked up quickly.

Opening it makes this entire thread public, including everything already posted. Nothing becomes public until you decide. Use the buttons below.

  • Open to the community - Before you click, take a moment to edit or remove anything you'd rather not share. The thread becomes publicly visible right away.
  • Keep it private and close the thread - Nothing becomes public. The thread closes, since this isn't something Railway support can take further.

Status changed to Awaiting User Response Railway 22 days ago


Railway
BOT

22 days ago

This thread has been opened as a public bounty so the community can help solve it. The thread and any further activity are now visible to everyone.

Status changed to Open Railway 22 days ago


Is your Postgres in the same environment and is online/healthy?


Yes i can access my database in railway dashbaord and i have updated the url from manual to dynamic . beacuse if i ever encountered this error i could not access database on dashboard as welll so it show delay of 10-30 seconds but today i can access it


Can you elaborate on "manual to dynamic"?

So is the issue still there now?


means where i was copying the url to env and now i am using ${{postgre.database_url}}


lastest few seconds ago

image.png

Attachments


Are there any errors in your Postgres logs?


22 days ago

Can you confirm that "Postgres" is your actual postgres service name? Also where do you see this error? Is it on build logs or deploy logs?

If it's on build logs, then yes, you can't access it because private network only available at runtime


i have changed the url to public url and now i can acess it but service are in same project

image.png

Attachments


logs are from deploy logs and i have other projects and i can access the private url in those projects only this one is showing error


Try using Postgres.railway.internal instead of postgres.railway.internal and see what happens.


22 days ago

They clearly said the error is on Deploy Logs not Build Logs


OP sent a screenshot that showed the services in the same environment.


0x5b62656e5d

Try using `Postgres.railway.internal` instead of `postgres.railway.internal` and see what happens.

I am using dynamic url so if in databse config it is P can i use p ?


abdulrehmanjr

I am using dynamic url so if in databse config it is P can i use p ?

22 days ago

changing it to use Postgres instead of postgres in the environment variable should hopefully make it reference the correct service, so yes use a capital P and try again


Okay i will try and let u know but i can access the url as if service name is wrong it should show null in varaible right ?


abdulrehmanjr

Okay i will try and let u know but i can access the url as if service name is wrong it should show null in varaible right ?

manuproject
HOBBY

22 days ago

public url working means db is fine, so its the private network dns. try redeploying postgres first then your app, that re-registers both on the private network. also make sure the env var is exactly ${{Postgres.DATABASE_URL}}, its case sensitive. switch back to private url after or you'll pay egress on the public one


now my build phase is stuck . i changed the database url again to private nertwork and its not initlizing the project i aborted the redeployment twice

image.png

Attachments


abdulrehmanjr

now my build phase is stuck . i changed the database url again to private nertwork and its not initlizing the project i aborted the redeployment twice ![image.png](https://station-server.railway.com/attachments/att_01kysww8g3e01st81qdj4mzjgn)

manuproject
HOBBY

22 days ago

ok so this actually explains everything. on railway the private network only works at runtime, its not available while your project is building. your build is running prisma migrate (or something that connects to the db), so with the public url the build could reach the db and passed, but with the private url it just sits there waiting forever - thats your "stuck" build. nothing is broken, its just trying to connect to a network that doesnt exist yet during build.

i think the solution is to move the migrate step out of the build. go to service settings - deploy - pre-deploy command and put npx prisma migrate deploy there. pre-deploy runs after the build finishes, when the private network is up, so it'll work with the private url fine. then your build phase should only compile the app, nothing db related.

and small thing, "taking a snapshot of the code" for a minute or two is normal, no need to abort, aborting just puts you back in the queue


Thank you everyone for your time and help. The error has been resolved, but I am still unable to find the root cause. First, the URL was set to private, then I changed it to public, and now it is back to private again (changing ${Postgre.Databe_Public_url} to ${Postgresql.Database_url}) and rebuilt. I tried this exact sequence earlier, but it did not work.


Welcome!

Sign in to your Railway account to join the conversation.

Loading...