You are browsing a read-only backup copy of Wikitech. The live site can be found at

MariaDB/Rebooting a host

From Wikitech-static
< MariaDB
Revision as of 11:10, 1 November 2021 by imported>Kormat (→‎After boot: add PME starting)
Jump to navigation Jump to search

Clean shutdown

  1. First, get a list of instances on the host (see MariaDB/Multiinstance for details).
  2. Check if the host is used by mediawiki.
    sudo dbctl instance <instance> get
    # E.g. for single-instance host:
    #   sudo dbctl instance db1123 get
    # E.g. for multi-instance host:
    #  sudo dbctl instance db1102:3312 get
    #  sudo dbctl instance db1102:3313 get
    #  sudo dbctl instance db1102:3320 get
    If any of the instances are known to dbctl, then the host will need to be depooled if it's in an active DC, and repooled afterwards.
  3. Downtime the host in icinga for 1h.
    sudo cookbook sre.hosts.downtime --hours 1 -r "Rebooting dbXXXX TXXXXXX" '<fqdn>'
    If the host has any replicas, they will also need to be downtimed, to prevent replication alerts from firing.
  4. Stop mariadb instance(s) on the host
    # single-instance:
    sudo systemctl stop mariadb
    # multi-instance, for each section:
    sudo systemctl stop mariadb@<section>
    # E.g.:
    #  sudo systemctl stop mariadb@s2
    #  sudo systemctl stop mariadb@s3
    #  sudo systemctl stop mariadb@x1
  5. Unmount /srv and disable swap, and finally reboot the host
    sudo umount /srv
    sudo swapoff -a
    sudo reboot

After boot

On most production hosts, the mariadb instance or instances won't restart automatically. This is intended behavior to prevent a crashed host to be pooled automatically with corrupt data or lag, before its health can be manually checked.

After a clean reboot, you can start mariadb by running:

sudo systemctl start mariadb

or if it is a multi-instance host:

sudo systemctl start mariadb@<section1>
sudo systemctl start mariadb@<section2>

Where section is the sections that are setup on that particular server (m1, x1, etc.). Don't worry, only configured sections on puppet will start, others will fail to start if tried.

The prometheus mysql exporter also needs to be started:

# Single-instance:
sudo systemctl start promtheus-mysqld-exporter
# Multi-instance, per instance:
sudo systemctl start promtheus-mysqld-exporter@<section>

Replication should start automatically, which can be checked with:

sudo mysql -e "SHOW SLAVE STATUS"

(It should return IO thread running: Yes / SQL thread running: Yes)

If it is stopped and should be running, you can run:

sudo mysql -e "START SLAVE"

If the server or the instance crashed

  • depool the host from production, if possible (dbctl, haproxy, etc.). If it is not possible, weight the impact of availability vs the possibility of exposing bad or outdated data (e.g. cache db vs enwiki primary server)
  • determine the root cause of the crash with os logs (syslog), hw logs (mgmt interface), etc.
  • start the instance without replication starting automatically (systemctl set-environment MYSQLD_OPTS="--skip-slave-start")
  • start mariadb
  • check the error log journalctl -u mariadb (or mariadb@<section>)
  • do a table check comparing it to other host check (db-compare) to ensure all data is consistent between all servers of the same section
    • Most production hosts have a configuration that makes them be durable on crash (innodb_flush_log_at_trx_commit=1). However, not all kinds of crash can ensure consistency (e.g. HW RAID controller failure)
  • If the sever looks good, start replication and repool it into service

In all cases, including normal restarts

  • systemctl restart prometheus-mysqld-exporter should do the trick. prometheus-mysqld-exporter@<section> for multiinstance sections
  • We should try not to reboot primary db instances for obvious reasons, and switch its active primary status beforehand, but that is sometimes done not by choice!

    This page is a part of the SRE Data Persistence technical documentation
    (go here for a list of all our pages)