Skip to content

Commit 0859940

Browse files
20231009 acrolinx
1 parent 963d78d commit 0859940

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

docs/relational-databases/sql-server-deadlocks-guide.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,12 @@ The second update statement in **Session A** will be blocked by **Session B** on
475475

476476
After a few seconds, the deadlock monitor will identify that the transactions in **Session A** and **Session B** are mutually blocking one another, and that neither can make progress. You should see a deadlock occur, with **Session A** chosen as the deadlock victim. **Session B** will complete successfully. An error message will appear in **Session A** with text similar to the following:
477477

478-
```
478+
```output
479479
Msg 1205, Level 13, State 51, Line 7
480480
Transaction (Process ID 51) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
481481
```
482482

483-
If a deadlock is not raised, verify that READ_COMMITTED_SNAPSHOT has been enabled in your sample database. Deadlocks may occur in any database configuration, but this example requires READ_COMMITTED_SNAPSHOT to be enabled.
483+
If a deadlock is not raised, verify that READ_COMMITTED_SNAPSHOT has been enabled in your sample database. Deadlocks can occur in any database configuration, but this example requires READ_COMMITTED_SNAPSHOT to be enabled.
484484

485485
You could then view details of the deadlock in the ring_buffer target of the `system_health` Extended Events session, which is enabled and active by default in SQL Server. Consider the following query:
486486

@@ -511,7 +511,7 @@ You can view the XML in the `Deadlock_XML` column inside SSMS, by selecting the
511511

512512
## Optimized locking and deadlocks
513513

514-
**Applies to:** [!INCLUDE[ssazure-sqldb](../../includes/ssazure-sqldb.md)]
514+
**Applies to:** [!INCLUDE[ssazure-sqldb](../includes/ssazure-sqldb.md)]
515515

516516
[Optimized locking](performance/optimized-locking.md) introduced a different method for locking mechanics that changes how deadlocks involving exclusive TID locks may be reported. Under each resource in the deadlock report's `<resource-list>`, each `<xactlock>` element reports the underlying resources and specific information for locks of each member of a deadlock.
517517

@@ -532,30 +532,33 @@ In session 1:
532532

533533
```sql
534534
--session 1
535-
begin tran foo;
536-
update t2 set b = b+ 10 where a = 1;
535+
BEGIN TRAN foo;
536+
UPDATE t2 SET b = b+ 10 WHERE a = 1;
537537
```
538538

539539
In session 2:
540+
540541
```sql
541542
--session 2:
542-
begin tran bar
543-
update t2 set b = b+ 10 where a = 2;
543+
BEGIN TRAN bar
544+
UPDATE t2 SET b = b+ 10 WHERE a = 2;
544545
```
545-
546+
546547
In session 1:
548+
547549
```sql
548550
--session 1:
549-
update t2 set b = b + 100 where a = 2;
551+
UPDATE t2 SET b = b + 100 WHERE a = 2;
550552
```
551-
553+
552554
In session 2:
555+
553556
```sql
554557
--session 2:
555-
update t2 set b = b + 20 where a = 1;
558+
UPDATE t2 SET b = b + 20 WHERE a = 1;
556559
```
557560

558-
This results in a deadlock. In this case, a keylock resource, where each session holds an X lock on its own TID and is waiting on the S lock on the other TID, resulting in a deadlock. The following XML, captured as the deadlock report, contains elements and attributes specific to optimized locking:
561+
This scenario of competing `UPDATE` statements results in a deadlock. In this case, a keylock resource, where each session holds an X lock on its own TID and is waiting on the S lock on the other TID, resulting in a deadlock. The following XML, captured as the deadlock report, contains elements and attributes specific to optimized locking:
559562

560563
:::image type="content" source="media/sql-server-deadlocks-guide/optimized-locking-tid-lock-deadlock-xml.png" alt-text="A screenshot of the XML of a deadlock report showing the UnderlyingResource nodes and keylock nodes specific to optimized locking." lightbox="media/sql-server-deadlocks-guide/optimized-locking-tid-lock-deadlock-xml.png":::
561564

0 commit comments

Comments
 (0)