上一篇,咱們寫了如何獲取oracle的TOP SQL,sql
這一篇,咱們來看看如何獲取db2的TOP SQL。oracle
相比oracle,db2在國內顯得更小衆點,因此資料可能會相對少點,好在IBM的文檔整理的挺規範整齊的,仍是免費查閱的(若是你能找到),這點比Oracle要良心多了。ide
從我我的的使用經從來看的話,db2的性能並不輸oracle,很簡單的道理,db2能夠研究oracle而後改進再超越oracle,固然我要這麼下結論,等等可能會被口水淹死。性能
言歸正傳,下面介紹獲取db2 TOP SQL的方式,這裏不得不吐槽下db2,監控的方便性確實差oracle一大截。code
db2 update dbm cfg using DFT_MON_BUFPOOL ON DFT_MON_LOCK ON DFT_MON_SORT ON DFT_MON_STMT ON DFT_MON_TABLE ON DFT_MON_UOW ON
SELECT * FROM sysibmadm.long_running_sql WHERE STMT_TEXT IS NOT NULL ORDER BY elapsed_time_min DESC
select * from sysibmadm.mon_current_sql;
SELECT m. * , n.APPL_NAME , n.AUTHID , n.APPL_ID , n.APPL_STATUS , n.CLIENT_NNAME FROM (SELECT x.AGENT_ID , x.ROWS_READ , x.ROWS_WRITTEN , x.QUERY_COST_ESTIMATE , x.QUERY_CARD_ESTIMATE , x.TOTAL_SORT_TIME , x.STMT_START , x.STMT_ELAPSED_TIME_S , x.STMT_TEXT FROM SYSIBMADM.SNAPSTMT x WHERE STMT_TEXT IS NOT NULL AND x.STMT_STOP IS NULL) m LEFT JOIN SYSIBMADM.APPLICATIONS n ON m.AGENT_ID = n.AGENT_ID ORDER BY m.STMT_START --按照最先執行時間排序 --ORDER BY m.STMT_ELAPSED_TIME_S DESC --按照執行時間倒序排序)x
我通常都是用這句監控TOP SQL。排序
SELECT * FROM (SELECT A.NUM_EXECUTIONS , A.ROWS_READ , A.ROWS_READ / A.NUM_EXECUTIONS AS AVG_ROWS_READ , A.STMT_SORTS , A.SORT_OVERFLOWS , A.TOTAL_SORT_TIME , CASE WHEN A.STMT_SORTS>0 THEN A.TOTAL_SORT_TIME / A.STMT_SORTS ELSE NULL END AS AVG_SORT_TIME , A.TOTAL_EXEC_TIME , A.TOTAL_EXEC_TIME / A.NUM_EXECUTIONS AS AVG_EXEC_TIME , A.POOL_DATA_L_READS , A.POOL_DATA_P_READS , A.POOL_DATA_P_READS / A.NUM_EXECUTIONS AS AVG_POOL_DATA_P_READS , A.POOL_TEMP_DATA_L_READS , A.POOL_TEMP_DATA_P_READS , A.POOL_INDEX_L_READS , A.POOL_INDEX_P_READS , A.POOL_TEMP_INDEX_L_READS , A.POOL_TEMP_INDEX_P_READS , A.STMT_TEXT FROM sysibmadm.SNAPDYN_SQL A WHERE A.NUM_EXECUTIONS > 0)x ORDER BY AVG_EXEC_TIME DESC FETCH FIRST 100 ROWS ONLY ;
還有一種方式是用db2top監控,不過這種方式感受仍是沒有直接查SQL來得方便。文檔
db2相比oracle,在監控方面的友好型和多樣性上面確實差了不是一點點。
不過好在,也基本夠用。it