# PgBouncer is now available in Supabase

[Supabase](https://yomu.fyi/company/supabase) · Angelico de los Reyes · Apr 2, 2021

**Type:** Announcement

## Summary

Serverless JavaScript frameworks and developer tools frequently establish separate database connections during bursty traffic, rapidly exhausting PostgreSQL connection limits in the absence of traditional middleware. To resolve connection surges, Supabase integrated the open-source connection pooler PgBouncer directly onto the PostgreSQL server across all newly created projects. Rather than increasing the total number of connections PostgreSQL can open, PgBouncer recycles open connections and queues excess requests until active connections become available. Developers can manage pooling through the dashboard across Session, Transaction, and Statement modes, with Transaction mode recommended for serverless functions despite disabling session features like prepared statements. The default pool size is initially configured to 15 connections.

## Context

Serverless functions lack middleware servers to maintain persistent database connections, causing them to create a new connection for each concurrent request. During bursty workloads, these direct connections can rapidly overwhelm a PostgreSQL database and exceed its connection limit.

## Approach / What changed

Supabase installed the open-source PgBouncer pooler on the same server as PostgreSQL for all new projects. PgBouncer manages pre-opened connections and queues incoming requests when all connections are in use, offering dashboard management for Session, Transaction, and Statement pool modes.

## Takeaways

- PgBouncer does not increase the maximum number of connections a Postgres instance can open; it maintains open connections and queues incoming requests instead of rejecting them when the pool is full.
- Transaction pool mode is recommended for serverless functions because it assigns connections only for the duration of a transaction, though it does not support features like prepared statements.
- Statement pool mode returns connections to the pool after every individual statement, which works best with AUTOCOMMIT and disallows multi-statement transactions.

**Tags:** [Architecture](https://yomu.fyi/topic/architecture), [Open Source](https://yomu.fyi/topic/open-source), [Postgres](https://yomu.fyi/topic/postgres), [Scalability](https://yomu.fyi/topic/scalability), [Serverless](https://yomu.fyi/topic/serverless)

[Read original post](https://supabase.com/blog/supabase-pgbouncer)
