Deploy PgBouncer
PgBouncer 1.26.1 connection pooler in front of Railway Postgres, with TLS
Just deployed
/var/lib/postgresql/data
PgBouncer
Just deployed
Deploy and Host PgBouncer on Railway
PgBouncer is a lightweight, open-source connection pooler for PostgreSQL. Applications connect to PgBouncer as if it were Postgres, and it hands out a small set of reused server connections. This keeps Postgres fast and within its connection limit when many app instances, workers or serverless functions connect at once.
About Hosting PgBouncer
This template deploys PgBouncer 1.26.1 next to a Railway Postgres database. PgBouncer is built from the official release tarball (checksum-pinned) in a public GitHub repo, so future version bumps reach you as Railway update notices. It needs no volume: all data stays in Postgres, on its own volume. PgBouncer listens on port 6432 on the private network and on a TCP proxy for outside clients, offers TLS with a generated certificate, and authenticates with SCRAM-SHA-256. Every Postgres role can log in with its own password through auth_query, so there is no userlist to maintain. Pool mode and sizes are plain variables you can change at any time.
Common Use Cases
- Keep many app replicas, background workers or cron jobs under Postgres's connection limit
- Pool connections for serverless or short-lived clients (Next.js, Prisma, Django, Rails) in transaction mode
- Give external tools one pooled, TLS-capable endpoint for your Railway database
Dependencies for PgBouncer Hosting
- PostgreSQL (Railway Postgres, included)
- A client that speaks the Postgres protocol (any Postgres driver or
psql)
Deployment Dependencies
- PgBouncer documentation: https://www.pgbouncer.org/config.html
- PgBouncer 1.26.1 release: https://github.com/pgbouncer/pgbouncer/releases/tag/pgbouncer_1_26_1
- Template source: https://github.com/aalfath/pgbouncer-railway-template
Implementation Details
Point your app at the pooled URL instead of the direct one:
DATABASE_URL=${{PgBouncer.DATABASE_URL}}
From outside Railway, use PgBouncer's DATABASE_PUBLIC_URL and add ?sslmode=require. Postgres itself has no public endpoint in this template.
The default pool mode is transaction, which gives the most pooling and supports prepared statements (max_prepared_statements = 200). Switch PGBOUNCER_POOL_MODE to session for apps that rely on session state such as LISTEN/NOTIFY, session-level advisory locks or SET without LOCAL. Any other PgBouncer setting can be added as a variable named PGBOUNCER_ plus the setting name in upper case, for example PGBOUNCER_MAX_DB_CONNECTIONS=80. To pool a different Postgres service, change PGHOST, PGPORT, PGUSER, PGPASSWORD and PGDATABASE on the PgBouncer service to reference it. The admin console is the pgbouncer database (SHOW POOLS;, SHOW STATS;), open to the Postgres superuser.
Why Deploy PgBouncer on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying PgBouncer on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
