Don’t enable SAVEQUEIRES in production WordPress sites

One of the common ways to debug DB queries in WordPress is to enable SAVEQUERIES, which keeps track of all the DB queries that are executed in WordPress, together with other information like how long it took for the query to execute, what are the functions that called it etc and stores in the global array variable $wpdb->queries.

While this is a great way to debug DB queries, this could be a huge issue on production sites.

Recently I was running a backend script in my development environment to selectively delete some posts from WordPress. Even though the code was simple and very less data was handled in each iteration, the script was running out of memory after about 100 queries.

After a couple of hours of debugging I found that SAVEQUEIRES was the culprit. Since it was enabled, WordPress was storing information about each query that got executed which quickly added up, which let to PHP running out of memory. And that’s when I realized that having SAVEQUERIES enabled could be a major performance issue.

So the tl;dr version is

Don’t ever enable SAVEQUEIRES in production sites. Also if you are doing any kind of data import/export in your development environment then disabling SAVEQUERIES, could really speed up things.

If you are using WP_Query you can find the SQL query generated by WordPress, instead of enabling it.

Also, remember that SAVEQUERIES is enabled by default in vip quickstart and by debugging plugins like Debug Bar.

Related posts

Tags: ,

0 Comments so far

Follow up comments through RSS Feed | Post a comment

You are the first one to start the discussion.

Leave a Reply

Your email address will not be published. Required fields are marked *