Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display all database queries made by Wordpress?

Using a method similar to the one described here, I can see the total number of queries being made in Wordpress when I load a page.

Now I'd like to display all database queries that are being made when a page loads. This would allow me to see who my biggest resource hogs are, without having to go through the process of elimination of all my plugins and theme scripts.

What would be the best way to display all database queries made by Wordpress?

like image 415
mattz Avatar asked Mar 18 '10 20:03

mattz


1 Answers

If you add define('SAVEQUERIES', true) to your configuration file, you can then list all the queries made for the current page by adding the following to your theme.

if (current_user_can('administrator')){
    global $wpdb;
    echo "<pre>";
    print_r($wpdb->queries);
    echo "</pre>";
}

See the documentation for more details: http://codex.wordpress.org/Editing_wp-config.php#Save_queries_for_analysis

like image 169
Richard M Avatar answered Oct 14 '22 14:10

Richard M