DB2之死锁

窗口1:
[db2inst1@t3-dtpoc-dtpoc-web04 ~]$ db2 +c "update employee1 set name='yo11' where id=1"
DB20000I  The SQL command completed successfully.
[db2inst1@t3-dtpoc-dtpoc-web04 ~]$ db2 +c "update employee1 set name='yo11' where id=2"
DB20000I  The SQL command completed successfully.

窗口2:

[db2inst1@t3-dtpoc-dtpoc-web04 ~]$ db2 +c "update employee1 set name='yo12' where id=2"
DB20000I  The SQL command completed successfully.
[db2inst1@t3-dtpoc-dtpoc-web04 ~]$ db2 +c "update employee1 set name='yo12' where id=1"

窗口3:
[db2inst1@t3-dtpoc-dtpoc-web04 ~]$ db2pd -d test -wlocks

Database Member 0 -- Database TEST -- Active -- Up 0 days 00:08:00 -- Date 2023-07-26-14.06.29.121734

Locks being waited on :
AppHandl [nod-index] TranHdl    Lockname                   Type       Mode Conv Sts CoorEDU    AppName  AuthID   AppID                           
10407    [000-10407] 14         02000101050000000000000052 RowLock    ..X       G   453        db2bp    DB2INST1 *LOCAL.db2inst1.230726055855     
10395    [000-10395] 3          02000101050000000000000052 RowLock    ..X       W   423        db2bp    DB2INST1 *LOCAL.db2inst1.230726055829     

10395    [000-10395] 3          02000101040000000000000052 RowLock    ..X       G   423        db2bp    DB2INST1 *LOCAL.db2inst1.230726055829     
10407    [000-10407] 14         02000101040000000000000052 RowLock    ..X       W   453        db2bp    DB2INST1 *LOCAL.db2inst1.230726055855 

DB2会有死锁监控监制,检测到死锁会自动把其中一个应用回滚。
DB21034E  The command was processed as an SQL statement because it was not a 
valid Command Line Processor command.  During SQL processing it returned:
SQL0911N  The current transaction has been rolled back because of a deadlock 
or timeout.  Reason code "2".  SQLSTATE=40001 

如何查看死锁的具体信息呢?
DB2中有一个默认的deadlock event monitor:DB2DETAILDEADLOCK,通过db2 "select * from SYSCAT.EVENTMONITORS"可以看到
db2 set event monitor db2detaildeadlock state=0 //打开死锁监视器
db2 set event monitor db2detaildeadlock state=1 //关闭死锁监视器
会把死锁数据生成到数据库目录:
/home/db2inst1/db2inst1/NODE0000/SQL00001/MEMBER0000/db2event/db2detaildeadlock
[db2inst1@t3-dtpoc-dtpoc-web04 db2detaildeadlock]$ ls -ltr
total 12
-rw-r----- 1 db2inst1 db2inst1   43 Jul 17 10:05 db2event.ctl
-rw-r--r-- 1 db2inst1 db2inst1 5950 Jul 26 14:06 00000000.evt
[db2inst1@t3-dtpoc-dtpoc-web04 db2detaildeadlock]$ 
到这个目录下执行db2evmon -path . > deadlock.out 
db2evmon -path .  -file 24 > deadlock.out  //指定文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值