Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsMay 17, 2026·3 min de lecture

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.

Prêt pour agents

Cet actif peut être lu et installé directement par les agents

TokRepo expose une commande CLI universelle, un contrat d'installation, le metadata JSON, un plan selon l'adaptateur et le contenu raw pour aider les agents à juger l'adaptation, le risque et les prochaines actions.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
PgCat Overview
Commande CLI universelle
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

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires