Monday, January 5, 2009

The new way to do show processlist

We all know and love the show processlist command to see what our queries are doing.

However, most of the show commands are being deprecated in favor of new information_schema virtual tables. (I believe the technical term is actually "system view".)

The new information_schema equivalent of show processlist is:

select * from information_schema.processlist \G

*************************** 1. row ***************************
     ID: 259584
   USER: readonly
   HOST: 192.168.0.186:44761
     DB: bln
COMMAND: Query
   TIME: 222
  STATE: Writing to net
   INFO: SELECT /*!40001 SQL_NO_CACHE */ * FROM `person5`
*************************** 2. row ***************************
     ID: 259468
   USER: readonly
   HOST: 192.168.0.108:43492
     DB: bln
COMMAND: Query
   TIME: 0
  STATE: executing
   INFO: select * from information_schema.processlist

The ID column appears to be the connection_id of the thread that is running the query.

The advantage of this method is that we can filter the results with a where clause, like so:

select * from information_schema.processlist where command <> 'Sleep' and id <> connection_id();

which will show only those queries that are not in sleep mode and excludes the current process.

No comments: