Rotating Header Image

Blocking vs Deadlocking… do you know the difference?

Seems simple enough doesn’t it? It always amazes me how many DBAs still get this wrong or don’t understand the difference between the two.

Blocking happens… can’t do much about it other then try and minimize the amount of time that a resource locks another. When a process tries to establish a lock SQL Server will first make sure that the resource is not currently locked. If it’s able to establish the lock then the process executes. When a process cannot establish the lock required it will wait until either the lock on the resource frees or a timeout of somekind occurs. THIS IS NOT DEADLOCKING. This is blocking.

Deadlocking occurs when 2 processes are wait on each other before they can continue processing. When this happens SQL Server will detect when a deadlock scenario is established and will punt one of the transactions in order to free up the resource for the other process. The process it punts is the one that can be rolled back with the least amount of resources and time. There are ways that you can control which process gets punted using something called SET DEADLOCK PRIORITY.

Hopefully this helps you in defining and understanding the differences between blocking and deadlocking.

Enjoy!!

Post to Twitter Post to Delicious Post to Digg Post to StumbleUpon

Leave a Reply

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.