pgraft: Raft-Based PostgreSQL Extension
Native Raft consensus for PostgreSQL clusters with automatic leader election and split-brain prevention
pgraft-demo
$
Speed:
Ready to run
PostgreSQL 16–18Strong ConsistencyZero Split-BrainRaft ConsensusBackground Worker
Overview
Why pgraft
Production-Grade Consensus
Built on proven libraft implementation for reliable leader election and distributed consensus.
Transparent Operations
All cluster state is inspectable through SQL functions—no external dependencies or control planes.
Fast Recovery
Automatic failover with deterministic leader elections and quick recovery during network partitions.
Operational Simplicity
Pure PostgreSQL extension with minimal configuration. Ideal for both development and production.
Durable & Crash Safe
Persistent Raft state and log entries ensure cluster consistency after restarts or failures.
Native Integration
Seamlessly integrates with PostgreSQL using background workers and shared memory IPC.
Depth
Feature Matrix
Capability | Description | Operational Impact | Performance | Scalability |
---|---|---|---|---|
Consensus (Raft) | Leader election, log replication, term monotonicity. | Deterministic failover; no split-brain. | Sub-second leader election | 3-5 nodes optimal |
State Durability | Persistent HardState, entries, snapshots. | Crash-safe recovery. | WAL-based persistence | Unlimited log entries |
Command Interface | SQL functions for init, membership, diagnostics. | Native DB admin UX. | Zero-latency SQL access | Per-connection scaling |
Monitoring Hooks | Cluster status, log stats, leader checks. | Simplifies observability. | Real-time metrics | Multi-cluster support |
Node Membership | Add/remove nodes through leader replication. | Controlled scaling. | Online reconfiguration | Dynamic cluster size |
Debug Mode | Toggle extended logging via SQL. | Faster incident analysis. | Configurable verbosity | Per-node granularity |
Comparison
Feature Comparison
Feature | pgraft | Patroni | Stolon | RepMgr |
---|---|---|---|---|
Consensus Protocol | Raft (libraft) | etcd/Consul | etcd | None |
PostgreSQL Integration | Native Extension | External Agent | External Agent | External Agent |
Split-Brain Prevention | ✔️ | ✔️ | ✔️ | ✗ |
SQL Interface | ✔️ | ✗ | ✗ | ✗ |
Zero External Dependencies | ✔️ | ✗ | ✗ | ✔️ |
Background Workers | ✔️ | ✗ | ✗ | ✗ |
Internals
Technical Documentation
Dive deep into pgraft's technical details, architecture, and internal workings with our comprehensive documentation.