Reputation: 1670
In my production server i am keep on facing deadlock issue. I have gone through many links but I am unable to find a solution.
Please find trace
deadlock-list
deadlock victim=process500ce08
process-list
process id=process500ce08 taskpriority=0 logused=0 waitresource=PAGE: 7:1:3509698 waittime=5074 ownerId=53243840
transactionname=implicit_transaction lasttranstarted=2015-10-20T04:00:02.037 XDES=0x2af523970 lockMode=IU schedulerid=6 kpid=7072
status=suspended spid=81 sbid=0 ecid=0 priority=0 trancount=2 lastbatchstarted=2015-10-20T04:00:02.037 lastbatchcompleted=2015-10-20T04:00:02.033
hostname=10.9.52.12 hostpid=0 loginname=prod isolationlevel=read committed (2) xactid=53243840 currentdb=7 lockTimeout=4294967295
clientoption1=671088928 clientoption2=128058
executionStack
frame procname=adhoc line=1 stmtstart=116 sqlhandle=0x020000008d082701122cdc931bffce58ad37dec1a2f23e9d
UPDATE dbo.InterfaceTable SET ERRORMESSAGE = @P1 , ACK_DATE = @P2 WHERE (SSID = @P3 )
frame procname=unknown line=1 sqlhandle=0x000000000000000000000000000000000000000000000000
unknown
inputbuf
(@P1 nvarchar(4000),@P2 datetimeoffset,@P3 nvarchar(4000))UPDATE dbo.InterfaceTable SET ERRORMESSAGE = @P1 , ACK_DATE = @P2 WHERE (SSID = @P3 )
process id=process6ca8748 taskpriority=0 logused=112 waitresource=PAGE: 7:1:6987355 waittime=4931 ownerId=53242925
transactionname=DELETE lasttranstarted=2015-10-20T04:00:01.320 XDES=0x4408a8080 lockMode=IX schedulerid=13 kpid=5820
status=suspended spid=123 sbid=0 ecid=0 priority=0 trancount=2 lastbatchstarted=2015-10-20T04:00:01.043 lastbatchcompleted=2015-10-20T04:00:01.043
clientapp=SQLAgent - TSQL JobStep (Job 0x12C15DD2EBA4CD4DAFEE3482987A95C6 : Step 1) hostname=APP01 hostpid=2972
loginname=APP01\sqlsupport isolationlevel=read uncommitted (1) xactid=53242925 currentdb=7 lockTimeout=4294967295 clientoption1=671088928
clientoption2=128056
executionStack
frame procname=adhoc line=1 sqlhandle=0x02000000bede8d1322a460d49c8399173b5b500cd397607c
Delete from INTERFACE_TABLE
where ( ERRORMESSAGE is null or ERRORMESSAGE like '%AGREEMENT NOT FOUND.;%' or ERRORMESSAGE like '%UNI:REALLOCATED%')
and ACK_DATE is not null
and ACKID is not null and SSID in(select SSID from INTERFACE_TABLE_2015 with(Nolock) )
frame procname=Data_Purging line=91 stmtstart=8514 stmtend=8574 sqlhandle=0x03000700dcdb321339b16c0034a500000100000000000000
exec(@Interface_Execution1)
frame procname=adhoc line=1 sqlhandle=0x01000700910a2006e0a057ab040000000000000000000000
exec Data_Purging
inputbuf
exec Data_Purging
resource-list
pagelock fileid=1 pageid=3509698 dbid=7 objectname=chola.dbo.INTERFACE_TABLE id=lockc1c6ec00 mode=U associatedObjectId=72057594778353664
owner-list
owner id=process6ca8748 mode=U
waiter-list
waiter id=process500ce08 mode=IU requestType=wait
pagelock fileid=1 pageid=6987355 dbid=7 objectname=chola.dbo.INTERFACE_TABLE id=lock25717c080 mode=U associatedObjectId=72057594781958144
owner-list
owner id=process500ce08 mode=U
waiter id=process6ca8748 mode=IX requestType=wait
waiter-list
Update InterfaceTable is a view. while updating this I am updating INTERFACE_TABLE table.
INTERFACE_TABLE table has primary key SSID
Please help me to avoid deadlock. Thanks in advance.
Upvotes: 0
Views: 224
Reputation: 19184
Going by this:
https://www.mssqltips.com/sqlservertip/2130/finding-sql-server-deadlocks-using-trace-flag-1222/
you can see two spids in there (81,123)
81 was the victim. it was running:
UPDATE dbo.InterfaceTable SET ERRORMESSAGE = @P1 , ACK_DATE = @P2 WHERE (SSID = @P3 )
it was run from hostname=10.9.52.12, loginname=prod
123 was the winner ,it was running:
Delete from INTERFACE_TABLE
where ( ERRORMESSAGE is null or ERRORMESSAGE
like '%AGREEMENT NOT FOUND.;%'
or ERRORMESSAGE like '%UNI:REALLOCATED%')
and ACK_DATE is not null
and ACKID is not null and SSID in(
select SSID from INTERFACE_TABLE_2015 with(Nolock)
)
it was from from hostname=APP01 hostpid=2972, loginname=APP01\sqlsupport in a SQL Agent job.
There are a few ways to attack this:
Understand what these two things were doing and change the process. It looks to me like the first one is a client app updating a single error log line and the second one a SQL Agent job that cleans up the logs. You could set the deadlock priority of the SQL Agent cleanup job so that it will fail rather than the application log (which is what you want)
Long transactions encourage deadlocks. Add indexes or optimise queries (why are you comparing to INTERFACE_TABLE_2015 every time?) so they don't take so long
Change your database to use SNAPSHOT ISOLATION and magically fix a lot of deadlock issues
Someone with more experience reading these could deduce exactly what happened here but that's a start.
Upvotes: 1