The Desi Architect
Notes / Docker Sandboxes / Database Connection Pool Exhaustion & Leak Detection
Docker Sandboxes · Tier 2: Data & Scale · Lab 29

Database Connection Pool Exhaustion & Leak Detection

Run a small connection pool against a real Postgres and break it on purpose. Hold transactions open and watch the pool run dry while the database sits idle. See server timeouts, a connection leak and the hard limit that Postgres enforces whatever your pool says.

Time35 minutes
StackPostgreSQL 16Ports 15448
MemoryAbout 80 MB
Before thisLab 05SQL Transaction Isolation Levels &
Verified runWindows, Mac, LinuxBash and PowerShell
  1. 1PrepareWhat you will learn
  2. 2PredictGuess before you run
  3. 3RunStep by step
  4. 4ObserveWhat you should see
  5. 5Break itChange one thing
  6. 6Clean upLeave nothing running
On this page
  1. 00 / What You Will Learn
  2. 01 / Why It Matters
  3. 02 / What We Are Building
  4. 03 / Words You Need
  5. 04 / Predict First
  6. 05 / Step by Step
  7. 06 / What You Should See
  8. 07 / Look Inside
  9. 08 / Break It, Fix It
  10. 09 / In Real Projects
  11. 10 / Interview Corner
  12. 11 / Clean Up

00 /What You Will Learn

By the end you will be able to
  • Explain a connection pool and why requests wait for a free connection.
  • Explain pool exhaustion, and why a slow call inside a transaction causes it.
  • Tell statement_timeout from idle_in_transaction_session_timeout and say what each one stops.
  • Show a connection leak and the context manager that prevents it.
  • Explain the max_connections limit and what a pooler like PgBouncer is for.

Before you start

Finish Lab 05 (SQL Transactions and Isolation) first. You should know BEGIN and COMMIT. Docker Desktop and Python 3 are needed.