What is a database connection pool?

In short
A database connection pool is a set of open connections to a database that an application keeps ready and reuses. Instead of opening a new connection for every request, the app borrows one from the pool and returns it when done. This saves time and protects the database from too many connections.
Why connections cost something
An application talks to a database over a network connection. Opening that connection takes time. The client and server must set up the link, and the server must allocate resources for it. If every web request opens a fresh connection and closes it at the end, the overhead adds up quickly.
A connection pool solves this. It opens a group of connections ahead of time and keeps them open. When your code needs the database, it borrows a connection from the pool, runs its queries, and gives the connection back. The next request can reuse the same connection without the setup cost.
How the limits work
A pool does not remove the database's own limits. The server still decides how many connections it accepts at once. In PostgreSQL, the setting max_connections controls the maximum number of concurrent connections to the database server. The default is typically 100, though the server may set it lower if the operating system cannot support that many.
The server also reserves some slots. The superuser_reserved_connections setting keeps a few connection slots for superusers, so administrators can still log in when the server is busy. A second setting, reserved_connections, can hold slots for roles that have been granted the pg_use_reserved_connections privilege. Your pool should stay well below the server's limit, leaving room for other applications, admin tools and these reserved slots.
Increasing max_connections is not free. PostgreSQL allocates resources based on that value, including shared memory, so a higher number means more memory use. A pool is usually a better fix than raising the limit.
How the network side behaves
Connections can fail silently. A network device may drop an idle link, and neither side notices until the next query. PostgreSQL offers TCP keepalive settings, such as tcp_keepalives_idle, tcp_keepalives_interval and tcp_keepalives_count. These tell the operating system when to send probe messages on an idle connection and how many lost probes mean the peer is gone. A value of 0 selects the operating system's default.
The tcp_user_timeout setting limits how long transmitted data may stay unacknowledged before the connection is forcibly closed. The documentation notes that these TCP options are supported only on certain systems, and that they are ignored for connections over a Unix-domain socket.
A pool should check connections before handing them out, or discard ones that have died. Otherwise your code may receive a broken connection and fail on its first query.
A simple example
The idea is easy to see in pseudocode. The pool starts with a few connections. Each request asks for one, uses it, and returns it.
pool = create_pool(host="db.internal", max_size=10)
function handle_request():
conn = pool.borrow()
try:
rows = conn.query("SELECT name FROM users LIMIT 5")
return rows
finally:
pool.give_back(conn)
The important part is the finally block. It returns the connection even when the query fails. If you forget this step, the pool slowly runs out of connections and requests start to wait.
Most language drivers and frameworks provide a ready-made pool, so you rarely write one yourself. The key choice is its maximum size. Make it too small and requests queue up. Make it too large and you can push the database past its max_connections limit when several app servers each open their own pool.
Common mistakes
The first mistake is sizing each application instance as if it were the only one. If you run ten instances, each with a pool of 20, the database sees up to 200 connections.
The second mistake is holding a connection while doing slow work that does not touch the database, such as calling an external API. The connection sits idle and cannot serve other requests.
The third mistake is leaking connections by skipping the return step on error paths. Use the language's cleanup mechanism so the return always runs.
The fourth mistake is ignoring the server's settings. Check max_connections and the reserved slot settings before choosing a pool size, and remember that a standby server must allow at least as many connections as the primary for queries to run there.
Alternatives
Some teams place a separate pooling service between applications and the database. This central layer shares a smaller set of server connections among many clients. It adds another component to run and monitor, so it suits larger setups best.
For a single small application, an in-process pool from your database driver is usually enough. Start there, watch how many connections are in use, and adjust the size based on real load.
For more on how the database itself handles connections, see the official PostgreSQL configuration reference linked above.
FAQ
Is a connection pool the same as a database server limit?
No. The pool lives in your application and decides how many connections that app keeps open. The server's max_connections setting is a separate hard limit on all clients together.
How big should my pool be?
There is no single right number. Keep the total across all application instances well below the server's connection limit, and tune the size using measured load and wait times.
Why does my app sometimes get a dead connection?
The network or a firewall may have dropped an idle link without telling either side. Pools usually test connections before use or discard broken ones, and TCP keepalive settings can help detect dead links sooner.
Do I need to write my own pool?
Usually not. Most database drivers and frameworks include a pool. You only configure its size, timeouts and health checks.
Sources
This page is based on the official documentation below. Read it for full detail.
Connection pooling — official documentation ↗Connection pooling in the news
Pinecone Releases Open Source pg_pinecone Extension for Vector Search in PostgreSQL
Pinecone has released pg_pinecone, an Apache 2.0 licensed PostgreSQL extension that adds its own vector search engine to existing pgvector columns. The company says it applies filters during search rather than after, and reports benchmark results against pgvector's HNSW index.
AlloyDB Omni Can Now Call Local Models Like Gemma 4 Directly From SQL
Google says its AlloyDB Omni PostgreSQL-compatible database now connects to locally hosted large language models such as Gemma 4 and Qwen3.8. The integration lets SQL queries call a model that runs inside the same environment as the data.
pgjumbo Adds Write Previews and Plan Comparison to a New PostgreSQL Client
Benjamin Ibrulj has released pgjumbo, a PostgreSQL client for macOS, Windows and Linux. It shows the likely impact of writes before they run and offers an optional AI assistant built on Claude Code.


