db2

Finding Lock waits in DB2

DB2 is  a little tough on its locking mechanism.  IBM says  DB2 V9.7 has improved a lot on this area, I haven’t had a chance to test it rigorously , so I have to take the word for it.

With DB2 V9.5 and lower, I have experienced lot of  application on lock wait on NS and S locks. This has been frustrating when there are application that just wont release the locks from a reads and other application would require an X lock.   I wrote a script that will take a snapshot on lock waits everytime is run and also will notify (email or page) when an application is on lock wait for more than 5 minutes.

You need to create a table to store the snapshot information  that can be used for investigative purpose.  The DDL for the table is as follows ;

create table dba.snap_lockwait
(
SNAPSHOT_TIMESTAMP  TIMESTAMP,
DB_NAME  VARCHAR (128) ,
AGENT_ID bigint,
APPL_NAME varchar(256)  ,
AUTHID VARCHAR (128),
TBSP_NAME VARCHAR (128),
TABSCHEMA   VARCHAR (128),
TABNAME      VARCHAR (128),
SUBSECTION_NUMBER   bigint,
LOCK_OBJECT_TYPE varchar(18),
LOCK_WAIT_START_TIME   TIMESTAMP ,
LOCK_NAME varchar(32),
LOCK_MODE      varchar(10),
LOCK_MODE_REQUESTED  varchar(10),
AGENT_ID_HOLDING_LK bigint,
APPL_ID_HOLDING_LK  VARCHAR (128),
LOCK_ESCALATION  SMALLINT,
DBPARTITIONNUM    SMALLINT
)

The script that does the job is  find_lockwait.txt .   I have it running on a crontab every 2 mins.

Like I always say,  ensure that the script is safe to run on your environment and use due dilegence.   If you have any comments or questions regarding this please let me know.