IBM Db2 LUW: How to Monitor Database Locks and Lock Waits

A slow SAP transaction on Db2 may be waiting on another database session. Check current lock waits before assuming the issue is an expensive SQL statement. Db2 provides monitoring functions for both waiting applications and the locks held by sessions.

Display current lock waits

Connect to the affected Db2 database using an account with suitable monitoring privileges, then run:

SELECT LOCK_NAME, LOCK_STATUS,
       HLD_APPLICATION_HANDLE, HLD_MEMBER
FROM TABLE(MON_GET_APPL_LOCKWAIT(NULL, -2)) AS W;

The result identifies locks that applications are waiting to obtain and provides available information about the holder. The member argument -2 includes all active members.

Find the locks for a particular session

Replace 123 with the application handle identified during troubleshooting.

SELECT APPLICATION_HANDLE, MEMBER,
       LOCK_NAME, LOCK_STATUS
FROM TABLE(MON_GET_LOCKS(
  CLOB('<application_handle>123</application_handle>'), -2
)) AS L;

Review the holder and waiter together. G represents a granted lock; W or C indicates a wait or conversion. Compare with the database monitoring views in DBACOCKPIT and the corresponding SAP work process or background job.

If the lock has already disappeared, a current snapshot may return no records. Use the appropriate lock event monitoring or historical diagnostics for intermittent incidents. Do not force an application without assessing its active transaction, rollback and business impact.

References

SAP Note: 3790539

IBM Documentation: MON_GET_LOCKS

IBM Documentation: Monitoring locking using table functions

You May Also Like

Leave a Reply?