pgraft: PostgreSQL Raft Consensus Extension
Production-ready Raft consensus for distributed PostgreSQL clusters with automatic leader election, crash-safe replication, and 100% split-brain prevention
pgraft-demo
$
Speed:
Ready to run
PostgreSQL 14-17etcd-io/raftZero Split-BrainAuto Leader ElectionBackground Workeretcd-Compatible KV
Key Features

Why pgraft

Automatic Leader Election

Quorum-based, deterministic, fully automated leader election using proven etcd-io/raft implementation.

Crash-Safe Replication

All state changes replicated and persisted across nodes. Survives crashes and network partitions.

100% Split-Brain Prevention

Mathematical guarantee via Raft consensus protocol—never more than one leader per term.

Zero-Downtime Failover

Sub-second detection and automatic recovery. Seamless failover with no service interruption.

Production-Grade Raft

Built on proven etcd-io/raft library used in production by etcd, Kubernetes, and other systems.

Native PostgreSQL Integration

Background worker architecture with no external dependencies. Pure PostgreSQL extension.

Comprehensive SQL API

Full cluster management via SQL functions. Monitor, manage, and control through standard SQL.

Built-in Observability

Status functions, metrics, detailed logging, and monitoring hooks for complete cluster visibility.

etcd-Compatible KV Store

Raft-replicated key-value storage included. Perfect for distributed configuration and coordination.

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
FeaturepgraftPatroniStolonRepMgr
Consensus ProtocolRaft (libraft)etcd/ConsuletcdNone
PostgreSQL IntegrationNative ExtensionExternal AgentExternal AgentExternal Agent
Split-Brain Prevention✔️✔️✔️
SQL Interface✔️
Zero External Dependencies✔️✔️
Background Workers✔️
Get Started

Deploy Raft Consensus for PostgreSQL

Install pgraft and enable automatic leader election, crash-safe replication, and 100% split-brain prevention for your PostgreSQL clusters.