Friday 16 September 2011

SQL Server deadlock caused by Inappropriete Index

Recently one of my projects experienced weird transaction deadlock error on the data processing component. The component was running well without errors in the first week of production, but suddenly threw dozens of SQL exception "Transaction (Process ID 69) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.". After digging into a day of the code and database analysis, it appears that a row update operation actually causes an exclusive table level lock. As the result, other update request(s) from my multi-threading component trigger the deadlocks. A further analysis, the grief was a inappropriate primary key index which trigger SQL Server escalates the lock level from row to table. Once the root cause was identified, the remediation is considerable easy and is to make sure the "ALLOW_ROW_LOCKS" option was checked which should be a default setting in SQL Server 2008, and the index type is clustered.

 
alter index [your_index_name] on [dbo].[your_table_name] set (allow_row_locks = ON);
 

1 comment:

  1. Hi, It’s Amazing to see your blog.This provide us all the necessary information regarding data analyst course in pune
    upcoming real estate project which having all the today’s facilities.

    ReplyDelete