Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsMay 17, 2026·3 min de lectura

PgCat — PostgreSQL Pooler with Sharding and Load Balancing

A high-performance PostgreSQL connection pooler written in Rust that supports sharding, read/write splitting, load balancing, and automatic failover.

Listo para agents

Este activo puede ser leído e instalado directamente por agents

TokRepo expone un comando CLI universal, contrato de instalación, metadata JSON, plan según adaptador y contenido raw para que los agents evalúen compatibilidad, riesgo y próximos pasos.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
PgCat Overview
Comando CLI universal
npx tokrepo install 30d2ad67-51a8-11f1-9bc6-00163e2b0d79

Introduction

PgCat is a PostgreSQL connection pooler and proxy written in Rust. It goes beyond simple pooling by offering built-in sharding, read/write query splitting, load balancing across replicas, and automatic failover, making it suitable for scaling PostgreSQL horizontally.

What PgCat Does

  • Pools client connections to reduce backend connection overhead
  • Routes read queries to replicas and writes to the primary automatically
  • Shards data across multiple PostgreSQL instances using configurable strategies
  • Performs health checks and automatic failover when a backend goes down
  • Supports both transaction-mode and session-mode pooling

Architecture Overview

PgCat runs as a single async Rust binary using Tokio. It accepts PostgreSQL wire protocol connections from clients and maintains pools of backend connections to one or more PostgreSQL servers. A router layer inspects queries to determine read vs write intent and selects the appropriate backend. Sharding logic hashes a configurable key to route queries to the correct shard.

Self-Hosting & Configuration

  • Deploy via Docker or compile from source with cargo build --release
  • Configure in pgcat.toml with pools, users, shards, and replicas
  • Set pool mode to transaction (default) or session per pool
  • Enable query routing with primary_reads_enabled and replica settings
  • Monitor via the built-in admin database accessible through SQL commands

Key Features

  • Transaction-mode pooling with up to 10,000+ client connections per instance
  • Automatic read/write splitting without application changes
  • Sharding support with consistent hashing or range-based routing
  • Health checks with configurable intervals and automatic ban/unban of failing backends
  • Zero-downtime configuration reloads via SIGHUP

Comparison with Similar Tools

  • PgBouncer — industry standard pooler but no sharding, no read/write splitting
  • Odyssey — multi-threaded pooler by Yandex, no built-in sharding
  • pgpool-II — feature-rich but complex configuration and single-threaded query parsing
  • Supavisor — Elixir-based pooler from Supabase, focused on multi-tenant cloud
  • HAProxy — generic TCP load balancer, no PostgreSQL protocol awareness

FAQ

Q: Can PgCat replace PgBouncer? A: Yes for most use cases. PgCat supports transaction-mode pooling like PgBouncer and adds features like sharding and read/write splitting.

Q: How does automatic failover work? A: PgCat health-checks backends at configurable intervals. If a primary fails health checks, it is banned and clients receive errors until it recovers or a new primary is promoted.

Q: Does PgCat support prepared statements? A: Yes in session mode. Transaction mode has limited prepared statement support due to connection multiplexing constraints.

Q: What is the performance overhead? A: Minimal. PgCat adds sub-millisecond latency per query due to its async Rust architecture with zero-copy parsing.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados