Datadog PG Proxy Explained: PostgreSQL Pooling, Routing, and Trade-Offs
PG Proxy is Datadog’s open-source PostgreSQL proxy and transaction-level connection pooler, written in Go. It sits between applications and database hosts, combining connection reuse with destination routing so backend clusters can change without forcing every client to adopt a new proxy endpoint or database name.
Key Takeaways- PG Proxy combines PostgreSQL connection pooling and backend routing in one access layer.
- Its transaction pool reuses backend connections, while tracking named prepared statements across assignments.
- Dynamic routing can send eligible read-only transactions to replicas and keep writes on the primary.
- Datadog reports large production use, but some internal monitoring and load-shedding features are not in the open-source release.
- Check protocol and driver compatibility before migrating; libpq 17 direct TLS with ALPN
postgresql is not supported today, Datadog says.
I’m Ermenildo Valdez Castro, Jr., a Filipino software engineer in Seattle who has worked on systems at Google, Microsoft, Amazon, and Zulily. I’ve seen database bottlenecks become application problems long before a team agrees on which proxy owns the fix. The useful question here is not whether PG Proxy replaces every tool, but whether one shared layer makes a particular PostgreSQL setup easier to operate.
Datadog built PG Proxy for its own large fleet, where applications had been connecting through a patchwork of direct connections, PgBouncer, HAProxy, and Envoy. Each tool did useful work, but each also brought its own settings, health checks, metrics, and scaling controls. When the database destination changed, application endpoints and DNS could become part of the same risky change.
There is a stewardship angle to this engineering problem. Reusing connections can reduce waste, but a proxy also becomes part of the path that protects customer data and keeps work available. A smaller connection count is only a win if correctness, visibility, and recovery remain solid.
What Is PG Proxy?
PG Proxy is a Go library and service that accepts PostgreSQL client connections, pools backend connections at the transaction level, and can direct traffic to configured database destinations. Instead of asking every application to manage several database tools, an operator can put a common proxy endpoint in front of the databases and manage routing behind it. The project’s code and documentation are available in the PG Proxy GitHub repository.
The important phrase is transaction-level pooling. A client may keep its connection to the proxy open, while the proxy assigns a backend PostgreSQL connection for a transaction and can return that backend connection to a shared pool afterward. Many application connections can therefore share fewer database connections. This is useful when applications create more client sessions than the database can comfortably serve as separate backend sessions.
That sharing changes the rules. In session pooling, one client can keep using the same backend session; in transaction pooling, the backend may change after a transaction ends. Session state that applications expect to persist may not behave as they do with a direct connection. Teams must test features such as session-level settings and temporary objects, rather than assume that a proxy makes them safe.
Prepared statements are a notable part of PG Proxy’s design. Datadog says the proxy tracks each client’s named prepared statements and prepares them on whichever backend connection is assigned for a transaction. That lets named statements remain usable even when transactions use different backend connections. When PG Proxy work began, PgBouncer did not yet support protocol-level named prepared statements in transaction pooling; PgBouncer’s current feature documentation describes support for prepared statements in transaction mode when configured appropriately. Check the current behavior of both products, not an old comparison.

