Skip to content

Quick Start

Deploy a resilient 3-node PostgreSQL HA cluster with L7 proxy and S3 backups in under 2 minutes.

Updated View as Markdown

PgVisor delivers production-ready PostgreSQL 18 High Availability (HA) without the operational complexity of Patroni, PgBouncer, Consul, and pgBackRest.

In this quick start guide, you will bootstrap a complete local 3-node HA cluster with automatic Raft consensus failover, continuous S3/MinIO backup archiving, and an embedded web dashboard.


Prerequisites

Before starting, ensure your system has:


One-Command Cluster Bootstrap

PgVisor includes a bootstrap script that orchestrates the entire cluster setup:

Clone and Navigate

Clone the PgVisor repository and change into the examples directory:

git clone https://github.com/dreamoutbox/pgvisor.git
cd pgvisor/examples

Run the Bootstrap Script

Execute setup.sh to initialize environment variables, start containers, and verify health checks:

./setup.sh

Verify Service Initialization

The bootstrap script automatically executes the following steps:

  1. Copies examples/.env.example to examples/.env if not already present.
  2. Starts MinIO object storage on port 9000 and provisions the pgvisor-backups bucket.
  3. Starts pgvisor-node1 as initial Raft Leader.
  4. Bootstraps pgvisor-node2 and pgvisor-node3 as streaming standby replicas.
  5. Starts pgvisor-proxy on port 5432 and the Web Dashboard on port 8080.
  6. Polls health endpoints until all nodes and services report ready.

Connecting to the Cluster

Applications and database clients connect directly to the PgVisor L7 Proxy on port 5432.

Using psql CLI

psql -h localhost -p 5432 -U postgres -d postgres

When prompted for password, enter postgres (default password configured in .env).

Application Connection String

Configure your application database pool or ORM with the standard PostgreSQL connection URI:

postgresql://postgres:postgres@localhost:5432/postgres

Transparent Read/Write Splitting

PgVisor’s L7 proxy inspects PostgreSQL 3.0 wire protocol messages in real time to provide automatic read/write splitting without application code changes:

  • Mutating Queries & DDL: Any INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, or explicit transaction block (BEGIN ... COMMIT) is forwarded strictly to the active Raft leader (pgvisor-node1).
  • Read Queries: Standalone SELECT, SHOW, and EXPLAIN statements are load-balanced across healthy standby replicas (pgvisor-node2, pgvisor-node3).

Try It Out

Connect with psql and execute a write followed by reads:

-- Creates table on the Raft leader
CREATE TABLE users (id serial PRIMARY KEY, username text);

-- Inserts record on the Raft leader
INSERT INTO users (username) VALUES ('alice'), ('bob');

-- Routed to a standby replica with connection pooling
SELECT * FROM users;

Testing Zero-Downtime Failover Buffering

PgVisor includes transparent failover query buffering. If the leader fails mid-flight, client connections do not crash; the proxy buffers requests in memory while OpenRaft elects and promotes a new leader.

Stop the Current Leader Node

In a separate terminal, stop pgvisor-node1:

docker compose -f examples/docker-compose.yml stop pgvisor-node1

Observe Consensus Election

The remaining nodes (pgvisor-node2 and pgvisor-node3) detect leader loss. Within 1,500ms, OpenRaft concludes an election, and the new leader is promoted via pg_ctl promote.

Query Continuously

Your active psql connection remains open and queries automatically route to the newly elected leader without connection resets:

INSERT INTO users (username) VALUES ('charlie');
SELECT * FROM users;

Management Commands

The setup.sh script provides lifecycle helpers:

# View all cluster logs
./setup.sh logs

# View logs for a specific container
./setup.sh logs pgvisor-proxy
./setup.sh logs pgvisor-node1
# Check health and container states
./setup.sh status
# Restart all containers
./setup.sh restart

# Stop cluster (volumes preserved)
./setup.sh down

# Wipe volumes and start clean
./setup.sh clean

Next Steps

Architecture

Learn how OpenRaft consensus, Quorum Lease fencing, and L7 proxying work under the hood.

Web Dashboard

Explore the embedded monitoring UI, manual switchover controls, and guarded SQL console.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close