**When:** During a pre-defined DBA maintenance windows
**Affected wikis:**: https://noc.wikimedia.org/conf/highlight.php?file=dblists/s4.dblist
**Checklist:**
NEW primary: db2179
OLD primary: db2240
[*] Check configuration differences between new and old primary:
```
sudo pt-config-diff --defaults-file /root/.my.cnf h=db2240.codfw.wmnet h=db2179.codfw.wmnet
```
**Failover prep:**
[*] Silence alerts on all hosts:
```
sudo cookbook sre.hosts.downtime --hours 1 -r "Primary switchover s4 T397163" 'A:db-section-s4'
```
[*] Set NEW primary with weight 0
```
sudo dbctl instance db2179 set-weight 0
sudo dbctl config commit -m "Set db2179 with weight 0 T397163"
```
[*] Depool NEW from any specific group (API, vslow, dump) if present.
```
sudo dbctl instance db2179 edit
# If some changes were made:
sudo dbctl config commit -m "Remove db2179 from API/vslow/dump T397163"
```
[*] Topology changes, move all replicas under NEW primary
```
sudo db-switchover --timeout=25 --replicating-master --read-only-master --only-slave-move db2240 db2179
```
[*] Disable puppet on both nodes
```
sudo cumin 'db2240* or db2179*' 'disable-puppet "primary switchover T397163"'
```
[*] Merge gerrit puppet change to promote NEW primary: FIXME
**Failover:**
[] Log the failover:
```
!log Starting s4 codfw failover from db2240 to db2179 - T397163
```
[*] Switch primaries:
```
sudo db-switchover --replicating-master --read-only-master --skip-slave-move db2240 db2179
echo "===== db2240 (OLD)"; sudo db-mysql db2240 -e 'show slave status\G'
echo "===== db2179 (NEW)"; sudo db-mysql db2179 -e 'show slave status\G'
```
[*] Promote NEW primary in dbctl
```
sudo dbctl --scope codfw section s4 set-master db2179
sudo dbctl config commit -m "Promote db2179 to s4 primary T397163"
```
[*] Clean up heartbeat table(s).
```
sudo db-mysql db2179 heartbeat -e "delete from heartbeat where file like 'db2240%';"
```
[*] Restart puppet on both hosts:
```
sudo cumin 'db2240* or db2179*' 'run-puppet-agent -e "primary switchover T397163"'
```
**Clean up tasks:**
[*] change events for query killer:
```
curl -sS 'https://gerrit.wikimedia.org/r/plugins/gitiles/operations/software/+/refs/heads/master/dbtools/events_coredb_master.sql?format=TEXT' | base64 -d | sudo db-mysql db2179
curl -sS 'https://gerrit.wikimedia.org/r/plugins/gitiles/operations/software/+/refs/heads/master/dbtools/events_coredb_slave.sql?format=TEXT' | base64 -d | sudo db-mysql db2240
```
[*] Update candidate primary dbctl and orchestrator notes
```
sudo dbctl instance db2240 set-candidate-master --section s4 true
sudo dbctl instance db2179 set-candidate-master --section s4 false
sudo cumin 'dborch*' 'orchestrator-client -c untag -i db2179 --tag name=candidate'
sudo cumin 'dborch*' 'orchestrator-client -c tag -i db2240 --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 db1215 zarcillo -e "select * from masters where section = 's4';"
```
[] (If needed): Depool db2240 for maintenance.
```
sudo dbctl instance db2240 depool
sudo dbctl config commit -m "Depool db2240 T397163"
```
[] Change db2240 weight to mimic the previous weight db2179 (main/api/vslow/dumps):
```
sudo dbctl instance db2240 edit
```
[*] Apply outstanding schema changes to db2240 (if any)
[*] Update/resolve this ticket.