8 months ago
Hi team,
I'm migrating an app from Heroku to Railway, which works fine if I use a postgres database hosted by Railway, and the DATABASE_PUBLIC_URL variable. However, I believe it introduces some latency, since it's routed through a proxy (?).
When I try to use the DATABASE_URL in the following format, I'm running into issues during the build phase of my app.
DATABASE_URL = postgresql://postgres:pw@postgres.railway.internal:5432/railway
Error:
django.db.utils.OperationalError: could not translate host name "postgres.railway.internal" to address: Name or service not known
In my Procfile, I've defined a release command that runs migrations in my app. Is the database not ready at that point? Is there a way to overwrite/ignore the Procfile, without removing it?
5 Replies
8 months ago
Is your postgres server hosted in the same project as the one you're attempting to connect with?
samgordon
Is your postgres server hosted in the same project as the one you're attempting to connect with?
8 months ago
Yes, it is.
8 months ago
Hi there, question: did you change any database variables - and if so, could you share the order of operations you took?
Status changed to Awaiting User Response Railway • 8 months ago
sarahkb125
Hi there, question: did you change any database variables - and if so, could you share the order of operations you took?
7 months ago
Hi Sarah, sorry I forgot to answer here. I think I didn't change the variable itself. I believe the problem might be related to the release process. Does my instance have access to DATABASE_URL already at that stage?
Status changed to Awaiting Railway Response Railway • 7 months ago
7 months ago
hi, that error happens because railway’s internal host (postgres.railway.internal) isn’t reachable during your build/release phase dns isn’t set up yet. that host only works at runtime inside the deployed service. to fix it use the public connection during build/migrate steps (like in a release or prestart command), e.g.: DATABASE_URL=$DATABASE_PUBLIC_URL python manage.py migrate
then switch to the internal host only after runtime, or just stick with DATABASE_PUBLIC_URL all the way through.