CHAPTER 19

image

Deadlocks

In a nutshell, a deadlock is just a special blocking case when multiple sessions or, sometimes, even multiple execution threads within a single session block each other.

Classic Deadlock

Classic deadlock occurs when two or more sessions are competing for the same set of resources. Let’s look at a by-the-book example and assume that you have two sessions updating the table. As the first step, session 1 updates the row R1 and session 2 updates the row R2. You know that at this point both sessions acquire and hold exclusive (X) lock on the rows. You can see this happening in Figure 19-1.

Figure 19-1. Classic deadlock, Step ...

Get Pro SQL Server Internals now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.