Quick Start (pgElephant Suite)¶
Get your first pgraft cluster up and running in minutes! All steps and health checks are up to date for the latest release and unified with the pgElephant suite.
Step 1: Configure PostgreSQL¶
Add these settings to your postgresql.conf:
shared_preload_libraries = 'pgraft' # Core cluster configuration pgraft.cluster_id = 'production-cluster' pgraft.node_id = 1 pgraft.address = '127.0.0.1' pgraft.port = 7001 pgraft.data_dir = '/var/lib/postgresql/pgraft' # Consensus settings (optional, these are defaults) pgraft.election_timeout = 1000 # milliseconds pgraft.heartbeat_interval = 100 # milliseconds pgraft.snapshot_interval = 10000 # entries pgraft.max_log_entries = 1000 # compaction threshold Configuration Tips
node_idmust be unique for each node (1, 2, 3, ...)cluster_idmust be the same for all nodes in the clusterportis for Raft communication (not PostgreSQL port)
Step 2: Restart PostgreSQL¶
Step 3: Initialize pgraft¶
Connect to PostgreSQL and create the extension:
Step 4: Set Up Additional Nodes¶
Repeat steps 1-3 on other nodes with different node_id values:
Node 2 (postgresql.conf):
Node 3 (postgresql.conf):
Step 5: Add Nodes to Cluster¶
Leader Only
Node addition must be performed only on the leader node.
Wait 10 seconds for leader election, then check which node is the leader:
-- Check if current node is leader SELECT pgraft_is_leader(); -- Get leader ID SELECT pgraft_get_leader(); On the leader node, add the other nodes:
Step 6: Verify Cluster Status¶
On any node, check the cluster status:
-- Get cluster status SELECT * FROM pgraft_get_cluster_status(); -- Get all nodes SELECT * FROM pgraft_get_nodes(); -- Check worker status SELECT pgraft_get_worker_state(); Expected Output
Quick Health Check¶
Run this query to quickly verify your cluster is healthy:
SELECT pgraft_is_leader() as is_leader, pgraft_get_term() as term, pgraft_get_leader() as leader_id, pgraft_get_worker_state() as worker; Success
You now have a working pgraft cluster with automatic leader election and log replication!
Next Steps¶
- Learn more about configuration options
- Follow the complete tutorial
- Understand the architecture
- Learn about automatic replication
Using the Test Harness¶
For testing and development, use the included test harness: