What's Actually Happening

Patroni switchover fails to promote new primary. Database remains on old primary or cluster becomes unavailable.

The Error You'll See

```bash $ patronictl switchover

Error: Switchover failed: no healthy replica available ```

Why This Happens

  1. 1.No healthy replica
  2. 2.DCS unavailable
  3. 3.Replication lag too high
  4. 4.Node not in sync
  5. 5.Configuration conflict

Step 1: Check Cluster Status

bash
patronictl list
patronictl topology

Step 2: Check DCS Status

bash
# For etcd:
etcdctl endpoint health
# For Consul:
consul members

Step 3: Check Replication Lag

bash
psql -U postgres -c "SELECT client_addr, state, sync_state, replay_lag FROM pg_stat_replication;"

Step 4: Check Replica Health

bash
patronictl list
# All replicas should show "running" state

Step 5: Check Logs

bash
journalctl -u patroni -f
tail -f /var/log/patroni.log

Step 6: Fix Replication Issues

bash
# On replica:
patronictl reinit mycluster replica-node

Step 7: Manual Switchover

bash
patronictl switchover --force --master old-primary --candidate new-primary

Step 8: Check PostgreSQL

bash
systemctl status postgresql
psql -U postgres -c "SELECT pg_is_in_recovery();"

Step 9: Restart Patroni

bash
systemctl restart patroni

Step 10: Verify After Switchover

bash
patronictl list
psql -U postgres -c "SELECT pg_is_in_recovery();"
  • [Fix Patroni Cluster No Leader](/articles/fix-patroni-cluster-no-leader)
  • [Fix PostgreSQL Streaming Replication Lag](/articles/fix-postgresql-streaming-replication-lag)