<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DEADLOCK | DBA von Nebenan</title>
	<atom:link href="https://dbavonnebenan.de/tag/deadlock/feed/" rel="self" type="application/rss+xml" />
	<link>https://dbavonnebenan.de</link>
	<description>Sql Server, Performance &#38; PowerShell Automation</description>
	<lastBuildDate>Sun, 08 Jun 2025 06:52:02 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://dbavonnebenan.de/wp-content/uploads/2025/04/cropped-www_logo-32x32.png</url>
	<title>DEADLOCK | DBA von Nebenan</title>
	<link>https://dbavonnebenan.de</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Dokumentation von Blocks und Deadlocks &#8211; Wenn der 3rd-Party Vendor Beweise fordert</title>
		<link>https://dbavonnebenan.de/reporting-sql-server-blocks-de/</link>
					<comments>https://dbavonnebenan.de/reporting-sql-server-blocks-de/#respond</comments>
		
		<dc:creator><![CDATA[Gabriel]]></dc:creator>
		<pubDate>Mon, 28 Apr 2025 18:11:00 +0000</pubDate>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[BLOCK]]></category>
		<category><![CDATA[DE]]></category>
		<category><![CDATA[DEADLOCK]]></category>
		<category><![CDATA[REPORTING]]></category>
		<guid isPermaLink="false">https://dbavonnebenan.de/?p=411</guid>

					<description><![CDATA[<p>Zu wissen, dass SQL Server Blocking- oder Deadlock-Probleme hat, ist noch ziemlich einfach. Man merkt das normalerweise in der Anwendung und mit den richtigen Queries kann man auch die entsprechenden Blocking-Ketten anzeigen. Am einfachsten geht das mit http://whoisactive.com. Ich hab auch noch eine eigene Entwicklung dazu, die werde ich in einem späteren Blogpost vorstellen, die [&#8230;]</p>
<p>The post <a href="https://dbavonnebenan.de/reporting-sql-server-blocks-de/">Dokumentation von Blocks und Deadlocks – Wenn der 3rd-Party Vendor Beweise fordert</a> first appeared on <a href="https://dbavonnebenan.de">DBA von Nebenan</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph">Zu wissen, dass SQL Server Blocking- oder Deadlock-Probleme hat, ist noch ziemlich einfach. Man merkt das normalerweise in der Anwendung und mit den richtigen Queries kann man auch die entsprechenden Blocking-Ketten anzeigen. Am einfachsten geht das mit <a href="http://whoisactive.com">http://whoisactive.com</a>.</p>



<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
SELECT 
    blocking_session_id   AS blocking_session,
    session_id            AS blocked_session,
    wait_time / 1000.0    AS waiting_sec,
    wait_type             AS waittype,
    resource_description  AS ressource
FROM 
    sys.dm_os_waiting_tasks
WHERE 
    blocking_session_id IS NOT NULL
ORDER BY 
    wait_time DESC
</pre></div>


<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">Ich hab auch noch eine eigene Entwicklung dazu, die werde ich in einem späteren Blogpost vorstellen, die meinen individuellen Anforderungen besser entspricht.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Das Problem</h2>



<p class="wp-block-paragraph">Jetzt kann ich AdHoc Blockings anzeigen, aber bei Deadlocks wird&#8217;s interessanter. Dafür muss die System Health Session gecheckt werden, die ist auch noch flüchtig.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
-- Query System Health Session for Deadlocks

SELECT
    event_data.value(&#039;(event/@timestamp)&#x5B;1]&#039;, &#039;datetime2&#039;) AS DeadlockDateTime,
    event_data.query(&#039;.&#039;)                                  AS DeadlockGraph
FROM
(
    SELECT 
        CAST(target_data AS XML) AS target_data
    FROM 
        sys.dm_xe_session_targets AS st
    JOIN 
        sys.dm_xe_sessions AS s ON s.address = st.event_session_address
    WHERE
             s.name = &#039;system_health&#039;
        AND st.target_name = &#039;ring_buffer&#039;
) AS data
CROSS APPLY
    target_data.nodes(&#039;//RingBufferTarget/event&#x5B;@name=&quot;xml_deadlock_report&quot;]&#039;) AS XEventData(event_data)
ORDER BY 
    DeadlockDateTime DESC;
</pre></div>


<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">Dieses Problem hatte ich bei einem Kunden, der extrem mit Deadlocks in einer 3rd Party Anwendung zu kämpfen hatte, aber der Support war bisschen&#8230; sagen wir mal zurückhaltend. 😉</p>



<p class="wp-block-paragraph">Wir mussten denen alles transparent melden, damit die anfangen eine Lösung zu finden. Query-Resultsets kann man natürlich als transparent betrachten, wenn man sie versteht oder verstehen will. Leider sind die XML von Health Sessions oder Extended Events nicht gerade dafür berühmt, lesbar zu sein. Der Kunde wollte aber einfach nur, dass das Problem gelöst wird.</p>



<p class="wp-block-paragraph">Also haben wir gemeinsam eine Reporting-Lösung entwickelt.</p>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Die Idee</h2>



<p class="wp-block-paragraph">Mit Extended Events hab ich XML-Daten und mit PowerShell kann ich XML parsen wie ich will, auch zu einem Report meiner Wahl.</p>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Das Ziel</h2>



<p class="wp-block-paragraph">Wir wollten eine Möglichkeit, abseits von SQL Server Resultsets, Anwendungsprobleme mit Anomalien in den SQL Server Metriken zu überlagern, um schnell Lösungen herbeizuführen.</p>



<p class="wp-block-paragraph">In der Woche nach dem Livegang der Lösung gab&#8217;s viele, viele &#8222;Aha&#8220;-Momente. Von falsch konfigurierten ERP-Parametern bis hin zu schlechtem Transaction-Handling.</p>



<div style="height:38px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Der Weg</h2>



<h3 class="wp-block-heading">Persistente Daten</h3>



<p class="wp-block-paragraph">Das Wichtigste ist, Blocking Session und Deadlock Events persistent zu speichern. Das geht perfekt mit Extended Events. Dafür gibt&#8217;s zwei Bereiche:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
-- SNIPPET!!

ADD EVENT sqlserver.blocked_process_report(
    ACTION(sqlserver.client_app_name,
           sqlserver.client_hostname,
           sqlserver.database_name)
),
ADD EVENT sqlserver.xml_deadlock_report(
    ACTION(sqlserver.client_app_name,
           sqlserver.client_hostname,
           sqlserver.database_name)
)
</pre></div>


<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">Das ganze wird in einem eigenen Extended Event konfiguriert und die Aufzeichnungen laufen bereits. <strong>Fast!</strong> Wir müssen noch SQL Server konfigurieren, damit Blocked Process als Extended Events behandelt werden.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
EXEC sp_configure &#039;show advanced options&#039;, 1;
GO
RECONFIGURE;
GO
EXEC sp_configure &#039;blocked process threshold&#039;, &#039;5&#039;; -- 5 Sekunden
RECONFIGURE
GO
</pre></div>


<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading"><strong>Daten auslesen</strong></h3>



<h3 class="wp-block-heading">100% PowerShell</h3>



<p class="wp-block-paragraph">Nachdem die Events geloggt werden, müssen sie ausgewertet werden. Was mir sofort eingefallen ist, waren die dbatools mit <a href="https://docs.dbatools.io/Read-DbaXEFile.html">Read-DbaXEFile</a>. Das Problem ist, dass die aktuell geschriebene Datei damit nicht gelesen werden kann. Du kannst dir vorstellen, dass Blocking- und Deadlock-Events nicht in solchen Massen auftreten, dass dutzende File-Rotationen innerhalb von 24h durchgeführt werden. Falls doch, hast du definitiv ein anderes Problem als es nur zu reporten. Also haben wir den Umweg über SQL Server genommen, da auch hier die aktuelle Datei gelesen werden kann.</p>



<h3 class="wp-block-heading">PowerShell + TSql</h3>



<p class="wp-block-paragraph">XML mit Queries zu lesen, fällt mir immer noch sehr schwer, aber DANKE an Brent Ozar, uns allen bekannt, für die <a href="https://www.brentozar.com/archive/2014/03/extended-events-doesnt-hard/">grundlegende Query</a>, auf der ich aufbauen konnte. Zumindest hatte ich jetzt ein Resultset zur Orientierung und ein separates XML für jedes Event im Log.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
-- Snippet
select
    *
FROM sys.fn_xe_file_target_read_file
   (&#039;C:\temp\XEventSessions\blocked_process*.xel&#039;,
    &#039;C:\temp\XEventSessions\blocked_process*.xem&#039;,
     null, null)
CROSS APPLY 
    (SELECT CAST(event_data AS XML) AS event_data) as xevents
</pre></div>


<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">Finalisierung mit PowerShell</h3>



<p class="wp-block-paragraph">Da ich endlich mein XML-Event hatte, konnte ich es mit PowerShell parsen, transformieren und letztendlich in einen schönen Text-Report verpacken.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
Sql Server Deadlock Analysis | Event Time: 2025-04-08T11:16:07.447
================================================================================

SQL STATEMENTS INVOLVED
--------------------------------------------------------------------------------

    Process ID:   process261b00cfc28
    SPID:         643
    Database:     DATABASENAME
    Query:        **DETAILED QUERY**

----------------------------------------

    Process ID:   process258294fbc28
    SPID:         650
    Database:     DATABASENAME
    Query:        **DETAILED QUERY**

----------------------------------------

VICTIM LIST
--------------------------------------------------------------------------------

    Process ID:   process261b00cfc28
    SPID:         643
    Database:     DATABASENAME


PROCESS LIST
--------------------------------------------------------------------------------

    Process ID:               process261b00cfc28
    SPID:                     643
    Isolation Level:          read uncommitted (1)
    Logical Reads:            700
    Wait Resource:            KEY: 6:72058005407662080 (fb04e1bc7788)
    Wait Time (ms):           2247
    Transaction:              user_transaction
    Last Transaction Started: 2025-04-08T11:16:07.447
    Client:                   &#039;dbserver_dll &amp;lt;ID@APPSERVER:34784&gt;&#039;
    Hostname:                 APPSERVER
    User:                     USERNAME


EXECUTED SQL STATEMENT
----------------------------------------

    **DETAILED QUERY**


Process Details
================================================================================


    Process ID:               process258294fbc28
    SPID:                     650
    Isolation Level:          read uncommitted (1)
    Logical Reads:            1904
    Wait Resource:            KEY: 6:72057996178358272 (2a9726d2d061)
    Wait Time (ms):           2278
    Transaction:              user_transaction
    Last Transaction Started: 2025-04-08T11:16:07.330
    Client:                   &#039;dbserver_dll &amp;lt;ID@APPSERVER:11664&gt;&#039;
    Hostname:                 APPSERVER
    User:                     USERNAME


EXECUTED SQL STATEMENT
----------------------------------------

    **DETAILED QUERY**


Process Details
================================================================================


RESOURCE LIST
--------------------------------------------------------------------------------

    Resource:
        Type:               keylock
        Database:           6
        Object:             DATABASENAME.dbo.tcprmp300100
        Index:              Itcprmp300100_1a
        Lock Mode:          X
        HOBT ID:            72058005407662080
        Associated Object ID: 72058005407662080

    Owners:
        Process ID:         process258294fbc28, Mode: X

    Waiting Processes:
        Process ID:         process261b00cfc28, Mode: U, Request Type: wait

================================================================================

    Resource:
        Type:               keylock
        Database:           6
        Object:             DATABASENAME.dbo.tcprrp011100
        Index:              Itcprrp011100_1a
        Lock Mode:          X
        HOBT ID:            72057996178358272
        Associated Object ID: 72057996178358272

    Owners:
        Process ID:         process261b00cfc28, Mode: X

    Waiting Processes:
        Process ID:         process258294fbc28, Mode: U, Request Type: wait

================================================================================
</pre></div>


<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">Umsetzung</h3>



<p class="wp-block-paragraph">Es wurde gewünscht, die Ergebnisse in den Daily Report zu integrieren, den wir bereits mit PowerShell umgesetzt hatten. Jetzt ist es nicht geil, potenziell jeden Morgen 200 Textdateien an eine E-Mail zu hängen, deshalb gibt das PowerShell-Script eine Tabelle zurück, die zeigt, wie Blocks und Locks in Zeitraum X aufgetreten sind, und bei Bedarf kann man proaktiv die Ordnerstruktur checken.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full has-custom-border"><img fetchpriority="high" decoding="async" width="662" height="223" src="https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-28_15-33.png" alt="" class="has-border-color has-base-border-color wp-image-261" style="border-width:1px" srcset="https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-28_15-33.png 662w, https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-28_15-33-300x101.png 300w" sizes="(max-width: 662px) 100vw, 662px" /></figure>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">Für den dramatischen Effekt und schnellen Überblick wird auch noch eine Excel-Datei generiert. In diesem Beispiel gab&#8217;s einen schönen Kollateralfund, dass die DWH-Jobs massive Probleme hatten 🙂</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-large has-custom-border is-style-default"><img decoding="async" width="1024" height="471" src="https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-27_17-18-1024x471.png" alt="" class="has-border-color wp-image-254" style="border-color:#000000;border-width:1px;border-radius:5px" srcset="https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-27_17-18-1024x471.png 1024w, https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-27_17-18-300x138.png 300w, https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-27_17-18-768x353.png 768w, https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-27_17-18.png 1131w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">Und schon hatten wir ein paar Reports, die wir dem Vendor in die Hand drücken konnten, und dann ging&#8217;s sehr schnell.</p>



<div style="height:24px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
Die Ordnerstruktur

_report/
├── text_reports/
│   └── YYYY/
│       └── MM/
│           └── DD/
│               ├── 20231120_123456_dbname_blocked.txt
│               ├── 20231120_123456_dbname_blocked.xml
│               └── 20231120_123456_dbname_deadlock.txt
└── excel_reports/
    └── BlockReport_20231120_123456.xlsx
</pre></div>


<div style="height:22px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph"><strong>Leider erlebe ich immer wieder, dass Anwendungsvendoren denken, ihre Kunden sind zu blöd und können die Anwendung nicht bedienen. Hört auf damit und glaubt euren Kunden manchmal auch ohne 101% Daten, die man nur sammeln kann, wenn man bereits Sachkenntnis hat.</strong></p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Repository ansehen</h2>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>


https://github.com/gabrielkoehl/get-snapBlockEvents


<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">Das Script hat verschiedene Parameter und Optionen, Details stehen in der README.MD. Falls du Fragen hast, lass sie in den Kommentaren oder kontaktier mich.</p>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Anderes</h2>



<p class="wp-block-paragraph">Erik Darling hat auch eine Lösung entwickelt, um Extended Events lesbar zu machen, falls andere Ansätze gebraucht werden. (<a href="https://github.com/erikdarlingdata/DarlingData/tree/main/sp_HumanEvents">sp_HumanEvents</a>)</p>



<div style="height:74px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full is-resized"><img decoding="async" width="295" height="294" src="https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-21_16-19.png" alt="" class="wp-image-113" style="width:223px;height:auto" srcset="https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-21_16-19.png 295w, https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-21_16-19-150x150.png 150w" sizes="(max-width: 295px) 100vw, 295px" /></figure>



<p class="has-text-align-center wp-block-paragraph"><strong>Gabriel, der DBAvonNebenan</strong></p>



<p class="wp-block-paragraph"></p><p>The post <a href="https://dbavonnebenan.de/reporting-sql-server-blocks-de/">Dokumentation von Blocks und Deadlocks – Wenn der 3rd-Party Vendor Beweise fordert</a> first appeared on <a href="https://dbavonnebenan.de">DBA von Nebenan</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dbavonnebenan.de/reporting-sql-server-blocks-de/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Reporting Blocks and Deadlocks: When the 3rd-Party Vendor Demands Evidence</title>
		<link>https://dbavonnebenan.de/reporting-sql-server-blocks-en/</link>
					<comments>https://dbavonnebenan.de/reporting-sql-server-blocks-en/#respond</comments>
		
		<dc:creator><![CDATA[Gabriel]]></dc:creator>
		<pubDate>Mon, 28 Apr 2025 14:19:36 +0000</pubDate>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[BLOCK]]></category>
		<category><![CDATA[DEADLOCK]]></category>
		<category><![CDATA[eng]]></category>
		<category><![CDATA[REPORTING]]></category>
		<guid isPermaLink="false">https://dbavonnebenan.de/?p=253</guid>

					<description><![CDATA[<p>Knowing that SQL Server has blocking or deadlock problems is still quite easy. You usually notice this in the application, and with the right queries, you can also display the corresponding blocking chains. The simplest way to do this is with http://whoisactive.com. I also have a custom development that I will present in a later [&#8230;]</p>
<p>The post <a href="https://dbavonnebenan.de/reporting-sql-server-blocks-en/">Reporting Blocks and Deadlocks: When the 3rd-Party Vendor Demands Evidence</a> first appeared on <a href="https://dbavonnebenan.de">DBA von Nebenan</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph">Knowing that SQL Server has blocking or deadlock problems is still quite easy. You usually notice this in the application, and with the right queries, you can also display the corresponding blocking chains. The simplest way to do this is with <a href="http://whoisactive.com">http://whoisactive.com</a>.</p>



<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
SELECT 
    blocking_session_id   AS blocking_session,
    session_id            AS blocked_session,
    wait_time / 1000.0    AS waiting_sec,
    wait_type             AS waittype,
    resource_description  AS ressource
FROM 
    sys.dm_os_waiting_tasks
WHERE 
    blocking_session_id IS NOT NULL
ORDER BY 
    wait_time DESC
</pre></div>


<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">I also have a custom development that I will present in a later blog post, which better meets my individual requirements.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">The Problem</h2>



<p class="wp-block-paragraph">Now I can display AdHoc blocks, but with deadlocks it gets more interesting. For this, the System Health Session must be checked, which is also volatile.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
-- Query System Health Session for Deadlocks

SELECT
    event_data.value(&#039;(event/@timestamp)&#x5B;1]&#039;, &#039;datetime2&#039;) AS DeadlockDateTime,
    event_data.query(&#039;.&#039;)                                  AS DeadlockGraph
FROM
(
    SELECT 
        CAST(target_data AS XML) AS target_data
    FROM 
        sys.dm_xe_session_targets AS st
    JOIN 
        sys.dm_xe_sessions AS s ON s.address = st.event_session_address
    WHERE
             s.name = &#039;system_health&#039;
        AND st.target_name = &#039;ring_buffer&#039;
) AS data
CROSS APPLY
    target_data.nodes(&#039;//RingBufferTarget/event&#x5B;@name=&quot;xml_deadlock_report&quot;]&#039;) AS XEventData(event_data)
ORDER BY 
    DeadlockDateTime DESC;
</pre></div>


<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">I encountered this problem with a client who was struggling enormously with deadlocks in a 3rd party application, but the support was a bit&#8230; let&#8217;s say reluctant. 😉</p>



<p class="wp-block-paragraph">We had to report everything transparently to them so they would start finding a solution. Of course, query result sets can be considered transparent if you understand them or want to understand them. Unfortunately, the XML of Health Sessions or Extended Events are not exactly famous for being readable. Yet the client simply wanted the problem to be fixed.</p>



<p class="wp-block-paragraph">So together we developed a reporting solution.</p>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">The Idea</h2>



<p class="wp-block-paragraph">With Extended Events I have XML data, and with PowerShell I can parse XML however I want, including into a report of my choice.</p>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">The Goal</h2>



<p class="wp-block-paragraph">We wanted a way, apart from SQL Server result sets, to overlay application problems with anomalies in the SQL Server metrics to quickly bring about solutions.</p>



<p class="wp-block-paragraph">In the week after the solution went live, there were many, many &#8222;aha&#8220; moments. From incorrectly configured ERP parameters to poor transaction handling.</p>



<div style="height:38px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">The Way</h2>



<h3 class="wp-block-heading">Persistent Data</h3>



<p class="wp-block-paragraph">The most important thing is to persistently store blocking session and deadlock events. This works perfectly with Extended Events. There are two areas for this:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
-- SNIPPET!!

ADD EVENT sqlserver.blocked_process_report(
    ACTION(sqlserver.client_app_name,
           sqlserver.client_hostname,
           sqlserver.database_name)
),
ADD EVENT sqlserver.xml_deadlock_report(
    ACTION(sqlserver.client_app_name,
           sqlserver.client_hostname,
           sqlserver.database_name)
)
</pre></div>


<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">The whole thing is configured in its own Extended Event and the recordings are already running. <strong>Nearly!</strong> We still need to configure SQL Server to treat Blocked Process as Extended Events.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
EXEC sp_configure &#039;show advanced options&#039;, 1;
GO
RECONFIGURE;
GO
EXEC sp_configure &#039;blocked process threshold&#039;, &#039;5&#039;; -- 5 Secconds
RECONFIGURE
GO
</pre></div>


<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading"><strong>Read Data</strong></h3>



<h3 class="wp-block-heading">100% PowerShell</h3>



<p class="wp-block-paragraph">After the events are logged, they need to be evaluated. What immediately came to my mind were the dbatools with <a href="https://docs.dbatools.io/Read-DbaXEFile.html">Read-DbaXEFile</a>. The problem is that the currently written file cannot be read with it. You can imagine that blocking and deadlock events don&#8217;t occur in such masses that dozens of file rotations are performed within 24 hours. If they do, you definitely have a different problem than just reporting it . So we took the detour via SQL Server, since the current file can also be read here.</p>



<h3 class="wp-block-heading">PowerShell + TSql</h3>



<p class="wp-block-paragraph">I still find it very difficult to read XML with queries, but THANKS to Brent Ozar, known to all of us, for the<a href="https://www.brentozar.com/archive/2014/03/extended-events-doesnt-hard/"> basic query</a> I could build upon. At least I now had a result set for orientation and a separate XML for each event in the log.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
-- Snippet
select
    *
FROM sys.fn_xe_file_target_read_file
   (&#039;C:\temp\XEventSessions\blocked_process*.xel&#039;,
    &#039;C:\temp\XEventSessions\blocked_process*.xem&#039;,
     null, null)
CROSS APPLY 
    (SELECT CAST(event_data AS XML) AS event_data) as xevents
</pre></div>


<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">Finalization with PowerShell</h3>



<p class="wp-block-paragraph">Since I finally had my XML event, I could parse it with PowerShell, transform it, and finally package it into a nice text report.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
Sql Server Deadlock Analysis | Event Time: 2025-04-08T11:16:07.447
================================================================================

SQL STATEMENTS INVOLVED
--------------------------------------------------------------------------------

    Process ID:   process261b00cfc28
    SPID:         643
    Database:     DATABASENAME
    Query:        **DETAILED QUERY**

----------------------------------------

    Process ID:   process258294fbc28
    SPID:         650
    Database:     DATABASENAME
    Query:        **DETAILED QUERY**

----------------------------------------

VICTIM LIST
--------------------------------------------------------------------------------

    Process ID:   process261b00cfc28
    SPID:         643
    Database:     DATABASENAME


PROCESS LIST
--------------------------------------------------------------------------------

    Process ID:               process261b00cfc28
    SPID:                     643
    Isolation Level:          read uncommitted (1)
    Logical Reads:            700
    Wait Resource:            KEY: 6:72058005407662080 (fb04e1bc7788)
    Wait Time (ms):           2247
    Transaction:              user_transaction
    Last Transaction Started: 2025-04-08T11:16:07.447
    Client:                   &#039;dbserver_dll &amp;lt;ID@APPSERVER:34784&gt;&#039;
    Hostname:                 APPSERVER
    User:                     USERNAME


EXECUTED SQL STATEMENT
----------------------------------------

    **DETAILED QUERY**


Process Details
================================================================================


    Process ID:               process258294fbc28
    SPID:                     650
    Isolation Level:          read uncommitted (1)
    Logical Reads:            1904
    Wait Resource:            KEY: 6:72057996178358272 (2a9726d2d061)
    Wait Time (ms):           2278
    Transaction:              user_transaction
    Last Transaction Started: 2025-04-08T11:16:07.330
    Client:                   &#039;dbserver_dll &amp;lt;ID@APPSERVER:11664&gt;&#039;
    Hostname:                 APPSERVER
    User:                     USERNAME


EXECUTED SQL STATEMENT
----------------------------------------

    **DETAILED QUERY**


Process Details
================================================================================


RESOURCE LIST
--------------------------------------------------------------------------------

    Resource:
        Type:               keylock
        Database:           6
        Object:             DATABASENAME.dbo.tcprmp300100
        Index:              Itcprmp300100_1a
        Lock Mode:          X
        HOBT ID:            72058005407662080
        Associated Object ID: 72058005407662080

    Owners:
        Process ID:         process258294fbc28, Mode: X

    Waiting Processes:
        Process ID:         process261b00cfc28, Mode: U, Request Type: wait

================================================================================

    Resource:
        Type:               keylock
        Database:           6
        Object:             DATABASENAME.dbo.tcprrp011100
        Index:              Itcprrp011100_1a
        Lock Mode:          X
        HOBT ID:            72057996178358272
        Associated Object ID: 72057996178358272

    Owners:
        Process ID:         process261b00cfc28, Mode: X

    Waiting Processes:
        Process ID:         process258294fbc28, Mode: U, Request Type: wait

================================================================================
</pre></div>


<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">Implementation</h3>



<p class="wp-block-paragraph">It was requested to add the results to the daily report, which we had already implemented with PowerShell. Now, it&#8217;s not great to potentially attach 200 text files to an email every morning, so the PowerShell script returns a table showing how blocks and locks occurred in time period X, and if needed, one can proactively check the folder structure.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full has-custom-border"><img loading="lazy" decoding="async" width="662" height="223" src="https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-28_15-33.png" alt="" class="has-border-color has-base-border-color wp-image-261" style="border-width:1px" srcset="https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-28_15-33.png 662w, https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-28_15-33-300x101.png 300w" sizes="auto, (max-width: 662px) 100vw, 662px" /></figure>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">For dramatic effect and a quick overview, an Excel file is also generated. In this example, there was a nice collateral finding that the DWH jobs had serious problems 🙂</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-large has-custom-border is-style-default"><img loading="lazy" decoding="async" width="1024" height="471" src="https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-27_17-18-1024x471.png" alt="" class="has-border-color wp-image-254" style="border-color:#000000;border-width:1px;border-radius:5px" srcset="https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-27_17-18-1024x471.png 1024w, https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-27_17-18-300x138.png 300w, https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-27_17-18-768x353.png 768w, https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-27_17-18.png 1131w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">And just like that, we had a few reports that we could hand over to the vendor, and then things moved very quickly.</p>



<div style="height:24px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
Die Ordner Struktur

_report/
├── text_reports/
│   └── YYYY/
│       └── MM/
│           └── DD/
│               ├── 20231120_123456_dbname_blocked.txt
│               ├── 20231120_123456_dbname_blocked.xml
│               └── 20231120_123456_dbname_deadlock.txt
└── excel_reports/
    └── BlockReport_20231120_123456.xlsx
</pre></div>


<div style="height:22px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph"><strong><strong>Unfortunately, I experience again and again that application vendors think their customers are stupid and cannot operate the application. Stop doing that and believe your customers sometimes without 101% data, which you can only collect if you already have knowledge of the subject matter.</strong></strong></p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">See Repository</h2>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>


https://github.com/gabrielkoehl/get-snapBlockEvents


<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">The script has various parameters and options, details are in the README.MD. If you have questions, leave them in the comments or contact me.</p>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Other</h2>



<p class="wp-block-paragraph">Erik Darling has also developed a solution to make Extended Events readable, in case other approaches are needed. (<a href="https://github.com/erikdarlingdata/DarlingData/tree/main/sp_HumanEvents">sp_HumanEvents</a>)</p>



<div style="height:74px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full is-resized"><img loading="lazy" decoding="async" width="295" height="294" src="https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-21_16-19.png" alt="" class="wp-image-113" style="width:223px;height:auto" srcset="https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-21_16-19.png 295w, https://dbavonnebenan.de/wp-content/uploads/2025/04/2025-04-21_16-19-150x150.png 150w" sizes="auto, (max-width: 295px) 100vw, 295px" /></figure>



<p class="has-text-align-center wp-block-paragraph"><strong>Gabriel, der DBAvonNebenan</strong></p>



<p class="wp-block-paragraph"></p><p>The post <a href="https://dbavonnebenan.de/reporting-sql-server-blocks-en/">Reporting Blocks and Deadlocks: When the 3rd-Party Vendor Demands Evidence</a> first appeared on <a href="https://dbavonnebenan.de">DBA von Nebenan</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dbavonnebenan.de/reporting-sql-server-blocks-en/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
