{"id":1964849,"date":"2025-04-08T17:22:10","date_gmt":"2025-04-08T21:22:10","guid":{"rendered":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/?p=1964849"},"modified":"2025-04-24T14:41:30","modified_gmt":"2025-04-24T18:41:30","slug":"how-to-find-and-share-slow-database-queries-in-wordpress","status":"publish","type":"post","link":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/how-to-find-and-share-slow-database-queries-in-wordpress\/","title":{"rendered":"How to find and share slow database queries in WordPress"},"content":{"rendered":"<figure class=\"wp-block-post-featured-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"1024\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2025\/04\/wordpress-database.png\" class=\"attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" style=\"object-fit:cover;\" srcset=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2025\/04\/wordpress-database.png 1536w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2025\/04\/wordpress-database-300x200.png 300w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2025\/04\/wordpress-database-1024x683.png 1024w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2025\/04\/wordpress-database-768x512.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/figure>\n\n\n<p>When your WordPress site feels slow, it\u2019s often challenging to know <em>why<\/em> it&#8217;s happening.<\/p>\n\n\n\n<p>When experiencing performance issues with plugins or themes, such as slowness when loading calendar views, saving events, or interacting with tickets, it&#8217;s important to identify what&#8217;s happening under the hood.<\/p>\n\n\n\n<p>This article explains <strong>two effective tools<\/strong> to identify slow queries:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>A quick, real-time option using the <strong>Query Monitor plugin<\/strong><\/li>\n\n\n\n<li>A deeper, long-term option using the <strong>MySQL Slow Query log<\/strong><\/li>\n<\/ol>\n\n\n\n<p>Both can help you and our support team pinpoint what&#8217;s causing performance issues.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-why-the-debug-log-isn-t-enough\">Why the debug.log isn\u2019t enough?<\/h2>\n\n\n\n<p>The <em><a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/how-to-enable-debugging-in-wordpress\/\" target=\"_blank\" rel=\"noreferrer noopener\">debug.log<\/a><\/em> file in WordPress only shows <strong>PHP-related errors, warnings, and notices<\/strong>. It doesn&#8217;t record how long a database query took to run. So if your site feels slow, it&#8217;s time to check the database performance too, and not only PHP errors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-option-1-query-monitor-plugin\">Option 1: Query Monitor Plugin<\/h2>\n\n\n\n<p><a href=\"https:\/\/wordpress.org\/plugins\/query-monitor\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Query Monitor<\/strong><\/a> is a free plugin that lets you inspect database queries during <strong>a single page load<\/strong> \u2014 great for quick diagnostics and identifying what\u2019s slowing a specific request. This plugin gives you real-time information on a page-by-page basis.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-what-it-shows\">What it Shows<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>All database queries run on the page<\/li>\n\n\n\n<li>Execution time for each query<\/li>\n\n\n\n<li>Which plugin, theme, or core function triggered the query<\/li>\n\n\n\n<li>Repeated or duplicated queries<\/li>\n\n\n\n<li>HTTP calls, hooks, PHP errors, and more<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-how-to-use-it\">How to Use It<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install from <strong>Plugins &gt; Add New<\/strong> \u2192 search for &#8220;Query Monitor&#8221;, and activate it<\/li>\n\n\n\n<li>While still logged on your admin account, visit the slow page (calendar view, single event, etc.)<\/li>\n\n\n\n<li>Look for the <strong>\u201cQuery Monitor\u201d<\/strong> item in the admin bar<\/li>\n\n\n\n<li>Click the Query Monitor Button (1 in the image below) and open <strong>\u201cDatabase Queries\u201d<\/strong> (2 in the image below)<\/li>\n\n\n\n<li>Look for slow queries and note the execution <strong>time<\/strong> and source (you can filter by <strong>component<\/strong> if you want to check requests from one specific plugin)<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"2560\" height=\"1373\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2025\/04\/query-monitor-scaled.jpg\" alt=\"\" class=\"wp-image-1964851\" srcset=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2025\/04\/query-monitor-scaled.jpg 2560w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2025\/04\/query-monitor-300x161.jpg 300w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2025\/04\/query-monitor-1024x549.jpg 1024w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2025\/04\/query-monitor-768x412.jpg 768w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2025\/04\/query-monitor-1536x824.jpg 1536w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2025\/04\/query-monitor-2048x1098.jpg 2048w\" sizes=\"auto, (max-width: 2560px) 100vw, 2560px\" \/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">\ud83e\udde0 <strong>Reminder:<\/strong> Query Monitor only captures queries from the <span style=\"text-decoration: underline;\">current<\/span> page load. If you navigate away or refresh, the data resets.<\/pre>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-when-to-use-query-monitor\">When to use Query Monitor<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Use Case<\/th><th>Should You Use It?<\/th><\/tr><\/thead><tbody><tr><td>You want a quick test on a single page<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>You want to know which plugin runs a query<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>You want to investigate AJAX or admin pages<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>You need historical data or logging across time<\/td><td>\u274c No \u2014 use Slow Query Log<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-after-testing\">After Testing<\/h3>\n\n\n\n<p>For performance and security, we recommend deactivating Query Monitor once you\u2019ve completed testing, especially on production sites.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-what-to-share-with-our-support-team\">What to Share With Our Support Team<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Gather slow query data (from Query Monitor or the slow log) and share screenshots <\/li>\n\n\n\n<li>Let us know what page URL(s) you were testing<\/li>\n\n\n\n<li>Share your <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/sharing-your-system-information\/\" target=\"_blank\" rel=\"noreferrer noopener\">system information<\/a>, <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/how-to-enable-debugging-in-wordpress\/\" target=\"_blank\" rel=\"noreferrer noopener\">debug log<\/a> files (so we can have more data about your environment), and the name of your hosting service<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-option-2-mysql-slow-query-log\">Option 2: MySQL Slow Query Log<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-what-is-a-slow-query-log\">What Is a Slow Query Log?<\/h3>\n\n\n\n<p>While the Query Monitor plugin is ideal for quick checks, it doesn\u2019t keep historical data. If you\u2019re trying to diagnose recurring slowness or understand what\u2019s happening over time, the best option is the <strong>MySQL slow query log<\/strong>. This log is a <a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.4\/en\/slow-query-log.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">feature of a MySQL database server<\/a>. <\/p>\n\n\n\n<p>The <strong>MySQL slow query log<\/strong> records SQL statements that take longer than a specified time to execute. These queries might:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Search large tables without indexes<\/li>\n\n\n\n<li>Join multiple tables inefficiently<\/li>\n\n\n\n<li>Run multiple times per request (e.g., in a loop)<\/li>\n<\/ul>\n\n\n\n<p>Slow queries can severely impact your site\u2019s speed, and they often originate from plugins, themes, or custom code.<\/p>\n\n\n\n<p>WordPress itself can\u2019t enable the MySQL slow query log. It must be configured at the server level. Here\u2019s how to enable the log depending on your hosting environment:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Shared or Managed Hosting (Ask Your Host)<\/h3>\n\n\n\n<p>Most shared and managed WordPress hosts (like WP Engine, SiteGround, Kinsta, or Bluehost) don\u2019t allow direct server access, but they can usually enable the slow query log for you.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-what-to-ask\">What to Ask:<\/h4>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u201cCan you enable the MySQL slow query log for my site? I\u2019d like to log queries that take longer than 1 second to execute.\u201d<\/p>\n<\/blockquote>\n\n\n\n<p>Optionally, you can include these specifications in your request:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>long_query_time = 1<\/li>\n\n\n\n<li>log_output = FILE<\/li>\n\n\n\n<li>Access to download the slow query log file<\/li>\n<\/ul>\n\n\n\n<p>Once enabled, you should reproduce the slowness by visiting the slow page, and ask your host to send you the new log entries (or download the log if they shared how to do it).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-advanced-enable-manually-on-vps-or-dedicated-hosting\">Advanced: Enable Manually on VPS or Dedicated Hosting<\/h3>\n\n\n\n<p>If you have SSH\/root access to the server, you can enable it yourself:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n-- MySQL CLI:\nSET GLOBAL slow_query_log = &#039;ON&#039;;\nSET GLOBAL slow_query_log_file = &#039;\/var\/log\/mysql-slow.log&#039;;\nSET GLOBAL long_query_time = 1;\nSET GLOBAL log_queries_not_using_indexes = ON;\n<\/pre><\/div>\n\n\n<p>To make it permanent, edit your MySQL config (<code>my.cnf<\/code> or <code>my.ini<\/code>):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n&#x5B;mysqld]\nslow_query_log = 1\nslow_query_log_file = \/var\/log\/mysql-slow.log\nlong_query_time = 1\nlog_queries_not_using_indexes = 1\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">\u26a0\ufe0f Requires administrative access and caution \u2014 improper edits may break your server.<\/pre>\n\n\n\n<p>Also, note that some dedicated hosts may already have it defaulted to enabled, so check with their support team first if they provided that.<\/p>\n\n\n\n<p>For example, if you\u2019re hosted on WP Engine, their system already captures slow queries and labels them as <strong><a href=\"https:\/\/wpengine.com\/support\/troubleshoot-wordpress-wp-engine-error-log\/#error_LONG_QUERY\">LONG QUERY<\/a><\/strong> in their error logs, and also provides a <a href=\"https:\/\/wpengine.com\/blog\/introducing-slow-query-monitor\/\" target=\"_blank\" rel=\"noreferrer noopener\">Slow Query Monitor<\/a> on their dashboard.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-what-to-share-with-our-support-team-0\">What to Share With Our Support Team<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The slow log file<\/li>\n\n\n\n<li>Share your <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/sharing-your-system-information\/\" target=\"_blank\" rel=\"noreferrer noopener\">system information<\/a>, <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/how-to-enable-debugging-in-wordpress\/\" target=\"_blank\" rel=\"noreferrer noopener\">debug log<\/a> files (so we can have more data about your environment), and the name of your hosting service<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-summary-which-method-should-you-use\">Summary: Which Method Should You Use?<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Scenario<\/th><th>Use Query Monitor<\/th><th>Use Slow Query Log<\/th><\/tr><\/thead><tbody><tr><td>Quick test of a single page<\/td><td>\u2705 Yes<\/td><td>\u274c No<\/td><\/tr><tr><td>Long-term slowness tracking<\/td><td>\u274c No<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Repeated database slowness<\/td><td>\u274c No<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Finding which plugin runs a query<\/td><td>\u2705 Yes<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Production site performance debug<\/td><td>\u26a0\ufe0f Short-term only<\/td><td>\u2705 Best option<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-learn-more\">Learn More<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a class=\"\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.4\/en\/slow-query-log.html\">MySQL Docs \u2013 The Slow Query Log<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/wordpress.org\/plugins\/query-monitor\/\">Query Monitor Plugin (WordPress.org)<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>When your WordPress site feels slow, it\u2019s often challenging to know why it&#8217;s happening. When experiencing performance issues with plugins or themes, such as slowness when loading calendar views, saving events, or interacting with tickets, it&#8217;s important to identify what&#8217;s happening under the hood. This article explains two effective tools to identify slow queries: Both&#8230;<\/p>\n","protected":false},"author":31,"featured_media":1964858,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_swpsp_post_exclude":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"ep_exclude_from_search":false,"footnotes":""},"categories":[93],"tags":[57],"stellar-product-taxonomy":[],"class_list":["post-1964849","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-errors","tag-performance"],"acf":[],"taxonomy_info":{"category":[{"value":93,"label":"Troubleshooting"}],"post_tag":[{"value":57,"label":"Performance"}]},"featured_image_src_large":["https:\/\/images.theeventscalendar.com\/kb\/uploads\/2025\/04\/wordpress-database-1024x683.png",1024,683,true],"author_info":{"display_name":"Guga Alves","author_link":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/author\/gugatheeventscalendar-com\/"},"comment_info":0,"category_info":[{"term_id":93,"name":"Troubleshooting","slug":"errors","term_group":0,"term_taxonomy_id":93,"taxonomy":"category","description":"","parent":0,"count":67,"filter":"raw","term_order":"0","cat_ID":93,"category_count":67,"category_description":"","cat_name":"Troubleshooting","category_nicename":"errors","category_parent":0}],"tag_info":[{"term_id":57,"name":"Performance","slug":"performance","term_group":0,"term_taxonomy_id":57,"taxonomy":"post_tag","description":"Learn all about how you can optimize your calendar's performance with The Events Calendar with these Knowledgebase articles.","parent":0,"count":25,"filter":"raw","term_order":"0"}],"_links":{"self":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1964849","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=1964849"}],"version-history":[{"count":6,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1964849\/revisions"}],"predecessor-version":[{"id":1964961,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1964849\/revisions\/1964961"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media\/1964858"}],"wp:attachment":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=1964849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=1964849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=1964849"},{"taxonomy":"stellar-product-taxonomy","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/stellar-product-taxonomy?post=1964849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}