Opening a database connection costs several network round trips and a server process; reusing open connections makes that cost disappear from every request.
Learn the idea first
An app server handles one web request that runs one small query against PostgreSQL over TLS. Move the round-trip slider: 1–2 ms is the same data centre, 30+ ms is another region. Timings are an illustrative model.
App server
one web request
Connection pool
inside the app
PostgreSQL
one process per connection
Swipe the diagram sideways to see every column →
Where the time goes
23 ms total
An app server handles one web request that runs one small query against PostgreSQL over TLS. Move the round-trip slider: 1–2 ms is the same data centre, 30+ ms is another region. Timings are an illustrative model.
Illustrative timings. Real numbers vary with distance, network quality and server load.