I am trying to understand what is causing this deadlock.
The update command in the first process is the result of the trigger from the insert command. So I am trying to understand if the insert trigger fire on update?
<deadlock>
<victim-list>
<victimProcess id="process1fb169468" />
</victim-list>
<process-list>
<process id="process1fb169468" taskpriority="0" logused="2044" waitresource="KEY: 5:72057598307401728 (c73677424644)" waittime="61674" ownerId="34455794" transactionname="user_transaction" lasttranstarted="2022-07-11T23:24:01.387" XDES="0x56bee18e0" lockMode="U" schedulerid="6" kpid="9800" status="suspended" spid="94" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2022-07-11T23:24:01.387" lastbatchcompleted="2022-07-11T23:24:01.387" lastattention="2022-07-11T22:02:36.350" clientapp="Vizion WMS" hostname="AGROXAWORK02" hostpid="10484" loginname="vizion" isolationlevel="read committed (2)" xactid="34455794" currentdb="5" currentdbname="WMSData" lockTimeout="4294967295" clientoption1="671219744" clientoption2="128056">
<executionStack>
<frame procname="WMSData.dbo.UpdateDes" line="5" stmtstart="154" stmtend="298" sqlhandle="0x030005000caa6e4b5b56dd0089a6000000000000000000000000000000000000000000000000000000000000">
update inventory set designation = 'FROZEN' where designation <> 'FROZEN </frame>
<frame procname="WMSData.dbo.PostReceipt" line="101" stmtstart="7960" stmtend="10026" sqlhandle="0x0300050071b68341909a680037ae000001000000000000000000000000000000000000000000000000000000">
INSERT INTO [wmsdata].[dbo].[Inventory]
([Customer],[Product],[Row],[Rack],[Slot],[Pallets],[Cases],[Net],[ProductDate],[ReceiverNumber],[LotNumber],[ReceiveDate],[StorThru],[Status],[PalletNumber],[CustomerPallet],[StartTime],[StopTime],[BornOnDate],[EnteredBy],[ImportOrManual],[FullPalletQty],[PalletQtyReceived],[CustomerReference],lpnumber,fcgpallet,designation,mark,invoptional1,invoptional2,invoptional3,invoptional4,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,rsrate)
select [Customer],[Product],[Row],[Rack],[Slot],[Pallets],[Cases],[Net],[ProductDate],[Receiver],[LotNumber],convert(char(12),getdate(),101) as [ReceiveDate],[StorThru],[Status],[PalletNumber],[CustomerPallet],[StartTime],[StopTime],convert(char(12),getdate(),101) as [BornOnDate],[EnteredBy],[ImportOrManual],[FullPalletQty],cases as [PalletQtyReceived], #r, lpnumber, fcgpallet,designation,mark,invoptional1,invoptional2,invoptional3,invoptional4,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,rsrate
from [wmsdata].[dbo].receipts with (nolock) where palletnum </frame>
<frame procname="adhoc" line="1" sqlhandle="0x0100050098f50238607f6f0b0500000000000000000000000000000000000000000000000000000000000000">
exec dbo.postreceipt '149496','RDAY' </frame>
</executionStack>
<inputbuf>
exec dbo.postreceipt '149496','RDAY' </inputbuf>
</process>
<process id="process46811bc28" taskpriority="0" logused="22480" waitresource="KEY: 5:72057598307401728 (771c8a402149)" waittime="4364" ownerId="34439550" transactionname="user_transaction" lasttranstarted="2022-07-11T23:22:34.483" XDES="0x5a043d770" lockMode="U" schedulerid="1" kpid="10752" status="suspended" spid="59" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2022-07-11T23:22:34.497" lastbatchcompleted="2022-07-11T23:22:33.330" lastattention="2022-07-11T23:17:04.210" clientapp="Vizion WMS" hostname="AGROXAWORK02" hostpid="12144" loginname="vizion" isolationlevel="read committed (2)" xactid="34439550" currentdb="5" currentdbname="WMSData" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack>
<frame procname="WMSData.dbo.PostShipment" line="161" stmtstart="16962" stmtend="17036" sqlhandle="0x0300050069a66001dd5e640021ac000001000000000000000000000000000000000000000000000000000000">
delete from inventory where cases <= </frame>
<frame procname="adhoc" line="1" sqlhandle="0x01000500f2278100b05d31790100000000000000000000000000000000000000000000000000000000000000">
exec Postshipment '257208', 'JJOHNSON' </frame>
</executionStack>
<inputbuf>
exec Postshipment '257208', 'JJOHNSON' </inputbuf>
</process>
</process-list>
<resource-list>
<keylock hobtid="72057598307401728" dbid="5" objectname="WMSData.dbo.Inventory" indexname="PK_Inventory" id="lock4e671e880" mode="X" associatedObjectId="72057598307401728">
<owner-list>
<owner id="process46811bc28" mode="X" />
</owner-list>
<waiter-list>
<waiter id="process1fb169468" mode="U" requestType="wait" />
</waiter-list>
</keylock>
<keylock hobtid="72057598307401728" dbid="5" objectname="WMSData.dbo.Inventory" indexname="PK_Inventory" id="lock52ec3d280" mode="X" associatedObjectId="72057598307401728">
<owner-list>
<owner id="process1fb169468" mode="X" />
</owner-list>
<waiter-list>
<waiter id="process46811bc28" mode="U" requestType="wait" />
</waiter-list>
</keylock>
</resource-list>
</deadlock>
I'm facing a deadlock problem, the sql server detects it and return an exception because it chose a process as a victim. I would like to avoid this problem, I tried to change the isolation level to read uncommitted and also add indexes but this did not resolve the problems, here is report that describe the deadlock problem:
<deadlock>
<victim-list>
<victimProcess id="process133b1e188" />
</victim-list>
<process-list>
<process id="process133b1e188" taskpriority="0" logused="5236" waitresource="RID: 18:1:3545:209" waittime="1939" ownerId="13564317" transactionname="implicit_transaction" lasttranstarted="2020-12-18T18:15:14.250" XDES="0x1a064a3a8" lockMode="U" schedulerid="2" kpid="23832" status="suspended" spid="71" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2020-12-18T18:15:14.280" lastbatchcompleted="2020-12-18T18:15:14.280" lastattention="1900-01-01T00:00:00.280" clientapp="jTDS" hostname="med" hostpid="123" loginname="med" isolationlevel="read uncommitted (1)" xactid="13564317" currentdb="18" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<executionStack>
<frame procname="adhoc" line="1" stmtstart="462" stmtend="592" sqlhandle="0x030012003d326d4a3bf62b0195ac000001000000000000000000000000000000000000000000000000000000"> UPDATE DEP SET name WHERE id = 2 </frame>
</executionStack>
</process>
<process id="process133b1e558" taskpriority="0" logused="30956" waitresource="KEY: 18:72057766865403904 (8c1a6a11df48)" waittime="1957" ownerId="13563835" transactionname="implicit_transaction" lasttranstarted="2020-12-18T18:15:14.113" XDES="0x1a064b668" lockMode="S" schedulerid="2" kpid="32596" status="suspended" spid="68" sbid="0" ecid="0" priority="0" trancount="1" lastbatchstarted="2020-12-18T18:15:14.263" lastbatchcompleted="2020-12-18T18:15:14.263" lastattention="1900-01-01T00:00:00.263" clientapp="jTDS" hostname="med" hostpid="123" loginname="med" isolationlevel="read committed (2)" xactid="13563835" currentdb="18" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<executionStack>
<frame procname="adhoc" line="1" stmtstart="24" sqlhandle="0x0200000064dbc4257a329ecd9ef9f0056fe48ce548b17d2e0000000000000000000000000000000000000000">
SELECT * FROM Worker w WHERE (w.id = #P0 ) </frame>
</executionStack>
</process>
</process-list>
<resource-list>
<ridlock fileid="1" pageid="3545" dbid="18" objectname="DEP" id="lock185869680" mode="X" associatedObjectId="72057766864551936">
<owner-list>
<owner id="process133b1e558" mode="X" />
</owner-list>
<waiter-list>
<waiter id="process133b1e188" mode="U" requestType="wait" />
</waiter-list>
</ridlock>
<keylock hobtid="72057766865403904" dbid="18" objectname="Worker" indexname="worker_id" id="lock17d9fdb80" mode="X" associatedObjectId="72057766865403904">
<owner-list>
<owner id="process133b1e188" mode="X" />
</owner-list>
<waiter-list>
<waiter id="process133b1e558" mode="S" requestType="wait" />
</waiter-list>
</keylock>
</resource-list>
</deadlock>
Try reading about:
set deadlock priority high
You should use high or 10 for the session you don't want to be the victim.
And I would say isolation level read uncommitted is not a good choice.
I am experiencing sporadic deadlock behaviour when my application tries to execute any DROP TABLE statement against my database.
I tried capturing the deadlock graph and this is the output from deadlock xml
<deadlock>
<victim-list>
<victimProcess id="process2bddc28" />
</victim-list>
<process-list>
<process id="process2bddc28" taskpriority="0" logused="0" waitresource="KEY: 6:281474978938880 (85262e079cd2)" waittime="1900" ownerId="76493296" transactionname="user_transaction" lasttranstarted="2016-02-22T05:58:15.867" XDES="0x621cb38e0" lockMode="S" schedulerid="6" kpid="10748" status="suspended" spid="119" sbid="0" ecid="0" priority="0" trancount="1" lastbatchstarted="2016-02-22T05:58:16.080" lastbatchcompleted="2016-02-22T05:58:16.080" lastattention="1900-01-01T00:00:00.080" hostname="DEV01" hostpid="13420" isolationlevel="read committed (2)" xactid="76493296" currentdb="6" lockTimeout="4294967295" clientoption1="671090784" clientoption2="128056">
<executionStack>
<frame procname="mssqlsystemresource.sys.sp_columns_100" line="138" stmtstart="12020" stmtend="17532" sqlhandle="0x0300ff7f78a964e13656e600e7a5000001000000000000000000000000000000000000000000000000000000">
</frame>
</executionStack>
<inputbuf>Proc [Database Id = 32767 Object Id = -513496712]</inputbuf>
</process>
<process id="process45c8ca8" taskpriority="0" logused="6748" waitresource="KEY: 6:562949956108288 (5db581fe7a0b)" waittime="1900" ownerId="76493663" transactionname="user_transaction" lasttranstarted="2016-02-22T05:58:16.087" XDES="0x16aeded90" lockMode="X" schedulerid="1" kpid="18268" status="suspended" spid="129" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2016-02-22T05:58:16.090" lastbatchcompleted="2016-02-22T05:58:16.090" lastattention="1900-01-01T00:00:00.090" hostname="DEV01" hostpid="20128" isolationlevel="read committed (2)" xactid="76493663" currentdb="6" lockTimeout="4294967295" clientoption1="671090784" clientoption2="128056">
<executionStack>
<frame procname="adhoc" line="1" sqlhandle="0x01000600702bfd0bd083047f0600000000000000000000000000000000000000000000000000000000000000">
DROP TABLE "dbo"."USER_TABLE_1" </frame>
</executionStack>
<inputbuf>
DROP TABLE "dbo"."USER_TABLE_1" </inputbuf>
</process>
</process-list>
<resource-list>
<keylock hobtid="281474978938880" dbid="6" objectname="DEV_01.sys.sysschobjs" indexname="clst" id="lock35af27b80" mode="X" associatedObjectId="281474978938880">
<owner-list><owner id="process45c8ca8" mode="X" /></owner-list>
<waiter-list><waiter id="process2bddc28" mode="S" requestType="wait" /></waiter-list>
</keylock>
<keylock hobtid="562949956108288" dbid="6" objectname="DEV_01.sys.syscolpars" indexname="nc" id="lock453c34600" mode="U" associatedObjectId="562949956108288">
<owner-list><owner id="process2bddc28" mode="S" /></owner-list>
<waiter-list><waiter id="process45c8ca8" mode="X" requestType="convert" /></waiter-list>
</keylock>
</resource-list>
</deadlock>
This behaviour was not seen in earlier versions of SQL Server. Any thoughts on this?
Recently we encountered deadlock issues when more users using the system, below is the log details, appreciate if someone can provide guides on how to resolve this:
How S or IX lock mode causing the deadlock?
I am thinking probably to improve the query time for the select statement, so that it could release the lock sooner.
<TextData>
<deadlock-list>
<deadlock victim="process6956d8">
<process-list>
<process id="process6956d8" taskpriority="0" logused="0" waitresource="PAGE: 8:1:6923" waittime="1840" ownerId="67336413" transactionname="implicit_transaction" lasttranstarted="2013-07-08T16:22:34.897" XDES="0x124272700" lockMode="S" schedulerid="2" kpid="5472" status="suspended" spid="64" sbid="0" ecid="0" priority="0" transcount="1" lastbatchstarted="2013-07-08T16:22:34.900" lastbatchcompleted="2013-07-08T16:22:34.900" clientapp="Microsoft SQL Server JDBC Driver" hostname="VIRTIPH-MAS001" hostpid="0" loginname="prtcmt_user" isolationlevel="read committed (2)" xactid="67336413" currentdb="8" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<executionStack>
<frame procname="adhoc" line="1" sqlhandle="0x02000000ec69351d69911b1227018da1e1e67e60256cd8be">
select top 290 workplan0_.id as id112_, workplan0_.request_mode as request2_112_, workplan0_.cmt_status_id as cmt3_112_, workplan0_.requestType_rd_id as requestT4_112_, workplan0_.requested_dt as requested5_112_, workplan0_.generic_desc as generic6_112_, workplan0_.brand_desc as brand7_112_, workplan0_.strength as strength112_, workplan0_.prod_form_name as prod9_112_, workplan0_.pack_desc as pack10_112_, workplan0_.inv_uom_desc as inv11_112_, workplan0_.pack_uom_desc as pack12_112_, workplan0_.requestType_name as request13_112_, workplan0_.site_name as site14_112_, workplan0_.priority as priority112_, workplan0_.source as source112_, workplan0_.cmt_status_code as cmt17_112_, workplan0_.prev_cmt_status_code as prev18_112_, workplan0_.swmd_prod_id as swmd19_112_, workplan0_.hppl_lookslike_id as hppl20_112_, workplan0_.amt_id as amt21_112_, workplan0_.locked_dt as locked22_112_ from ipharm_workPlanView workplan0_ where workplan0_.requestType_rd_id=6 and workplan0_.cmt_status_id=33 order by workplan0_.generic_des </frame>
<frame procname="unknown" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000">
unknown </frame>
</executionStack>
<inputbuf>
select top 290 workplan0_.id as id112_, workplan0_.request_mode as request2_112_, workplan0_.cmt_status_id as cmt3_112_, workplan0_.requestType_rd_id as requestT4_112_, workplan0_.requested_dt as requested5_112_, workplan0_.generic_desc as generic6_112_, workplan0_.brand_desc as brand7_112_, workplan0_.strength as strength112_, workplan0_.prod_form_name as prod9_112_, workplan0_.pack_desc as pack10_112_, workplan0_.inv_uom_desc as inv11_112_, workplan0_.pack_uom_desc as pack12_112_, workplan0_.requestType_name as request13_112_, workplan0_.site_name as site14_112_, workplan0_.priority as priority112_, workplan0_.source as source112_, workplan0_.cmt_status_code as cmt17_112_, workplan0_.prev_cmt_status_code as prev18_112_, workplan0_.swmd_prod_id as swmd19_112_, workplan0_.hppl_lookslike_id as hppl20_112_, workplan0_.amt_id as amt21_112_, workplan0_.locked_dt as locked22_112_ from ipharm_workPlanView workplan0_ where workplan0_.requestType_rd_id=6 and workplan0_.cmt_status_id=33 order by workplan0_.generic_de </inputbuf>
</process>
<process id="processc7c5ec58" taskpriority="0" logused="9904" waitresource="PAGE: 8:1:6922" waittime="936" ownerId="67336189" transactionname="implicit_transaction" lasttranstarted="2013-07-08T16:22:33.930" XDES="0x123635380" lockMode="IX" schedulerid="1" kpid="5232" status="suspended" spid="61" sbid="0" ecid="0" priority="0" transcount="2" lastbatchstarted="2013-07-08T16:22:35.930" lastbatchcompleted="2013-07-08T16:22:35.927" clientapp="Microsoft SQL Server JDBC Driver" hostname="VIRTIPH-MAS001" hostpid="0" loginname="prtcmt_user" isolationlevel="read committed (2)" xactid="67336189" currentdb="8" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<executionStack>
<frame procname="adhoc" line="1" stmtstart="890" sqlhandle="0x02000000a89737254800790c60bb4d0fa72b9640012d8592">
update requestedProduct set version=#P0, create_user=#P1, create_dt=#P2, last_update_user=#P3, last_update_dt=#P4, requested_by=#P5, requested_dt=#P6, requested_byName=#P7, requested_byTitle=#P8, status_id=#P9, status_by=#P10, status_date=#P11, cmt_status_id=#P12, prev_cmt_status_id=#P13, prod_id=#P14, source_prod_id=#P15, hppl_lookslike_id=#P16, amt_id=#P17, fred_code=#P18, source=#P19, swmd_prod_id=#P20, locked_dt=#P21, locked_by=#P22, request_mode=#P23, original_request_mode=#P24, site_rd_id=#P25, priority_rd_id=#P26, submitted_priority_rd_id=#P27, requestType_rd_id=#P28, comment=#P29 where id=#P30 and version=#P31 </frame>
<frame procname="unknown" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000">
unknown </frame>
</executionStack>
<inputbuf>
(#P0 int,#P1 nvarchar(4000),#P2 datetime,#P3 nvarchar(4000),#P4 datetime,#P5 bigint,#P6 datetime,#P7 nvarchar(4000),#P8 nvarchar(4000),#P9 bigint,#P10 bigint,#P11 datetime,#P12 bigint,#P13 bigint,#P14 int,#P15 int,#P16 nvarchar(4000),#P17 nvarchar(4000),#P18 nvarchar(4000),#P19 nvarchar(4000),#P20 varchar(8000),#P21 datetime,#P22 bigint,#P23 int,#P24 int,#P25 bigint,#P26 bigint,#P27 bigint,#P28 bigint,#P29 varchar(8000),#P30 bigint,#P31 int)update requestedProduct set version=#P0, create_user=#P1, create_dt=#P2, last_update_user=#P3, last_update_dt=#P4, requested_by=#P5, requested_dt=#P6, requested_byName=#P7, requested_byTitle=#P8, status_id=#P9, status_by=#P10, status_date=#P11, cmt_status_id=#P12, prev_cmt_status_id=#P13, prod_id=#P14, source_prod_id=#P15, hppl_lookslike_id=#P16, amt_id=#P17, fred_code=#P18, source=#P19, swmd_prod_id=#P20, locked_dt=#P21, locked_by=#P22, request_mode=#P23, original_request_mode=#P24, site_rd_id=#P25, priority_rd_id=#P26, submitted_priority_rd_id=#P27, requestType_r </inputbuf>
</process>
</process-list>
<resource-list>
<pagelock fileid="1" pageid="6923" dbid="8" objectname="MYDB.dbo.requestedProduct" id="lockedec4680" mode="IX" associatedObjectId="72057594227261440">
<owner-list>
<owner id="processc7c5ec58" mode="IX" />
</owner-list>
<waiter-list>
<waiter id="process6956d8" mode="S" requestType="wait" />
</waiter-list>
</pagelock>
<pagelock fileid="1" pageid="6922" dbid="8" objectname="MYDB.dbo.requestedProduct" id="lockfa82e880" mode="SIU" associatedObjectId="72057594227261440">
<owner-list>
<owner id="process6956d8" mode="S" />
</owner-list>
<waiter-list>
<waiter id="processc7c5ec58" mode="IX" requestType="convert" />
</waiter-list>
</pagelock>
</resource-list>
</deadlock>
</deadlock-list>
</TextData>)
I'm working with some stored procedure and deadlock situation.
I've been using SQL Server Profiler and get some information about the deadlock from 'Deadlock graph' event in form of the .xdl file.
Below content of that file.
I've just cleared some informations about the statement.The statement marked as <executionStack> in the .xdl was something like this (for both processes the same statement):
SELECT SomeColumn, SomeColumn2
FROM SomeTable WITH (UPDLOCK)
INNER JOIN SomeTable2 ON SomeTable.SomeTable2ID = SomeTable2.SomeTable2ID
INNER JOIN SomeTable3 ON SomeTable2.SomeTable3ID = SomeTable3.SomeTable3ID
WHERE SomeColumn = #Something AND SomeColumn2 = #Something2
And the content of the .xdl file:
<deadlock-list>
<deadlock victim="processc19dc8">
<process-list>
<process id="processc19dc8" taskpriority="0" logused="0" waitresource="KEY: 5:72057594042646528 (8194443284a0)" waittime="1541" ownerId="21923027" transactionname="user_transaction" lasttranstarted="2013-07-02T18:03:42.260" XDES="0x80051950" lockMode="RangeS-U" schedulerid="2" kpid="2712" status="suspended" spid="54" sbid="0" ecid="0" priority="0" trancount="1" lastbatchstarted="2013-07-02T18:03:42.260" lastbatchcompleted="2013-07-02T18:03:42.260" clientapp=".Net SqlClient Data Provider" hostname="XXX" hostpid="2148" loginname="XXX" isolationlevel="serializable (4)" xactid="21923027" currentdb="5" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
...
</process>
<process id="processc4d048" taskpriority="0" logused="0" waitresource="KEY: 5:72057594042646528 (a0c936a3c965)" waittime="1541" ownerId="21923023" transactionname="user_transaction" lasttranstarted="2013-07-02T18:03:42.260" XDES="0x80049800" lockMode="RangeS-U" schedulerid="4" kpid="2492" status="suspended" spid="53" sbid="0" ecid="0" priority="0" trancount="1" lastbatchstarted="2013-07-02T18:03:42.260" lastbatchcompleted="2013-07-02T18:03:42.260" clientapp=".Net SqlClient Data Provider" hostname="XXX" hostpid="2148" loginname="XXX" isolationlevel="serializable (4)" xactid="21923023" currentdb="5" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
...
</process>
</process-list>
<resource-list>
<keylock hobtid="72057594042646528" dbid="5" objectname="dbo.SomeTable" indexname="PK_SomeTable" id="lock83d99200" mode="RangeS-U" associatedObjectId="72057594042646528">
<owner-list>
<owner id="processc4d048" mode="RangeS-U"/>
</owner-list>
<waiter-list>
<waiter id="processc19dc8" mode="RangeS-U" requestType="wait"/>
</waiter-list>
</keylock>
<keylock hobtid="72057594042646528" dbid="5" objectname="dbo.SomeTable" indexname="PK_SomeTable" id="lock89b52900" mode="U" associatedObjectId="72057594042646528">
<owner-list>
<owner id="processc19dc8" mode="U"/>
</owner-list>
<waiter-list>
<waiter id="processc4d048" mode="RangeS-U" requestType="wait"/>
</waiter-list>
</keylock>
</resource-list>
</deadlock>
</deadlock-list>
So it looks like the first process owns a resource with mode=U, and the second owns the same resource with mode=RangeS-U.
How it is possible if these two modes are not compatible with each other (according to the compatibility matrix)?