What is livelock exactly? In SQL when/how does it happen? Anything T-SQL developer can do to avoid it?

2.8k views Asked by At

I have encountered this jargon for SQL Server, I am just not able to understand what it is exactly it happens in SQL Server. I am looking at some SQL Server example where it occurs...

I have been searching on google but all keep getting is 2 people in corridor example.

1

There are 1 answers

0
Aaron Bertrand On

A deadlock occurs when two processes compete for the same resources, but in an order which causes a stalemate. For example, A locks X, then tries to lock Y, while B has locked Y and tries to lock X. The key is that the two (or more) processes are preventing each other from doing anything.

A livelock occurs when there are overlapping shared locks that prevent another process from acquiring the exclusive lock it needs. The difference is that all of these overlapping processes continue to get their work done, so they are still "live" - only the victim is blocked until they are done. Which may be never on a busy enough, poorly designed system. :-) You may be able to overcome this situation by escalating the deadlock priority for your writers, but I'll be honest, this isn't a scenario I've seen very often, and I've worked with SQL Server since 6.5...