清單6. 鎖定超時報告
- LOCK TIMEOUT REPORT
- Date: 03/01/2008
- Time: 07:34:31
- Instance: DB2
- Database: SAMPLE
- Database Partition: 0
- Lock Information:
- Lock Name: 02000600040040010000000052
- Lock Type: Row
- Lock Specifics: Tablespace ID=2, Table ID=6, Row ID=x0400400100000000
- Lock Requestor:
- System Auth ID: FECHNER
- Application Handle: [0-38]
- Application ID: *LOCAL.DB2.080103063343
- Application Name: db2bp.exe
- Requesting Agent ID: 5232
- Coordinator Agent ID: 5232
- Coordinator Partition: 0
- Lock timeout Value: 10000 milliseconds
- Lock mode requested: ..U
- Application Status: (SQLM_UOWEXEC)
- Current Operation: (SQLM_EXECUTE_IMMEDIATE)
- Lock Escalation: No
- Context of Lock Request:
- Identification: UOW ID (1); Activity ID (1)
- Activity Information:
- Package Schema: (NULLID )
- Package Name: (SQLC2G13NULLID )
- Package Version: ()
- Section Entry Number: 203
- SQL Type: Dynamic
- Statement Type: DML, Insert/Update/Delete
- Effective Isolation: Cursor Stability
- Statement Unicode Flag: No
- Statement: UPDATE EMPLOYEE SET BONUS = SALARY * 0.1
- WHERE JOB = 'MANAGER'
- Lock Owner (Representative):
- System Auth ID: FECHNER
- Application Handle: [0-33]
- Application ID: *LOCAL.DB2.080103063332
- Application Name: db2bp.exe
- Requesting Agent ID: 5488
- Coordinator Agent ID: 5488
- Coordinator Partition: 0
- Lock mode held: ..X
- List of Active SQL Statements: Not available
- List of Inactive SQL Statements from current UOW: Not available
清單6. 鎖定超時報告
- LOCK TIMEOUT REPORT
- Date: 03/01/2008
- Time: 07:34:31
- Instance: DB2
- Database: SAMPLE
- Database Partition: 0
- Lock Information:
- Lock Name: 02000600040040010000000052
- Lock Type: Row
- Lock Specifics: Tablespace ID=2, Table ID=6, Row ID=x0400400100000000
- Lock Requestor:
- System Auth ID: FECHNER
- Application Handle: [0-38]
- Application ID: *LOCAL.DB2.080103063343
- Application Name: db2bp.exe
- Requesting Agent ID: 5232
- Coordinator Agent ID: 5232
- Coordinator Partition: 0
- Lock timeout Value: 10000 milliseconds
- Lock mode requested: ..U
- Application Status: (SQLM_UOWEXEC)
- Current Operation: (SQLM_EXECUTE_IMMEDIATE)
- Lock Escalation: No
- Context of Lock Request:
- Identification: UOW ID (1); Activity ID (1)
- Activity Information:
- Package Schema: (NULLID )
- Package Name: (SQLC2G13NULLID )
- Package Version: ()
- Section Entry Number: 203
- SQL Type: Dynamic
- Statement Type: DML, Insert/Update/Delete
- Effective Isolation: Cursor Stability
- Statement Unicode Flag: No
- Statement: UPDATE EMPLOYEE SET BONUS = SALARY * 0.1
- WHERE JOB = 'MANAGER'
- Lock Owner (Representative):
- System Auth ID: FECHNER
- Application Handle: [0-33]
- Application ID: *LOCAL.DB2.080103063332
- Application Name: db2bp.exe
- Requesting Agent ID: 5488
- Coordinator Agent ID: 5488
- Coordinator Partition: 0
- Lock mode held: ..X
- List of Active SQL Statements: Not available
- List of Inactive SQL Statements from current UOW: Not available
清單9. 包含 SQL 語句歷史信息的鎖定超時報告
- LOCK TIMEOUT REPORT
- Date: 03/01/2008
- Time: 15:10:13
- Instance: DB2
- Database: SAMPLE
- Database Partition: 0
- Lock Information:
- Lock Name: 02000600040040010000000052
- Lock Type: Row
- Lock Specifics: Tablespace ID=2, Table ID=6, Row ID=x0400400100000000
- Lock Requestor:
- System Auth ID: FECHNER
- Application Handle: [0-202]
- Application ID: *LOCAL.DB2.080103140934
- Application Name: db2bp.exe
- Requesting Agent ID: 2356
- Coordinator Agent ID: 2356
- Coordinator Partition: 0
- Lock timeout Value: 10000 milliseconds
- Lock mode requested: ..U
- Application Status: (SQLM_UOWEXEC)
- Current Operation: (SQLM_EXECUTE_IMMEDIATE)
- Lock Escalation: No
- Context of Lock Request:
- Identification: UOW ID (1); Activity ID (1)
- Activity Information:
- Package Schema: (NULLID )
- Package Name: (SQLC2G13NULLID )
- Package Version: ()
- Section Entry Number: 203
- SQL Type: Dynamic
- Statement Type: DML, Insert/Update/Delete
- Effective Isolation: Cursor Stability
- Statement Unicode Flag: No
- Statement: UPDATE EMPLOYEE SET BONUS = SALARY * 0.1
- WHERE JOB = 'MANAGER'
- Lock Owner (Representative):
- System Auth ID: FECHNER
- Application Handle: [0-188]
- Application ID: *LOCAL.DB2.080103140511
- Application Name: db2bp.exe
- Requesting Agent ID: 5488
- Coordinator Agent ID: 5488
- Coordinator Partition: 0
- Lock mode held: ..X
- List of Active SQL Statements: Not available
- List of Inactive SQL Statements from current UOW:
- Entry: #1
- Identification: UOW ID (6); Activity ID (2)
- Package Schema: (NULLID )
- Package Name: (SQLC2G13)
- Package Version: ()
- Section Entry Number: 201
- SQL Type: Dynamic
- Statement Type: DML, Select (blockable)
- Effective Isolation: Cursor Stability
- Statement Unicode Flag: No
- Statement: SELECT LASTNAME, FIRSTNME, SALARY FROM EMPLOYEE
- ORDER BY LASTNAME ASC
- Entry: #2
- Identification: UOW ID (6); Activity ID (1)
- Package Schema: (NULLID )
- Package Name: (SQLC2G13)
- Package Version: ()
- Section Entry Number: 203
- SQL Type: Dynamic
- Statement Type: DML, Insert/Update/Delete
- Effective Isolation: Cursor Stability
- Statement Unicode Flag: No
- Statement: UPDATE EMPLOYEE SET SALARYSALARY = SALARY * 1.02
這個鎖定超時報告的開始部分與前面看到的相同。但是,這次的 Lock Owner 部分包含額外的、有價值的信息。在標題 List of Inactive SQL Statements from current UOW 下邊,可以看到在發生鎖定超時之前鎖持有者的事務執行的所有 SQL 語句。從這組 SQL 語句中,可以找到導致問題鎖定的語句。在這個場景中,使用 UPDATE 語句增加每個員工的工資。
注意,這個功能是對結合使用 db2cos 和 db2pd 方法的一個重大改進。使用 db2cos 與 db2pd 相結合的方法,只能看到鎖持有者的應用程序執行的最後一條語句 — 在這個場景中是對 EMPLOYEE 表的查詢。但是由於查詢並沒有導致出現問題的獨占鎖,您仍然不知道是哪條語句導致了鎖定。使用新方法 — DB2_CAPTURE_LOCKTIMEOUT 和死鎖事件監視器 — 您擁有在鎖擁有者的事務中執行的所有 SQL 語句的歷史信息,這就可以將 UPDATE 確定為相關的語句。
使用鎖定超時報告的提示
帶有語句歷史功能的死鎖事件監視器適用於所有應用程序,會增加 DB2 數據庫管理程序對監視器堆的大量使用。所以應該謹慎使用。您應該始終首先設置 DB2_CAPTURE_LOCKTIMEOUT=ON,然後只在必要的時候使用 DETAILS HISTORY 選項激活死鎖事件監視器。
使用鎖定超時報告時,您可能會注意到,DIAGPATH 中的鎖定超時報告文件的數量在持續增加。DB2 不會刪除這些報告文件,所以 DBA 需要刪除它們或者將它們移動到不同的位置,以便在 DIAGPATH 的文件系統上始終有足夠的空間。
即使擁有了鎖定超時報告功能,也不是總能夠輕松確定出導致鎖定超時的原因。例如,如果鎖定超時由靜態 SQL 或 DB2 內部鎖定引起時,就沒有那麼容易確定原因。DB2 9.5 文檔的 Lock timeout reporting 一章提供了這些局限性的一個簡短列表(參見下面的 參考資料)。但是,DB2 9.5 中的鎖定超時報告絕對是一個許多 DBA 期待已久的功能,而且將大大簡化對鎖定超時的分析。
以上的相關內容就是對分析DB2 9.5中的鎖定超時原因的介紹,望你能有所收獲。