Quick answer: PgBouncer recycles PostgreSQL connections – instead of 500 connections only 20 real ones. Install between app and DB on your VPS.
Related
VPS & root servers: Order VPS in Germany · NexoraHost · nexorahost.com (Maincubes FRA01 Frankfurt · Ryzen · NVMe)
Frequently asked questions (FAQ)
When do I need PgBouncer?
From ~50 concurrent DB connections or when your app opens a new connection per request (PHP, serverless-style). Symptom: "too many connections".
transaction or session pool_mode?
transaction (default): connection returned after each transaction. session: for prepared statements. statement: rare, special cases only.
PgBouncer port?
PostgreSQL stays 5432 internally. PgBouncer listens on 6432 (default). App connects to 6432 instead of 5432.
PgBouncer with Docker Compose?
Yes – most popular setup. App → pgbouncer:6432 → postgres:5432. See copy-paste compose below.
How many connections are enough?
default_pool_size=20 often enough for 500+ app users. PostgreSQL max_connections can stay low (50–100).