Rebuild a broken replica with Patroni (reinit)
PostgreSQLPatroniCommand
# Wipe the replica's PGDATA and rebuild it (create_replica_methods: pgbackrest/basebackup):
patronictl -c /etc/patroni/patroni.yml reinit <cluster> <member> --wait --force
# Take the basebackup directly from the leader instead of the backup repository:
patronictl -c /etc/patroni/patroni.yml reinit <cluster> <member> --from-leader --wait --forceWhat it does
Deletes the specified replica's data directory and rebuilds it from scratch according to Patroni's create_replica_methods (pgBackRest restore or pg_basebackup).
When to use it
When a replica cannot rejoin replication due to a timeline mismatch, failed pg_rewind, missing WAL or data corruption.
Caution
All local data on the member is deleted; double-check that the command targets the right member (Patroni refuses reinit on the leader). On large databases this can take hours and adds I/O/network load on the leader; the cluster runs one replica short meanwhile. --from-leader exists only in recent Patroni 4.x releases (check with patronictl reinit --help); it skips create_replica_methods and takes a pg_basebackup from the leader.
Related
- Show Patroni cluster status, topology and history
- Perform a planned switchover with Patroni
- Perform a manual failover with Patroni
- Change cluster-wide parameters in Patroni (edit-config) and apply pending restarts
- Put Patroni into maintenance mode and back (pause/resume)
- Check Patroni DCS (etcd/Consul) and REST API health