db2查找执行次数最多的sql

用此方法同时能够得到cost最大的语句

--首先抓取snapshot
[db2inst2@localhost ~]$ db2 get snapshot for all on sample > snap.out

--根据执行次数排序
[db2inst2@localhost ~]$ grep -ni "number of executions" snap.out |grep -v "=0" |sort -k 6,6rn
846: Number of executions               = 306
1198: Number of executions               = 117
1038: Number of executions               = 43
654: Number of executions               = 43
814: Number of executions               = 43

--然后在vi可以根据行数找到具体的sql语句(vi  :line#)
Number of executions               = 306
 Number of compilations             = 1
 Worst preparation time (ms)        = 32
 Best preparation time (ms)         = 32
 Internal rows deleted              = Not Collected
 Internal rows inserted             = Not Collected
 Rows read                          = Not Collected
 Internal rows updated              = Not Collected
 Rows written                       = Not Collected
 Statement sorts                    = Not Collected
 Statement sort overflows           = Not Collected
 Total sort time                    = Not Collected
 Buffer pool data logical reads     = 0
 Buffer pool data physical reads    = 0
 Buffer pool temporary data logical reads   = 0
 Buffer pool temporary data physical reads  = 0
 Buffer pool index logical reads    = 0
 Buffer pool index physical reads   = 0
 Buffer pool temporary index logical reads  = 0
 Buffer pool temporary index physical reads = 0
 Buffer pool xda logical reads      = 0
 Buffer pool xda physical reads     = 0
 Buffer pool temporary xda logical reads    = 0
 Buffer pool temporary xda physical reads   = 0
 Total execution time (sec.microsec)= Not Collected
 Total user cpu time (sec.microsec) = Not Collected
 Total system cpu time (sec.microsec)= Not Collected
 Total statistic fabrication time (milliseconds) = Not Collected
 Total synchronous runstats time  (milliseconds) = Not Collected
 Statement text                     = SELECT CREATE_TIME FROM SYSTOOLS.HMON_ATM_INFO WHERE SCHEMA = ? AND NAME = ? FOR UPDATE

你可能感兴趣的:(sql,db2)