---
title: "Deploy PgBouncer"
description: "PgBouncer 1.26.1 connection pooler in front of Railway Postgres, with TLS"
category: "Storage"
url: https://railway.com/deploy/pgbouncer-1
---

# Deploy PgBouncer

PgBouncer 1.26.1 connection pooler in front of Railway Postgres, with TLS

**[Deploy PgBouncer on Railway](https://railway.com/template/pgbouncer-1)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/pgbouncer-1/manifest.json

- **Creator:** Agaz Self-Host
- **Category:** Storage
- **Total deploys:** 2

## Template content

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:18

### PgBouncer https://raw.githubusercontent.com/pgbouncer/pgbouncer.github.io/master/images/apple-touch-icon.png

- **Source:** https://github.com/aalfath/pgbouncer-railway-template

## Documentation

# 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.



## Similar templates

- [RustFS | (Just Updated) S3 Object Store, Public URL and Keys Set](https://railway.com/deploy/rustfs-or-just-updated-s3-object-store-p) — S3-compatible object store, keys and public URL preset, volume kept
- [TimescaleDB](https://railway.com/deploy/timescaledb-railway-template) — A PostgreSQL-based time-series database for analytics on Railway.
- [Neo4j 2026.10 Community](https://railway.com/deploy/neo4j-202610-community) — Neo4j graph database with APOC, Browser, Bolt TCP proxy and a volume

Open this page in a browser: https://railway.com/deploy/pgbouncer-1
