Azure SQL Database: capture full deadlock graphs with Extended Events in Blob Storage
Why the Log Analytics deadlock XML is truncated, and how to write complete xml_deadlock_report events to a blob container with managed identity (what to grant, the credential, the errors you meet).
Tested on Azure SQL Database (logical server, elastic pool), November 2026. It works as described below.
Why not just Log Analytics?
The diagnostic setting category Deadlocks sends every deadlock to AzureDiagnostics (deadlock_xml_s). It is the easiest source, but:
- the XML is cut at about 24 KB. On a busy database roughly one document in four is truncated, mostly the big ones (many sessions);
- object names, index names and statement text are filtered (
objectname='filtered',inputbuf= filtered); - the retention is the one of the workspace (often 30 days).
A truncated document keeps the victim list and the process list (query hash, lock mode, wait resource), but loses the resource list (who owns what). Good enough to count patterns, not to draw the graph.
A database-scoped Extended Events session writing to a blob container has none of these limits: you get the complete xml_deadlock_report, as an .xel file you open in SSMS.
system_health does not exist in Azure SQL Database, so you create your own session.
What you need
| Item | Detail |
|---|---|
| Storage account | Standard general-purpose v2, same region as the database, no hierarchical namespace, Hot tier, redundancy matching the database (ZRS/GZRS for a zone-redundant pool) |
| Container | Any name, no immutability policy |
| Authentication | Managed identity (no secret to rotate) or a SAS token (needs shared key access enabled on the account) |
| Permission in the database | CONTROL to create the credential; creating the session needs less |
Setup with managed identity
1. Give the SQL server access to the container
This is the step that is easy to forget: the logical SQL server itself must be added in the storage account.
- SQL server, Identity: check that a system-assigned managed identity is on. If it is off and you only use user-assigned identities, use the one set as primary identity.
- Storage account (or the container), Access control (IAM), Add role assignment: role Storage Blob Data Contributor, member = the managed identity of the SQL server.
- Wait a few minutes for the assignment to propagate.
If the storage firewall is on with the "trusted Azure services" exception, also add the server as a Microsoft.Sql/servers resource instance in the network rules.
2. Create the credential in the user database
Connect to the user database (not master). The credential name must be exactly the container URL: no trailing slash, no file name.
CREATE DATABASE SCOPED CREDENTIAL
[https://<storage-account>.blob.core.windows.net/<container>]
WITH IDENTITY = 'MANAGED IDENTITY';
No secret and no master key are needed with managed identity. The credential belongs to that database only: one per database.
3. Create and start the session
CREATE EVENT SESSION [deadlocks] ON DATABASE
ADD EVENT sqlserver.xml_deadlock_report
ADD TARGET package0.event_file
(
SET filename = N'https://<storage-account>.blob.core.windows.net/<container>/deadlocks.xel',
max_file_size = 50,
max_rollover_files = 20
);
ALTER EVENT SESSION [deadlocks] ON DATABASE STATE = START;
xml_deadlock_report only fires when a deadlock happens, so the overhead is negligible.
Errors you may meet
| Error when creating or starting the session | Cause |
|---|---|
error 86: The specified network password is not correct |
No database-scoped credential named exactly like the container URL in this database, or the name ends with / |
error 5: Access is denied |
The server identity has no Storage Blob Data Contributor on the account or container (not propagated yet?), or the storage firewall blocks the server |
error 3: The system cannot find the path specified |
The container does not exist |
error 13: The data is invalid |
Immutability policy on the container, or hierarchical namespace enabled on the account |
In my case error 86 was shown first because the credential was missing; once it existed, the role assignment of the server on the storage account was the missing piece, and then the session started.
Check what exists in the database:
SELECT name, credential_identity FROM sys.database_scoped_credentials;
SELECT name FROM sys.database_event_sessions;
SELECT name FROM sys.dm_xe_database_sessions; -- running sessions
Read the deadlocks
- SSMS: Extended Events node under the database, session, View Target Data (SSMS 19.2 and later read the blobs directly), or download the
.xelfiles and use File > Open (several rollover files: Merge Extended Event Files). Eachxml_deadlock_reportevent shows the graph. - T-SQL:
SELECT CAST(event_data AS xml) AS deadlock
FROM sys.fn_xe_file_target_read_file(
'https://<storage-account>.blob.core.windows.net/<container>/deadlocks*.xel', NULL, NULL, NULL);
Notes
- The session belongs to the database. After a geo-failover or a database copy, check on the new primary that the session exists and runs.
- A SAS token works too (credential
IDENTITY = 'SHARED ACCESS SIGNATURE', secret = token without the leading?, permissionsrwdl, no IP restriction, valid for the whole life of the session), but it expires silently: managed identity is simpler. - To find recurring patterns, group the deadlocks by the pair of query hashes (and lock resources) rather than reading them one by one: a few statements usually explain most of them. Without RCSI, shared locks of read committed readers deadlock with writers that touch the same rows in a different order, in bursts at peak hours.
See also KQL queries to monitor Azure SQL Database for the Log Analytics side (deadlock counts per day).