Back to Docs
Recipe

Recipe: PgBouncer pool design

Production-grade connection pooling for PostgreSQL on Meridian infrastructure.

Overview

PgBouncer sits between your application and PostgreSQL, maintaining a pool of persistent connections. This eliminates connection churn under load and keeps your database responsive when traffic spikes.

Architecture

App ──► PgBouncer :6432 ──► PostgreSQL :5432
              (transaction pooling)

Use transaction pooling for web workloads. Connections are assigned only for the duration of a transaction, then returned to the pool.

Configuration

[databases]
meridian = host=localhost port=5432 dbname=meridian

[pgbouncer]
listen_addr = 0.0.0.0
listen_port = 6432
pool_mode = transaction
default_pool_size = 25
max_client_conn = 200

Connection string

DATABASE_URL=postgres://user:pass@localhost:6432/meridian

Point your application at port 6432. PgBouncer handles the rest.

Monitoring

Connect to the admin console to inspect pool health:

psql -p 6432 -U pgbouncer pgbouncer
SHOW POOLS;
SHOW STATS;