pgraft Configuration

Configure pgraft extension and PostgreSQL for optimal Raft consensus performance.

PostgreSQL Configuration

postgresql.conf Settings

# Required settings
shared_preload_libraries = 'pgraft'

# Recommended settings
max_connections = 200
shared_buffers = 256MB
wal_level = replica
max_wal_senders = 10
hot_standby = on

pg_hba.conf Configuration

# Allow replication connections
local replication postgres peer
host replication postgres 127.0.0.1/32 md5
host replication postgres ::1/128 md5

pgraft Configuration

Extension Parameters

# Set in postgresql.conf or via ALTER SYSTEM
pgraft.listen_address = '0.0.0.0:5433'
pgraft.heartbeat_interval = 100ms
pgraft.election_timeout = 1000ms
pgraft.snapshot_threshold = 1000
pgraft.max_log_entries = 10000

Runtime Configuration

# Check current configuration
SELECT * FROM pgraft_get_config();

# Update configuration
SELECT pgraft_set_config('heartbeat_interval', '50ms');
SELECT pgraft_set_config('election_timeout', '500ms');

Cluster Setup

Initialize Cluster

# Create cluster
SELECT pgraft_init_cluster('my-cluster');

# Add nodes
SELECT pgraft_add_member('my-cluster', 'node1', 'host=192.168.1.10 port=5432');
SELECT pgraft_add_member('my-cluster', 'node2', 'host=192.168.1.11 port=5432');
SELECT pgraft_add_member('my-cluster', 'node3', 'host=192.168.1.12 port=5432');

Verify Cluster

# Check cluster status
SELECT * FROM pgraft_cluster_status('my-cluster');

# Check leader
SELECT * FROM pgraft_leader('my-cluster');

Performance Tuning

High Throughput

pgraft.heartbeat_interval = 50ms
pgraft.election_timeout = 500ms
pgraft.snapshot_threshold = 5000
pgraft.max_log_entries = 20000

Low Latency

pgraft.heartbeat_interval = 25ms
pgraft.election_timeout = 250ms
pgraft.snapshot_threshold = 1000
pgraft.max_log_entries = 5000