大家好,本人维护的一个营业收费系统经常出现死锁的现象。只要有两台收费客户端在同一时间收费,就会出现死锁。希望大家帮我分析一下。
数据库是Mssql2000,关于最近一次死锁的日志如下:
2012-07-22 08:10:09.81 spid4 ResType:LockOwner Stype:'OR' Mode: IX SPID:63 ECID:0 Ec:(0x60D0F9A8) Value:0x54
2012-07-22 08:10:09.81 spid4 Victim Resource Owner:
2012-07-22 08:10:09.81 spid4 ResType:LockOwner Stype:'OR' Mode: IX SPID:63 ECID:0 Ec:(0x60D0F9A8) Value:0x54
2012-07-22 08:10:09.81 spid4 Requested By:
2012-07-22 08:10:09.81 spid4 Grant List 2::
2012-07-22 08:10:09.81 spid4 Input Buf: Language Event: HFYS_Bill_OK 'Bcss=103;skrID=38;skfs=现金;Version=200
2012-07-22 08:10:09.81 spid4 SPID: 58 ECID: 0 Statement Type: UPDATE Line #: 231
2012-07-22 08:10:09.81 spid4 Owner:0x2447b140 Mode: S Flg:0x0 Ref:0 Life:00000001 SPID:58 ECID:0
2012-07-22 08:10:09.81 spid4 Grant List 1::
2012-07-22 08:10:09.81 spid4 PAG: 7:1:912827 CleanCnt:2 Mode: SIU Flags: 0x2
2012-07-22 08:10:09.81 spid4 Node:2
2012-07-22 08:10:09.81 spid4
2012-07-22 08:10:09.81 spid4 ResType:LockOwner Stype:'OR' Mode: IX SPID:58 ECID:0 Ec:(0x310319A8) Value:0x63
2012-07-22 08:10:09.81 spid4 Requested By:
2012-07-22 08:10:09.81 spid4 Input Buf: Language Event: HFYS_Bill_OK 'Bcss=22;skrID=31;skfs=现金;Version=2004
2012-07-22 08:10:09.81 spid4 SPID: 63 ECID: 0 Statement Type: UPDATE Line #: 231
2012-07-22 08:10:09.81 spid4 Owner:0x7612dd60 Mode: S Flg:0x0 Ref:0 Life:00000001 SPID:63 ECID:0
2012-07-22 08:10:09.81 spid4 Grant List 2::
2012-07-22 08:10:09.81 spid4 Grant List 1::
2012-07-22 08:10:09.81 spid4 PAG: 7:1:349518 CleanCnt:2 Mode: SIU Flags: 0x2
2012-07-22 08:10:09.81 spid4 Node:1
2012-07-22 08:10:09.81 spid4
2012-07-22 08:10:09.81 spid4 Wait-for graph
2012-07-22 08:10:09.81 spid4
2012-07-22 08:10:09.81 spid4 ...
通过日志我大概知道应该是HFYS_Bill_OK存储过程的第231行update语句引发了死锁,该行完整语句如下:
Update h1 set h1.Byss=h2.Byss,h1.Bcss=h2.Bcss,h1.Byye_Ysk=h2.Byye_Ysk,h1.Pay_Flag=h2.Pay_Flag,
h1.printed=h2.printed,h1.Skyf=h2.Skyf,h1.Skr_Date=h2.Skr_Date,h1.Skr=h2.Skr
from Hthhf as h1 ,Hfys_Hthhf as h2 where [email protected] and h1.Hzyf=h2.Hzyf and h1.Hth=h2.Hth and h1.Kemu=h2.Kemu
但是到现在我就不知道该怎么分析了,因为只是做维护不是做开发的,这方面的底子还是太浅了。厂家那边看过一次也没解决。是这个语句本身的问题还是可能有其它的原因?
------解决方案--------------------
如果表都有主键,[email protected]
再update ... where [email protected]
------解决方案--------------------
用SQL PROFILER跟踪下啊。
单纯的你这个语句是不会引起死锁的。
------解决方案--------------------
跟踪跟踪