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

karlojacmenjakHOBBY

a year ago

Basically I'm making a engine with env var stored in DATABASEPRIVATEURL 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)
    (...)

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?

Solved

8 Replies

karlojacmenjakHOBBY

a year ago

ff816097-dff3-4925-9c7d-c91d0c42ee5b


a year ago

please read this docs section -


karlojacmenjakHOBBY

a year ago

yup, that resolved it, thanks!


a year ago

no prob


gaborlakatosTRIAL

a year ago

i have the same problem, what docs section was mentioned? I cant see it here in the comment.


a year ago

Blame this forums formatting, I've edited the message now.


gaborlakatosTRIAL

a year ago

Thanks! Do you know what start command should i add to start 3 seconds later my fastapi app?


a year ago

The docs include various examples.


voidkandyHOBBY

a year ago

Im having a similar issue. Im using Railway's Postgres template 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. According to what I saw in the postgres template repo, it should be open to IPv6 connections, so I'm not sure what I'm doing wrong


a year 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


cerefrePRO

9 months ago

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 :(


9 months ago

Do you have the runtime V2 enabled in your service settings?


jdelisacfcHOBBY

9 months ago

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?


9 months ago

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.


Status changed to Solved brody 9 months ago