TIBCO LogLogic LMI - Suppress sleeping MySQL threads in SHOW PROCESSLIST
book
Article ID: KB0075693
calendar_today
Updated On:
Products
Versions
TIBCO LogLogic Log Management Intelligence
all versions
Description
One of the most useful MySQL troubleshooting tools is the command SHOW (FULL) PROCESSLIST. However, in many cases, you may find that what is returned is a long list of open threads, the vast majority of which are in the SLEEP state. These threads provide little useful information for troubleshooting purposes, and so we can suppress their output in the following ways described in the resolution below.
Issue/Introduction
This article shows a couple of ways in which you can run a SHOW (FULL) PROCESSLIST to hide sleeping connections.
Resolution
Firstly, we can use the pager command to pass the output of the SHOW (FULL) PROCESSLIST command to grep, where we can filter out the sleeping threads. We can do this with the following syntax:
pager grep -v Sleep
Note that the command character \P is functionally equivalent to pager, and so either can be used. Setting this pager changes the output of the SHOW (FULL) PROCESSLIST command from this:
mysql> pager grep -v Sleep PAGER set to 'grep -v Sleep' mysql> show full processlist; +---------+------+-----------------+--------------+---------+------+----------+-----------------------+ | Id | User | Host | db | Command | Time | State | Info | +---------+------+-----------------+--------------+---------+------+----------+-----------------------+ | 4108041 | root | localhost | logappconfig | Query | 0 | starting | show full processlist | +---------+------+-----------------+--------------+---------+------+----------+-----------------------+ 21 rows in set (0.00 sec)
Secondly, we can also get the same data from the information_schema.processlist table. As we can query this using standard SQL, we can write a query like this:
select * FROM information_schema.processlist WHERE command != 'Sleep' order by id;
This returns the following example output:
mysql> select * FROM information_schema.processlist WHERE command != 'Sleep' order by id; +---------+------+-----------+--------------+---------+------+-----------+-----------------------------------------------------------------------------------+ | ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO | +---------+------+-----------+--------------+---------+------+-----------+-----------------------------------------------------------------------------------+ | 4113216 | root | localhost | logappconfig | Query | 0 | executing | SELECT * FROM information_schema.processlist WHERE command != 'Sleep' ORDER BY id | +---------+------+-----------+--------------+---------+------+-----------+-----------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
As this is a standard SQL query, it is also possible to order the result set using any of the table columns by changing the column name in the ORDER BY clause.