PG Proxy also has an important boundary. In response to a question about an embeddable Go replacement for PgBouncer, Datadog Developers said the specific combination of libpq 17 direct TLS with ALPN postgresql was not handled at that time. If an application relies on that connection path, treat it as a compatibility test, not a footnote. Protocol details can decide whether an otherwise promising proxy is usable.
Core Benefits and Why They Matter
One access layer can simplify operations. Datadog previously combined direct database connections with PgBouncer for pooling, HAProxy for load balancing and traffic shifts, and Envoy for discovery and health checks. Each tool had a job. The trouble was the handoff between them: operators had to understand multiple configurations, metric systems, and scaling controls. PG Proxy brings pooling and routing into a shared layer, which can reduce the number of places an operator must change during a migration.
That does not mean “one tool” automatically means “simple.” A shared proxy becomes important infrastructure, so teams need clear ownership, alerts, capacity plans, and a recovery path. I’ve watched teams simplify a diagram while quietly creating a new single point of confusion. Write down who owns proxy configuration and who responds when the database is healthy but the proxy is not.
Stable client endpoints can make migrations less disruptive. With destinations managed behind the proxy, operators can update backend targets while clients continue to use the same proxy endpoint and database name. Datadog describes using that approach to move some reads to a new cluster before shifting writes. That can break a large cutover into smaller steps instead of asking applications, DNS, and database infrastructure to move together on one date.
Transaction pooling can use database connections more carefully. Long-lived application connections do not have to map one-for-one to long-lived backend connections. When a service has many idle client sessions, sharing backend connections may help keep the database within its connection budget. The gain depends on transaction length and workload shape; a pool cannot fix slow queries or a database that is short on CPU.
Read and write routing can support deliberate changes. With dynamic routing enabled, read-only transactions can go to replicas while writes remain on the primary. The client can opt in through a connection startup option. Datadog says routing favors the primary for locking reads and most function calls, a sensible caution where a read may depend on primary-side behavior. Replica lag and application consistency requirements still need testing.
The reported scale is meaningful, but not a benchmark promise. Datadog reports more than 1,000 messages per second per core, over 200 million authentications per day, more than 600,000 open client connections, and about four trillion messages proxied per month. Those are Datadog’s production figures, not an independent test or a forecast for another company’s workload. The useful signal is that the project was built under serious internal use; your own measurements still decide fit.
Step-by-Step Implementation Guide
- Map the current connection path. List each application, driver, proxy, database destination, and authentication method. Record client connection counts, backend connection counts, transaction duration, and peak traffic. Note which clients use named prepared statements, session-level settings, TLS options, or features that assume a stable backend session. A whiteboard sketch is fine, but leave with an inventory someone can check.
- Check protocol compatibility before changing production traffic. Test the exact PostgreSQL client libraries and versions used by your services. Include startup parameters, TLS negotiation, authentication, and prepared statements. In particular, Datadog has said PG Proxy does not currently handle libpq 17 direct TLS with ALPN
postgresql. Test any such path directly. Read the PostgreSQL protocol documentation when you need to understand what the client and server exchange; protocol assumptions are not interchangeable. - Choose a small, low-risk pilot. Start with a non-critical service or a limited traffic slice. Point it to the proxy while keeping a clear rollback route to its existing path. Compare connection counts, query errors, transaction latency, and database load before and after. Do not change the pooler, database version, and application driver in the same release. If something breaks, you want one likely cause, not a guessing contest.
- Set a connection budget. Estimate the backend connection ceiling the database can safely support, then reserve capacity for administration, failover, and other workloads. Pool settings should fit that budget across all proxy instances and database destinations. More client connections do not mean you should open the same number of backend connections. Start conservatively, watch queueing and transaction time, and change one setting at a time. Exact configuration options belong in the project’s current documentation, not in a copied snippet from an old post.
- Enable read routing deliberately. First identify transactions that are safe to run on replicas. Then opt in the relevant clients using the documented startup option and confirm where their read-only transactions land. Keep writes on the primary, as the feature is described. Test read-after-write behavior, replica lag, locking reads, and functions that may have side effects. If the application needs the freshest value after a write, sending its next read to a lagging replica may return a result users consider wrong.
- Make authentication and traces visible. The open-source build exposes extension points for authentication and tracing. Datadog’s internal services use JWTs in the PostgreSQL password field, but that JWT system is not part of the public release; teams must supply an identity approach that fits their environment. Spans can cover protocol handling and query proxying, and may join application traces when clients provide supported context. PG Proxy supports Datadog telemetry or OpenTelemetry; see the OpenTelemetry traces overview. Confirm that trace context survives the full client-to-database path.
- Plan a measured migration and a way back. Update backend destinations centrally in stages. For example, shift selected reads to a new cluster, compare results and health, and move writes only after the relevant checks pass. Keep the existing endpoint or a documented rollback configuration available until the new route has proved itself under normal and peak load. A migration plan should name the person who can reverse the change, not just the person who approved it.
- Watch the proxy as well as PostgreSQL. Monitor client connections, backend pool use, transaction duration, errors, routing decisions, and proxy CPU. Datadog says its internal load-shedding and Database Monitoring hooks are not included in the open-source release today. Do not assume your deployment includes those safeguards. Decide how your own service will alert, shed load, and recover if the proxy becomes the bottleneck.

