获取涉及死锁图的对象

时间:2015-02-03 05:22:24

标签: sql-server sql-server-2008

我们正面临着我们的一个应用程序的死锁问题,下面是获得的sql日志。我无法解释确切的问题。

有人可以帮我理解这个。

这是从SQL日志获取的等待时间图。

`Node:1  
KEY: 8:72057594538426368 (e1e76d2c41ad) CleanCnt:2 Mode:RangeX-X Flags: 0x1
 Grant List 1:
   Owner:0x00000001511ACE00 Mode: RangeX-X Flg:0x40 Ref:0 Life:02000000 SPID:95 ECID:0 XactLockInfo: 0x000000019F52F990
   SPID: 95 ECID: 0 Statement Type: CONDITIONAL Line #: 143
   Input Buf: RPC Event: Proc [Database Id = 8 Object Id = 1003150619]
Requested by: 
  ResType:LockOwner Stype:'OR'Xdes:0x00000001FAE1A3B0 Mode: RangeS-S SPID:97 BatchID:0 ECID:0 TaskProxy:(0x00000001F42BA540) Value:0x9f71a8c0 Cost:(0/1228)
NULL
Node:2  
KEY: 8:72057594538426368 (79a08f80fbf1) CleanCnt:2 Mode:X Flags: 0x1
 Grant List 1:
   Owner:0x00000001CDD00940 Mode: X        Flg:0x40 Ref:0 Life:02000000 SPID:97 ECID:0 XactLockInfo: 0x00000001FAE1A3F0
   SPID: 97 ECID: 0 Statement Type: CONDITIONAL Line #: 143
   Input Buf: RPC Event: Proc [Database Id = 8 Object Id = 1003150619]
Requested by: 
  ResType:LockOwner Stype:'OR'Xdes:0x000000019F52F950 Mode: RangeS-S SPID:95 BatchID:0 ECID:0 TaskProxy:(0x00000001A4432540) Value:0x5d929e80 Cost:(0/2312)
NULL
Victim Resource Owner:
 ResType:LockOwner Stype:'OR'Xdes:0x00000001FAE1A3B0 Mode: RangeS-S SPID:97 BatchID:0 ECID:0 TaskProxy:(0x00000001F42BA540) Value:0x9f71a8c0 Cost:(0/1228)
deadlock-list
 deadlock victim=process807dfdc8
  process-list
   process id=process807dfdc8 taskpriority=0 logused=1228 waitresource=KEY: 8:72057594538426368 (e1e76d2c41ad) waittime=2828 ownerId=775643922 transactionname=user_transaction lasttranstarted=2015-02-02T09:24:00.767 XDES=0x1fae1a3b0 lockMode=RangeS-S schedulerid=2 kpid=7948 status=suspended spid=97 sbid=0 ecid=0 priority=0 trancount=1 lastbatchstarted=2015-02-02T09:24:00.767 lastbatchcompleted=2015-02-02T09:24:00.763 clientapp=.Net SqlClient Data Provider hostname=servername1 hostpid=11600 loginname=ABC isolationlevel=serializable (4) xactid=775643922 currentdb=8 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
    executionStack
     frame procname=ABC.dbo.usp_UpdateFun line=143 stmtstart=11630 stmtend=12584 sqlhandle=0x030008001bddca3b985a410027a400000100000000000000
IF EXISTS                 
 (                
  SELECT a.*                
  FROM                
   tblBookings a                
   INNER JOIN OPENXML(@doc, 'EventRequest/Bookings', 2) WITH (resourceId int) b ON a.resourceId = b.resourceId                
  WHERE                
   (a.start > @start OR a.finish > @start) AND                 
   (a.start < @finish OR a.finish < @finish)                
 )     
    inputbuf
Proc [Database Id = 8 Object Id = 1003150619]    
   process id=process807dfb88 taskpriority=0 logused=2312 waitresource=KEY: 8:72057594538426368 (79a08f80fbf1) waittime=4107 ownerId=775643278 transactionname=user_transaction lasttranstarted=2015-02-02T09:23:58.540 XDES=0x19f52f950 lockMode=RangeS-S schedulerid=2 kpid=11876 status=suspended spid=95 sbid=0 ecid=0 priority=0 trancount=1 lastbatchstarted=2015-02-02T09:23:58.540 lastbatchcompleted=2015-02-02T09:23:58.540 clientapp=.Net SqlClient Data Provider hostname=servername1 hostpid=11600 loginname=ABC isolationlevel=serializable (4) xactid=775643278 currentdb=8 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
    executionStack
     frame procname=ABC.dbo.usp_UpdateFun line=143 stmtstart=11630 stmtend=12584 sqlhandle=0x030008001bddca3b985a410027a400000100000000000000
IF EXISTS                 
 (                
  SELECT a.*                
  FROM                
   tblBookings a                
   INNER JOIN OPENXML(@doc, 'EventRequest/Bookings', 2) WITH (resourceId int) b ON a.resourceId = b.resourceId                
  WHERE                
   (a.start > @start OR a.finish > @start ) AND                 
   (a.start < @finish OR a.finish < @finish )                
 )     
    inputbuf
Proc [Database Id = 8 Object Id = 1003150619]    
  resource-list
   keylock hobtid=72057594538426368 dbid=8 objectname=ABC.dbo.tblBookings indexname=IX5_tblBookings id=lock18c90fe00 mode=RangeX-X associatedObjectId=72057594538426368
    owner-list
     owner id=process807dfb88 mode=RangeX-X
    waiter-list
     waiter id=process807dfdc8 mode=RangeS-S requestType=wait
   keylock hobtid=72057594538426368 dbid=8 objectname=ABC.dbo.tblBookings indexname=IX5_tblBookings id=lock1d2d12d80 mode=X associatedObjectId=72057594538426368
    owner-list
     owner id=process807dfdc8 mode=X
    waiter-list
     waiter id=process807dfb88 mode=RangeS-S requestType=wait`

