BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Datadog Open-Sources PG Proxy to Unify PostgreSQL Pooling and Routing

Datadog Open-Sources PG Proxy to Unify PostgreSQL Pooling and Routing

Listen to this article -  0:00

Datadog has open-sourced PG Proxy, a PostgreSQL proxy and transaction-level connection pooler in Go. This tool enables platform teams to manage connection pooling, routing, and destinations in one unified solution, rather than relying on separate tools. PG Proxy operates in front of thousands of PostgreSQL hosts and hundreds of logical clusters.

Before the project, Datadog applications reached PostgreSQL through a mix of direct connections and combinations of PgBouncer for pooling, HAProxy for load balancing and traffic shifting, and Envoy for discovery and health checks. That split left separate configurations, metrics, and scaling knobs, and made migrations harder because DNS, proxy settings, and application endpoints had to move together. PG Proxy consolidates pooling and routing into a common access layer so destinations can change while clients keep the same proxy endpoint and database name.

PG Proxy uses transaction pooling so long-lived client sessions share a smaller pool of backend connections. Named prepared statements remain usable across those reassignments. Datadog says the pooler tracks each client’s statements and prepares them on the backend connection assigned for a transaction. When work on PG Proxy began, PgBouncer did not yet support protocol-level named prepared statements with transaction pooling.

Protocol edges still matter for newer libpq clients. On X, one user asked whether an embeddable Go PgBouncer replacement handles libpq 17 direct TLS with ALPN postgresql and prepared statements in transaction mode out of the box. Datadog Developers replied:

We don’t handle that specific feature today, but you can open up an issue on the GitHub repo if it’s something you'd like to see, and we can take a look.

Unlike PgBouncer’s single-threaded process model, each PG Proxy instance can use multiple CPU cores. Datadog reports more than 1,000 messages per second per core, more than 200 million authentications per day, more than 600,000 open client connections, and about 4 trillion messages proxied per month. Internal load-shedding and Database Monitoring hooks used at Datadog are not in the open-source release today.

With dynamic routing enabled, read-only transactions can go to replicas, while write transactions stay on the primary server. Clients can opt in per connection using a startup option. The system prioritizes the primary server for locking reads and most function calls. Operators can update backend destinations centrally during migrations, including moving some reads to a new cluster before the write cutover.

Authentication and tracing are extension points in the OSS build. At Datadog, services authenticate with JWTs carried in the PostgreSQL password field, but that JWT system stays internal. The public library exposes hooks for other identity checks. Spans cover protocol handling and query proxying and can join application traces when clients supply supported context, via native Datadog telemetry or OpenTelemetry.

Source and docs are on GitHub.

About the Author

Rate this Article

Adoption
Style

BT