analyze debug queries output for wordpress

Some time back, my website became too slow and I started getting timeout response for quite a lot of my pages. When I analyzed things, I found the issue was with the DB queries taking a lot of time. So, I thought of getting my hands dirty and started with installing the plugin “Debug Queries”. Just in case, you don’t know about the plugin, it lists all the queries to DB along with the time taken for the query when a Admin user visits any page.

The output of the plugin is below the whole page and looks something like this:

45. Time: 0.0030910968780518
Query: SELECT * FROM <>  WHERE <>
Call from: require

Note: The list contains the actual complete query and also all the calls to the query. But as I had more than 40 odd queries, looking at .00 something time was tiresome to find the highest time. So, I copied this text into a text file called “test” and wrote this one line to get me the highest time.

sed -n '/.*Time:/ s/.*://p' test |sort -n

Once you have the time, simply search or grep for this values and you know the highest time taking query.

Enhanced by Zemanta

List all the rpms by size – quick way to find out what is eating your disk space in root partition

Here is a quick command to check the list of installed packages by their size in reverse order. Very useful if you want to remove unwanted rpms just to clean up some space on your disk:

rpm -q -a --qf "%10{SIZE}\t%{NAME}\n" | sort -k1,1nr |more

Sample output:

78070452    kernel
78060477    kernel
50708634    jre
50316408    libgcj
48581593    wireshark
47778643    gimp
47674675    jre
47303084    qt-x11
45838912    otrs
45657248    chromium-libs
42070128    wxPython

Execute mysql command from shell

phpMyAdmin is a very slow application if you want to execute a query on your database. If you know the name of the database then any GUI tool is an overhead. So I have written a one liner shell script to do that for me 🙂

Here\’s the script:

echo \”select * from table where field like \”%$1%\”\”|mysql -h -u amit -p -D amit -r –password=hello

When run with one argument it will execute the sql query directly without asking for password also.