WIUNIX ACADEMY
PostgreSQL with Patroni: replication, quorum and safe switchover
Page 6 of 6. Review the earlier steps and prerequisites before continuing.
YOUR SYSTEM. YOUR STEPS.
Where are you working?
Choose your OS and version. The prerequisites, commands and troubleshooting follow your environment.
USE YOUR OWN VALUES
Configure this tutorial
Set the example values for your environment; related explanations and copy panels update together. Never enter passwords, private keys or tokens. Values stay in this tab and are not sent to the server or share links. Check actual DNS, certificates and network policy before running commands.
Different IP addresses, domains or ports? Open the settings below, change the values and select “Apply to tutorial”, then copy the updated commands.
Set values for my environment11 editable values
Keep divergent data before attempting rejoin
For a former primary, first isolate client writes and retain a private snapshot/copy of its stopped data and required WAL. Identify the authoritative timeline using healthy cluster evidence and the business recovery decision. pg_rewind modifies the target and may discard its divergent transactions; it needs checksums or wal_log_hints plus required WAL and full_page_writes. This lab initializes checksums. The two remove_data_directory flags remain false so failure does not silently delete data. Do not run reinit, delete the DCS prefix, rerun initdb, or overwrite a nonempty target. If rewind cannot safely work, keep the original and restore/clone into a separately approved empty destination. Rejoin as standby, check both markers/LSN, then consider a later planned switchover; failback is not an automatic overwrite of the old primary.
LET’S BUILD
Stop the lab without deleting evidence
Stop writers first. On all three VMs stop the dedicated Patroni unit, then the dedicated etcd unit. Do not stop or unmask vendor units on a host with other services. No deletion command is supplied. Retain data/config/logs privately until the recovery review is finished; configs contain passwords and keys remain protected. These units were not enabled for boot; boot persistence and reboot behavior are not tested. For production, resolve fencing, off-host backup/PITR, endpoint routing, TLS rotation, resource/storage monitoring and OS-specific lifecycle tests before enabling anything.
Disposable database VM; Bash as administrator
sudo systemctl stop academy-pg-patroni.service
sudo systemctl stop academy-pg-etcd.service
sudo systemctl is-active academy-pg-patroni.service academy-pg-etcd.service || true
sudo ss -lntup
Only lab-owned services stopped; data, keys and configs retained privately.
GO TO THE SOURCE
Official references
Each environment states how it was reviewed. A documentation review does not claim a hands-on test of every version.
- PostgreSQL18 release notes
- Ubuntu PGDG packages
- Debian PGDG packages
- Physical streaming replication and slots
- Client certificate verification
- Host authentication rules
- PITR and continuous archiving
- pg_rewind requirements and risks
- Patroni replication modes
- Patroni YAML configuration
- Patroni security
- Watchdog and split brain
- etcd 3.7.3 release
- etcd transport security
- etcd clustering
- etcd authentication
- Ubuntu Python versions
- Patroni package and isolated pip installation
- PostgreSQL RPM repository
- Arch PostgreSQL package
- Manjaro package synchronization
- firewalld rich rules
KEEP LEARNING