日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

【DB2】监控动态SQL语句

發布時間:2023/12/19 综合教程 31 生活家
生活随笔 收集整理的這篇文章主要介紹了 【DB2】监控动态SQL语句 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、db2監控動態SQL(快照監控

db2示例用戶登陸后,使用腳本語句db2 get snapshot for all on dbname>snap.out

也可以使用db2 get snapshot for dynamic SQL on dbname>snap.out,此語句是只記錄上一語句中的部分

Tips:如果需要監控盡可能多的SQL語句,建議增加DBM配置參數


以下是動態SQL快照

Dynamic SQL Snapshot Result

 Database name                      = QINDB

 Database path                      = /db2home/db2inst1/db2inst1/NODE0000/SQL00002/
 Number of executions               = 3 --編譯次數,為累加值
 Number of compilations             = 1 --SQL語句編譯的最長時間
 Worst preparation time (ms)        = 87
 Best preparation time (ms)         = 87
 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     = Not Collected
 Buffer pool data physical reads    = Not Collected
 Buffer pool temporary data logical reads   = Not Collected
 Buffer pool temporary data physical reads  = Not Collected
 Buffer pool index logical reads    = Not Collected
 Buffer pool index physical reads   = Not Collected
 Buffer pool temporary index logical reads  = Not Collected
 Buffer pool temporary index physical reads = Not Collected
 Buffer pool xda logical reads      = Not Collected
 Buffer pool xda physical reads     = Not Collected
 Buffer pool temporary xda logical reads    = Not Collected
 Buffer pool temporary xda physical reads   = Not Collected
 Total execution time (sec.microsec)= Not Collected --SQL語句的總執行時間
 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 * from len.cust_info where cust_id like '%09' --SQL語句文本

Number of executetions:可以幫助找到最優的那些重要語句,它對于幫助計算語句的平均執行時間也很有用。

Rows read :可以幫助識別讀取行數最多的動態SQL語句,如果讀取行數最多,通常意味著進行全表掃描。

Total execution time:是將語句每次執行時間加起來得到的總時間,我們可以利用該時間除以Number of executrtions,可以得到平均執行時間。如果語句的平均執行時間很長,可能是因為表掃描或者出現鎖等待。

基于上述使用語句db2 get snapshot for all on dbname生成的文本內容,我們可以使用grep對快照的輸出內容執行搜索

例如:

<1> 識別是否存在死鎖

grep -n "Deadlocks detected" snap.out |grep -v "= 0" |more

<2> 搜索執行最頻繁的SQL語句

grep -n "Number of executions" snap.out | grep -v "= 0" | sort -k 6rn |more

<3> 查詢總的執行時間

 grep -n "Total execution time" snap.out | grep -v "= 0.0"| sort -k 6nr| more

二、監控動態SQL(db2top)

使用db2top命令找出最頻繁、最耗時的SQL(使用db2數據庫用戶登錄)

db2top –d dbname

按D,進入到SQL監控界面(如果沒開大寫,可以使用shift+d)

按z,倒序排序

輸入排序列的序號,從0開始

按L,輸入SQL的序列號,查看SQL明細

以下為示例操作:

(1)db2inst1@Linux:/qinys> db2top -d qindb


(2)按D進入


(3)按z倒序排序,此處我輸入3,表示按照執行時間排序

(4)按L輸入SQL序列號,查看SQL詳細

從上圖我們就可以查看SQL詳細了

總結

以上是生活随笔為你收集整理的【DB2】监控动态SQL语句的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。