Perform a planned switchover with Patroni
PostgreSQLPatroniCommand
# 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> switchoverWhat 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.
Related
- Show Patroni cluster status, topology and history
- Perform a manual failover with Patroni
- Rebuild a broken replica with Patroni (reinit)
- 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