SQLalchemy could not translate host name "postgres.railway.internal"

Basically I'm making a engine with env var stored in DATABASE_PRIVATE_URL that references my Postgres DB internal address like following:
SQLALCHEMY_DATABASE_URL: str | None = os.environ.get("DATABASE_PRIVATE_URL")
if SQLALCHEMY_DATABASE_URL != None:
engine = create_engine(SQLALCHEMY_DATABASE_URL)
(...)
SQLALCHEMY_DATABASE_URL: str | None = os.environ.get("DATABASE_PRIVATE_URL")
if SQLALCHEMY_DATABASE_URL != None:
engine = create_engine(SQLALCHEMY_DATABASE_URL)
(...)
Using the public address seems to work, but using the postgres.railway.internal address yields this error: sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "postgres.railway.internal" to address: Name or service not known I am not sure if changing the address to postgres would resolve it?
10 Replies
Percy
Percyβ€’8mo ago
Project ID: ff816097-dff3-4925-9c7d-c91d0c42ee5b
𝘬𝘒𝘱𝘱𝘺
ff816097-dff3-4925-9c7d-c91d0c42ee5b
Solution
𝘬𝘒𝘱𝘱𝘺
yup, that resolved it, thanks!
Brody
Brodyβ€’8mo ago
no prob
Duchess
Duchessβ€’6mo ago
New reply sent from Help Station thread:
i have the same problem, what docs section was mentioned? I cant see it here in the comment.
You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
Blame this forums formatting, I've edited the message now.
You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
Thanks! Do you know what start command should i add to start 3 seconds later my fastapi app?
You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
The docs include various examples.
You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
Im having a similar issue. Im using Railway's default Postgres service for my database and I'm trying to make a backups microservice that connects to the database via the private network. I get this error: could not translate host name "postgres.railway.internal" to address: Name or service not known . My service is sleeping for 4 seconds before running, and it's running in a debian image. I think I may need to open the Postgres service up to IPv6 connections, but I'm not sure how to do that from within railway
You're seeing this because this thread has been automatically linked to the Help Station thread.
Brody
Brodyβ€’6mo ago
Postgres does listen on IPv6 by default. you have covered most of the basics already, is your postgres service in the same project and environment as the backup service? a private network is scoped to an environment within a project
Duchess
Duchessβ€’5mo ago
New reply sent from Help Station thread:
Hi - having a similar issue. Just added PGbouncer in front of my postgres db and now seeing Exception inside application: could not translate host name "pgbouncer.railway.internal" to address: Name or service not known every once in a while in my logs, though I'm not having to do anything to fix it (obviously I don't want the errors though). I can't see the docs mentioned in the comments :(
You're seeing this because this thread has been automatically linked to the Help Station thread.
Brody
Brodyβ€’5mo ago
Do you have the runtime V2 enabled in your service settings?
Duchess
Duchessβ€’4mo ago
New reply sent from Help Station thread:
Hello- I am currently have the same error as karlojacmenjak however I can not see the file the mentioned in the comments. Based off the other comments I have added a sleep statement but I am still encountering this error: could not translate host name "postgres.railway.internal" to address: Name or service not known. Would you be able direct me to where the docs might be?
You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
The Docs that I have linked to are no longer relevant.But there are still a bunch of common mistakes people make when using databases on Railway, so please open your own thread so we can narrow down what issue you are facing.
You're seeing this because this thread has been automatically linked to the Help Station thread.
Want results from more Discord servers?
Add your server