Skip to main content
InterviewHubPRO
Section Overview
Q19

Question 19 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

38%
PostgreSQL Enterprise (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

What is Connection Pooling and why is PgBouncer essential for PostgreSQL?

senior LevelSystem DesignDatabases & SQLPostgreSQL

In Simple Words: Because PostgreSQL forks an entire operating system process per connection, each connection consumes ~10 MB of RAM, and 500 connections cause massive CPU context switching:

  • PgBouncer: Ultra-lightweight connection pooler that sits between clients and PostgreSQL.
  • Pooling Modes:
    1. Session Pooling: Connection assigned to client for entire session lifetime.
    2. Transaction Pooling (Best Practice): Connection assigned to client strictly for the duration of a single transaction (BEGIN to COMMIT), and released immediately afterward. Allows 10,000 web clients to share 50 PostgreSQL connections!
    3. Statement Pooling: Reassigned after every single SQL statement.