Optimize PostgreSQL connections for throughput and latency
Unlock the complete study guide + 1,040 practice questions across 16 full exams.
Bundled into the existing Developing AI Cloud Solutions on Azure premium course — no separate purchase.
14-day money-back guarantee — no questions asked.
Included in this chapter:
- Two budgets: server processes and round trips
- What one connection costs, and where it runs out
- Sizing the client-side pool
- Running the built-in PgBouncer
- Choosing a pooling mode
- Fewer round trips: distance, pipelining, COPY
- Keeping a pooled connection alive
- Exam-pattern recognition
PgBouncer pooling modes: when the server connection goes back to the pool
| Behavior | Session pooling | Transaction pooling | Statement pooling |
|---|---|---|---|
| Server connection returned | When the client disconnects | At the end of each transaction | After each individual statement |
| Default where | Open-source PgBouncer | Azure built-in PgBouncer | Neither |
| Clients per backend process | One at a time | Many | Most |
| Session-scoped state survives | Yes | No | No |
| Multi-statement transactions | Supported | Supported | Not supported |
| Prepared statements | Work normally | Protocol-level only, and only once `pgbouncer.max_prepared_statements` is above its default of 0 | Cannot be used |
Decision tree
Cheat sheet
Unlock with Premium — includes all practice exams and the complete study guide.
References
- PgBouncer in Azure Database for PostgreSQL Flexible Server
- PostgreSQL: Architectural Fundamentals
- Connection Pooling Strategy Using PgBouncer in Azure Database for PostgreSQL Flexible Server
- Limits in Azure Database for PostgreSQL flexible server
- Psycopg 3: Connection pools
- SQLAlchemy: Connection Pooling
- PostgreSQL: SET
- PostgreSQL: Explicit Locking (advisory locks)
- PostgreSQL: LISTEN
- PostgreSQL: PREPARE
- asyncpg API reference
- What Is Azure Database for PostgreSQL flexible server?
- Plan Azure Database for PostgreSQL flexible server Deployments for Operational Performance Well-Architected
- Azure network round-trip latency statistics
- Psycopg 3: Pipeline mode support
- psycopg2: Extra specialized adapters and helpers
- PostgreSQL: Populating a Database
- Handle Transient Connectivity Errors
- Configure load balancer TCP reset and idle timeout
- PostgreSQL: libpq connection parameters
- Connections and Authentication / TCP Settings parameters