Skip to main content
SRE

MySQL

MySQL slow queries

warning

Overview

What does this alert mean?

The rate of slow queries (exceeding long_query_time) is elevated.

Contributing factors

  • Missing indexes on frequently queried columns
  • Full table scans on large tables
  • Lock contention from long-running transactions
  • Inefficient query patterns after a schema or data volume change

Affected components

  • Application services making database queries
  • InnoDB buffer pool (cache thrashing from full scans)

Expected action

Identify the slow queries using the slow query log or EXPLAIN, then add indexes or rewrite the query.

Services

Metrics

Metric

mysql_global_status_slow_queries

Description & unit

Cumulative counter of queries exceeding long_query_time. mysqld_exporter wraps this in rate().

Unit: queries per second

Threshold rationale

Any sustained rate above 0 indicates queries exceeding the configured slow query threshold.

Normal behavior

Should be 0 or near-0 in a well-tuned database.

Screenshots

Dashboard when slow query rate is elevated
Dashboard when slow query rate is elevated
Dashboard after slow queries return to baseline
Dashboard after slow queries return to baseline

Alert Behavior

Silencing

Silence during batch jobs or ETL runs that are expected to run slow queries.

Expected frequency

Occasional — often follows schema changes, data growth, or missing index after a new feature deploy.

Severities

Severity guidance

Warning severity. Escalate if slow queries are causing connection pile-up or user-visible latency.

Impacted users

Users of services making the slow queries.

Things to check to determine severity

  • Was there a recent schema change or new feature deploy?
  • Has the data volume grown significantly?
  • Is lock contention visible in SHOW PROCESSLIST?

Verification

Prometheus query

rate(mysql_global_status_slow_queries[5m]) > 0

Dashboards

  • MySQL Query Performance — Fill in: dashboard URL

Log queries

  • MySQL slow query log — Fill in: log query URL

Troubleshooting

Steps

  1. 1Enable slow query log if not active: SET GLOBAL slow_query_log = 1; SET GLOBAL long_query_time = 1;
  2. 2Tail the slow query log: /var/log/mysql/slow.log
  3. 3Digest with pt-query-digest: pt-query-digest /var/log/mysql/slow.log | head -100
  4. 4For the top queries, run EXPLAIN: EXPLAIN SELECT ...
  5. 5Look for type=ALL (full scan) in the EXPLAIN output — add an index on the filtered column

Useful commands

SET GLOBAL slow_query_log = 1;SET GLOBAL long_query_time = 1;pt-query-digest /var/log/mysql/slow.log | head -100

Possible Resolutions

  • Missing index on a foreign key column. Adding the index dropped slow query rate to zero.

Dependencies

  • Application query patterns
  • InnoDB buffer pool sizing

Escalation

Guidance

Escalate if slow queries are causing thread pile-up or end-user latency alerts.

Slack channels

  • #database-oncall — Fill in: channel URL

Definitions

Alert rule

Fill in: link to the alert rule in _data/rules.yml on GitHub

Tuning notes

If this fires too often for acceptable batch workloads, increase long_query_time rather than raising the alert threshold.

Related Links

Template adapted from https://runbooks.gitlab.com/template-alert-playbook/