Query Monitor on a WordPress site that takes 4 seconds to render an admin page will list 800 queries. The natural reaction is to assume the database is the problem — but five of those queries account for 80% of the time, and Query Monitor will tell you which five if you read the right columns. This article is the read-it-correctly guide that turns Query Monitor’s output into a prioritized fix list.
What’s happening
Query Monitor is a free WordPress plugin that intercepts every database query made during a request and surfaces them in an admin bar dropdown. By default it shows total query count and time, but the deeper panels (Queries by Caller, Queries by Component, Slowest Queries, Duplicate Queries) are where the diagnosis lives.
WordPress query problems fall into three categories:
- Many small queries: a plugin or theme that calls
get_post_metainside a loop withoutupdate_meta_cacheproduces N+1 queries. Fix is bulk-prefetching. - One slow query: a missing index on
wp_postmeta,wp_options, orwp_actionscheduler_actions. Fix is adding the index. - Repeated identical queries: the same query runs 50 times in one request because nothing caches the result. Fix is either WordPress object cache or a function-level memoization.
How to verify
Install Query Monitor and reproduce the slow request as a logged-in admin:
wp plugin install query-monitor --activate
Open the admin bar dropdown. The relevant panels:
- Queries → Queries by Component: which plugin or theme is responsible for the most query time. The top entry is usually the culprit.
- Queries → Queries by Caller: which function called the query. Useful when the component is “Core” but the query came from a specific plugin’s hook.
- Queries → Slowest Queries: the literal slowest queries by duration. A query above 50 ms is worth investigating; above 200 ms is a clear fix target.
- Queries → Duplicate Queries: identical queries run multiple times. Each duplicate is a missed caching opportunity.
For continuous monitoring on production without Query Monitor enabled, use MySQL slow log:
# /etc/mysql/mysql.conf.d/slow.cnf
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 0.5
log_queries_not_using_indexes = 1
Then mysqldumpslow -s t /var/log/mysql/slow.log | head -20 to find the worst offenders.
The fix
- For many small
get_post_metaqueries in a loop: prefetch withupdate_meta_cache('post', $post_ids)before the loop. WordPress will pull all meta for the listed IDs in one query, and subsequentget_post_metacalls will hit the in-memory cache. - For slow queries on
wp_postmeta: add the standard composite index if missing.ALTER TABLE wp_postmeta ADD INDEX meta_key_value (meta_key(191), meta_value(191)). The 191-character prefix is required for utf8mb4 collations. - For slow queries on
wp_optionswithautoload='yes': an oversized autoloaded option is the cause.SELECT option_name, length(option_value) FROM wp_options WHERE autoload='yes' ORDER BY length(option_value) DESC LIMIT 20. Anything over 100 KB should beautoload='no'. - For repeated identical queries: enable an external object cache (Redis), then verify the affected query is using the cache. Some plugins query the database directly via
$wpdband bypassWP_Object_Cache— those need a plugin patch or a wrapping cache. - For Action Scheduler slow queries: the
wp_actionscheduler_actionstable needs maintenance. Runwp action-scheduler cleanweekly and add the composite indexes recommended in the Action Scheduler README. - For WooCommerce slow product queries: enable HPOS (High-Performance Order Storage) if not already on. Audit metadata that should be a database column on the orders table.
Re-measure with Query Monitor after each fix to verify the query count and time dropped. Do not move to the next fix until the previous one is confirmed.
Stack Harbor runs WordPress database audits across enterprise WordPress support accounts and maintains the index and option-autoload hygiene continuously. If your admin pages take more than 3 seconds to load, book a database review.