PostgreSQL Enterprise (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Connection Pooling with PgBouncer: Sizing and Modes.
senior LevelPostgreSQL
In Simple Words: PostgreSQL uses a process-based model (each client connection spawns a new OS backend process consuming ~10MB RAM). PgBouncer multiplexes thousands of client connections onto a tiny pool of backend PostgreSQL connections:
- Session Pooling: Connection held for the lifetime of client connection.
- Transaction Pooling (Most Common): Connection returned to pool as soon as
COMMITorROLLBACKexecutes (enables 10,000 clients to share 50 DB connections!). - Statement Pooling: Connection returned after every single SQL statement (does not support multi-statement transactions).