I can't connect to database using pg_bouncer
pixelpioneer80
PROOP

2 months ago

Hi Railway Team.

I recently installed pg_bouncer and tried to connect to the database using public domain of pg bouncer. I wanted to see the database in pgAdmin4. But it shows timout expired. Not sure I did wrong way.

Any help would be appreciated!

Thanks.

Solved$20 Bounty

Pinned Solution

manuproject
FREE

2 months ago

the public domain is the problem. a railway domain routes HTTP through the edge, but postgres (and pgbouncer) speak their own TCP protocol, not HTTP. so pgAdmin connects, sends a postgres handshake, the edge doesn't know what to do with it and never replies, and you get a timeout. that's exactly the symptom you're seeing.

what you want instead is a TCP proxy on the pgbouncer service:

open the pgbouncer service → Settings → Networking → TCP Proxy, and set the target port to whatever pgbouncer listens on (6432 by default). railway gives you a host and port like shuttle.proxy.rlwy.net:15140.

then in pgAdmin use that host and port, with your normal postgres username, password and database name. remove the public domain, it isn't doing anything useful for this service.

docs: https://docs.railway.com/networking/tcp-proxy and https://docs.railway.com/databases/postgresql-pgbouncer

worth noting if your app is inside railway too, it should connect over the private network instead (something like pgbouncer.railway.internal:6432), the tcp proxy is only for reaching it from outside like pgAdmin.

1 Replies

Railway
BOT

2 months ago

This thread has been opened as a bounty so the community can help solve it.

Status changed to Open Railway • about 2 months ago


manuproject
FREE

2 months ago

the public domain is the problem. a railway domain routes HTTP through the edge, but postgres (and pgbouncer) speak their own TCP protocol, not HTTP. so pgAdmin connects, sends a postgres handshake, the edge doesn't know what to do with it and never replies, and you get a timeout. that's exactly the symptom you're seeing.

what you want instead is a TCP proxy on the pgbouncer service:

open the pgbouncer service → Settings → Networking → TCP Proxy, and set the target port to whatever pgbouncer listens on (6432 by default). railway gives you a host and port like shuttle.proxy.rlwy.net:15140.

then in pgAdmin use that host and port, with your normal postgres username, password and database name. remove the public domain, it isn't doing anything useful for this service.

docs: https://docs.railway.com/networking/tcp-proxy and https://docs.railway.com/databases/postgresql-pgbouncer

worth noting if your app is inside railway too, it should connect over the private network instead (something like pgbouncer.railway.internal:6432), the tcp proxy is only for reaching it from outside like pgAdmin.


Status changed to Solved mayori • about 2 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...