**When:** Any time
** Prerequisites **: https://wikitech.wikimedia.org/wiki/MariaDB/Primary_switchover
**Checklist:**
NEW primary: es2024
OLD primary: es2023
[] Check configuration differences between new and old primary:
```
sudo pt-config-diff --defaults-file /root/.my.cnf h=es2023.codfw.wmnet h=es2024.codfw.wmnet
```
**Failover prep:**
[] Silence alerts on all hosts:
```
sudo cookbook sre.hosts.downtime --hours 1 -r "Primary switchover es5 T337204" 'A:db-section-es5'
```
[] Set NEW primary with weight 0 (and depool it from API or vslow/dump groups if it is present).
```
sudo dbctl instance es2024 set-weight 0
sudo dbctl config commit -m "Set es2024 with weight 0 T337204"
```
[] Topology changes, move all replicas under NEW primary
```
sudo db-switchover --read-only-master --replicating-master --timeout=25 --only-slave-move es2023 es2024
```
[] Disable puppet on both nodes
```
sudo cumin 'es2023* or es2024*' 'disable-puppet "primary switchover T337204"'
```
[] Merge gerrit puppet change to promote NEW primary: TODO
**Failover:**
[] Log the failover:
```
!log Starting es5 codfw failover from es2023 to es2024 - T337204
```
[] Switch primaries:
```
sudo db-switchover --read-only-master --replicating-master --skip-slave-move es2023 es2024
echo "===== es2023 (OLD)"; sudo db-mysql es2023 -e 'show slave status\G'
echo "===== es2024 (NEW)"; sudo db-mysql es2024 -e 'show slave status\G'
```
[] Promote NEW primary in dbctl, and remove read-only
```
sudo dbctl --scope codfw section es5 set-master es2024
sudo dbctl config commit -m "Promote es2024 to es5 primary and set section read-write T337204"
```
[] Restart puppet on both hosts:
```
sudo cumin 'es2023* or es2024*' 'run-puppet-agent -e "primary switchover T337204"'
```
**Clean up tasks:**
[] Clean up heartbeat table(s).
```
sudo db-mysql es2024 heartbeat -e "delete from heartbeat where file like 'es2023%';"
```
[] change events for query killer:
```
events_coredb_master.sql on the new primary es2024
events_coredb_slave.sql on the new slave es2023
```
[] Update candidate primary dbctl and orchestrator notes
```
sudo dbctl instance es2023 set-candidate-master --section es5 true
sudo dbctl instance es2024 set-candidate-master --section es5 false
(dborch1001): sudo orchestrator-client -c untag -i es2024 --tag name=candidate
(dborch1001): sudo orchestrator-client -c tag -i es2023 --tag name=candidate
```
[] Check zarcillo was updated
** db-switchover should do this. If it fails, do it manually: https://phabricator.wikimedia.org/P13956
```
sudo db-mysql db1115 zarcillo -e "select * from masters where section = 'es5';"
```
[] (If needed): Depool es2023 for maintenance.
```
sudo dbctl instance es2023 depool
sudo dbctl config commit -m "Depool es2023 T337204"
```
[] Change es2023 weight to mimic the previous weight es2024:
```
sudo dbctl instance es2023 edit
```
[] Update/resolve this ticket.