ProxySQL vs PgBouncer: Connection Pooling Isn't Just a Postgres Problem
MySQL and MariaDB run into the same wall, they just get there differently

Contents
I’ve written before about reaching for PgBouncer before you think you need it, and every time that post gets a comment or a question, someone eventually asks the MySQL/MariaDB equivalent. There isn’t a direct one — PgBouncer is Postgres-specific, tied closely to the Postgres wire protocol, and there is no port of it for MySQL’s rather different protocol. The closest equivalent for the MySQL world is ProxySQL, and it is best understood as a different tool that happens to solve the same underlying problem — too many short-lived client connections overwhelming a database that would rather serve fewer, longer-lived ones — with a noticeably different design philosophy.
The problem both tools solve
Every database connection, Postgres or MySQL, costs the server memory and, for Postgres specifically, a full OS process per connection — MySQL uses threads rather than processes, which is lighter per-connection but still not free at scale. An application that opens a new connection per request, or that runs many worker processes each holding their own connection pool, can rack up hundreds of simultaneous connections doing essentially no work most of the time. Past a few hundred connections, both databases spend measurable CPU just on connection bookkeeping and context switching rather than running actual queries, and eventually you hit a hard max_connections ceiling and start seeing connection-refused errors under load that has nothing to do with query complexity.

