← Lessons

quiz vs the machine

Silver1090

Databases

The Slow Query Log

The slow query log records statements that cross a time threshold, giving real examples with parameters to investigate.

4 min read · intro · beat Silver to climb

What It Captures

The slow query log writes an entry for every statement whose execution exceeds a configured threshold, often with the duration, the full text, and the actual parameters used. Where aggregate stats show you a normalized query, the slow log shows a real offending instance you can replay.

Setting the Threshold

  • Too low a threshold floods the log and adds logging overhead to every request.
  • Too high a threshold misses the moderately slow queries that add up.
  • Start with a threshold above normal latency, then lower it as you fix the worst cases.

Using It Well

  • Pair the slow log with statistics views for ranking; use the log to grab a concrete example with parameters.
  • Reproduce a logged statement under EXPLAIN ANALYZE to see why it was slow.
  • Watch for spikes in slow log volume as an early warning of regression or a load shift.

A Caution

The threshold is on a single statement's time, so it can miss a fast query run a million times. Combine it with cumulative stats so neither blind spot is left uncovered.

Key idea

The slow query log records real statements that cross a time threshold, giving concrete examples to replay, but pair it with cumulative stats to catch fast queries run very often.

Check yourself

Answer to earn rating on the learn ladder.

1. What does the slow query log capture?

2. What blind spot does the slow query log have?