PG Proxy vs. PgBouncer: A Practical Comparison
PgBouncer is the clearest comparison because Datadog previously used it for pooling, and it remains a widely used PostgreSQL connection pooler. PG Proxy’s pitch is broader: it joins pooling and routing in one access layer, with a multi-core Go implementation. PgBouncer is a focused pooler with its own mature feature set and operating model. Neither is the right answer for every database fleet.
| Area | Datadog PG Proxy | PgBouncer |
|---|
| Main role | PostgreSQL proxy combining transaction pooling and destination routing | PostgreSQL connection pooler focused on sharing backend connections |
| Implementation model | Go; each instance can use multiple CPU cores | Single-threaded process model, as contrasted by Datadog |
| Transaction pooling | Reuses backend connections across client transactions | Supports session, transaction, and statement pooling modes, subject to its documented constraints |
| Named prepared statements | Tracks client statements and prepares them on the backend assigned to a transaction, according to Datadog | Current feature documentation describes prepared statement support in transaction pooling when configured |
| Routing | Dynamic routing can send eligible read-only transactions to replicas and keep writes on the primary | Primarily a pooler; teams may use separate tools or application logic for broader routing needs |
| Operational fit | Useful when a shared layer for pooling and destination changes is the goal | Useful when a dedicated, established pooler meets the need |
The PgBouncer feature list and configuration reference are worth reading before treating it as a simple baseline. PG Proxy’s reported multi-core behavior may matter when a single process’s CPU use is a constraint, but raw messages per second do not tell you how your queries, TLS settings, network, or database will behave. I would run the same workload against both tools, including failure cases, before choosing.
A fair decision also counts operational cost. If a team already runs PgBouncer reliably and handles routing elsewhere without frequent mistakes, replacement may add more risk than value. If each database move requires coordinated changes across DNS, proxy rules, and application endpoints, a shared destination layer may pay for itself. Frankly, migration pain is a better reason to evaluate PG Proxy than a large number on a slide.
Common Mistakes to Avoid
Assuming transaction pooling behaves like a persistent database session. This is the easiest trap. A client keeps talking to the proxy, but a later transaction may use a different PostgreSQL backend. Applications that depend on state surviving between transactions need careful review. Read the product documentation and run integration tests that exercise real driver behavior. “It worked in the smoke test” is not a compatibility plan.
Treating every read as safe for a replica. Read-only does not always mean the result can be stale. A user may write a record and expect to see it immediately; a replica may not have caught up. Some reads take locks, and some functions have effects or assumptions that make routing less obvious. Start with transactions whose consistency needs are clear. Keep a primary route available for operations that need it.
Confusing vendor scale with your own capacity test. The reported figures show Datadog operates PG Proxy at high volume in its environment. They do not say how many connections your service can pool or how much CPU a query mix will use. I’ve seen teams copy a “fast enough” number from a benchmark and skip their own traffic replay. That is how a tidy pilot turns into an expensive surprise.
Assuming the open-source package includes Datadog’s internal systems. It does not include the internal load-shedding and Database Monitoring hooks described by Datadog. The public build has extension points for authentication and tracing, not Datadog’s private JWT authentication system. Make a list of the features your team expects, then verify each one against the public repository and current docs. Similar names do not mean identical deployments.
Ignoring protocol edges. Drivers change. TLS modes change. Prepared statements and startup parameters can differ across library versions. The stated gap around libpq 17 direct TLS with ALPN postgresql is a concrete warning: test your exact combination before rolling out broadly. For other TLS and protocol questions, use the project’s issue tracker rather than guessing what a proxy ought to support.
Adding a proxy without assigning ownership. A proxy can reduce complexity for applications while adding a new service that needs upgrades, monitoring, and incident response. Decide who owns releases, what metrics trigger action, and how clients behave if a proxy instance is unavailable. The dignity of this work is in doing the unglamorous checks before users pay for an outage.
Frequently Asked Questions
What does Datadog PG Proxy do?
PG Proxy is an open-source PostgreSQL proxy and transaction-level connection pooler written in Go. It can share backend connections across client transactions and provide a common layer for managing destinations. With dynamic routing enabled, eligible read-only transactions can go to replicas while write transactions stay on the primary. The proxy does not remove the need to test session behavior, driver compatibility, or database capacity.
Does PG Proxy support named prepared statements with transaction pooling?
Datadog says PG Proxy tracks named prepared statements for each client and prepares them on the backend connection assigned to a transaction. That design lets clients use those statements across backend reassignments. Test the specific client library and statement behavior you use. PgBouncer’s current feature documentation also describes prepared statement support in transaction pooling when configured, so do not rely on an outdated claim that it cannot do this.
Does PG Proxy support libpq 17 direct TLS with ALPN postgresql?
Not today, according to Datadog Developers’ response to a user asking about that exact feature. The response invited users to open an issue if they wanted it considered. If that protocol path is required, treat it as a blocker until the project confirms support or your own tests establish a working alternative.
Is PG Proxy a replacement for PgBouncer?
It can be an alternative for teams that want pooling and routing in one Go-based layer, but “replacement” depends on the workload. PgBouncer is a focused pooler with a mature configuration model; PG Proxy adds destination-routing capabilities described by Datadog. Compare operational features, client compatibility, metrics, failure handling, and the effort of migration. A tool that works well today does not need replacing just because another tool has a broader pitch.

Final thought. PG Proxy addresses a real problem: database access becomes hard to change when pooling, routing, discovery, and application endpoints live in separate places. A common proxy layer can make destination changes less disruptive and help a platform team use backend connections carefully. That is a worthwhile engineering goal, not a magic trick.
I would judge the project by a small set of plain questions. Does it work with the exact client protocols your services use? Does transaction pooling preserve the behavior your applications need? Can your operators see routing, capacity, and failure clearly? Can you return to the old path without a late-night scramble? If the answers are yes, PG Proxy deserves a measured trial. If not, fix the gaps before moving traffic.
Good infrastructure respects both machines and the people who depend on them. Thoughtful connection reuse is a form of stewardship; careful routing is a form of responsibility. Ermenildo Castro