【详细信息】
1. 首先要打开DBMS监控开关和快照开关:
db2 update dbm cfg using DFT_MON_LOCK on DFT_MON_STMT on
db2 update monitor switches using lock on buffpool on sort on uow on table on statement on
2. 获取锁相关的快照信息:
db2 get snapshot for database on <dbname> |grep -i lock
Locks held currently = 346
Lock waits = 257
Time database waited on locks (ms) = 0
Lock list memory in use (Bytes) = 147136
Deadlocks detected = 5
Lock escalations = 0
Exclusive lock escalations = 0
Agents currently waiting on locks = 0
Lock Timeouts = 0
Block IOs = Not Collected
Pages from block IOs = Not Collected
Internal rollbacks due to deadlock = 4
Number of MDC table blocks pending cleanup = 0
Memory Pool Type = Lock Manager Heap
3. 如果存在锁等待或者死锁,找到锁的信息:
db2pd -db <dbname> -locks showlocks wait
Address TranHdl Lockname Type Mode Sts Owner Dur HoldCount Att ReleaseFlg
6.通过占有锁的agentid找出引起锁等待的SQL和客户端进程
db2 get snapshot for application agentid 20687
Application handle = 20687
Application status = UOW Waiting
Status change time = 01/30/2011 16:44:31.200616
Application code page = 1386
Application country/region code = 1
DUOW correlation token = *LOCAL.xxx.110130082456
Application name = db2bp
Application ID = *LOCAL.xxx.110130082456
Sequence number = 00002
Dynamic SQL statement text:
update xxxdb.tbl_xxx_trans_log1_1 set trans_st='10000' where sys_tra_no='004918'
7. 关闭快照监控和DBMS监控开关
db2 update monitor switches using lock off buffpool off uow off sort off table off statement off
db2 update dbm cfg using DFT_MON_LOCK off DFT_MON_STMT off