Hands-on guide series
PostgreSQL Replication and HA: A Hands-On Guide
A five-part, hands-on guide to PostgreSQL high availability on a single VPS: streaming replication, synchronous replication and slots, failover and promotion with pg_rewind, connection routing with PgBouncer, and point-in-time recovery. Every command tested on a live Ubuntu 24.04 server running two clusters.
What you will build
Security is layers, not a switch. Each part closes a different category of attack, from the automated sweep that finds a brand-new server, to the day one gets in anyway. Read them in order, or jump to what you need.
- 1
Streaming Replication: A Live StandbySet up PostgreSQL streaming replication on Ubuntu 24.04: clone a standby with pg_basebackup, then prove a real row crosses from the primary to the standby.9 min - 2
Synchronous Replication and SlotsCreate a PostgreSQL replication slot, then switch a commit to synchronous replication and watch it wait for the standby before it confirms the write.7 min - 3
Failover and PromotionPerform a PostgreSQL failover on a live server: promote the standby, watch the timeline bump, then rewind the diverged old primary with pg_rewind.7 min - 4
Connection Routing with PgBouncerPostgreSQL connection routing with PgBouncer: send writes to the primary and reads to the standby over pooled connections, proven with the pool stats.6 min - 5
Backups and Point-in-Time RecoverySet up PostgreSQL point-in-time recovery with WAL archiving, then restore to a chosen second and prove one row is present and a later one is gone.7 min