如果您希望我添加更多信息,请与我们联系。

1 个答案:

答案 0 :(得分:1)

那里有很多信息。有2个会话,SPID:97具有锁定对象ID 1003150619.是一个RangeX-X类型的锁。然后SPID:95有一个RangeS-S锁。死锁的受害者是SPID:97。

Jonathan Kehayias的这篇条目 Anatomy of a Deadlock - Part Deux 应该会有所帮助。有关每个条目的详细信息,请参阅 Detecting and Ending Deadlocks 。你会在Gail Shaw找到关于如何阅读和处理死锁的大量示例 SQL Server Deadlocks by Example 。以及有关如何分析 MSDN blogs 上的死锁的详细示例。

这里有一些查询肯定会帮助您开始处理死锁所涉及的对象,并了解正在发生的事情。

--get details on which object the hobt_id is representing
SELECT OBJECT_SCHEMA_NAME(object_id), OBJECT_NAME(object_id)
FROM   sys.partitions
WHERE  hobt_id IN (72057594538426368);

--get information on tsql been executed, if still available
SELECT * FROM sys.dm_exec_sql_text(0x030008001bddca3b985a410027a400000100000000000000);

SELECT OBJECT_NAME(p.object_id)  AS TableName,
       i.name                    AS IndexName
FROM   sys.partitions            AS p
       INNER JOIN sys.indexes    AS i
            ON  p.object_id = i.object_id
            AND p.index_id = i.index_id
WHERE  partition_id = 1003150619

SELECT   OBJECT_NAME(S.[OBJECT_ID]) AS [OBJECT NAME], 
         I.[NAME] AS [INDEX NAME], 
         USER_SEEKS, 
         USER_SCANS, 
         USER_LOOKUPS, 
         USER_UPDATES 
FROM     SYS.DM_DB_INDEX_USAGE_STATS AS S 
         INNER JOIN SYS.INDEXES AS I 
           ON I.[OBJECT_ID] = S.[OBJECT_ID] 
              AND I.INDEX_ID = S.INDEX_ID 
WHERE    OBJECTPROPERTY(S.[OBJECT_ID],'IsUserTable') = 1
    AND I.[object_id] = 1003150619