A connection pooler sits between the application and the database, holding a much smaller pool of actual database connections open, and multiplexes many client connections onto that smaller pool. From the application’s point of view nothing changes — same host, same port, same protocol. From the database’s point of view, connection count drops from hundreds to a few dozen, and it can spend its resources on query execution instead of connection overhead.
PgBouncer: a thin, protocol-aware multiplexer
PgBouncer does one job and does it with almost no overhead: it speaks the Postgres wire protocol on both sides, holds a pool of real backend connections, and hands them out to clients according to a pooling mode (session, transaction or statement level). It has essentially no query awareness — it does not parse SQL, does not route queries, does not care what you’re asking the database to do. That narrowness is a deliberate design choice and the reason it adds almost no measurable latency to a query path.
| |
Point the application at port 6432 instead of Postgres’s usual 5432, and PgBouncer multiplexes up to a thousand client connections onto a real pool of twenty backend connections to Postgres itself. pool_mode = transaction is the setting doing the actual work — a backend connection gets returned to the pool the instant a transaction commits, rather than being held for the lifetime of the client’s own connection, which is what makes the multiplexing ratio possible in the first place.
ProxySQL: a query-aware proxy that happens to pool connections too
ProxySQL starts from a different premise entirely. It is a full SQL-aware proxy that parses every query passing through it, well beyond a thin multiplexer bolted onto the MySQL protocol, and pooling is one of several things it does with that visibility, alongside query routing, read/write splitting across replicas, query caching, and query rewriting rules applied in flight.
| |
ProxySQL’s configuration lives in its own SQLite-backed admin database, reachable over a separate MySQL-protocol port (6032 by default) using ordinary SQL INSERT/UPDATE statements against configuration tables — an unusual but genuinely convenient design once you’re used to it, since the same tool you use to query the database is also how you reconfigure the proxy in front of it, live, without a restart.
Where the philosophies diverge in practice
PgBouncer’s narrowness is a feature for the common homelab case: a single Postgres instance, one or a few applications, and a straightforward need to cap connection count. Adding PgBouncer changes essentially nothing about how queries behave — it is invisible except for the connection count relief it provides.
ProxySQL’s query awareness is overkill for that same simple case and genuinely valuable the moment your MySQL/MariaDB setup has more than one server behind it — a primary plus one or more read replicas, say. ProxySQL can route SELECT statements to replicas and everything else to the primary automatically, based on query pattern matching rules, without the application needing to know which server is which:
| |
That pair of rules sends anything matching SELECT ... FOR UPDATE (which needs primary-level consistency) to hostgroup 0 (the primary), and every other SELECT to hostgroup 1 (replicas), while everything that isn’t a SELECT at all falls through to the primary by default. Postgres has read-replica routing tools too, but they live in a separate layer (Pgpool-II, or application-level routing) rather than inside PgBouncer itself, which stays deliberately out of that business.
Pooling mode nuances that bite people
Both tools support multiple pooling levels, and picking the wrong one for your workload is the single most common cause of hard-to-debug application errors after adopting either.
PgBouncer’s transaction mode — the one that gives you the highest multiplexing ratio — breaks session-level Postgres features that assume a connection persists across transactions: session-level advisory locks and SET statements meant to apply for the whole session rather than one transaction. Prepared statements were also a casualty until PgBouncer 1.21 added protocol-level support in transaction mode through max_prepared_statements. Applications that rely on any of those need session mode instead, which pools far less aggressively (roughly one backend connection per active client connection) but preserves full session semantics.
ProxySQL has an analogous but not identical set of caveats around multiplexing: certain session-level MySQL features (user-defined variables, some SET statements, temporary tables) similarly disable connection reuse for that session unless explicitly whitelisted in ProxySQL’s own multiplexing rules, and the failure mode looks the same as PgBouncer’s — an application that worked fine talking directly to the database starts behaving as though its session state randomly resets partway through a request.
Visibility into what the pooler is actually doing
Both tools expose their own internal state through their admin protocol, and checking it is the first move whenever pooling behaviour looks wrong rather than guessing from application-side symptoms. PgBouncer answers a set of SHOW commands over its own admin connection:
| |
SHOW POOLS is the one I check first under any connection-pressure incident — it breaks down, per database, how many client connections are currently waiting for a backend connection to free up (cl_waiting), which is the single clearest sign that default_pool_size is set too small for the actual concurrent load rather than the client-side connection count being the real problem.
ProxySQL’s stats live in its admin database as ordinary queryable tables, which fits its overall philosophy of treating configuration and observability as SQL rather than a separate CLI syntax:
| |
stats_mysql_connection_pool shows per-backend-server connection counts and status, useful for confirming read/write splitting is actually distributing load the way the query rules intend rather than everything quietly landing on the primary despite rules that look correct on paper.
TLS termination
Both tools can terminate TLS from the client side and either re-encrypt or run plaintext to the actual database, which matters if the database itself lives on a different host than the pooler — a common homelab layout where the pooler runs alongside the application and the database sits on a separate storage-focused box.
| |
ProxySQL’s equivalent lives in its admin tables rather than a flat config file, consistent with everything else about how it’s configured:
| |
For a homelab where the pooler and database share a host, or sit on the same trusted internal VLAN, I generally skip TLS between the pooler and the database itself and only terminate it on the client-facing side — the same trust-boundary reasoning I apply to most internal-only service-to-service traffic, reserving the cost of full mutual TLS for links that actually cross a boundary I don’t fully control.
ProxySQL’s query cache: a feature PgBouncer has no equivalent for
Because ProxySQL parses every query, it can also cache SELECT results in memory and serve repeat queries without touching the database at all, keyed on the exact query text and its parameters:
| |
That sets a 5-second cache TTL on the read-replica-routed rule from earlier — short enough that stale data is rarely a real problem for most read-heavy workloads, long enough to absorb a burst of identical queries (a dashboard several users load at once, say) without each one hitting the database. This has no PgBouncer equivalent, precisely because PgBouncer doesn’t parse queries at all; anything cache-shaped on the Postgres side has to live in the application or in a dedicated cache like Redis in front of the query path instead.
Running ProxySQL at home
For a homelab MariaDB or MySQL setup with a single primary and no replicas yet, ProxySQL is genuinely more machinery than the problem calls for — the same “don’t reach for more than you need” instinct that applies when comparing plain KVM against the full Proxmox stack applies here too. A well-tuned MariaDB instance with sane max_connections handles a handful of applications directly without needing a proxy in front of it at all.
| |
Where it earns its complexity at home specifically: a self-hosted app stack with a MariaDB primary and a replica kept purely for read-heavy reporting queries, or several applications sharing one database server where you want per-application connection limits enforced centrally rather than trusting each application’s own pool configuration.
At a glance:
| PgBouncer | ProxySQL | |
|---|---|---|
| Database | PostgreSQL | MySQL and MariaDB |
| Reads the SQL | No | Yes, every query |
| Read/write splitting | No | Yes, through query rules |
| Query cache | No | Yes, time-based TTL |
| Configuration | pgbouncer.ini | SQL tables on admin port 6032 |
| Pooling levels | Session, transaction, statement | Multiplexing, switched off per session by some features |
Troubleshooting
Application gets “prepared statement does not exist” errors after adding PgBouncer. Classic transaction-mode incompatibility on PgBouncer older than 1.21, or on newer versions where max_prepared_statements is set to 0. Upgrade and set max_prepared_statements above zero, or switch the application’s driver to use simple query protocol instead of prepared statements, or drop to session mode if the multiplexing loss is acceptable.
ProxySQL routes a write query to a read replica. Check query rule ordering — rules are evaluated in rule_id order and the first match wins, so an overly broad early rule can shadow a more specific one meant to catch a particular write pattern. EXPLAIN isn’t relevant here; check stats_mysql_query_rules in ProxySQL’s own stats schema to see which rule actually matched.
Connection count still climbing despite pooling. Confirm the application is actually connecting to the pooler’s port, not the database’s real port directly — a partial migration where some services were repointed and others weren’t is the most common cause, and it produces a confusing hybrid where connection pressure drops but doesn’t disappear.
ProxySQL admin changes don’t survive a restart. Configuration loaded with LOAD ... TO RUNTIME is active immediately but not persisted; the matching SAVE ... TO DISK command is a separate, required step, easy to forget mid-troubleshooting session when you’re focused on getting the runtime behaviour right first.
Query cache serves stale data after a write. ProxySQL’s query cache has no automatic invalidation tied to writes — it is a pure time-based TTL cache, not a write-through one, so a SELECT cached five seconds ago will keep serving the pre-write result until the TTL expires regardless of what happened to the underlying rows in between. Set the TTL deliberately short for any table with frequent writes, or exclude write-sensitive queries from caching entirely via the query rule’s cache_ttl being left unset for that pattern.
PgBouncer’s cl_waiting count stays elevated even after load drops. Check default_pool_size against actual peak concurrency rather than average — a pool sized for typical load will show queuing during any burst above that average, and the fix is either raising the pool size (bounded by what the database’s own max_connections can absorb) or smoothing the application’s own concurrency rather than assuming the pooler itself is misbehaving.
Both tools solve the same shaped problem for their respective databases, but reaching for ProxySQL because “it’s the MySQL PgBouncer” undersells what it actually does, and reaching for PgBouncer expecting query routing undersells what it deliberately doesn’t. Match the tool to what your setup actually needs rather than assuming feature parity between them: a single-database homelab wants the narrowest tool that solves connection exhaustion and nothing else, and a multi-server setup with genuine read/write separation wants the tool that was built to understand the queries flowing through it. Picking based on which database engine you happen to run is the right first filter, but it shouldn’t be the only one, since the two tools’ actual feature sets diverge by more than the protocol they speak.




