一、db2監控動態sql(快照監控)
db2示例使用者登陸後,使用指令碼語句db2 get snapshot for all ondbname>snap.out
也可以使用db2 get snapshot for dynamic sql ondbname>snap.out,此語句是只記錄上一語句中的部分
tips:如果需要監控盡可能多的sql語句,建議增加dbm配置引數
以下是動態sql快照
dynamic sql snapshot resultnumber of executetions:可以幫助找到最優的那些重要語句,它對於幫助計算語句的平均執行時間也很有用。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語句文字
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 –ddbname
按d,進入到sql監控介面(如果沒開大寫,可以使用shift+d)
按z,倒序排序
輸入排序列的序號,從0開始
按l,輸入sql的序列號,檢視sql明細
以下為示例操作:
(2)按d進入
(3)按z倒序排序,此處我輸入3,表示按照執行時間排序
(4)按l輸入sql序列號,檢視sql詳細
從上圖我們就可以檢視sql詳細了
跟蹤DB2的sql語句
查到了以下資料 修改一下db zhang的建議.db2 update monitor switches using bufferpool lock sort statement table timestamp uow on是基於程序 除此之外還可以更改dbm引數 會影響效能 dft mon bufp...
DB2 用到的基本SQL語句
匯出某個資料庫中的user表的資料 export to e date user.ixf of ixf messages e date user.out select from db2admin.user匯入到某個庫中user表的資料 首先建立同樣的一張user表,然後進行匯入 import from...
Oracle和DB2的SQL語句區別
1 取前n條記錄 oracle select from tablename where rownum n db2 select from tablename fetch first n rows only 2 取得系統日期 oracle select sysdate from dual db2 se...