如何监视DB2中的死锁

时间:2018-03-01 07:17:23

标签: db2 deadlock aix db2-luw

我正在关注此链接并尝试模拟死锁问题:

http://www.dba-db2.com/2012/06/how-to-monitor-a-deadlock-in-db2.html

我可以看到我的命令运行成功。

之后我会通过DbVisualiser工具模拟死锁错误。但是,我没有看到任何文件生成到路径。

有人可以将错误指向我吗?

而且,我尝试回读那些旧的0000000.evt文件,它向我展示了如下内容:

                            EVENT LOG HEADER
  Event Monitor name: DB2DETAILDEADLOCK
  Server Product ID: SQL10059
  Version of event monitor data: 12
  Byte order: BIG ENDIAN
  Number of nodes in db2 instance: 1
  Codepage of database: 1208
  Territory code of database: 1
  Server instance name: db2inst1
--------------------------------------------------------------------------

--------------------------------------------------------------------------
  Database Name: MYDB   
  Database Path: /db2home/db2inst1/NODE0000/SQL00003/MEMBER0000/
  First connection timestamp: 01/29/2018 10:00:17.694784
  Event Monitor Start time:   01/29/2018 10:00:18.951331
--------------------------------------------------------------------------

--------------------------------------------------------------------------
  Database Name: MYDB   
  Database Path: /db2home/db2inst1/NODE0000/SQL00003/MEMBER0000/
  First connection timestamp: 01/29/2018 10:12:54.382936
  Event Monitor Start time:   01/29/2018 10:12:54.697223
--------------------------------------------------------------------------

这意味着没有死锁?

1 个答案:

答案 0 :(得分:0)

正确地为我工作(linux,Db2 v11.1)。以下是一些带注释的命令行。您需要为每个命令拥有合适的授权/特权。我正在使用实例所有者帐户。

首先禁用默认的db2detaildeadlock监视器,然后创建自己的监视器:

$ db2 "set event monitor db2detaildeadlock state=0"      
DB20000I  The SQL command completed successfully.
$ 
$ db2 "create event monitor dlmon for deadlocks write to file '/tmp'"
DB20000I  The SQL command completed successfully.
$
$ db2 "set event monitor dlmon state=1"
DB20000I  The SQL command completed successfully.
$

生成死锁,确保您看到此SQLCODE -911,原因码为2。 如果你没有看到原因代码2,那么你有任何死锁,但你可能有超时,超时并没有记录在死锁监视器中。

这里我展示了死锁的受害者收到回滚的通知,你可以看到正确的原因代码:

$ db2 +c "select * from db2inst1.dlk where a=4 with rr"
SQL0911N  The current transaction has been rolled back because of a deadlock 
or timeout.  Reason code "2".  SQLSTATE=40001

使用db2evmon调查监视器输出并查看生成的文件

$ db2evmon -db mydb -evm dlmon > /tmp/db2evmon.dlmon.1

Reading /tmp/00000000.evt ...

$ view /tmp/db2evmon.dlmon.1
...<snip>
...
3) Deadlock Event ...
  Deadlock ID:   2
  Number of applications deadlocked: 2
  Deadlock detection time: 01/03/2018 09:06:39.019854
  Rolled back Appl participant no: 2
  Rolled back Appl Id: *LOCAL.db2inst1.180301090546
  Rolled back Appl seq number: 00001
  Rolled back Appl handle: 11872

...<snip>