A PostgreSQL proxy and transaction-level connection pooler, written in Go.
Every PostgreSQL connection is a backend process with its own memory, so a server can only hold so many. Applications often open far more connections than they actively use, and most of them sit idle between queries.
PG Proxy sits between your applications and PostgreSQL. Client sessions share a smaller pool of backend connections: a session holds a connection only for the length of a transaction, then returns it to the pool. Datadog's PostgreSQL Platform team built it and runs it in production.
- Run the binary.
cmd/pg-proxyreads a YAML or JSON config file that maps databases, clusters, and listener settings. See the quick start. - Embed the Go library. Build your own proxy and supply configuration, authentication, routing, load shedding, and telemetry through Go interfaces. See Go library configuration.
- Transaction pooling. Keep many more client sessions open than backend connections.
- Prepared statements. Named prepared statements keep working when transactions run on different backend connections.
- Read routing. Map client-facing database names to clusters, and send eligible reads to replicas.
- Session limits. Cap client sessions separately from backend connections. Applications that embed the library can also add load shedding.
- Traffic mirroring. Replay live traffic against a separate database without slowing clients. Go library only.
- Graceful shutdown. Drain sessions at transaction boundaries during a planned stop.
- TLS and SCRAM authentication. Secure client connections and verify passwords with SCRAM-SHA-256.
- Observability. Logs, metrics, and query traces through OpenTelemetry or native Datadog.
You need Go 1.26+, a C compiler (CGO is required), Docker, and psql.
Start a disposable PostgreSQL:
docker run -d --name pg -p 127.0.0.1:5432:5432 -e POSTGRES_PASSWORD=postgres postgres:18Build the proxy:
git clone https://github.com/DataDog/pg-proxy.git
cd pg-proxy
go build -o bin/pg-proxy ./cmd/pg-proxySave this as proxy.yaml:
databases:
- name: primary
host: 127.0.0.1
port: 5432
dbname: postgres
username: postgres
password: postgres
sslmode: disable
max_conns: 10
clusters:
local:
primary: primary
logical_databases:
local_db:
cluster: local
proxy:
listener_address: 127.0.0.1:15432Check the configuration without starting the proxy:
./bin/pg-proxy -config proxy.yaml -validate-configThis runs local startup checks, including credential references and TLS files, but does not check database connectivity or listener availability. See the local development guide for details.
Run it:
./bin/pg-proxy -config proxy.yamlConnect through the proxy from another terminal:
psql 'postgres://postgres@127.0.0.1:15432/local_db?sslmode=disable' -c 'select 1'This setup is for local development: the proxy listens on loopback and trusts the backend username. To deploy it, follow Run in production.
The full docs live in docs/site:
- Features and limitations
- Configuration file and flags
- Telemetry: OpenTelemetry and Datadog
- Transaction-pooling compatibility
- Using the Go library and package overview
- How PG Proxy compares with PgBouncer, Pgpool-II, Odyssey, and PgDog
We welcome bug reports, fixes, and docs improvements. Please open an issue before starting non-trivial work. See CONTRIBUTING.md for development setup and the checks to run before a pull request.
To report a security issue, email security@datadoghq.com. Do not open a public issue.
Apache-2.0. Third-party licenses are listed in LICENSE-3rdparty.csv.