SQL Server中的自死锁

问题描述 投票:1回答:1

在事务中运行的安装过程中,我突然收到以下错误:

事务(进程ID 61)被另一个进程锁定在锁资源上,并被选择为死锁受害者。重新运行事务。

这很奇怪,因为没有其他会话访问数据库。我还关闭了服务器上的并行处理。这是在运行Sql Server Developer 2017的开发机上发生的:

死锁图看起来像:

<deadlock-list>
 <deadlock victim="process23c22077088">
  <process-list>
   <process id="process23c22077088" taskpriority="0" logused="0" waitresource="METADATA: database_id = 40 SCHEMA(schema_id = 16), lockPartitionId = 0" waittime="3489" ownerId="19528332" transactionname="GetInitializedIMA" lasttranstarted="2019-09-30T18:40:58.847" XDES="0x23b6850fac0" lockMode="Sch-S" schedulerid="12" kpid="17636" status="suspended" spid="53" sbid="0" ecid="0" priority="0" trancount="1" lastbatchstarted="2019-09-30T18:40:58.783" lastbatchcompleted="2019-09-30T18:40:58.783" lastattention="2019-09-30T18:36:47.943" clientapp=".Net SqlClient Data Provider" hostname="RND68" hostpid="29660" loginname="S-1-9-3-2459696885-1204846140-3013888703-3157444644" isolationlevel="read committed (2)" xactid="19528330" currentdb="40" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
    <executionStack>
     <frame procname="unknown" line="129" stmtstart="-1" sqlhandle="0x03002800205b3c6bdde23301d8aa000001000000000000000000000000000000000000000000000000000000">
unknown     </frame>
     <frame procname="adhoc" line="1" stmtend="104" sqlhandle="0x01002800f50e5536807d84d63b02000000000000000000000000000000000000000000000000000000000000">
EXEC SoftadminMapQBIntegration.QueryModel_SyncWithMa     </frame>
    </executionStack>
    <inputbuf>
EXEC SoftadminMapQBIntegration.QueryModel_SyncWithMap
EXEC SoftadminMapQB.CacheDatabaseNames

    </inputbuf>
   </process>
  </process-list>
  <resource-list>
   <metadatalock subresource="SCHEMA" classid="schema_id = 16" dbid="40" lockPartition="0" id="lock23bb4ee9b00" mode="Sch-M">
    <owner-list>
     <owner id="process23c22077088" mode="Sch-M"/>
     <owner id="process23c22077088" mode="Sch-S" requestType="wait"/>
    </owner-list>
    <waiter-list>
     <waiter id="process23c22077088" mode="Sch-S" requestType="wait"/>
    </waiter-list>
   </metadatalock>
  </resource-list>
 </deadlock>
</deadlock-list>

错误总是在同一位置发生。客户端是使用SqlClient运行一系列SQL批处理的.NET应用程序。

我已将错误跟踪到事务处理期间创建的视图。在以后的批处理中出现对此视图的引用时,将发生错误。我可以通过删除其定义中的联接(FK上的常规联接等于PK)来修改视图,以消除死锁。

以前有没有人看过类似的东西或知道发生了什么事?

完整版本信息:

Microsoft SQL Server 2017 (RTM-GDR) (KB4505224) - 14.0.2027.2 (X64) Jun 15 2019 00:26:19 
Copyright (C) 2017 Microsoft Corporation
Developer Edition (64-bit) on Windows 10 Pro 10.0 <X64> (Build 17763:) (Hypervisor)
sql-server database-deadlocks
1个回答
0
投票

我在开发机上面临着一个非常相似的问题,我的脚本几天前运行良好,现在每次都出现死锁……当您在进行事务处理(.NET应用使用SQL客户端执行脚本),并且未建立任何其他连接。我设置的唯一变化是几个小时前将实例从2017年迁移到2019年。我设法通过将目标数据库的兼容模式从2017(140)升级到2019(150)来解决此问题,不再出现死锁了!

希望获得帮助。

© www.soinside.com 2019 - 2024. All rights reserved.