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

CapabilityDescriptionOperational ImpactPerformanceScalability
Consensus (Raft)Leader election, log replication, term monotonicity.Deterministic failover; no split-brain.Sub-second leader election3-5 nodes optimal
State DurabilityPersistent HardState, entries, snapshots.Crash-safe recovery.WAL-based persistenceUnlimited log entries
Command InterfaceSQL functions for init, membership, diagnostics.Native DB admin UX.Zero-latency SQL accessPer-connection scaling
Monitoring HooksCluster status, log stats, leader checks.Simplifies observability.Real-time metricsMulti-cluster support
Node MembershipAdd/remove nodes through leader replication.Controlled scaling.Online reconfigurationDynamic cluster size
Debug ModeToggle extended logging via SQL.Faster incident analysis.Configurable verbosityPer-node granularity
Comparison

Feature Comparison

FeaturepgraftPatroniStolonRepMgr
Consensus ProtocolRaft (libraft)etcd/ConsuletcdNone
PostgreSQL IntegrationNative ExtensionExternal AgentExternal AgentExternal Agent
Split-Brain Prevention✔️✔️✔️
SQL Interface✔️
Zero External Dependencies✔️✔️
Background Workers✔️
Internals

Technical Documentation