PgDog
lastmod 2026-01-31created 2025-05-084 edits
Ultra-fast transaction pooling and sharding manager for PostgreSQL
About
- PostgreSQL transaction pooling + sharding + load balancing tool written in Rust + Tokio, efficiently managing hundreds of databases and hundreds of thousands of connections
- A PostgreSQL-specific application layer (OSI L7) proxy that works like PgBouncer but also supports query analysis and replication
- Easy to deploy with Kubernetes and Docker; cluster setup, load balancing, replication, and multi-shard management can all be handled in a single configuration
- With its own logical replication management, it can scale out an existing PostgreSQL cluster through sharding without downtime
Key features
- Load balancing
- Distributes traffic based on PostgreSQL queries at OSI Layer 7
- Automatically routes SELECT to replicas and INSERT/UPDATE etc. to the primary node
- Strategies: supports round robin, random, least active connections, and more
- Real-time health checks and automatic Failover on failure
- Supports session/transaction-level pooling, similar to PgBouncer
- Can serve hundreds of thousands of clients with a few PostgreSQL connections
- Extracts the shard key by analyzing SQL and automatically forwards the query to the matching shard
- For cross-shard queries, results are combined in memory and returned to the user as a single response
- COPY commands are also split and processed per shard
- Logical replication support: an existing DB can be scaled out through sharding without downtime
- Uses PgBouncer-style .toml configuration; settings can be changed without a restart
- Per-user authentication, per-database connections, and even shard information can be configured
- Standard PgBouncer admin port + OpenMetrics support
- Includes a Datadog integration example and dashboard
See also
Favorite site
- Github - pgdogdev/pgdog
- PgDog - Ultra-fast transaction pooling and sharding manager for PostgreSQL | GeekNews
- PgDog - A tool for sharding Postgres without a separate extension | GeekNews
- Removing Protobuf for direct Rust↔C bindings improves performance 5x | GeekNews (Protobuf)
- [Original] Replacing Protobuf with Rust to go 5 times faster | PgDog
- PgDog, a PostgreSQL scaling proxy, adopted direct Rust bindings instead of Protobuf serialization to improve SQL parsing performance
- Replaced the existing Protobuf-based structure with direct C–Rust conversion (bindgen + Claude-generated wrappers), speeding up parsing 5.45x and deparsing 9.64x
- The performance bottleneck was found in the pg_query_parse_protobuf function; even after trying caching, the structure was changed for a fundamental improvement
- Used the Claude LLM to automatically generate 6,000 lines of Rust–C conversion code, applied to key functions such as parse, deparse, fingerprint, and scan
- This optimization reduced PgDog's CPU usage and latency, greatly improving its efficiency as a PostgreSQL horizontal scaling proxy