Introduction
PG Proxy sits between PostgreSQL clients and their databases. The Go library handles the PostgreSQL wire protocol, client sessions, routing, and transaction-level connection pooling.
Early development. Configuration and Go APIs may change between releases.
There are two ways to use PG Proxy: run the pg-proxy binary, or use the Go library to build your own proxy.
Run the pg-proxy binary: Configure it with a YAML or JSON file. Start with Local development, then follow Run in production to deploy it with TLS and password authentication.
Build your own application with the Go library: Supply your own configuration, authentication, routing, and telemetry integrations. See Go library configuration and Packages.
About PG Proxy
Section titled “About PG Proxy”We’re Datadog’s PostgreSQL Platform team. We started building PG Proxy in 2023 after running into limitations with existing tools, including PgBouncer. We needed a pooler and proxy that we could adapt to how we run PostgreSQL at Datadog, so we built our own.
Since then, we’ve run it in production, fixed it, and learned what works. We think that work is useful outside Datadog too.
Overview
Section titled “Overview”- Features: Pooling, prepared statements, read routing, observability, and application integrations.
- Limitations: Transaction-pooling constraints and current implementation limits.
- Compare poolers: How PG Proxy compares with other connection poolers such as PgBouncer, Pgpool-II, Odyssey, and PgDog.
- Benchmarks: PG Proxy throughput and latency under pgbench, and the settings used to measure them.
How-to guides
Section titled “How-to guides”- Local development: Build
pg-proxyand run it against a local PostgreSQL database. - Run in production: Deploy the binary with TLS, authentication, sizing, telemetry, and safe restarts.
- Set connection and session limits: Configure the connection pool and client-session cap.
- Send OTel metrics to Datadog: Configure the Collector to export event counters as rates.
Reference
Section titled “Reference”Configuration
Section titled “Configuration”- Configuration file and flags: every
pg-proxybinary setting and its default. - Client connection options: PG Proxy session options, defaults, and connection examples.
- Timeouts: Backend statement limits, transaction overrides, shutdown, and fixed limits.
- Client TLS: TLS between clients and the proxy.
- Client authentication: Password and SCRAM users, and credential references.
Observability
Section titled “Observability”- Telemetry configuration: Backend selection, options, defaults, and examples for OpenTelemetry and Datadog.
- Metrics: Metric clients, session overrides, and selected measurements.
- Tracing: Span operations, propagation, and recorded data.
Compatibility and operations
Section titled “Compatibility and operations”- Requirements and tested versions: Go, operating systems, PostgreSQL versions, and client features.
- Transaction-pooling compatibility: Session state, prepared statements, and connection reuse.
- Troubleshooting: Common startup and connection errors.
Go library
Section titled “Go library”- Go library configuration: Process dependencies, listener settings, and routing interfaces.
- Adapting configuration: Change parts of the configuration schema in your application.
- Packages: Responsibilities of the library’s public packages.
Explanation
Section titled “Explanation”- Authentication and TLS: Understand client authentication, transport security, and channel binding.
- Transaction pooling: Understand how client sessions share backend connections.
- Prepared statements: How statement mappings survive backend connection changes.
- Read routing: How the proxy selects clusters and replica pools.
- Traffic mirroring: Replay traffic on a separate database and understand what can be dropped.
- Graceful shutdown: How sessions drain and clients reconnect.
Contribute
Section titled “Contribute”- Contribute to PG Proxy: Report bugs, propose changes, and prepare a pull request.
- Contribute to the documentation: Edit, preview, and validate the documentation site.
