1. 使用性能视图
相关视图如下:
sysibmadm.snapappl
sysibmadm.snapappl_info
sysibmadm.lockwaits
获取锁升级、死锁和锁超时
select substr(ai.appl_name,1,10) as application ,
substr(ai.primary_auth_id,1,10) as authid,
int(ap.locks_held) as locks_held,
int(ap.lock_escals) as lock_escals,
int(ap.lock_timeouts) as lock_timeouts,
int(ap.deadlocks) as deadlocks,
int(ap.int_deadlock_rollbacks) as int_deadlock_rollbacks,
substr(inbound_comm_address,1,15) as address
from sysibmadm.snapappl ap,sysibmadm.snapappl_info ai
where ap.agent_id = ai.agent_id;
监控锁等待时间(定位是否存在严重锁等待)
select substr(ai.appl_name,1,20) as appl_name ,
substr(ai.primary_auth_id,1,10) as auth_id,
ap.lock_waits,ap.lock_wait_time/1000 as total_waits,
(ap.lock_wait_time/ap.lock_waits) as avg_waits
from sysibmadm.snapappl_info ai,sysibmadm.snapappl ap
where ai.agent_id = ap.agent_id and ap.lock_waits > 0;
监控LOCK CHAIN(定位谁持有锁,谁在锁等待)
select substr(ai_h.appl_name,1,10) as hold_app,
substr(ai_h.primary_auth_id,1,10) as holder,
substr(lw.appl_name,1,10) as wait_app,
substr(lw.authid,1,10) as waiter,
lw.lock_mode,
lw.lock_object_type,
substr(lw.tabname,1,20) as tabname,
substr(lw.tabschema,1,10) as schema,
timestampdiff(2,char(lw.snapshot_timestamp-lw.lock_wait_start_time)) as waiting_time
from sysibmadm.lockwaits lw,sysibmadm.snapappl_info ai_h
where lw.agent_id_holding_lk = ai_h.agent_id;
2. 使用DB2TOP查看
执行命令DB2TOP –d [dbname]后输入d(database)查看数据库信息:
看LockUsed(锁使用)、LockEscals(锁升级)和Lock Wait(锁等待数量),如果LockEscals数量很大时,则增加LOCKLIST和MAXLOCKS数据库参数是一个好主意或者寻找那些引起这个问题的不良查询语句。
输入l(session)查看是否有session状态是否为lock waiting,在此界面中使用“←”查看锁等待的时间(Lockwait(sec))
输入U(Lock)查看锁信息,同样可以使用“←”键来查看具体情况以确定锁等待相关的agent是哪些,输入L(Lock Chain)查看锁链信息(id1→id2表示id2在等待id1的完成)
在Lock界面输入a后输入agentid可以查看具体SQL语句,输入e可以获取该SQL的执行计划。
3. 待补充
参考材料:
DB2常用监控语句:https://blog.csdn.net/cs_1436161885/article/details/78545728
DB2TOP介绍和使用:
http://www.bigdatalyn.com/2016/02/24/DB2-db2top/