WP Debug Toolkit 1.2.0 is LIVE. Get $300 discount on the lifetime deal now
Use Discount Code WPDTLTD
Get WP Debug Toolkit

Navigate to WP Debug Toolkit › Overview › Database Queries and click Record, set a duration, and click Start Recording. Reproduce the slow page load once while the recording is active. Afterward, open the Viewer App and go to Database Queries to read the results. Slow queries carry a red SLOW badge, N+1 patterns carry an ⚠ N+1 badge, and each query shows the plugin, theme, or WordPress core component that generated it. Hover over any flagged query and click View file to open the responsible code in the File Viewer. Query logs are written to disk as encrypted log files, so recording adds no database overhead to the system being analyzed.

What You’re Diagnosing

When a page loads slowly and the WordPress error log shows nothing, database queries are the most common culprit. A single poorly-indexed query can add seconds to a page load. 

A loop-based query pattern, one where code asks the database for one record per iteration rather than fetching all at once, can multiply database work silently on every request without triggering any visible error.

WPDT’s Database Monitor and File Viewer address this as a paired workflow. The Database Monitor records every SQL query that runs during a page load, annotates each one with execution time and component attribution, and automatically flags slow queries and N+1 patterns. 

The File Viewer connects any flagged query directly to the PHP code that generated it. This lets you see which function called it and on which line. 

This guide walks you from a slow page load to the exact line of code responsible for it.

Tools Used in This Guide

WPDT ToolRole in This Guide
Database Monitor (Query Logger)Records every SQL query during a request and includes timing, component attribution, and automatic detection of slow queries and N+1 patterns, so you can see exactly what is happening in the database
File ViewerProvides code context for any flagged query, showing the PHP file and the surrounding lines that generated it

Before You Begin

This guide assumes you have the following in place before you start diagnosing:

  • WP Debug Toolkit Pro installed and active
  • The slow page or action reproducible on demand. Query recording or Always Log Queries mode must be active before you trigger it, as queries cannot be captured retroactively
  • Enhanced Query Logging mode enabled for component attribution and stack trace data. WPDT automatically enables this when you start a recording session (or enable Always Log Queries) and installs the db.php drop-in as part of that process, without any manual step.

Note: If a non-WPDT db.php file already exists in wp-content/, WPDT will not overwrite it. Component attribution and stack traces will not appear until the conflicting file is removed.

Walkthrough: Diagnosing Slow Database Queries

Phase 1: Start a Recording Session

A recording session captures all database queries during a specific time window. Start it immediately before you reproduce the slow behavior.

Navigate to WP Debug Toolkit in the WordPress admin sidebar. The Overview tab opens by default. The Database Queries section is visible on that page without expanding anything. When no recording is active, the Record button sits on the right side of the Database Queries section header. Click it to open the Record Queries dialog.

In the dialog, set a Recording duration between 1 and 3,600 seconds. 60 seconds is sufficient for diagnosing a specific page load. You can also add an optional Recording tag to label the session, for example, checkout-slow, which makes it easier to filter results afterward. Click Start Recording (the button shows the formatted duration, for example Start Recording (1m)).

When the recording starts, WPDT automatically enables SAVEQUERIES and Enhanced Query Logging. The db.php drop-in is installed at this point, which intercepts queries at the WordPress database layer and captures a full stack trace for each one.

✅ What You Should See: The Record button is replaced by a countdown timer showing the remaining recording time alongside a small stop icon in the Database Queries section header, confirming the recording is active.

wp-debug-toolkit-query-recording

Phase 2: Reproduce the Slow Request

Load the slow page, trigger the slow admin action, or perform the operation that produces the slow behavior. Reproduce it exactly once during the recording window. A second reproduction in the same window mixes its queries into the log alongside the first. This makes it harder to isolate the source of the slowness.

Once you have triggered the slow behavior, either wait for the recording timer to expire or click the stop icon in the Database Queries section header to end the session immediately.

✅ What You Should See: The countdown timer disappears and the Record button returns to the Database Queries section header, confirming the recording has ended and the query log has been written to disk.

Phase 3: Read the Analysis and Trace to Source

Open the Viewer App and navigate to Database Queries in the sidebar (keyboard shortcut: M). The view displays every query captured during the recording window, each showing its execution time, SQL type, component, and any problem flags. Slow query rows have a red background tint to draw immediate attention.

Click Filters (shortcut: F) to open the filter panel, then use the toggles to narrow the view:

  • Click Slow (shortcut: 4) to show only queries that exceeded your slow-query threshold.
  • Click N+1 (shortcut: 6) to show only queries flagged as part of a repeating loop pattern.

If you used a Recording tag, click the Recording filter (shortcut: 7) to isolate queries from your specific session.

wp-debug-toolkit-viewer-app-slow-queries

🔀 Decision Point

  • If you see queries with a red SLOW badge: these are slow queries; each one exceeded your configured slow-query threshold (50ms by default). Note the component shown on the row, which identifies the plugin, theme, or WordPress core component that generated the query. Hover over the row to reveal the View file button and open the query’s origin in the File Viewer. A slow individual query most often points to a missing database index or a JOIN across an unindexed column.
  • If you see queries with an ⚠ N+1 badge: this is a loop-based query problem. WPDT flags a query as a potential N+1 pattern when the exact same SQL string (same text, same values) fires five or more times within a single request. The badge shows the repetition count. Note the component to identify the responsible plugin or theme, then use the File Viewer to find the template or function calling the database inside a loop. The fix is typically a single batch query replacing the loop, or WordPress object caching to avoid repeat calls.

After identifying which category your problem falls into, hover over the flagged query row. A View file button appears alongside a Copy SQL button. Click View file (or press Q) to open that query’s origin in the File Viewer.

✅ What You Should See: The File Viewer displays the PHP file responsible for the query, with the specific line highlighted and surrounding code visible in context. The Component label in the detail panel confirms the plugin, theme, or core file that owns the code.

wp-debug-toolkit-file-viewer-slow-query-file-path

Frequently Asked Questions

Will the Query Logger slow down my production site while it’s recording?

Recording writes query data to disk as encrypted log files rather than storing anything in the database, so the act of logging adds no database overhead to the system being analyzed. There is a separate consideration, though: once the db.php drop-in is installed, it instruments every query on every page load, not only during an active recording, so there is some CPU overhead while the drop-in is in place. That overhead is gone entirely once you turn off query logging and remove the drop-in. For most sites this is negligible, but on very high-traffic pages, keep recordings short and avoid leaving Always Log Queries on indefinitely.

I can see a slow query but don’t recognize the SQL. How do I find out which plugin wrote it?

The component shown on each query row identifies the originating plugin, theme, or WordPress core component directly from the backtrace. If the component shows a plugin name, that plugin’s code generated the query. Hover over the row and click View file to open the specific file and line in the File Viewer.

Related Documentation

Slow Query, N+1, and Duplicate Detection – Explains exactly how WPDT identifies each query problem type, including how the slow-query threshold is calculated, what triggers an N+1 flag, and how duplicates are fingerprinted.

Recording WordPress Database Queries – Takes you through the full recording workflow: starting a session, stopping it early, using the countdown timer, and reading the results.

How to Debug WordPress – Start here if slow database queries turn out not to be the cause. This guide routes you to the right diagnostic tool for whatever you are seeing.

On this page
Try WP Debug Toolkit
The best error log viewer with amazing developer tools to help you troubleshoot your WordPress site securely and efficiently. Something something more.