客户某个数据库突然锁超时增多.
通过分析db2locktimeout文件, 发现90%的locktimeout的原因都是因为Read Stability隔离级别导致的。
主要涉及的表:P_CUSTOM_ARCH_TABLE,P_CUSTOM_TABLE_ARCH_EXT,P_BUSI_QUERY,P_ALCMNG_PRO。
下面是对db2locktimeout.0.282904.2015-05-13-15-50-08文件的分析:
Cursor Stability:游标稳定性隔离级别(db2默认隔离级别), 只在记录扫描的时候获得行锁,离开后释放。
Read Stability:可重复读隔离级别(was默认隔离级别), 会一直持有扫描过的记录的锁, 直到事务结束。
以下SQL是持锁应用,因为采用的是RS隔离级别,SQL没有结束就一直持有行锁,当行锁数量超过了MAXLOCKS的限制,会发生锁升级, 正如db2diag.log记录的。
select count(*) from PL_PTRX.P_CUSTOM_ARCH_TABLE a left join PL_PTRX.P_CUSTOM_TABLE_ARCH_EXT c on a.tkiid=c.tkiid,PL_PTRX.P_BU
SI_QUERY b where a.p_piid=b.PIID and b.CLTNAM= ? and a.state= ?
2015-05-13-15.49.35.527820+480 E201222A543 LEVEL: Warning
PID : 17957114 TID : 263969 PROC : db2sysc 0
INSTANCE: XXXXX NODE : 000 DB : XXXXX
APPHDL : 0-44637 APPID: XXXXXXXXXX.61297.150513061717
AUTHID : SF_RPT
EDUID : 263969 EDUNAME: db2agent (XXXXX) 0
FUNCTION: DB2 UDB, data management, sqldEscalateLocks, probe:3
MESSAGE : ADM5502W The escalation of "95133" locks on table "PL_PTRX
.P_CUSTOM_ARCH_TABLE" to lock intent "S" was successful.
以下SQL是等锁应用, 等待P_CUSTOM_ARCH_TABLE表的IX锁, 但是IX和S锁不兼容,所以必须等待,因为持锁的SQL执行时间长,从而导致了锁超时。
insert into Pl_PTRX.P_CUSTOM_ARCH_TABLE( WIID,APP_NAME,TKIID,USER_ID,STATE,EVERYBODY,STAFF_TYPE,PIID,TASK_NAME,PARENT_TEMPL_NAM
E,DISPLAY_NAME,FIRST_ACTIVATION_TIME,LAST_MODIFIED_TIME,PROC_INS_STARTER,PROC_INS_START_TIME,PTID,TKTID,BUSS_NO,BUSS_ID,P_PIID) values(?,?,?,?,?,?,?,?,?,?,?,
?,?,?,?,?,?,?,?,?)
locktimeout文件信息:
db2locktimeout.0.282904.2015-05-13-15-50-08
Lock Information:
Lock Name: 0004024C000000000000000054
Lock Type: Table
Lock Specifics: Tablespace ID=4, Table ID=588
Lock Requestor:
System Auth ID: SF_RPT
Application Handle: [0-7071]
Application Name: db2jcc_application
Lock timeout Value: 30000 milliseconds
Lock mode requested: .IX
Context of Lock Request:
Identification: UOW ID (2956); Activity ID (9)
Activity Information:
Effective Isolation: Read Stability
Statement: insert into Pl_PTRX.P_CUSTOM_ARCH_TABLE( WIID,APP_NAME,TKIID,USER_ID,STATE,EVERYBODY,STAFF_TYPE,PIID,TASK_NAME,PARENT_TEMPL_NAM
E,DISPLAY_NAME,FIRST_ACTIVATION_TIME,LAST_MODIFIED_TIME,PROC_INS_STARTER,PROC_INS_START_TIME,PTID,TKTID,BUSS_NO,BUSS_ID,P_PIID) values(?,?,?,?,?,?,?,?,?,?,?,
?,?,?,?,?,?,?,?,?)
Lock Owner (Representative):
System Auth ID: SF_RPT
Application Handle: [0-44637]
Application Name: db2jcc_application
Lock mode held: ..S
List of Active SQL Statements:
Effective Isolation: Read Stability
Statement: select count(*) from PL_PTRX.P_CUSTOM_ARCH_TABLE a left join PL_PTRX.P_CUSTOM_TABLE_ARCH_EXT c on a.tkiid=c.tkiid,PL_PTRX.P_BU
SI_QUERY b where a.p_piid=b.PIID and b.CLTNAM= ? and a.state= ?