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

PgCat — PostgreSQL Connection Pooler with Sharding and Load Balancing

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

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
PgCat Overview
Commande d'installation directe
npx -y tokrepo@latest install d8cf927e-5940-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

PgCat is an open-source PostgreSQL connection pooler and proxy written in Rust, developed by the PostgresML team. It sits between your application and PostgreSQL servers, managing connection pools while adding load balancing, read/write splitting, and automatic failover — capabilities that go well beyond traditional poolers.

What PgCat Does

  • Pools PostgreSQL connections to reduce the overhead of opening and closing database connections
  • Balances read queries across multiple replicas for horizontal read scaling
  • Splits reads and writes automatically, routing writes to the primary and reads to replicas
  • Detects failed database instances and reroutes traffic to healthy ones
  • Supports sharding queries across multiple PostgreSQL instances by partition key

Architecture Overview

PgCat is an async Rust application built on Tokio that acts as a transparent PostgreSQL proxy. It speaks the PostgreSQL wire protocol, so applications connect to PgCat as if it were a regular PostgreSQL server. Internally, PgCat maintains pools of server connections organized by role (primary or replica) and shard. A query parser inspects incoming SQL to determine routing: writes go to the primary, reads go to replicas in round-robin. Health checks run periodically against all backends to detect failures. Configuration is loaded from a TOML file and can be reloaded at runtime without dropping connections.

Self-Hosting & Configuration

  • Deploy as a single binary or Docker container between your application and PostgreSQL
  • Configure database pools in pgcat.toml with host, port, role, and pool size per backend
  • Enable transaction or session pooling mode depending on your application requirements
  • Set up health check intervals and thresholds for automatic failover behavior
  • Reload configuration at runtime by sending SIGHUP — no restart or connection drop needed

Key Features

  • Written in Rust with async I/O for minimal latency overhead (sub-millisecond per query)
  • Query-level load balancing distributes individual queries rather than entire sessions
  • Automatic primary/replica detection using pg_is_in_recovery() health checks
  • Admin interface for monitoring pool statistics, active connections, and server states
  • Zero-downtime configuration reloads for adding or removing backends

Comparison with Similar Tools

  • PgBouncer — the standard PostgreSQL pooler, but lacks load balancing, failover, and sharding; PgCat adds all three
  • Odyssey — Yandex pooler with multi-threading; PgCat offers similar performance with a simpler configuration model
  • Supavisor — Supabase's Elixir-based pooler designed for multi-tenant SaaS; PgCat is a general-purpose pooler
  • HAProxy — TCP-level load balancer; PgCat understands the PostgreSQL protocol for smarter routing
  • Citus — sharding extension that modifies PostgreSQL itself; PgCat shards at the proxy layer without database changes

FAQ

Q: Can I use PgCat as a drop-in replacement for PgBouncer? A: In most cases, yes. PgCat supports the same pooling modes (session and transaction). Some PgBouncer-specific admin commands differ, but application connections work without changes.

Q: Does PgCat support prepared statements? A: Yes, in both session and transaction pooling modes. PgCat tracks prepared statements per server connection and re-prepares them when needed.

Q: How does PgCat decide which queries go to replicas? A: By default, queries inside a read-only transaction or explicit SELECT statements are routed to replicas. Write operations and DDL always go to the primary.

Q: What happens when a replica goes down? A: PgCat's health checker detects the failure and removes the replica from the pool. Queries are redistributed to remaining healthy replicas. When the replica recovers, it is automatically added back.

Sources

Fil de discussion

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

Actifs similaires