Skip to main content
InMotion Cloud
BLOG · OPTIMIZATION & PERFORMANCE

Connection Pooling With PgBouncer and ProxySQL

More app servers mean more database connections, until databases run out. How PgBouncer & ProxySQL pool connections, which mode to use & what breaks.

Updated November 24, 2026 by Danish Rumane

6 Minutes to Read

Many application connections funnelling through a pooler into a few database connections.

When traffic rises, you add application servers. Each new server opens its own pool of database connections. Somewhere along the way, the database hits its connection limit, and new requests start failing with "too many connections" errors while CPU still looks fine. On peak day, that is one of the most common ways a well-scaled site falls over.

A connection pooler sits between your application and the database and lets many application connections share a much smaller number of real database connections. This guide explains why connections run out, how PgBouncer (for PostgreSQL) and ProxySQL (for MySQL) solve it, and what can break when you add one. For context on how the pieces fit together, see how modern applications run on cloud infrastructure. If your web tier already sits behind a load balancer, this is the matching step for the database.

Why databases run out of connections

Database connections are expensive. In PostgreSQL, each connection is a separate operating system process with its own memory. MySQL uses threads, which are lighter, but each one still holds memory and competes for the same CPU.

The defaults are modest. PostgreSQL's max_connections is 100 by default, and MySQL's is 151. Raising the limit helps up to a point, but past that, the database spends more time switching between connections than doing work.

Now do the arithmetic for a peak day. Six application servers, each running 20 worker processes, each holding a few connections, can easily ask for several hundred connections. Most of them are idle at any moment, waiting for the application to send the next query. They still count against the limit.

Six application servers opening many connections to one database with a 100-connection limit, with the excess connections failing with a too many connections error.

Six servers with 20 workers each can exceed a 100-connection limit before the database is busy. Even idle connections take up a slot.

What a connection pooler does

A pooler accepts connections from your application, keeps a small set of real connections open to the database, and hands those real connections out only when a query actually needs one. Hundreds of mostly idle application connections become a few dozen busy database connections.

You get three things from that:

  • The connection limit stops being the ceiling. Add application servers without touching the database's limit.
  • Connection storms are absorbed. When traffic spikes and every server tries to open connections at once, the pooler queues them instead of the database collapsing.
  • Faster requests. Opening a database connection takes time; reusing one that is already open does not.
Application servers connecting to a pooler, which forwards their requests over a small number of database connections that stay within the database's limit.

The same six servers now send work through a pooler. PgBouncer for PostgreSQL or ProxySQL for MySQL can reuse open connections as requests arrive.

If you would rather engineers set up and tune pooling with you, it is part of the managed services included on every InMotion Cloud plan, alongside managed databases.

PgBouncer for PostgreSQL

PgBouncer is a small, single-purpose pooler. Its main decision is the pool mode.

Session mode. A client keeps a database connection for as long as it is connected. Safe for everything, but saves the least, because idle clients still hold connections.

Transaction mode. A client gets a database connection only for the length of a transaction, then gives it back. This is where the big savings come from, and it is what most busy web applications use.

Statement mode. The connection is returned after every statement. Multi-statement transactions are not allowed, so it suits only specific workloads.

What transaction mode can break. Anything that relies on state living on one connection between transactions: session-level settings, advisory locks held across transactions, LISTEN/NOTIFY, and temporary tables kept beyond a transaction. Older PgBouncer versions also did not support prepared statements in transaction mode; recent versions can, if configured. Check your framework and driver settings before switching.

ProxySQL for MySQL

ProxySQL does more than pool. It sits in front of MySQL and can:

  • Multiplex connections, sharing a small number of backend connections between many clients
  • Split reads and writes, sending writes to the primary and reads to replicas, using rules you define
  • Route or rewrite queries by pattern, and cache selected query results
  • Take an unhealthy server out of rotation and send traffic to the others

That extra power comes with more configuration. Start with connection multiplexing alone, prove it under load, then add read/write splitting as a separate step.

What can break. Similar to PgBouncer: session variables, temporary tables and locks can stop ProxySQL from sharing a connection, which reduces the benefit. Read/write splitting also means a user might not see their own write immediately if a read goes to a replica that is a moment behind.

Where the pooler runs

On each application server, as a local pooler. Simple, and no extra network hop, but each server still opens its own set of database connections.

As a shared tier between the application and the database. Gives the biggest reduction in connections, but it becomes a dependency of everything, so run at least two and put them behind a load balancer, as our overview of high availability options describes.

Either way, keep pooler traffic on a private network, never on public interfaces.

Comparison of a pooler running on each application server and a shared pooler tier of two poolers behind a load balancer between the applications and the database.

Local pools are simple, but their connections add up across servers. A shared tier pools across applications; run at least two poolers and test failover.

Before peak day

  • Add the pooler before the freeze, not during it, and load test with it in place.
  • Size the pool to what the database can handle, not to what the application asks for.
  • Watch the pooler's own metrics: clients waiting for a connection is the early warning that the pool or the database needs attention.
  • Test failure: restart the pooler during a test and confirm the application reconnects cleanly.

Where InMotion Cloud fits

InMotion Cloud includes managed databases on every plan, and our engineers can help you add and tune a connection pooler in front of PostgreSQL or MySQL, size the pool and test it under load. Pooler traffic can run over your environment's private network. Our guide to instance performance covers the server side of database tuning.

What stays with you: checking that your application's database usage is compatible with the pool mode you choose, and the queries themselves. A pooler protects the database from too many connections, not from slow queries.

Summary

More application servers mean more database connections, and databases run out long before CPU does. A pooler lets many application connections share a few real ones. Use PgBouncer in transaction mode for PostgreSQL and ProxySQL multiplexing for MySQL, check what each mode breaks, keep poolers redundant and on a private network, and load test with them in place before the freeze.


Worried your database will run out of connections on peak day?

InMotion Cloud engineers will help you add and test a connection pooler before your freeze.


Frequently asked questions

What is database connection pooling? Sharing a small number of real database connections between many application connections, so the database is not overwhelmed by mostly idle connections.

Should I use PgBouncer transaction mode or session mode? Transaction mode gives much larger savings and suits most web applications. Use session mode if your application depends on session-level state between transactions.

Is ProxySQL only a connection pooler? No. It also routes queries, splits reads and writes across replicas, caches selected results and removes unhealthy servers from rotation.

Should I just raise max_connections instead? Only a little. Past a point, more connections make the database slower, because it spends more time switching between them. Pooling fixes the cause.


Danish Rumane writes about hosting and cloud technology with a focus on what it means for businesses. His perspective draws on more than a decade in marketing, building brands and creating content across industries.

Read more from Danish Rumane
Share this Article
RELATED RESOURCES

Let’s map your infrastructure to the right plan

A free 30-minute call with our cloud team. We review your current environment and show you exactly what a move to InMotion Cloud would look like: timeline, architecture, and cost.

Compare plans