Using the Slow Query Log

July 3, 2026

Before you can fix what’s slow, you need to know which queries are slow and where they’re coming from. A page that takes four seconds to load is rarely slow for one obvious reason. It’s usually a handful of queries, often triggered by a plugin or theme you’d never have suspected, each adding a bit of delay. Guessing wastes your time. You want the evidence.

The Slow Query Log records any query that takes longer than a limit you set, measured in seconds. For each slow query it captures the SQL that ran and a stack trace showing which plugin or theme triggered it. That stack trace is the useful part, because it tells you not just that a query is slow but who’s responsible for it.

Set your threshold to suit the site. On a busy site you might start at one second to catch the worst offenders, then lower it as you clear them.

If a single table or query type is generating a lot of noise, you can optionally restrict logging to queries matching a pattern, for example a table name. That keeps the log focused on the problem you’re actually chasing rather than everything the site does.

There’s also a drop-in profiler option, which creates a wp-content/db.php symlink, for capturing timing on every query rather than only the slow ones. That’s for when you want the full picture.

One warning worth repeating: logging has its own performance cost. Recording queries and building stack traces isn’t free, so this isn’t something to leave running permanently. Use it to diagnose a problem, find your slow queries, then switch it off.

In short: the Slow Query Log is a diagnostic tool, not an optimisation in itself. It won’t make anything faster on its own. What it does is tell you exactly what to optimise, and where it’s coming from, so the fixes you make afterwards are the ones that count.

×
1/1