vova21 Mar 2025 18:42

What is your workflow for working with the MySQL slow query log? We have it enabled with long_query_time=1 but the volume of logs makes it hard to process manually.

Tools, query aggregation, where to start?

Replies (6)
alex_petrov21 Mar 2025 19:02

pt-query-digest from Percona Toolkit is the standard tool. It aggregates slow query log entries by normalized query pattern and shows you the top offenders by total time, not just per-query time. Install it and run it on a day of logs, the output is actionable.

0
petr_sys21 Mar 2025 20:20

Lower long_query_time to 0.1 seconds on staging if you want to catch more queries. On production 0.5 is usually reasonable without flooding the log.

0
ivan_morozov21 Mar 2025 21:41

MySQLWorkbench has a built-in slow query analyzer that is easier for one-off investigations. pt-query-digest is better for automation.

0
vova21 Mar 2025 21:57

After you find the slow query, run EXPLAIN and look for full table scans (type = ALL) and high row counts in the Extra column. Those are your targets. Missing index or missing composite index covers most cases.

0
sergey_web21 Mar 2025 23:19

One thing people miss: queries that are fast individually but run 5000 times per minute. pt-query-digest sorts by total time which catches these. A 50ms query that runs 10k times is worse than a 2s query that runs once.

0
katedev22 Mar 2025 01:09

We use Datadog APM which captures slow queries automatically with query sampling. More expensive but you get correlation with request traces which makes root cause analysis much faster.

0