Websites · Glossary

What is a connection pooler?

A connection pooler is a proxy between an application and a database that keeps a small set of open database connections and lends them to many clients in turn. Postgres starts a separate process for every connection, so thousands of direct connections would exhaust memory; a pooler such as PgBouncer or Supabase's Supavisor lets far more clients share far fewer connections.

Serverless functions and busy websites open connections in bursts. A pooler absorbs those bursts so the database only ever sees a manageable number of connections.

· Co-founder

4 min read · Published

Pooling modes compared
ModeWhen a connection returns to the poolGood forWatch out for
Session poolingWhen the client disconnectsLong lived servers; features that need session stateLittle saving when clients stay connected
Transaction poolingWhen each transaction endsServerless functions and many short requestsPrepared statements, session settings and LISTEN across transactions
Statement poolingAfter every statementVery simple read workloadsNo multi statement transactions

What it is

PostgreSQL handles each connection with its own server process, which costs memory and setup time, and the max_connections setting caps how many can exist at once. Applications that open a connection per request, especially serverless functions that scale to hundreds of copies, can hit that cap quickly. A connection pooler accepts client connections cheaply and maps them onto a limited pool of real database connections. PgBouncer is the long standing open source pooler; managed platforms often run their own, such as Supabase's Supavisor.

How it works

The client connects to the pooler as if it were the database, with the same protocol. In session mode the client keeps one server connection until it disconnects, which preserves everything a session can do but saves little. In transaction mode the client borrows a server connection only for each transaction and returns it immediately after, so hundreds of mostly idle clients can share a few dozen connections. Supabase's documentation, for example, offers a transaction pooler on port 6543 for serverless and edge functions and a session pooler as an IPv4 alternative to a direct connection on port 5432.

When it matters

A pooler matters when many short lived clients talk to one database: serverless API routes, background jobs scaling up, or a platform hosting many small sites against one database cluster. It matters less for a single long running server that keeps a small fixed pool of its own. Many website owners never touch it directly, because their framework or database provider uses one behind the scenes, but connection limit errors under load are usually the sign that one is needed or misconfigured.

Common mistakes

Pointing serverless functions at the direct database address instead of the pooler, then hitting too many connections errors during a traffic spike. Using transaction mode with code that relies on session features, such as prepared statements without support for them, temporary tables or session level settings. Setting the pool size larger than the database's own connection limit. Running migrations through a transaction pooler when the migration tool needs session mode. And forgetting that a pooler adds a network hop, so placing it far from the database adds latency.

Where it shows up in OneCraft

A OneCraft site that needs data gets a schema of its own in OneCraft's pool project, with a login role that can reach no other site, or a project on the owner's own Supabase account. Visitors reach the data through Supabase's APIs with row level security on every table, so site owners do not manage database connections or pool sizes themselves. Hosted schemas are available on every plan, or owners can connect their own Supabase account.

Questions people ask

Is a connection pooler the same as a load balancer?

No. A load balancer spreads requests across several servers. A connection pooler sits in front of one database and reuses a limited number of its connections for many clients. Some tools do both, routing reads to replicas, but pooling itself is about connection reuse, not spreading load.

Do I need a pooler with Supabase?

If you use Supabase's client libraries over its REST or GraphQL APIs, the API server manages connections for you. If you connect directly with a Postgres driver from serverless functions, use Supabase's transaction pooler connection string to avoid exhausting connections.

What is PgBouncer?

PgBouncer is a lightweight open source connection pooler for PostgreSQL. It supports session, transaction and statement pooling and is widely used in front of self hosted and managed Postgres databases. Many hosting platforms run PgBouncer or a similar pooler for you.

Why do prepared statements fail with transaction pooling?

A prepared statement belongs to one server connection. In transaction mode, the next transaction may run on a different connection where that statement does not exist. Newer poolers and drivers have workarounds, but the simplest fix is to disable prepared statements in the driver or use session mode.

How many connections does a small website need?

Usually very few. A site whose server keeps a pool of ten connections can serve many visitors, because each query takes milliseconds. Problems come from code that opens a new connection per request without a pooler, not from the number of visitors itself.

Make one with websites

The button opens the generator with this use case already described. Change the wording to match your own.

Create a website with OneCraft

Related questions

Sources

Written and checked by the OneCraft team. Last checked .