DBAtlas · Database operations atlas

Perform a planned switchover with Patroni

PostgreSQLPatroni

Command

# Immediate switchover without confirmation:
patronictl -c /etc/patroni/patroni.yml switchover <cluster> --leader <leader_member> --candidate <member> --force
# Scheduled switchover (ISO 8601 timestamp with time zone):
patronictl -c /etc/patroni/patroni.yml switchover <cluster> --leader <leader_member> --candidate <member> --scheduled '2026-10-10T02:00:00+03:00' --force
# Cancel a pending scheduled switchover:
patronictl -c /etc/patroni/patroni.yml flush <cluster> switchover

What it does

Demotes the healthy leader in a controlled way and promotes the chosen replica (--candidate); the former leader automatically rejoins as a replica of the new leader. --scheduled defers the operation to the given time.

When to use it

To move the primary to another node before maintenance (OS patching, hardware replacement, minor version upgrade) or to restore the original roles after a failover.

Caution

All connections drop when the leader changes; the application must be able to reconnect. Patroni rejects the switchover if the candidate's lag exceeds maximum_lag_on_failover. With synchronous_mode enabled the candidate must be a synchronous standby.

Open in DBAtlas →

Related