Start from the SYSIBMADM.MON_LOCKWAITS view.
If you need more info on participating applications, you may use the monitoring table functions which this view is based on directly:
MON_GET_APPL_LOCKWAIT
MON_GET_CONNECTION
SELECT
-- locked table
CASE WHEN L.TBSP_ID > 0 THEN T.TABSCHEMA ELSE S.TABSCHEMA END AS TABSCHEMA
, CASE WHEN L.TBSP_ID > 0 THEN T.TABNAME ELSE S.TABNAME END AS TABNAME
, CASE WHEN L.TBSP_ID > 0 THEN T.DATA_PARTITION_ID ELSE -1 END AS DATA_PARTITION_ID
--, L.* -- lock info
, H.CLIENT_HOSTNAME -- holder connection info
, HC.STMT_TEXT AS HLD_STMT_TEXT_CURR -- holder's currently executing statement
, HL.STMT_TEXT AS HLD_STMT_TEXT_LAST -- holder's last executed statement
, R.CLIENT_HOSTNAME -- requester connection info
, RC.STMT_TEXT AS REQ_STMT_TEXT_CURR -- requester's current statement
FROM TABLE (MON_GET_APPL_LOCKWAIT (NULL, -2)) L
LEFT JOIN TABLE (MON_GET_TABLE (NULL, NULL, L.HLD_MEMBER)) T ON T.TBSP_ID = L.TBSP_ID AND T.TAB_FILE_ID = L.TAB_FILE_ID
LEFT JOIN SYSCAT.TABLES S ON S.TBSPACEID = L.TBSP_ID AND S.TABLEID = L.TAB_FILE_ID
-- Holder's info
LEFT JOIN TABLE (MON_GET_CONNECTION (L.HLD_APPLICATION_HANDLE, L.HLD_MEMBER)) H ON 1=1
LEFT JOIN TABLE (MON_GET_ACTIVITY (L.HLD_APPLICATION_HANDLE, L.HLD_MEMBER)) HC ON 1=1
LEFT JOIN TABLE (MON_GET_UNIT_OF_WORK (L.HLD_APPLICATION_HANDLE, L.HLD_MEMBER)) HU ON 1=1
LEFT JOIN TABLE (MON_GET_PKG_CACHE_STMT (NULL, HU.LAST_EXECUTABLE_ID, NULL, L.HLD_MEMBER)) HL ON 1=1
-- Requester's info
LEFT JOIN TABLE (MON_GET_CONNECTION (L.REQ_APPLICATION_HANDLE, L.REQ_MEMBER)) R ON 1=1
LEFT JOIN TABLE (MON_GET_PKG_CACHE_STMT (NULL, L.REQ_EXECUTABLE_ID, NULL, L.REQ_MEMBER)) RC ON 1=1
Notes:
- You can't get the statement placed the lock, which requester is waiting on. There is no explicit binding between a lock and a statement placed this lock in Db2. You may get a current statement (if any) and the last completed statement for a holder as above. None of these statements may place this lock.
- You can't get parameter values for all returned statements with the query above.
What you can do to get more information on the lock wait / timeout event is to create an event monitor for locking - some kind of "logger" for lockwait, locktimeout, deadlock events. The corresponding information is written to database tables created for this monitor. Refer to the Information written to tables for a locking event monitor topic. The amount of data you get in these tables depend on setting of the database configuration parameter:
Lock timeout events (MON_LOCKTIMEOUT) = HIST_AND_VALUES
Deadlock events (MON_DEADLOCK) = HIST_AND_VALUES
Lock wait events (MON_LOCKWAIT) = HIST_AND_VALUES
Lock wait event threshold (MON_LW_THRESH) = 5000000
For example, if you set these parameters as above, very detailed information (including all statement parameter values) on all 3 types of events (lockwait event will be generated, if the requester waits more than 5 seconds) will be written to the event monitor tables.
If you have such an active event monitor and MON_DEADLOCK = HISTORY
at least, you have an additional activity to whole transaction history for all applications currently having open transactions with db2pd -apinfo -db mydb
being run on the server.