Unable to Connect to postgres.railway.internal (Connection Timed Out)

bukfa-web
HOBBY

2 months ago

Dear Railway Support Team,

In my project "exciting-kindness" (production), my web app cannot connect to the PostgreSQL database at postgres.railway.internal:5432. I get this error: psycopg2.OperationalError: connection to server at "postgres.railway.internal" (fd12:8ef7:6466:0:1000:33:2c3e:6991), port 5432 failed: Connection timed out

Is the server running on that host and accepting TCP/IP connections? psycopg2.OperationalError: connection to server at "postgres.railway.internal" (fd12:8ef7:6466:0:1000:33:2c3e:6991), port 5432 failed: Connection timed out

Is the server running on that host and accepting TCP/IP connections? The database is running (log: 2025-05-28 15:59:32 UTC): 2025-05-28 15:59:32.294 UTC [6] LOG: starting PostgreSQL 16.8

2025-05-28 15:59:32.294 UTC [6] LOG: listening on IPv4 address "0.0.0.0", port 5432

2025-05-28 15:59:32.294 UTC [6] LOG: listening on IPv6 address "::", port 5432

2025-05-28 15:59:32.406 UTC [6] LOG: database system is ready to accept connections. My DATABASE_URL is: postgresql://postgres:################@postgres.railway.internal:5432/railway. I switched to DATABASE_PUBLIC_URL (shortline.proxy.rlwy.net:18108), and it works, but I’d prefer the private endpoint to avoid egress fees and improve performance.

Web app logs (2025-05-28 15:24:51 UTC): [2025-05-28 15:24:51 +0000] [5] [ERROR] Exception in worker process

Traceback (most recent call last):

File "/opt/venv/lib/python3.12/site-packages/gunicorn/arbiter.py", line 608, in spawn_worker

worker.init_process()

File "/opt/venv/lib/python3.12/site-packages/gunicorn/workers/base.py", line 135, in init_process

self.load_wsgi()

File "/opt/venv/lib/python3.12/site-packages/gunicorn/workers/base.py", line 147, in load_wsgi

self.wsgi = self.app.wsgi()

File "/app/app.py", line 28, in <module>

db_pool = psycopg2.pool.SimpleConnectionPool(

File "/opt/venv/lib/python3.12/site-packages/psycopg2/pool.py", line 59, in init

self._connect()

File "/opt/venv/lib/python3.12/site-packages/psycopg2/__init__.py", line 122, in connect

conn = connect(dsn, connectionfactory=connection_factory, **kwasync)

psycopg2.OperationalError: connection to server at "postgres.railway.internal" (fd12:8ef7:6466:0:1000:33:2c3e:6991), port 5432 failed: Connection timed out

Is the server running on that host and accepting TCP/IP connections? Please help resolve the internal networking issue so I can use postgres.railway.internal.

Thank you, Bukfa

Solved$10 Bounty

7 Replies

2 months ago

Hey man, you might want to remove your password from the question.


ju-li

Hey man, you might want to remove your password from the question.

bukfa-web
HOBBY

2 months ago

Thank you for your help.


lofimit
HOBBY

2 months ago

I believe your web app and DB aren't in the same environment (like prod/dev/preview) or project on Railway.

I think postgres.railway.internal only works internally between services in the same Railway project, so double check the environment and if they are in the same Project.


bukfa-web
HOBBY

2 months ago

Thank you for your help.


bukfa-web

Thank you for your help.

lofimit
HOBBY

2 months ago

Did I solve your problem?


bukfa-web
HOBBY

2 months ago

I'm still looking for the error. I'll report back if it's resolved


Anonymous
FREE

2 months ago

Check if the internal network is properly linked


Status changed to Solved chandrika about 1 month ago