DBAtlas · Database operations atlas

Rebuild a broken replica with Patroni (reinit)

PostgreSQLPatroni

Command

# 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 --force

What 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.

Open in DBAtlas →

Related