# Pooler between servers and database

> Put a Connection Pooler between the App Servers and the Database so many app connections share a few database connections.

Place a Connection Pooler in front of the Database and point every App Server at it.

## Move up when

- The Database card reads that it is refusing queries for too many connections while its CPU is not full.
- Adding an App Server, or deploying, makes the errors worse.

## The Design





Both pictures run the same servers. In the first, each PHP-FPM worker holds its own connection, so two servers ask for more than the Database allows and requests are refused. In the second, the servers connect to the pooler, which holds a few connections to the Database.

## Why it works

Postgres forks a process per connection, so its limit arrives early. The pooler turns many short client connections into a few long server ones. The Database card in the second picture shows a small, steady connection count, and the refused requests are gone.

## What it costs

The pooler adds a small hop and one more Node that can fail. Transaction mode breaks code that keeps session state, such as prepared statements or session-level settings, so a share of requests crash until your Team finishes the Drop session state task. Statement mode cannot run a transaction that spans statements, so checkouts fail. Session mode breaks nothing and helps little.

## In Quorum

Research [Connection pooling](https://wiki.playquorum.dev/research/pooling.md) to unlock the [Connection Pooler](https://wiki.playquorum.dev/components/pooler.md). The [Connection Limit](https://wiki.playquorum.dev/sandboxes/connection-limit.md) Sandbox shows the failure, and [Connection exhaustion](https://wiki.playquorum.dev/incidents/connections.md) is the incident. [Connection pooling](https://wiki.playquorum.dev/patterns/connection-pooling.md) covers the pattern. The next rung is [DNS in front](https://wiki.playquorum.dev/patterns/dns-in-front.md).

Source: https://wiki.playquorum.dev/patterns/pooler-between-servers-and-database
