use*_*420 5 sql-server locking blocking
我有一个 .NET 应用程序,它正在获取 SQL 更新超时,我相信正在发生某种阻塞/锁定,这导致了这种情况。我在数据库上运行了一个阻塞进程报告,发现了一些潜在的罪魁祸首:17 秒的阻塞。
下面是这样的日志(有很多类似的):
<blocked-process-report>
<blocked-process>
<process id="process308898748" taskpriority="0" logused="0" waitresource="OBJECT: 99:774293818:0 " waittime="17146" ownerId="66317995993" transactionname="UPDATE" lasttranstarted="2015-06-15T12:59:05.817" XDES="0x3bc9cd970" lockMode="IX" schedulerid="7" kpid="11204" status="suspended" spid="161" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2015-06-15T12:59:05.817" lastbatchcompleted="2015-06-15T12:59:05.817" clientapp=".Net SqlClient Data Provider" hostname="WORKFLOWG10" hostpid="6832" loginname="WorkflowStateUpdaterSP" isolationlevel="read committed (2)" xactid="66317995993" currentdb="99" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack>
<frame line="1" stmtstart="16" sqlhandle="0x02000000cb1bb914fe051a308bd33cb2b873948749c2a96d"/>
<frame line="1" sqlhandle="0x0200000075c8f5236facd1f18bca0258f9d4babad99091d6"/>
</executionStack>
<inputbuf>
UPDATE [ScheduDB].[dbo].[SP_ScheduleEvent] set DateLastProcessed = GETDATE() where ScheduleEventID = 3111573 </inputbuf>
</process>
</blocked-process>
<blocking-process>
<process status="suspended" waitresource="OBJECT: 99:774293818:0 " waittime="17182" spid="278" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2015-06-15T12:59:05.780" lastbatchcompleted="2015-06-15T12:59:05.780" clientapp=".Net SqlClient Data Provider" hostname="WORKFLOWG12" hostpid="9944" loginname="WorkflowStateUpdaterSP" isolationlevel="read committed (2)" xactid="66317995589" currentdb="99" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack>
<frame line="1" stmtstart="16" sqlhandle="0x02000000cb1bb914fe051a308bd33cb2b873948749c2a96d"/>
<frame line="1" sqlhandle="0x0200000001c6452aee248fd8f9f2be0e27c7038cfa4e334f"/>
</executionStack>
<inputbuf>
UPDATE [ScheduDB].[dbo].[SP_ScheduleEvent] set DateLastProcessed = GETDATE() where ScheduleEventID = 3807096 </inputbuf>
</process>
</blocking-process>
</blocked-process-report>
Run Code Online (Sandbox Code Playgroud)
如您所见,两个更新似乎相互阻塞,我正在努力找出原因。
以下是可能对您有所帮助的数据库细节:
TABLE: SP_ScheduleEvent
------
|ScheduleEventID| PK| bigint| not null|
...
|DateLastProcessed| | datetime| not null|
...
INDEX:
ScheduleEventID, "use page locks when accessing the index is set to" FALSE ( row locks is on )
Run Code Online (Sandbox Code Playgroud)
通常,我在不同的机器上运行了许多会触发此更新的进程,我从 .NET 应用程序(Linq to SQL)中的 DBDataContext 运行更新,如下所示:
string sqlUpdateString = "UPDATE [ScheduDB].[dbo].[SP_ScheduleEvent] set DateLastProcessed = GETDATE() where ScheduleEventID = " + scheduleEvent.ScheduleEventID;
db.ExecuteCommand(sqlUpdateString);
Run Code Online (Sandbox Code Playgroud)
谢谢
Ion*_*nic -1
如果您有权访问数据库本身,则可以运行应用程序并查看正在运行的请求(sys.dm_exec_request)。在那里您将找到当前运行的查询。您还可以查看 sys.dm_tran_locks,它可以让您很好地了解在哪个资源上请求的锁。
另一个想法是在数据库表上使用 tsql 重播模板运行探查器并抛出结果。我想这会对你有帮助。
如果您需要更多信息。请告诉我。
归档时间: |
|
查看次数: |
541 次 |
最近记录: |