Large deletions blocked by negative SPID

Mike Wright 31 Reputation points
2022-03-21T13:02:46.893+00:00

I have a nightly "archive and delete" process that writes all data from a large, busy table >150 days old to Blob storage, and deletes the same from the hosting table. The process performance is terrible - and in fact, it may take more than a day to delete a day's worth of data!

When I check for blocking, I see this process is almost always blocked by SPID "-5" ... my research tells me that this is an orphaned DT. However, when I run this:

SELECT DISTINCT(request_owner_guid) as UoW_Guid FROM sys.dm_tran_locks WHERE request_session_id =-5

It returns no rows.

There have been a few times where the performance of this operation deleted >30k a minute, which is great. So, something going on is transient but I can't pin it down. When it's in this state, the deletions take 10-30x longer.

Some background: This is an Azure SQL Managed Instance. I couldn't find a category just for that, so I posted in Azure SQL Databases, although I understand they are different.

How can I find out what SPID -5 is so I can fix the problem?

Thanks.

Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. Alberto Morillo 32,886 Reputation points MVP
    2022-03-21T13:16:00.3+00:00

    SInce -5 is related to IO latches, as author of the article you shared with us stated. Let's make sure we have configured the storage subsystem well.

    IO latches indicate that the database engine is waiting to fetch or save data pages from memory to data file. In General Purpose tier, you might fix this issue by pre-allocating the data file as explained on this article.