Documentationpgraft Documentation
Install pgRaft on PostgreSQL 16–18
Prerequisites
Before installing pgRaft, ensure you have:
- PostgreSQL 16, 17, or 18 installed with development headers
- Go toolchain 1.21+ available on PATH
- gcc/clang, make, and pkg-config installed on build host
- Ability to restart PostgreSQL after updating postgresql.conf
Run which pg_config to confirm it points to the target PostgreSQL installation before compiling.
Install system dependencies
Install PostgreSQL packages and build prerequisites on your operating system.
Ubuntu / Debian
Install packages
sudo apt-get update
sudo apt-get install -y postgresql-18 postgresql-server-dev-18 postgresql-contrib-18 golang-go build-essential pkg-configRHEL / Rocky / AlmaLinux
Install packages
sudo yum install -y postgresql18 postgresql18-devel postgresql18-contrib golang gcc make pkgconfigmacOS (Homebrew)
Install packages
brew install postgresql@18 go pkg-config
brew link --overwrite postgresql@18Clone repository and build
Compile the PostgreSQL extension plus the Go-based Raft worker library.
Build pgRaft binaries
Compile
git clone https://github.com/pgElephant/pgraft.git
cd pgraft
make clean && make
# Override PostgreSQL location as needed
# make clean && make PG_CONFIG=/path/to/pg_configExpected artifacts
Validate output
ls -lh ./dist
# pgraft.so (SQL extension)
# pgraft_go.so (embedded Raft worker)Install pgRaft into PostgreSQL
Install the compiled shared libraries and SQL files into PostgreSQL's extension directories.
make install
sudo make install
# Validate install directories
pg_config --libdir
ls -lh $(pg_config --libdir)/pgraft*Update postgresql.conf and restart
Load pgRaft at startup and define node identity for your cluster.
Configure Raft identity
postgresql.conf
shared_preload_libraries = 'pgraft'
# Node identity (adjust per node)
pgraft.cluster_id = 'production-cluster'
pgraft.node_id = 1
pgraft.address = '10.0.0.11'
pgraft.port = 7001
pgraft.data_dir = '/var/lib/postgresql/pgraft'
# Recommended WAL settings
synchronous_commit = on
wal_level = logical
max_wal_senders = 10Restart PostgreSQL
Apply configuration
sudo systemctl restart postgresql # systemd
# or
brew services restart postgresql@18 # macOSCreate extension and verify
Register pgRaft in your database, initialize metadata, and confirm worker health.
Enable pgRaft
Initialize node
CREATE EXTENSION pgraft;
SELECT pgraft_init();
SELECT extversion
FROM pg_extension
WHERE extname = 'pgraft';Verify worker state
Diagnostics
SELECT pgraft_is_leader() AS is_leader,
pgraft_get_term() AS current_term,
pgraft_get_worker_state() AS worker_state;
df+ pgraft_*Next Steps
- Cluster bootstrap - Promote the first leader and add followers to your Raft cluster.
- Configuration reference - Tune Raft timeouts, log retention, and networking once installation is complete.
- Troubleshooting playbooks - Resolve build failures, worker startup issues, and connectivity errors.