Skip to content

PgBouncer Connection Pooling

Source: g2labs-in/linode-infra@677a40e · docs/adr/0003-pgbouncer-connection-pooling.md · updated 2026-05-29

We added PgBouncer in front of PostgreSQL on billuu-db to multiplex many Sequelize client connections into a smaller pool of actual database connections. The backend connects to PgBouncer on port 6432 instead of PostgreSQL on 5432. PgBouncer runs as a Docker Swarm service using edoburu/pgbouncer in transaction pool mode with scram-sha-256 auth via userlist.txt (matching PostgreSQL 18 defaults). Config lives at /opt/pgbouncer/ on the host. Both the app database and control plane database go through PgBouncer. SSL between PgBouncer and PostgreSQL is omitted because Tailscale already encrypts inter-VPS traffic. The backend env vars (DATABASE_URL, CONTROL_PLANE_DATABASE_URL) are updated via Dokploy UI to point to port 6432. The remaining SET search_path calls in schemaEnforcement.js are deferred — server_reset_query = DISCARD ALL in PgBouncer handles session state leakage in transaction mode.