<?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>Extended Events Archives | SQL Solutions Group</title>
	<atom:link href="https://sqlsolutionsgroup.com/tag/extended-events/feed/" rel="self" type="application/rss+xml" />
	<link>https://sqlsolutionsgroup.com/tag/extended-events/</link>
	<description></description>
	<lastBuildDate>Tue, 07 Jul 2026 23:04:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.2</generator>

<image>
	<url>https://sqlsolutionsgroup.com/wp-content/uploads/2021/01/cropped-SSG_FAVICON0002-32x32.png</url>
	<title>Extended Events Archives | SQL Solutions Group</title>
	<link>https://sqlsolutionsgroup.com/tag/extended-events/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Using Extended Event Session (XE) to track queries going against Always On AG primary</title>
		<link>https://sqlsolutionsgroup.com/using-extended-event-session/</link>
		
		<dc:creator><![CDATA[Steve Rezhener]]></dc:creator>
		<pubDate>Thu, 16 Jul 2020 09:34:00 +0000</pubDate>
				<category><![CDATA[SQL Group]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[#microsftcertifedmaster]]></category>
		<category><![CDATA[#microsftpartner]]></category>
		<category><![CDATA[#SQLAB]]></category>
		<category><![CDATA[#SQlatino]]></category>
		<category><![CDATA[#SQlatinoamerica]]></category>
		<category><![CDATA[#sqldatabase]]></category>
		<category><![CDATA[#sqldeveloper]]></category>
		<category><![CDATA[#SQLgroupie]]></category>
		<category><![CDATA[#sqlimer]]></category>
		<category><![CDATA[#sqlimerbymay]]></category>
		<category><![CDATA[#sqlinjection]]></category>
		<category><![CDATA[#sqlinternals]]></category>
		<category><![CDATA[#sqlite]]></category>
		<category><![CDATA[#sqlite3]]></category>
		<category><![CDATA[#SQLLearning]]></category>
		<category><![CDATA[#SQLMagazine]]></category>
		<category><![CDATA[#sqlmanagementstudio]]></category>
		<category><![CDATA[#sqlmanager]]></category>
		<category><![CDATA[#Sqlmap]]></category>
		<category><![CDATA[#sqlrun]]></category>
		<category><![CDATA[#sqlsaturday2017]]></category>
		<category><![CDATA[#sqlsatvienna]]></category>
		<category><![CDATA[#sqlserver]]></category>
		<category><![CDATA[#SQLserver2012]]></category>
		<category><![CDATA[#sqlserver2014]]></category>
		<category><![CDATA[#sqlserver2017]]></category>
		<category><![CDATA[#sqlserver2022]]></category>
		<category><![CDATA[#SQLServeronLinux]]></category>
		<category><![CDATA[#SQLsolutionsgroup]]></category>
		<category><![CDATA[#SQLTraining]]></category>
		<category><![CDATA[#SQLYog]]></category>
		<category><![CDATA[AG]]></category>
		<category><![CDATA[Always On]]></category>
		<category><![CDATA[availability groups]]></category>
		<category><![CDATA[Extended Events]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQLPASS]]></category>
		<category><![CDATA[SQLSaturday]]></category>
		<category><![CDATA[SSG]]></category>
		<guid isPermaLink="false">https://sqlsolutionsgroup.com/?p=5135</guid>

					<description><![CDATA[<p>The post <a href="https://sqlsolutionsgroup.com/using-extended-event-session/">Using Extended Event Session (XE) to track queries going against Always On AG primary</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p><a href="https://sqlsolutionsgroup.com/wp-content/uploads/2020/07/XE-AG.jpg"><img fetchpriority="high" decoding="async" class="aligncenter wp-image-5136 size-full" src="https://sqlsolutionsgroup.com/wp-content/uploads/2020/07/XE-AG.jpg" alt="Using Extended Event Session with AG" width="728" height="546" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2020/07/XE-AG.jpg 728w, https://sqlsolutionsgroup.com/wp-content/uploads/2020/07/XE-AG-300x225.jpg 300w" sizes="(max-width: 728px) 100vw, 728px" /></a></p>
<p><em>Using Extended Event Session, once we add filters, we can see specifics – queries that are hitting a specific database on Server A (primary) from a specific server (and many excluding the monitoring software).</em></p>
<h3><strong>Introduction</strong></h3>
<p>The Always On Availability Group (aka AG) feature in SQL Server provides a great HADR (high-availability and disaster recovery) solution. This HADR solution can also be used to alleviate the pain from a single database server. AG allows the user to add new servers to offload reporting needs (read replicas) without any prior domain knowledge.</p>
<p>To start with a new read replica, you would need a new Database Server and AG as a data synchronization mechanism (synchronous mode for time sensitive needs and asynchronous mode for everything else). Read replica provides a database on a new server that will help to lift the pressure from a single Server A (AG primary) by making Server B (AG secondary/read replica) available for all the read queries.</p>
<h3><strong>Problem</strong></h3>
<p>AG is relying on a connection string directive called <strong>Read-Intent only</strong> which instructs SQL Server to redirect all the calls to a read replica. Unfortunately, all the existing connections were defined before AG introduction, so what do we do now? How would we identify all the read queries that need a connection string change? Again, without changing connection strings, all the existing queries will still be hitting Server A, hence AG by itself would not solve the problem.</p>
<h3><strong>Solution</strong></h3>
<p>Introducing Extended Event sessions (aka XE session). XE is essentially a replacement for SQL Profiler, which enables us to see everything that is hitting the SQL Server while offering better interface and scripting capabilities. Once we add filters, we can see specifics – queries that are hitting a specific database on Server A (primary) from a specific server (and many excluding the monitoring software).</p>
<p>The following script creates a new XE session that ignores system queries, includes queries that are going against a Database called Database from a server called DW while excluding queries from SentryOne monitoring software.</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">CREATE</span> EVENT <span class="kw1">SESSION</span> <span class="br0">[</span>DW going against <span class="kw1">PRIMARY</span><span class="br0">]</span> <span class="kw1">ON</span> SERVER 
<span class="kw1">ADD</span> EVENT sqlserver.<span class="me1">sql_batch_starting</span><span class="br0">&#40;</span>
    <span class="kw1">ACTION</span><span class="br0">&#40;</span>sqlserver.<span class="me1">client_app_name</span>,sqlserver.<span class="me1">client_hostname</span>,sqlserver.<span class="me1">database_name</span>,sqlserver.<span class="me1">nt_username</span>,sqlserver.<span class="me1">sql_text</span>,sqlserver.<span class="me1">username</span><span class="br0">&#41;</span>
&nbsp;
<span class="kw1">WHERE</span> <span class="br0">&#40;</span><span class="br0">[</span>package0<span class="br0">]</span>.<span class="br0">[</span>equal_boolean<span class="br0">]</span><span class="br0">&#40;</span><span class="br0">[</span>sqlserver<span class="br0">]</span>.<span class="br0">[</span>is_system<span class="br0">]</span>,<span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span> 
&nbsp;
<span class="sy0">AND</span> <span class="br0">[</span>sqlserver<span class="br0">]</span>.<span class="br0">[</span>like_i_sql_unicode_string<span class="br0">]</span><span class="br0">&#40;</span><span class="br0">[</span>sqlserver<span class="br0">]</span>.<span class="br0">[</span>sql_text<span class="br0">]</span>,N<span class="st0">'%OLTP_Database%'</span><span class="br0">&#41;</span> 
&nbsp;
<span class="sy0">AND</span> <span class="br0">[</span>sqlserver<span class="br0">]</span>.<span class="br0">[</span>equal_i_sql_unicode_string<span class="br0">]</span><span class="br0">&#40;</span><span class="br0">[</span>sqlserver<span class="br0">]</span>.<span class="br0">[</span>client_hostname<span class="br0">]</span>,N<span class="st0">'DW'</span><span class="br0">&#41;</span> 
&nbsp;
<span class="sy0">AND</span> <span class="br0">[</span>sqlserver<span class="br0">]</span>.<span class="br0">[</span>not_equal_i_sql_unicode_string<span class="br0">]</span><span class="br0">&#40;</span><span class="br0">[</span>sqlserver<span class="br0">]</span>.<span class="br0">[</span>client_app_name<span class="br0">]</span>,N<span class="st0">'SentryOne 20.0-Server'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp;
<span class="kw1">WITH</span> <span class="br0">&#40;</span>MAX_MEM<span class="sy0">OR</span>Y<span class="sy0">=</span>4096 KB,EVENT_RETENTION_MODE<span class="sy0">=ALL</span>OW_S<span class="sy0">IN</span>GLE_EVENT_LOSS,MAX_DISPATCH_LATENCY<span class="sy0">=</span>5 SECONDS,MAX_EVENT_SIZE<span class="sy0">=</span>0 KB,MEM<span class="sy0">OR</span>Y_PARTITION_MODE<span class="sy0">=</span>PER_CPU
,TRACK_CAUSALITY<span class="sy0">=</span><span class="kw1">ON</span>,STARTUP_STATE<span class="sy0">=</span><span class="kw1">OFF</span><span class="br0">&#41;</span>
GO</pre></div></div>
<p><strong>Disclaimer</strong></p>
<p>This blog post is partially based on the following sources:</p>
<p><a href="https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/always-on-availability-groups-sql-server?view=sql-server-ver15#:~:text=The%20Always%20On%20availability%20groups%20feature%20is%20a,a%20set%20of%20user%20databases%20for%20an%20enterprise.">https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/always-on-availability-groups-sql-server</a></p>
<p><a href="https://docs.microsoft.com/en-us/sql/relational-databases/extended-events/sql-server-extended-events-sessions?view=sql-server-ver15#:~:text=%20The%20following%20aspects%20of%20an%20Extended%20Events,of%20an%20Extended%20Events%20session%2C%20such...%20More%20">https://docs.microsoft.com/en-us/sql/relational-databases/extended-events/sql-server-extended-events-sessions</a></p>
<p>The post <a href="https://sqlsolutionsgroup.com/using-extended-event-session/">Using Extended Event Session (XE) to track queries going against Always On AG primary</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>sp_server_diagnostics &#8211; Black Box Recorder</title>
		<link>https://sqlsolutionsgroup.com/sp_server_diagnostics-black-box-recorder/</link>
		
		<dc:creator><![CDATA[Jason Brimhall]]></dc:creator>
		<pubDate>Tue, 26 Jul 2016 13:20:25 +0000</pubDate>
				<category><![CDATA[Extended Events]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Group]]></category>
		<category><![CDATA[#microsftcertifedmaster]]></category>
		<category><![CDATA[#microsftpartner]]></category>
		<category><![CDATA[#SQLAB]]></category>
		<category><![CDATA[#SQlatino]]></category>
		<category><![CDATA[#SQlatinoamerica]]></category>
		<category><![CDATA[#sqldatabase]]></category>
		<category><![CDATA[#sqldeveloper]]></category>
		<category><![CDATA[#SQLgroupie]]></category>
		<category><![CDATA[#sqlimer]]></category>
		<category><![CDATA[#sqlimerbymay]]></category>
		<category><![CDATA[#sqlinjection]]></category>
		<category><![CDATA[#sqlinternals]]></category>
		<category><![CDATA[#sqlite]]></category>
		<category><![CDATA[#sqlite3]]></category>
		<category><![CDATA[#SQLLearning]]></category>
		<category><![CDATA[#SQLMagazine]]></category>
		<category><![CDATA[#sqlmanagementstudio]]></category>
		<category><![CDATA[#sqlmanager]]></category>
		<category><![CDATA[#Sqlmap]]></category>
		<category><![CDATA[#sqlrun]]></category>
		<category><![CDATA[#sqlsaturday2017]]></category>
		<category><![CDATA[#sqlsatvienna]]></category>
		<category><![CDATA[#sqlserver]]></category>
		<category><![CDATA[#SQLserver2012]]></category>
		<category><![CDATA[#sqlserver2014]]></category>
		<category><![CDATA[#sqlserver2017]]></category>
		<category><![CDATA[#sqlserver2022]]></category>
		<category><![CDATA[#SQLServeronLinux]]></category>
		<category><![CDATA[#SQLsolutionsgroup]]></category>
		<category><![CDATA[#SQLTraining]]></category>
		<category><![CDATA[#SQLYog]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[SQL Administration]]></category>
		<category><![CDATA[SQLPASS]]></category>
		<category><![CDATA[SQLSaturday]]></category>
		<category><![CDATA[SSG]]></category>
		<category><![CDATA[XE]]></category>
		<guid isPermaLink="false">http://sqlsolutionsgroup.com/?p=2967</guid>

					<description><![CDATA[<p>A few months back I began a series about the SQL Black Box Recorder, that you can read here, with a promise of at least two more posts. The first article in the series laid the groundwork about the black box recorder in SQL Server. Furthermore, there was a brief introduction into the three components [&#8230;]</p>
<p>The post <a href="https://sqlsolutionsgroup.com/sp_server_diagnostics-black-box-recorder/">sp_server_diagnostics &#8211; Black Box Recorder</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A few months back I began a series about the SQL Black Box Recorder, that you can read <a href="https://bit.ly/1JIyYXX">here</a>, with a promise of at least two more posts. <img decoding="async" class="alignright wp-image-2769" src="https://sqlsolutionsgroup.com/wp-content/uploads/2016/01/blackbox2.png" alt="sp_server_diagnostics" width="325" height="247" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2016/01/blackbox2.png 506w, https://sqlsolutionsgroup.com/wp-content/uploads/2016/01/blackbox2-300x228.png 300w" sizes="(max-width: 325px) 100vw, 325px" />The first article in the series laid the groundwork about the black box recorder in SQL Server. Furthermore, there was a brief introduction into the three components of the black box recorder. The three components as laid out in that article are: Default Trace, system_health Extended Event Session, and the sp_server_diagnostics procedure.</p>
<p>The first article went into deeper detail about the first leg of this three-legged black box recorder—the default trace. In the second article, the focus was directed to the next leg of the black box recorder—or the system_health Extended Event Session. If by some measure you are in the dark about what Extended Events is, then I recommend you read my personal blog series on the subject. There are numerous articles stepping through the subject in easy-to-digest fashion. You can find many of the articles in the following table of contents—<span style="text-decoration: underline;"><a href="https://bit.ly/XE60Days">here</a></span>.</p>
<p>The focus of this article will take on the topic of the third piece of the black box recorder, sp_server_diagnostics. I will show how this procedure is critical in gathering pertinent information that is crucial to gathering an overall picture of the system—from a default black box recorder perspective.</p>
<h2>SQL Black Box Recorder</h2>
<h3>What is the sp_server_diagnostics process?</h3>
<p>Beyond being a component of the black box for SQL Server, what exactly is this diagnostics process? The sp_server_diagnostics is much as the name implies—it is a “diagnostics” service that attempts to gather information about various events that may affect the overall health of the SQL Server instance.</p>
<p>The diagnostics process will trap various server related health (diagnostics) information related to the SQL Server instance in an effort to try and detect potential failures and errors. This diagnostics session/process traps information for five different categories by default. There is a sixth category of information for those special servers that happen to be running an Availability Group.</p>
<h4>The Six</h4>
<ul>
<li><strong>system</strong>: overall health of the server including information about spinlocks, severe processing conditions, non-yielding tasks, page faults, and CPU usage.</li>
<li><strong>resource</strong>: health of resources, specifically including physical and virtual memory, buffer pools, pages, cache and other memory objects</li>
<li><strong>query_processing</strong>: captures query processing data about worker threads, tasks, wait types, CPU intensive sessions, and blocking tasks.</li>
<li><strong>io_subsystem</strong>: health related data to IO.</li>
<li><strong>events</strong>: errors and events of interest recorded by the server, including details about ring buffer exceptions, ring buffer events about memory broker, out of memory, scheduler monitor, buffer pool, spinlocks, security, and connectivity.</li>
<li><strong>AvailabilityGroup</strong>: basic information about the AvailabilityGroup if there is an AvailabilityGroup enabled on the server.</li>
</ul>
<p>This is fantastic introductory information. As luck would have it, you can also read more about it from my <a href="https://bit.ly/1GMfikp">blog – here</a>.</p>
<h3>How to use this process?</h3>
<p>What good is any level of information if we don’t quite know how to use or consume that data? Do we consume it via trace? Do we execute the stored procedure? Do we capture the information from some other means? The answer is yes! Wait, yes to what? Yes to all of it! Let’s explore how to consume this data.</p>
<h4>Option 1</h4>
<p>The first step to learning how to consume this data is to start at probably the most basic of levels. As you have already noted, this is a stored procedure. It was probably the sp_ in the name that gave it away, right? Since it comes in the form of a stored procedure, it makes it pretty easy to figure out the first means to get the data from it—just execute it. Actually, let me clarify that just a bit. sp_server_diagnostics is a CLR stored procedure. Nonetheless, all that needs be done is execute it at this level to get to the data.</p>
<p><div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">EXECUTE</span> sp_server_diagnostics;</pre></div></div></p>
<p><a class="thickbox" href="https://jasonbrimhall.info/wp-content/uploads/2018/12/spdiag_components.png"><img decoding="async" class="aligncenter size-large wp-image-4872" src="https://jasonbrimhall.info/wp-content/uploads/2018/12/spdiag_components-1024x161.png" sizes="(max-width: 560px) 100vw, 560px" srcset="https://jasonbrimhall.info/wp-content/uploads/2018/12/spdiag_components-1024x161.png 1024w, https://jasonbrimhall.info/wp-content/uploads/2018/12/spdiag_components-300x47.png 300w, https://jasonbrimhall.info/wp-content/uploads/2018/12/spdiag_components-768x121.png 768w, https://jasonbrimhall.info/wp-content/uploads/2018/12/spdiag_components-50x8.png 50w" alt="" width="560" height="88" /></a></p>
<p>Look at that! Pretty slick! I execute the stored procedure and I can see a point in time result of the “health check” from this component of the black box recorder. Notice here that I only have five of the six categories that I had mentioned. This is due to the lack of a configured availability group (AlwaysOn) from this particular instance. Another point of interest is that the data column is not in a very friendly format for DBA consumption. This is flat text that just goes on and on. It is painful to consume in this manner.</p>
<h4>Tidy that Code</h4>
<p><div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">CREATE</span> <span class="kw1">TABLE</span> #ServerDiagnosticsResult
	<span class="br0">&#40;</span>
		create_time <span class="kw1">DATETIME</span>
		, component_type sysname
		, component_name sysname
		, <span class="kw1">STATE</span> <span class="kw1">INT</span>
		, state_desc sysname
		, <span class="kw1">DATA</span> XML
	<span class="br0">&#41;</span>;  
<span class="kw1">INSERT</span> <span class="kw1">INTO</span> #ServerDiagnosticsResult
		<span class="kw1">EXECUTE</span> sp_server_diagnostics;  
&nbsp;
<span class="kw1">SELECT</span> <span class="sy0">*</span>
	<span class="kw1">FROM</span> #ServerDiagnosticsResult;
&nbsp;
<span class="kw1">DROP</span> <span class="kw1">TABLE</span> #ServerDiagnosticsResult;
<span class="kw1">CREATE</span> <span class="kw1">TABLE</span> #ServerDiagnosticsResult
	<span class="br0">&#40;</span>
		create_time <span class="kw1">DATETIME</span>
		, component_type sysname
		, component_name sysname
		, <span class="kw1">STATE</span> <span class="kw1">INT</span>
		, state_desc sysname
		, <span class="kw1">DATA</span> XML
	<span class="br0">&#41;</span>;  
<span class="kw1">INSERT</span> <span class="kw1">INTO</span> #ServerDiagnosticsResult
		<span class="kw1">EXECUTE</span> sp_server_diagnostics;  
&nbsp;
<span class="kw1">SELECT</span> <span class="sy0">*</span>
	<span class="kw1">FROM</span> #ServerDiagnosticsResult;
&nbsp;
<span class="kw1">DROP</span> <span class="kw1">TABLE</span> #ServerDiagnosticsResult;</pre></div></div></p>
<p>Looking at the code, you can see quickly the difference. I have changed the data column to be XML-based to better match the data being output from the stored procedure. Let’s see that in action:</p>
<p><a class="thickbox" href="https://jasonbrimhall.info/wp-content/uploads/2018/12/spdiag_componentxml.png"><img loading="lazy" decoding="async" class="aligncenter size-large wp-image-4874" src="https://jasonbrimhall.info/wp-content/uploads/2018/12/spdiag_componentxml-1024x166.png" sizes="(max-width: 560px) 100vw, 560px" srcset="https://jasonbrimhall.info/wp-content/uploads/2018/12/spdiag_componentxml-1024x166.png 1024w, https://jasonbrimhall.info/wp-content/uploads/2018/12/spdiag_componentxml-300x49.png 300w, https://jasonbrimhall.info/wp-content/uploads/2018/12/spdiag_componentxml-768x124.png 768w, https://jasonbrimhall.info/wp-content/uploads/2018/12/spdiag_componentxml-50x8.png 50w" alt="" width="560" height="91" /></a></p>
<p>That is much better. Now I can simply click one of the data results and see a nicely formatted easy to read XML output of that component. Here is an example from the query_processing component:</p>
<p><a class="thickbox" href="https://jasonbrimhall.info/wp-content/uploads/2018/12/query_processingxml.png"><img loading="lazy" decoding="async" class="aligncenter size-large wp-image-4877" src="https://jasonbrimhall.info/wp-content/uploads/2018/12/query_processingxml-1024x351.png" sizes="(max-width: 560px) 100vw, 560px" srcset="https://jasonbrimhall.info/wp-content/uploads/2018/12/query_processingxml-1024x351.png 1024w, https://jasonbrimhall.info/wp-content/uploads/2018/12/query_processingxml-300x103.png 300w, https://jasonbrimhall.info/wp-content/uploads/2018/12/query_processingxml-768x263.png 768w, https://jasonbrimhall.info/wp-content/uploads/2018/12/query_processingxml-50x17.png 50w" alt="" width="560" height="192" /></a></p>
<h4>Option 2</h4>
<p>Cool! I have just shown one means of exploring this facet of the black box recorder. Now, let’s take a look at other means to get at this particular data, beyond just executing the stored procedure. Did you know that this procedure is very closely related to Extended Events? (I am sure that you picked up on that nugget due to reading the <a href="https://jasonbrimhall.info/2018/12/29/sql-servers-black-box-recorder-system_health/">previous article in the series</a> or possibly the other article I mentioned <a href="https://jasonbrimhall.info/2018/12/28/sql-servers-black-box-recorder-def-trace/">here</a>). With such a close relationship to Extended Events, it makes sense that sp_server_diagnostics also has a couple of events and is consumed by multiple sessions.</p>
<p>SQL Server comes with various default Extended Event sessions, of those sp_server_diagnostics is consumed by the system_health session as well as the hidden session for SQLDiag that is used by Windows Clustering and Availability Groups to determine server health. You already heard about the system_health (from the previous article), but few have heard about the hidden session. I will take a look at the events as well as the sessions that consume the sp_server_diagnostics data.</p>
<h4>Events</h4>
<p>First, I will share the details for each of the events related to the sp_server_diagnostics process.</p>
<p><a class="thickbox" href="https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag.png"><img loading="lazy" decoding="async" class="aligncenter size-large wp-image-4881" src="https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag-1024x82.png" sizes="(max-width: 560px) 100vw, 560px" srcset="https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag-1024x82.png 1024w, https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag-300x24.png 300w, https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag-768x61.png 768w, https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag-50x4.png 50w" alt="" width="560" height="45" /></a></p>
<p>As I have shown here, you can see that these events are a part of the debug channel. In the next couple of images, I want to show some of the payload attached to these events.</p>
<p><a class="thickbox" href="https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag_extra.png"><img loading="lazy" decoding="async" class="aligncenter size-large wp-image-4884" src="https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag_extra-1024x159.png" sizes="(max-width: 560px) 100vw, 560px" srcset="https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag_extra-1024x159.png 1024w, https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag_extra-300x47.png 300w, https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag_extra-768x119.png 768w, https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag_extra-50x8.png 50w" alt="" width="560" height="87" /></a></p>
<p><a class="thickbox" href="https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag_ult.png"><img loading="lazy" decoding="async" class="aligncenter size-large wp-image-4887" src="https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag_ult-1024x350.png" sizes="(max-width: 560px) 100vw, 560px" srcset="https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag_ult-1024x350.png 1024w, https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag_ult-300x103.png 300w, https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag_ult-768x263.png 768w, https://jasonbrimhall.info/wp-content/uploads/2018/12/xe_serverdiag_ult-50x17.png 50w" alt="" width="560" height="191" /></a></p>
<p>These events show what I have shown previously with regards to output of the stored procedure. There is a consistency in the output of the diagnostics process. What I have yet to show in this data is one more piece of information that could be helpful down the road and that pertains specifically to the extended events data. That piece of information I need to share is the keyword associated with each of these events. When looking for related events, I need you to understand that the sp_server_diagnostics events are a part of the <strong>scheduling</strong> classification. There, I have said it. I just gave you a big clue to help you in your troubleshooting endeavors and the use of the diagnostics processes/events.</p>
<h4>Which Sessions then?</h4>
<p>Now that I have shown which events are related to diagnostics, I can finally show which sessions are dependent upon the diagnostics data. To show that kind of information, I have this next query to help:</p>
<p><div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="coMULTI">/* session that is running */</span>
<span class="kw1">SELECT</span> xs.<span class="me1">name</span> <span class="kw1">AS</span> SessionName
		, xse.<span class="me1">event_name</span>
	<span class="kw1">FROM</span> sys.<span class="me1">dm_xe_session_events</span> xse
		<span class="kw1">INNER</span> <span class="sy0">JOIN</span> sys.<span class="me1">dm_xe_sessions</span> xs
			<span class="kw1">ON</span> xse.<span class="me1">event_session_address</span> <span class="sy0">=</span> xs.<span class="me1">address</span>
	<span class="kw1">WHERE</span> xse.<span class="me1">event_name</span> <span class="sy0">IN</span> <span class="br0">&#40;</span> <span class="st0">'sp_server_diagnostics_result_set'</span>,
								<span class="st0">'sp_server_diagnostics_component_result'</span> <span class="br0">&#41;</span>;
&nbsp;
<span class="coMULTI">/* sessions on the server but may be stopped */</span>
<span class="kw1">SELECT</span> ses.<span class="me1">name</span> <span class="kw1">AS</span> SessionName
		, sese.<span class="me1">name</span> <span class="kw1">AS</span> event_name
	<span class="kw1">FROM</span> sys.<span class="me1">server_event_session_events</span> sese
		<span class="kw1">INNER</span> <span class="sy0">JOIN</span> sys.<span class="me1">server_event_sessions</span> ses
			<span class="kw1">ON</span> ses.<span class="me1">event_session_id</span> <span class="sy0">=</span> sese.<span class="me1">event_session_id</span>
	<span class="kw1">WHERE</span> sese.<span class="me1">name</span> <span class="sy0">IN</span> <span class="br0">&#40;</span> <span class="st0">'sp_server_diagnostics_result_set'</span>,
							<span class="st0">'sp_server_diagnostics_component_result'</span> <span class="br0">&#41;</span>;</pre></div></div></p>
<p>When I execute the statements in the preceding query, I will receive a single result—system_health. That said, do not believe everything I just showed you with that query. SQL Server does a decent job at hiding some of the details. When I run the next query, I will see a little bit more information.</p>
<p><div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">SELECT</span> <span class="sy0">*</span>
	<span class="kw1">FROM</span> sys.<span class="me1">dm_xe_sessions</span>;</pre></div></div></p>
<p>When I run the preceding query, I will see the following two sessions (given that I have not change the default settings):</p>
<p><a class="thickbox" href="https://jasonbrimhall.info/wp-content/uploads/2018/12/blackbox_sessions.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-4891" src="https://jasonbrimhall.info/wp-content/uploads/2018/12/blackbox_sessions.png" sizes="(max-width: 916px) 100vw, 916px" srcset="https://jasonbrimhall.info/wp-content/uploads/2018/12/blackbox_sessions.png 916w, https://jasonbrimhall.info/wp-content/uploads/2018/12/blackbox_sessions-300x32.png 300w, https://jasonbrimhall.info/wp-content/uploads/2018/12/blackbox_sessions-768x83.png 768w, https://jasonbrimhall.info/wp-content/uploads/2018/12/blackbox_sessions-50x5.png 50w" alt="" width="916" height="99" /></a></p>
<p>Take note of the names of those two sessions. I showed that the system_health session is reliant upon the diagnostics events. Now, I am showing that there is another event session called “<strong>sp_server_diagnostics session</strong>“. Wait, there is more! SQL Server continues to hide stuff from us.</p>
<h4>Hidden Sessions</h4>
<p>When you have AlwaysOn configured, there is an additional hidden session that is not visible within the sessions lists inside of SQL Server. To view this hidden session, you must follow the directions shown in <a href="https://msdn.microsoft.com/en-us/library/dn135337%28v=sql.110%29.aspx?f=255&amp;MSPPError=-2147217396">this article on msdn</a>. Once you have navigated to the folder containing the hidden XEL files, you can open them in Management Studio and view the data. It is while viewing the data that you will be able to see the relationship between sp_server_diagnostics and this newly discovered trace file.</p>
<p><a class="thickbox" href="https://jasonbrimhall.info/wp-content/uploads/2018/12/clusterhealth.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-4894" src="https://jasonbrimhall.info/wp-content/uploads/2018/12/clusterhealth.png" sizes="(max-width: 765px) 100vw, 765px" srcset="https://jasonbrimhall.info/wp-content/uploads/2018/12/clusterhealth.png 765w, https://jasonbrimhall.info/wp-content/uploads/2018/12/clusterhealth-300x133.png 300w, https://jasonbrimhall.info/wp-content/uploads/2018/12/clusterhealth-50x22.png 50w" alt="" width="765" height="338" /></a></p>
<p>The payload from this image demonstrates the relationship between sp_server_diagnostics and the hidden trace file. I challenge you to take some time to explore this hidden trace file on one of your servers where AlwaysOn is configured. I know you will be thankful for the investment at some point down the road.</p>
<h3>Conclusion</h3>
<p>I have just shown a ton of info about the third component of the black box recorder—sp_server_diagnostics. This procedure may be lesser known than the first two components, but it is highly integral into the overall monitoring and health of your SQL Server instance. In this article, I have not only shown how to use sp_server_diagnostics (albeit quickly), but I have also shown that the diagnostics are heavily relied upon by other components of the black box recorder. In addition, I have shown how this component is integrated into other hidden traces that are essential in the monitoring and troubleshooting of your instance.</p>
<p>The black box recorder is real. You need to invest time in getting to know the black box recorder components and how they can be of help to you in becoming a superhero DBA.</p>
<p>The post <a href="https://sqlsolutionsgroup.com/sp_server_diagnostics-black-box-recorder/">sp_server_diagnostics &#8211; Black Box Recorder</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Black Box Recorder part II</title>
		<link>https://sqlsolutionsgroup.com/sql-black-box-recorder-part-ii/</link>
		
		<dc:creator><![CDATA[Jason Brimhall]]></dc:creator>
		<pubDate>Wed, 06 Apr 2016 13:35:34 +0000</pubDate>
				<category><![CDATA[Extended Events]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Group]]></category>
		<category><![CDATA[#microsftcertifedmaster]]></category>
		<category><![CDATA[#microsftpartner]]></category>
		<category><![CDATA[#SQLAB]]></category>
		<category><![CDATA[#SQlatino]]></category>
		<category><![CDATA[#SQlatinoamerica]]></category>
		<category><![CDATA[#sqldatabase]]></category>
		<category><![CDATA[#sqldeveloper]]></category>
		<category><![CDATA[#SQLgroupie]]></category>
		<category><![CDATA[#sqlimer]]></category>
		<category><![CDATA[#sqlimerbymay]]></category>
		<category><![CDATA[#sqlinjection]]></category>
		<category><![CDATA[#sqlinternals]]></category>
		<category><![CDATA[#sqlite]]></category>
		<category><![CDATA[#sqlite3]]></category>
		<category><![CDATA[#SQLLearning]]></category>
		<category><![CDATA[#SQLMagazine]]></category>
		<category><![CDATA[#sqlmanagementstudio]]></category>
		<category><![CDATA[#sqlmanager]]></category>
		<category><![CDATA[#Sqlmap]]></category>
		<category><![CDATA[#sqlrun]]></category>
		<category><![CDATA[#sqlsaturday2017]]></category>
		<category><![CDATA[#sqlsatvienna]]></category>
		<category><![CDATA[#sqlserver]]></category>
		<category><![CDATA[#SQLserver2012]]></category>
		<category><![CDATA[#sqlserver2014]]></category>
		<category><![CDATA[#sqlserver2017]]></category>
		<category><![CDATA[#sqlserver2022]]></category>
		<category><![CDATA[#SQLServeronLinux]]></category>
		<category><![CDATA[#SQLsolutionsgroup]]></category>
		<category><![CDATA[#SQLTraining]]></category>
		<category><![CDATA[#SQLYog]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[SQL Administration]]></category>
		<category><![CDATA[SQLPASS]]></category>
		<category><![CDATA[SQLSaturday]]></category>
		<category><![CDATA[SSG]]></category>
		<category><![CDATA[XE]]></category>
		<guid isPermaLink="false">http://sqlsolutionsgroup.com/?p=2911</guid>

					<description><![CDATA[<p>A few months back I began a series, about the SQL Black Box Recorder that you can read here, with a promise of at least two more posts. The first article in the series laid the groundwork about the black box recorder in SQL Server. Furthermore, there was a brief introduction into the three components [&#8230;]</p>
<p>The post <a href="https://sqlsolutionsgroup.com/sql-black-box-recorder-part-ii/">SQL Black Box Recorder part II</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A few months back I began a series, about the SQL Black Box Recorder that you can read <a href="https://bit.ly/1JIyYXX">here</a>, with a promise of at least two more posts. <img loading="lazy" decoding="async" class="alignright wp-image-2769" src="https://sqlsolutionsgroup.com/wp-content/uploads/2016/01/blackbox2.png" alt="black box recorder" width="325" height="247" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2016/01/blackbox2.png 506w, https://sqlsolutionsgroup.com/wp-content/uploads/2016/01/blackbox2-300x228.png 300w" sizes="(max-width: 325px) 100vw, 325px" />The first article in the series laid the groundwork about the black box recorder in SQL Server. Furthermore, there was a brief introduction into the three components of the black box recorder. The three components as laid out in that article are:</p>
<ul>
<li>Default Trace</li>
<li>system_health Extended Event Session</li>
<li>sp_server_diagnostics procedure</li>
</ul>
<p>The first article went into deeper detail about the first leg of this three-legged black box recorder &#8211; the default trace. In this article, the focus will be directed to the next leg of the black box recorder &#8211; or the system_health Extended Event Session. If by some measure you are in the dark about what Extended Events is, then I recommend you read my personal blog series on the subject. There are numerous articles stepping through the subject in easy-to-digest fashion. You can find many of the articles in the following table of contents &#8211; <a href="https://bit.ly/XE60Days">here</a>.</p>
<p>The focus of this article will not be to introduce the topic of Extended Events. Rather, it will be to introduce the system_health session and dive into it a fair bit.</p>
<h2>SQL Black Box Recorder</h2>
<h3>What is the system_health session?</h3>
<p>Beyond being a component of the black box for SQL Server, what exactly is this event session? The system_health is much as the name implies – it is a “trace” that attempts to gather information about various events that may affect the overall health of the SQL Server instance.</p>
<p>The event session will trap various events related to deadlocks, waits, clr, memory, schedulers, and reported errors. To get a better grasp of this, let’s take a look at the event session makeup based on the available metadata in the dmvs and catalog views.</p>
<p><div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">DECLARE</span> @SessionName <span class="kw1">VARCHAR</span><span class="br0">&#40;</span><span class="nu0">256</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="st0">'system_health'</span>;
&nbsp;
<span class="coMULTI">/* note: this only works if the session is running and the source is &quot;server&quot; not internal or something else.
*/</span>
&nbsp;
<span class="kw1">SELECT</span> xs.<span class="me1">name</span> <span class="kw1">AS</span> SessionName
		, xs.<span class="me1">session_source</span>
		, xse.<span class="me1">event_name</span>
		, xo.<span class="me1">description</span> <span class="kw1">AS</span> EventDesc
		, xsea.<span class="me1">action_name</span>
		, xoa.<span class="me1">description</span> <span class="kw1">AS</span> ActionDesc
		, xse.<span class="me1">event_predicate</span>
		, sese.<span class="me1">predicate</span>, sese.<span class="me1">predicate_xml</span>
	<span class="kw1">FROM</span> sys.<span class="me1">dm_xe_sessions</span> xs
		<span class="kw1">INNER</span> <span class="sy0">JOIN</span> sys.<span class="me1">dm_xe_session_events</span> xse
			<span class="kw1">ON</span> xs.<span class="me1">address</span> <span class="sy0">=</span> xse.<span class="me1">event_session_address</span>
		<span class="kw1">LEFT</span> <span class="sy0">OUTER</span> <span class="sy0">JOIN</span> sys.<span class="me1">dm_xe_session_event_actions</span> xsea
			<span class="kw1">ON</span> xse.<span class="me1">event_session_address</span> <span class="sy0">=</span> xsea.<span class="me1">event_session_address</span>
				<span class="sy0">AND</span> xse.<span class="me1">event_name</span> <span class="sy0">=</span> xsea.<span class="me1">event_name</span>
		<span class="kw1">INNER</span> <span class="sy0">JOIN</span> sys.<span class="me1">dm_xe_objects</span> xo
			<span class="kw1">ON</span> xse.<span class="me1">event_name</span> <span class="sy0">=</span> xo.<span class="me1">name</span>
				<span class="sy0">AND</span> xse.<span class="me1">event_package_guid</span> <span class="sy0">=</span> xo.<span class="me1">package_guid</span>
				<span class="sy0">AND</span> xo.<span class="me1">object_type</span> <span class="sy0">=</span> <span class="st0">'event'</span>
		<span class="kw1">LEFT</span> <span class="sy0">OUTER</span> <span class="sy0">JOIN</span> sys.<span class="me1">dm_xe_objects</span> xoa
			<span class="kw1">ON</span> xsea.<span class="me1">action_name</span> <span class="sy0">=</span> xoa.<span class="me1">name</span>
				<span class="sy0">AND</span> xsea.<span class="me1">action_package_guid</span> <span class="sy0">=</span> xoa.<span class="me1">package_guid</span>
				<span class="sy0">AND</span> xoa.<span class="me1">object_type</span> <span class="sy0">=</span> <span class="st0">'action'</span>
		<span class="kw1">INNER</span> <span class="sy0">JOIN</span> sys.<span class="me1">server_event_sessions</span> ses
			<span class="kw1">ON</span> xs.<span class="me1">name</span> <span class="sy0">=</span> ses.<span class="me1">name</span>
		<span class="kw1">LEFT</span> <span class="sy0">OUTER</span> <span class="sy0">JOIN</span> sys.<span class="me1">server_event_session_events</span> sese
			<span class="kw1">ON</span> ses.<span class="me1">event_session_id</span> <span class="sy0">=</span> sese.<span class="me1">event_session_id</span>
			<span class="sy0">AND</span> xse.<span class="me1">event_name</span> <span class="sy0">=</span> sese.<span class="me1">name</span>
	<span class="kw1">WHERE</span> xs.<span class="me1">name</span> <span class="sy0">=</span> @SessionName
	<span class="kw1">ORDER</span> <span class="kw1">BY</span> xs.<span class="me1">name</span>,xse.<span class="me1">event_name</span>, xsea.<span class="me1">action_name</span>;</pre></div></div></p>
<p>In addition to the types of events I mentioned, there are also a few more interesting things to discover from the results of this particular query. For instance, the actions that are being employed help to gather even more information such as the callstack, tsql_callstack, database id, and sql text of the query that was executing at the moment of the event that is trapped.</p>
<p>One very peculiar event that is trapped is the sp_server_diagnostics_component_result event. Remember from earlier in this article that I noted the third leg of the black box record happens to be a very similarly named session – “sp_server_diagnostics procedure”. When I cover this third leg, it will make a little more sense. Understand, for now, that your suspicion of it being a bit more integral to the black box (than merely 1/3 of the overall black box) is confirmed.</p>
<p>This is a good set of information that can be trapped. Furthermore, this is a <strong>good set of information</strong> which can give a fairly good diagnosis of several different potential problems within your SQL Server Instance! (Yes it may seem repetitive, but I wanted to underscore the importance of the data that can be trapped.) That said, compare the types of events to those of the default trace. Take note of how many events actually overlap between the two components of the black box recorder.</p>
<p>For ease of comparison, let’s simplify that previous query to get a set of events to read without the duplication due to the actions on each event.</p>
<p><div id="wpshdo_7" class="wp-synhighlighter-outer"><div id="wpshdt_7" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_7"></a><a id="wpshat_7" class="wp-synhighlighter-title" href="#codesyntax_7"  onClick="javascript:wpsh_toggleBlock(7)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_7" onClick="javascript:wpsh_code(7)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_print(7)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_7" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">DECLARE</span> @SessionName <span class="kw1">VARCHAR</span><span class="br0">&#40;</span><span class="nu0">256</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="st0">'system_health'</span>;
&nbsp;
<span class="kw1">SELECT</span> xs.<span class="me1">name</span> <span class="kw1">AS</span> SessionName, xse.<span class="me1">event_name</span>
	<span class="kw1">FROM</span> sys.<span class="me1">dm_xe_sessions</span> xs
		<span class="kw1">INNER</span> <span class="sy0">JOIN</span> sys.<span class="me1">dm_xe_session_events</span> xse
			<span class="kw1">ON</span> xs.<span class="me1">address</span> <span class="sy0">=</span> xse.<span class="me1">event_session_address</span>
	<span class="kw1">WHERE</span> xs.<span class="me1">name</span> <span class="sy0">=</span> @SessionName
	<span class="kw1">ORDER</span> <span class="kw1">BY</span> xse.<span class="me1">event_name</span>;</pre></div></div></p>
<p><img decoding="async" src="https://jasonbrimhall.info/wp-content/uploads/2018/12/system_health_events.png" /></p>
<p>And since I am feeling particularly generous, I have lumped the events from the two traces together in the following query:</p>
<p><div id="wpshdo_8" class="wp-synhighlighter-outer"><div id="wpshdt_8" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_8"></a><a id="wpshat_8" class="wp-synhighlighter-title" href="#codesyntax_8"  onClick="javascript:wpsh_toggleBlock(8)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_8" onClick="javascript:wpsh_code(8)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_8" onClick="javascript:wpsh_print(8)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_8" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">DECLARE</span> @SessionName <span class="kw1">VARCHAR</span><span class="br0">&#40;</span><span class="nu0">256</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="st0">'system_health'</span>;
&nbsp;
<span class="kw1">SELECT</span> xs.<span class="me1">name</span> <span class="kw1">AS</span> SessionName
		, xse.<span class="me1">event_name</span> <span class="kw1">AS</span> EventName
		, mv.<span class="me1">map_value</span> <span class="kw1">AS</span> CategoryName
	<span class="kw1">FROM</span> sys.<span class="me1">dm_xe_sessions</span> xs
		<span class="kw1">INNER</span> <span class="sy0">JOIN</span> sys.<span class="me1">dm_xe_session_events</span> xse
			<span class="kw1">ON</span> xs.<span class="me1">address</span> <span class="sy0">=</span> xse.<span class="me1">event_session_address</span>
		<span class="kw1">INNER</span> <span class="sy0">JOIN</span> sys.<span class="me1">dm_xe_objects</span> xo
			<span class="kw1">ON</span> xse.<span class="me1">event_package_guid</span> <span class="sy0">=</span> xo.<span class="me1">package_guid</span>
			<span class="sy0">AND</span> xse.<span class="me1">event_name</span> <span class="sy0">=</span> xo.<span class="me1">name</span>
			<span class="sy0">AND</span> xo.<span class="me1">object_type</span> <span class="sy0">=</span> <span class="st0">'event'</span>
		<span class="kw1">INNER</span> <span class="sy0">JOIN</span> sys.<span class="me1">dm_xe_object_columns</span> oc
			<span class="kw1">ON</span> oc.<span class="kw2">OBJECT_NAME</span> <span class="sy0">=</span> xo.<span class="me1">name</span>
			<span class="sy0">AND</span> oc.<span class="me1">object_package_guid</span> <span class="sy0">=</span> xo.<span class="me1">package_guid</span>
			<span class="sy0">AND</span> oc.<span class="me1">name</span> <span class="sy0">=</span> <span class="st0">'KEYWORD'</span>
		<span class="kw1">INNER</span> <span class="sy0">JOIN</span> sys.<span class="me1">dm_xe_map_values</span> mv
			<span class="kw1">ON</span> oc.<span class="me1">type_name</span> <span class="sy0">=</span> mv.<span class="me1">name</span>
			<span class="sy0">AND</span> oc.<span class="me1">column_value</span> <span class="sy0">=</span> mv.<span class="me1">map_key</span>
			<span class="sy0">AND</span> oc.<span class="me1">object_package_guid</span> <span class="sy0">=</span> mv.<span class="me1">object_package_guid</span>
	<span class="kw1">WHERE</span> xs.<span class="me1">name</span> <span class="sy0">=</span> @SessionName
<span class="kw1">UNION</span> <span class="sy0">ALL</span>
<span class="coMULTI">/* events */</span>
<span class="kw1">SELECT</span> <span class="st0">'Default Trace'</span> <span class="kw1">AS</span> SessionName
		, te.<span class="me1">name</span> <span class="kw1">AS</span> EventName
		, tca.<span class="me1">name</span> <span class="kw1">AS</span> CategoryName
	<span class="kw1">FROM</span> sys.<span class="me1">traces</span> t
		<span class="sy0">CROSS</span> APPLY <span class="br0">&#40;</span> <span class="kw1">SELECT</span> <span class="kw1">DISTINCT</span> gei.<span class="me1">eventid</span>
							<span class="kw1">FROM</span> sys.<span class="kw4">FN_TRACE_GETEVENTINFO</span><span class="br0">&#40;</span>t.<span class="me1">id</span><span class="br0">&#41;</span> gei
					<span class="br0">&#41;</span> ca
		<span class="kw1">INNER</span> <span class="sy0">JOIN</span> sys.<span class="me1">trace_events</span> te
			<span class="kw1">ON</span> te.<span class="me1">trace_event_id</span> <span class="sy0">=</span> ca.<span class="me1">eventid</span>
		<span class="kw1">INNER</span> <span class="sy0">JOIN</span> sys.<span class="me1">trace_categories</span> tca
			<span class="kw1">ON</span> te.<span class="me1">category_id</span> <span class="sy0">=</span> tca.<span class="me1">category_id</span>
	<span class="kw1">WHERE</span> t.<span class="me1">is_default</span> <span class="sy0">=</span> 1
	<span class="kw1">ORDER</span> <span class="kw1">BY</span> EventName;</pre></div></div></p>
<p>That should help to compare the 17 events from the system_health session and the 34 from the default trace with a little more ease and speed. The events from the two sessions are rather complimentary to each as they help to construct the SQL Server Black Box recorder.</p>
<h3>How to use this session</h3>
<p>With the events trapped by this session, there are a few ways to use the trapped data that should stand out pretty easily. To me, the quick application of the data from this session can come from the review of deadlocks, reported errors, or even waits analysis. Using the deadlock as probably the most common problem people will want to troubleshoot, this information is suddenly much more valuable and easy to access (no more need for that trace flag). Since the system_health is now trapping the deadlock by default, one could quickly access the deadlock graph from the event data and proceed to troubleshooting. More information on getting that deadlock graph can be found <a href="https://sqlsolutionsgroup.com/wean-off-sql-profiler-part-1/">here </a>and <a href="https://blog.waynesheffield.com/wayne/code-library/deadlocks/shred-deadlock-graph/">here</a>.</p>
<p>Learn to use the data made available through this member of the black box recorder. Becoming familiar with this tool (and additionally with Extended Events) will make you a rock-star in the office. The information needed to troubleshoot most problems is right at your fingertips through the use of the different pieces of the black box recorder. If it is not available there, then more than likely it can be made available through a bit of tinkering with Extended Events. Get to know the tools and be that rock-star DBA.</p>
<p>The post <a href="https://sqlsolutionsgroup.com/sql-black-box-recorder-part-ii/">SQL Black Box Recorder part II</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Black Box Recorder</title>
		<link>https://sqlsolutionsgroup.com/sql-black-box-recorder/</link>
		
		<dc:creator><![CDATA[Jason Brimhall]]></dc:creator>
		<pubDate>Tue, 12 Jan 2016 19:33:32 +0000</pubDate>
				<category><![CDATA[Extended Events]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Group]]></category>
		<category><![CDATA[#microsftcertifedmaster]]></category>
		<category><![CDATA[#microsftpartner]]></category>
		<category><![CDATA[#SQLAB]]></category>
		<category><![CDATA[#SQlatino]]></category>
		<category><![CDATA[#SQlatinoamerica]]></category>
		<category><![CDATA[#sqldatabase]]></category>
		<category><![CDATA[#sqldeveloper]]></category>
		<category><![CDATA[#SQLgroupie]]></category>
		<category><![CDATA[#sqlimer]]></category>
		<category><![CDATA[#sqlimerbymay]]></category>
		<category><![CDATA[#sqlinjection]]></category>
		<category><![CDATA[#sqlinternals]]></category>
		<category><![CDATA[#sqlite]]></category>
		<category><![CDATA[#sqlite3]]></category>
		<category><![CDATA[#SQLLearning]]></category>
		<category><![CDATA[#SQLMagazine]]></category>
		<category><![CDATA[#sqlmanagementstudio]]></category>
		<category><![CDATA[#sqlmanager]]></category>
		<category><![CDATA[#Sqlmap]]></category>
		<category><![CDATA[#sqlrun]]></category>
		<category><![CDATA[#sqlsaturday2017]]></category>
		<category><![CDATA[#sqlsatvienna]]></category>
		<category><![CDATA[#sqlserver]]></category>
		<category><![CDATA[#SQLserver2012]]></category>
		<category><![CDATA[#sqlserver2014]]></category>
		<category><![CDATA[#sqlserver2017]]></category>
		<category><![CDATA[#sqlserver2022]]></category>
		<category><![CDATA[#SQLServeronLinux]]></category>
		<category><![CDATA[#SQLsolutionsgroup]]></category>
		<category><![CDATA[#SQLTraining]]></category>
		<category><![CDATA[#SQLYog]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[SQL Administration]]></category>
		<category><![CDATA[SQL Internals]]></category>
		<category><![CDATA[SQLPASS]]></category>
		<category><![CDATA[SQLSaturday]]></category>
		<category><![CDATA[SSG]]></category>
		<guid isPermaLink="false">http://sqlsolutionsgroup.com/?p=2764</guid>

					<description><![CDATA[<p>Across many professions and industries there is often a need to have some sort of device that &#8220;audits&#8221; everything that happens with a device or process. We are probably all quite familiar with the infamous black box recorders used by the passenger airline and train industries. It is also quite possibly fairly common knowledge that [&#8230;]</p>
<p>The post <a href="https://sqlsolutionsgroup.com/sql-black-box-recorder/">SQL Black Box Recorder</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://bit.ly/1ZhJI1f"><img loading="lazy" decoding="async" class="alignright wp-image-2769" src="https://sqlsolutionsgroup.com/wp-content/uploads/2016/01/blackbox2.png" alt="trace blackbox" width="280" height="213" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2016/01/blackbox2.png 506w, https://sqlsolutionsgroup.com/wp-content/uploads/2016/01/blackbox2-300x228.png 300w" sizes="(max-width: 280px) 100vw, 280px" /></a>Across many professions and industries there is often a need to have some sort of device that &#8220;audits&#8221; everything that happens with a device or process. We are probably all quite familiar with the infamous black box recorders used by the passenger airline and train industries. It is also quite possibly fairly common knowledge that many pace makers perform the same sort of functionality &#8211; on a smaller scale. Various metrics and data points are registered and recorded somewhere. Whether to a local storage device or whether the device phones home to some other remote location, it is recorded.</p>
<p>We often pontificate about the what-ifs for a black box recorder within SQL Server, right? We wish and dream and go about creating our own little recorder to suit the requirements we deem necessary for successful monitoring of the server for the just-in-case scenario. Well, the truth of the matter is that we really don&#8217;t need to go to such great lengths to create a &#8220;black box recorder&#8221; because Microsoft has already done all of that for us.</p>
<p>Wait, what? Yes, that’s right! Truth be told this shouldn’t be much news for most Senior Level data professionals working with SQL Server for the past few years. But if you are new to the product, this might be good news for you. Then again, it might just be bad news depending on your take.</p>
<p>Very much like what you may find with the airline industry, the black box recorder in SQL Server is not just a single method (device) implemented to capture all of the desired data points. On a passenger jet, you may find that there are three or more such devices that contribute to the capture and recording of the in-flight data. In SQL Server, there are three major processes that help capture our in-flight data. Over the next few articles I will discuss each of these processes. These processes include:</p>
<ul>
<li>Default Trace</li>
<li>system_health Extended Event Session</li>
<li>sp_server_diagnostics procedure</li>
</ul>
<p>This multi-tiered approach does provide a sort of fail-safe system. If one should be disabled, there still remain up to two more processes that may be running. That said, each of these can be disabled but it does take a bit of an overt effort. And since it does require somebody to put out effort to try and disable each of the black box components, you could potentially capture the culprit via audits from the other components or via an explicit audit that you create for these types of purposes.</p>
<p>Since this will be something to discuss over a few articles, I will break out each process into an individual article. For today, I will discuss the default trace.</p>
<h2>Default Trace</h2>
<p>The <a href="https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/default-trace-enabled-server-configuration-option?view=sql-server-2017">default trace</a> by itself is something that can be turned off via configuration option. There may be good reason to disable the default trace. Before disabling the default trace, please consider the following that can be captured via the default trace. I will use a query to demonstrate the events and categories that are configured for capture in the default trace.</p>
<p><div id="wpshdo_9" class="wp-synhighlighter-outer"><div id="wpshdt_9" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_9"></a><a id="wpshat_9" class="wp-synhighlighter-title" href="#codesyntax_9"  onClick="javascript:wpsh_toggleBlock(9)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_9" onClick="javascript:wpsh_code(9)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_9" onClick="javascript:wpsh_print(9)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_9" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="coMULTI">/* events */</span>
<span class="kw1">SELECT</span> te.<span class="me1">name</span> <span class="kw1">AS</span> EventName
		,tca.<span class="me1">name</span> <span class="kw1">AS</span> CategoryName
		, <span class="kw1">CASE</span> tca.<span class="me1">type</span> <span class="kw1">WHEN</span> <span class="st0">'0'</span> <span class="kw1">THEN</span> <span class="st0">'Normal'</span>
				<span class="kw1">WHEN</span> <span class="st0">'1'</span> <span class="kw1">THEN</span> <span class="st0">'Connection'</span>
				<span class="kw1">WHEN</span> <span class="st0">'2'</span> <span class="kw1">THEN</span> <span class="st0">'ERROR'</span> <span class="kw1">END</span> <span class="kw1">AS</span> CategoryType
		, t.<span class="kw1">PATH</span> <span class="kw1">AS</span> TracePath
		, oa.<span class="me1">logical_operator</span>,oa.<span class="me1">comparison_operator</span>, oa.<span class="kw1">VALUE</span> <span class="kw1">AS</span> FilteredValue
	<span class="kw1">FROM</span> sys.<span class="me1">traces</span> t
		<span class="sy0">CROSS</span> APPLY <span class="br0">&#40;</span><span class="kw1">SELECT</span> <span class="kw1">DISTINCT</span> gei.<span class="me1">eventid</span> <span class="kw1">FROM</span> sys.<span class="kw4">FN_TRACE_GETEVENTINFO</span><span class="br0">&#40;</span>t.<span class="me1">id</span><span class="br0">&#41;</span> gei<span class="br0">&#41;</span> ca
		<span class="kw1">INNER</span> <span class="sy0">JOIN</span> sys.<span class="me1">trace_events</span> te
			<span class="kw1">ON</span> te.<span class="me1">trace_event_id</span> <span class="sy0">=</span> ca.<span class="me1">eventid</span>
		<span class="kw1">INNER</span> <span class="sy0">JOIN</span> sys.<span class="me1">trace_categories</span> tca
			<span class="kw1">ON</span> te.<span class="me1">category_id</span> <span class="sy0">=</span> tca.<span class="me1">category_id</span>
		<span class="sy0">OUTER</span> APPLY <span class="br0">&#40;</span><span class="kw1">SELECT</span> gfi.<span class="me1">columnid</span>,gfi.<span class="me1">logical_operator</span>,gfi.<span class="me1">comparison_operator</span>,gfi.<span class="kw1">VALUE</span> <span class="kw1">FROM</span> sys.<span class="kw4">FN_TRACE_GETFILTERINFO</span><span class="br0">&#40;</span>t.<span class="me1">id</span><span class="br0">&#41;</span> gfi<span class="br0">&#41;</span> oa
	<span class="kw1">WHERE</span> t.<span class="me1">is_default</span> <span class="sy0">=</span> <span class="nu0">1</span></pre></div></div></p>
<p>In this query, I have requested a few more data points than necessary to illustrate the point. That is to help illustrate an additional point that the default trace isn’t filtering out any data for these events. If the event fires (in this trace), it is recorded. Let’s divert right back to the events and categories for now. The results of that query will produce the following sample list of events for me on SQL Server 2014:</p>
<p><img decoding="async" src="https://jasonbrimhall.info/wp-content/uploads/2018/12/deftrace_events-968x1024.png" /></p>
<p>That is quite a range of events covered by this particular recording device. From changes to objects down to security related events and even errors and warnings. If somebody drops an object, the default trace can catch it. If one of the various DBCC statements is executed, it will be trapped in this trace.</p>
<p>There is one thing that is captured by this trace that is not overly obvious. In fact, it is rather annoying in how it is recorded in my opinion. Server configuration settings such as “cost threshold of parallelism” or the lesser utilized “user options” are not registered as an “Object:Alter” event but rather as an ErrorLog event. I wouldn’t call this type of “change” an error and don’t necessarily like seeing these registered with other legitimate errors. That said, it would be nice to see these logged differently (they are currently logged the same way with Extended Events). So, if somebody is dorking around with server configurations, it becomes a bit more convoluted to figure it out, but we can get there. Let’s see how that works:</p>
<p><div id="wpshdo_10" class="wp-synhighlighter-outer"><div id="wpshdt_10" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_10"></a><a id="wpshat_10" class="wp-synhighlighter-title" href="#codesyntax_10"  onClick="javascript:wpsh_toggleBlock(10)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_10" onClick="javascript:wpsh_code(10)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_10" onClick="javascript:wpsh_print(10)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_10" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="co1">-- server configs Audited via Def Trace</span>
<span class="kw1">SELECT</span> 	T.<span class="me1">StartTime</span>
		, T.<span class="me1">SPID</span>
		, T.<span class="me1">LoginName</span>
		, T.<span class="me1">HostName</span>
		, T.<span class="me1">ApplicationName</span>
		, T.<span class="me1">DatabaseName</span>
		<span class="co1">--, ObjectName,sv.number AS ObjTypeVal, sv.name [ObjectType]</span>
		<span class="co1">--, T.TextData</span>
		, ConfigOption <span class="sy0">=</span> <span class="kw2">SUBSTRING</span><span class="br0">&#40;</span>T.<span class="me1">TextData</span>,<span class="kw2">CHARINDEX</span><span class="br0">&#40;</span><span class="st0">''</span><span class="st0">''</span>,T.<span class="me1">TextData</span><span class="br0">&#41;</span><span class="sy0">+</span>1,<span class="kw2">CHARINDEX</span><span class="br0">&#40;</span><span class="st0">' changed from '</span>,T.<span class="me1">TextData</span><span class="br0">&#41;</span><span class="sy0">-</span><span class="kw2">CHARINDEX</span><span class="br0">&#40;</span><span class="st0">''</span><span class="st0">''</span>,T.<span class="me1">TextData</span><span class="br0">&#41;</span><span class="sy0">-</span>2<span class="br0">&#41;</span>
		, PrevValue <span class="sy0">=</span> <span class="kw2">SUBSTRING</span><span class="br0">&#40;</span>T.<span class="me1">TextData</span>,<span class="kw2">CHARINDEX</span><span class="br0">&#40;</span><span class="st0">'from '</span>,T.<span class="me1">TextData</span><span class="br0">&#41;</span><span class="sy0">+</span>5,<span class="kw2">CHARINDEX</span><span class="br0">&#40;</span><span class="st0">'to '</span>,T.<span class="me1">TextData</span><span class="br0">&#41;</span><span class="sy0">-</span><span class="kw2">CHARINDEX</span><span class="br0">&#40;</span><span class="st0">'from '</span>,T.<span class="me1">TextData</span><span class="br0">&#41;</span><span class="sy0">-</span>5<span class="br0">&#41;</span>
		, NewValue <span class="sy0">=</span> <span class="kw2">SUBSTRING</span><span class="br0">&#40;</span>T.<span class="me1">TextData</span>,<span class="kw2">CHARINDEX</span><span class="br0">&#40;</span><span class="st0">'to '</span>,T.<span class="me1">TextData</span><span class="br0">&#41;</span><span class="sy0">+</span>3,<span class="kw2">CHARINDEX</span><span class="br0">&#40;</span><span class="st0">'. Run'</span>,T.<span class="me1">TextData</span><span class="br0">&#41;</span><span class="sy0">-</span><span class="kw2">CHARINDEX</span><span class="br0">&#40;</span><span class="st0">'to '</span>,T.<span class="me1">TextData</span><span class="br0">&#41;</span><span class="sy0">-</span>3<span class="br0">&#41;</span>
		, EventName <span class="sy0">=</span> te.<span class="me1">name</span>
		, T.<span class="me1">EventClass</span>
	<span class="kw1">FROM</span> sys.<span class="kw4">FN_TRACE_GETTABLE</span><span class="br0">&#40;</span><span class="kw1">CONVERT</span><span class="br0">&#40;</span><span class="kw1">VARCHAR</span><span class="br0">&#40;</span>150<span class="br0">&#41;</span>, 
			<span class="br0">&#40;</span> <span class="kw1">SELECT</span> <span class="kw2">REVERSE</span><span class="br0">&#40;</span><span class="kw2">SUBSTRING</span><span class="br0">&#40;</span><span class="kw2">REVERSE</span><span class="br0">&#40;</span><span class="kw1">PATH</span><span class="br0">&#41;</span>,
					<span class="kw2">CHARINDEX</span><span class="br0">&#40;</span><span class="st0">'<span class="es0">\'</span>,REVERSE(path)),256)) + '</span><span class="kw2">LOG</span>.<span class="me1">trc</span><span class="st0">'
				FROM    sys.traces
				WHERE   is_default = 1)), DEFAULT) AS T  
		INNER JOIN sys.trace_events AS te
			ON T.EventClass = te.trace_event_id
	WHERE T.EventClass = 22
		AND T.TextData LIKE '</span><span class="sy0">%</span>config<span class="sy0">%</span><span class="st0">'
	ORDER BY T.StartTime DESC;</span></pre></div></div></p>
<p>Looking at my system, I get the following sample results:</p>
<p><img decoding="async" src="https://jasonbrimhall.info/wp-content/uploads/2018/12/deftrace_servconfigs-1024x200.png" /></p>
<p>You can see there are plenty of settings that I have been playing with captured by the default trace. If you happen to have a junior DBA or maybe a cowboy DBA that loves to shoot from the hip and make changes, this will help you find all the necessary details to bring to that DBA for discussion.</p>
<p>The default trace comprises one third of the black box recorder. I have shown a quick use for the default trace and have also shown some of the various events that are captured from this trace. I recommend getting to know your default trace just a little bit better. You never know when you may need to resort to the flight recorder data held in the default trace. Being familiar with the default trace before you need to use it will help improve your comfort level when under the stress of trying to figure out what happened just before the server went belly up!</p>
<p>The post <a href="https://sqlsolutionsgroup.com/sql-black-box-recorder/">SQL Black Box Recorder</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Freakin&#8217; out on XE at the FreeCon</title>
		<link>https://sqlsolutionsgroup.com/freakin-out-on-xe/</link>
		
		<dc:creator><![CDATA[Jason Brimhall]]></dc:creator>
		<pubDate>Tue, 29 Sep 2015 18:02:07 +0000</pubDate>
				<category><![CDATA[SQL Group]]></category>
		<category><![CDATA[#microsftcertifedmaster]]></category>
		<category><![CDATA[#microsftpartner]]></category>
		<category><![CDATA[#SQLAB]]></category>
		<category><![CDATA[#SQlatino]]></category>
		<category><![CDATA[#SQlatinoamerica]]></category>
		<category><![CDATA[#sqldatabase]]></category>
		<category><![CDATA[#sqldeveloper]]></category>
		<category><![CDATA[#SQLgroupie]]></category>
		<category><![CDATA[#sqlimer]]></category>
		<category><![CDATA[#sqlimerbymay]]></category>
		<category><![CDATA[#sqlinjection]]></category>
		<category><![CDATA[#sqlinternals]]></category>
		<category><![CDATA[#sqlite]]></category>
		<category><![CDATA[#sqlite3]]></category>
		<category><![CDATA[#SQLLearning]]></category>
		<category><![CDATA[#SQLMagazine]]></category>
		<category><![CDATA[#sqlmanagementstudio]]></category>
		<category><![CDATA[#sqlmanager]]></category>
		<category><![CDATA[#Sqlmap]]></category>
		<category><![CDATA[#sqlrun]]></category>
		<category><![CDATA[#sqlsaturday2017]]></category>
		<category><![CDATA[#sqlsatvienna]]></category>
		<category><![CDATA[#sqlserver]]></category>
		<category><![CDATA[#SQLserver2012]]></category>
		<category><![CDATA[#sqlserver2014]]></category>
		<category><![CDATA[#sqlserver2017]]></category>
		<category><![CDATA[#sqlserver2022]]></category>
		<category><![CDATA[#SQLServeronLinux]]></category>
		<category><![CDATA[#SQLsolutionsgroup]]></category>
		<category><![CDATA[#SQLTraining]]></category>
		<category><![CDATA[#SQLYog]]></category>
		<category><![CDATA[Extended Events]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQLPASS]]></category>
		<category><![CDATA[SQLSaturday]]></category>
		<category><![CDATA[SSG]]></category>
		<category><![CDATA[XE]]></category>
		<guid isPermaLink="false">http://sqlsolutionsgroup.com/?p=2648</guid>

					<description><![CDATA[<p>Just a couple weeks ago I announced that SQL Solutions Group was getting ready to host a day of free training—a FREECON if you will—in Seattle as a prelude to the PASS Summit of 2015. You can read all about that here, with registration being here. I am hopeful to see the room filled with people looking [&#8230;]</p>
<p>The post <a href="https://sqlsolutionsgroup.com/freakin-out-on-xe/">Freakin&#8217; out on XE at the FreeCon</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Just a couple weeks ago I announced that SQL Solutions Group was getting ready to host a day of free training—a FREECON if you will—in Seattle as a prelude to the PASS Summit of 2015. You can <a href="https://bit.ly/1Kl8m99">read all about that here</a>, with <a href="https://bit.ly/SSGSummit15">registration being here</a>.</p>
<p>I am hopeful to see the room filled with people looking to get some fantastic training. I also want to note that this training is not a part of the Summit, though I hope it is viewed as an effort to enhance the learning made available during the week of Summit and to give the attendees more options.</p>
<p>An option is only really any good if some sort of detail can be attained about the option. While I announced previously that the event was going to happen with a brief introduction into the the topics to be covered, one may be left wondering what really will be covered during the day.</p>
<p>With this post, I hope to help make the SSG FreeCon option a better option  by including a little detail into what it is that I will be presenting during my session on Extended Events.</p>
<h3>Extended Events</h3>
<p>This should come as a huge surprise given the <a href="https://bit.ly/XE60Days">60 Days of XEvents</a> series that I am currently publishing. While I am publishing a lot of information about XE in this series, this FreeCon session will cover the methodology that I, as a consultant, would use to troubleshoot various issues when a client seeks my help.</p>
<p>It is well known that there is a wealth of information within Extended Events. One can tap plenty of information about performance issues, errors, or general interest type stuff by setting up an XEvent Session and trapping some (hopefully) useful information.</p>
<p><a href="https://jasonbrimhall.info/wp-content/uploads/2015/09/roadmap.jpg"><img loading="lazy" decoding="async" class="alignright wp-image-3014 size-medium" src="https://jasonbrimhall.info/wp-content/uploads/2015/09/roadmap-300x206.jpg" alt="roadmap to XE understanding" width="300" height="206" /></a>During this session at the FreeCon, I want to help show how I would use Extended Events as a consultant to help find the pertinent information that will bring to light the problems the client is having.</p>
<p>How can I use XE as a consultant to perform a health check on your server? That information will be covered throughout this session.</p>
<p>How can I determine where precisely the backup failed (and when) and be able to procure more information to determine if it was caused by some other event on the network? This is the type of information included in the methodology that I plan to share.</p>
<p>Think of this session as a condensed road-map to XE Success. I look forward to seeing you there.</p>
<p>The post <a href="https://sqlsolutionsgroup.com/freakin-out-on-xe/">Freakin&#8217; out on XE at the FreeCon</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>FreeCon, October 27, 2015 Seattle</title>
		<link>https://sqlsolutionsgroup.com/freecon-october-27-2015-seattle-2/</link>
		
		<dc:creator><![CDATA[Wayne Sheffield]]></dc:creator>
		<pubDate>Wed, 23 Sep 2015 20:16:05 +0000</pubDate>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Group]]></category>
		<category><![CDATA[#microsftcertifedmaster]]></category>
		<category><![CDATA[#microsftpartner]]></category>
		<category><![CDATA[#SQLAB]]></category>
		<category><![CDATA[#SQlatino]]></category>
		<category><![CDATA[#SQlatinoamerica]]></category>
		<category><![CDATA[#sqldatabase]]></category>
		<category><![CDATA[#sqldeveloper]]></category>
		<category><![CDATA[#SQLgroupie]]></category>
		<category><![CDATA[#sqlimer]]></category>
		<category><![CDATA[#sqlimerbymay]]></category>
		<category><![CDATA[#sqlinjection]]></category>
		<category><![CDATA[#sqlinternals]]></category>
		<category><![CDATA[#sqlite]]></category>
		<category><![CDATA[#sqlite3]]></category>
		<category><![CDATA[#SQLLearning]]></category>
		<category><![CDATA[#SQLMagazine]]></category>
		<category><![CDATA[#sqlmanagementstudio]]></category>
		<category><![CDATA[#sqlmanager]]></category>
		<category><![CDATA[#Sqlmap]]></category>
		<category><![CDATA[#sqlrun]]></category>
		<category><![CDATA[#sqlsaturday2017]]></category>
		<category><![CDATA[#sqlsatvienna]]></category>
		<category><![CDATA[#sqlserver]]></category>
		<category><![CDATA[#SQLserver2012]]></category>
		<category><![CDATA[#sqlserver2014]]></category>
		<category><![CDATA[#sqlserver2017]]></category>
		<category><![CDATA[#sqlserver2022]]></category>
		<category><![CDATA[#SQLServeronLinux]]></category>
		<category><![CDATA[#SQLsolutionsgroup]]></category>
		<category><![CDATA[#SQLTraining]]></category>
		<category><![CDATA[#SQLYog]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Extended Events]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[Presenting]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[SQLPASS]]></category>
		<category><![CDATA[SQLSaturday]]></category>
		<category><![CDATA[SSG]]></category>
		<category><![CDATA[Training]]></category>
		<guid isPermaLink="false">https://blog.waynesheffield.com/wayne/?p=2474</guid>

					<description><![CDATA[<p>The company that I work with, SQL Solutions Group, is conducting a free community event. The week of the PASS Summit, on Tuesday, we will be hosting a day of free training. This is an event for all data professionals who happen to be in the Seattle area the days leading up to Summit but [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://blog.waynesheffield.com/wayne/archive/2015/09/freecon-october-27-2015-seattle/">FreeCon, October 27, 2015 Seattle</a> appeared first on <a rel="nofollow" href="https://blog.waynesheffield.com/wayne">Wayne Sheffield</a>.</p>
<p>The post <a href="https://sqlsolutionsgroup.com/freecon-october-27-2015-seattle-2/">FreeCon, October 27, 2015 Seattle</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The company that I work with, <a href="https://blog.waynesheffield.com/wayne/?feed-stats-url=aHR0cDovL3d3dy5zcWxzb2x1dGlvbnNncm91cC5jb20%3D&amp;feed-stats-url-post-id=2474">SQL Solutions Group</a>, is conducting a free community event. The week of the PASS Summit, on Tuesday, we will be hosting a day of free training. This is an event for all data professionals who happen to be in the Seattle area the days leading up to Summit but may not be able to attend one of the <a href="https://blog.waynesheffield.com/wayne/?feed-stats-url=aHR0cDovL3d3dy5zcWxwYXNzLm9yZy9zdW1taXQvMjAxNS9TZXNzaW9ucy9QcmVDb25mZXJlbmNlLmFzcHg%3D&amp;feed-stats-url-post-id=2474">Summit Precons</a>.  This day of free training will be conducted by four of our <a href="https://blog.waynesheffield.com/wayne/?feed-stats-url=aHR0cDovL3d3dy5zcWxzb2x1dGlvbnNncm91cC5jb20vbWljcm9zb2Z0LWNlcnRpZmllZC1tYXN0ZXIv&amp;feed-stats-url-post-id=2474">MCM</a>s. If you’re not going to be at one of the PASS Summit Precons, then we’d love to have you come out to see us!</p>
<p>The workshops that we will be presenting are:</p>
<p><strong>Code Smells for the Consultant </strong>(which I’ll be presenting)<strong><br />
</strong></p>
<blockquote><p>Throughout my career, I’ve seen developers do some pretty crazy things to databases ( I know because I come from a developer background). Come to this session to learn both what I (and SSG) look for and why it’s bad for the database (or your career), and alternatives that can be used. Some of the topics that I will discuss include; how coding mistakes open up the database for SQL Injection attacks, how coding choices can slow down the server, and how design choices keep SQL Server dumb ( if SQL Server was allowed to be smart, it would be faster!). Trust me, your DBA will love you for identifying and fixing these code smells.</p></blockquote>
<p><strong>A Masters Passport to Extended Events </strong>(presented by Jason Brimhall)<strong><br />
</strong></p>
<blockquote><p>As is commonly the case, all good things come to an end.  And now is as good a time as any for the use of SQL Trace and Profiler to come to an end.  Let’s face it, Trace was a good tool and had some wonderful uses.  Profiler for that matter was a good tool and was useful at times.</p>
<p>It is time to let those old tools retire gracefully and move into the world of XE.  This workshop will provide you the means to let Profiler and Trace be retired from your toolset as you discover all that XE has to offer.</p>
<p>This focused session on Extended Events will help prepare you to put this tool to immediate use as you walk back to your daily duties.  This workshop will teach you about Extended Events starting with the basics and moving through to some specific XE sessions that I would use to troubleshoot in a client environment – while doing so with minimal impact.</p>
<p>You will be exposed to advanced troubleshooting techniques as we work through complex issues that are made easier through the use of XE.  Take advantage of this opportunity to dive into the world of Extended Events and learn how you can make best use of this tool in your SQL 2008+ environment.</p></blockquote>
<p>You can read the rest of this article over <a href="https://bit.ly/1iMzl7T">here</a>.</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" style="display: none;" src="https://blog.waynesheffield.com/wayne/?feed-stats-post-id=2474" width="1" height="1" /></p>
<p>The post <a href="https://blog.waynesheffield.com/wayne/archive/2015/09/freecon-october-27-2015-seattle/" rel="nofollow">FreeCon, October 27, 2015 Seattle</a> appeared first on <a href="https://blog.waynesheffield.com/wayne" rel="nofollow">Wayne Sheffield</a>.</p>
<p>The post <a href="https://sqlsolutionsgroup.com/freecon-october-27-2015-seattle-2/">FreeCon, October 27, 2015 Seattle</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>What Sessions are Deployed?</title>
		<link>https://sqlsolutionsgroup.com/view-deployed-sessions/</link>
		
		<dc:creator><![CDATA[Jason Brimhall]]></dc:creator>
		<pubDate>Tue, 01 Sep 2015 12:48:47 +0000</pubDate>
				<category><![CDATA[Extended Events]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Group]]></category>
		<category><![CDATA[#microsftcertifedmaster]]></category>
		<category><![CDATA[#microsftpartner]]></category>
		<category><![CDATA[#SQLAB]]></category>
		<category><![CDATA[#SQlatino]]></category>
		<category><![CDATA[#SQlatinoamerica]]></category>
		<category><![CDATA[#sqldatabase]]></category>
		<category><![CDATA[#sqldeveloper]]></category>
		<category><![CDATA[#SQLgroupie]]></category>
		<category><![CDATA[#sqlimer]]></category>
		<category><![CDATA[#sqlimerbymay]]></category>
		<category><![CDATA[#sqlinjection]]></category>
		<category><![CDATA[#sqlinternals]]></category>
		<category><![CDATA[#sqlite]]></category>
		<category><![CDATA[#sqlite3]]></category>
		<category><![CDATA[#SQLLearning]]></category>
		<category><![CDATA[#SQLMagazine]]></category>
		<category><![CDATA[#sqlmanagementstudio]]></category>
		<category><![CDATA[#sqlmanager]]></category>
		<category><![CDATA[#Sqlmap]]></category>
		<category><![CDATA[#sqlrun]]></category>
		<category><![CDATA[#sqlsaturday2017]]></category>
		<category><![CDATA[#sqlsatvienna]]></category>
		<category><![CDATA[#sqlserver]]></category>
		<category><![CDATA[#SQLserver2012]]></category>
		<category><![CDATA[#sqlserver2014]]></category>
		<category><![CDATA[#sqlserver2017]]></category>
		<category><![CDATA[#sqlserver2022]]></category>
		<category><![CDATA[#SQLServeronLinux]]></category>
		<category><![CDATA[#SQLsolutionsgroup]]></category>
		<category><![CDATA[#SQLTraining]]></category>
		<category><![CDATA[#SQLYog]]></category>
		<category><![CDATA[SQL Administration]]></category>
		<category><![CDATA[SQL Internals]]></category>
		<category><![CDATA[SQLPASS]]></category>
		<category><![CDATA[SQLSaturday]]></category>
		<category><![CDATA[SSG]]></category>
		<category><![CDATA[XE]]></category>
		<guid isPermaLink="false">http://sqlsolutionsgroup.com/?p=2550</guid>

					<description><![CDATA[<p>As a DBA, it is not uncommon to feel like you are marooned off on some tiny little island trying to figure things out for yourself. It may even be very common to feel the icy pain of the development cold shoulder (intentional or not) as you go about doing your duties to protect the [&#8230;]</p>
<p>The post <a href="https://sqlsolutionsgroup.com/view-deployed-sessions/">What Sessions are Deployed?</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://sqlsolutionsgroup.com/wp-content/uploads/2015/08/polarbear.png"><img loading="lazy" decoding="async" class="alignright wp-image-2551" src="https://sqlsolutionsgroup.com/wp-content/uploads/2015/08/polarbear.png" alt="He's wondering about deployed sessions" width="270" height="241" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2015/08/polarbear.png 369w, https://sqlsolutionsgroup.com/wp-content/uploads/2015/08/polarbear-300x268.png 300w" sizes="(max-width: 270px) 100vw, 270px" /></a>As a DBA, it is not uncommon to feel like you are marooned off on some tiny little island trying to figure things out for yourself. It may even be very common to feel the icy pain of the development cold shoulder (intentional or not) as you go about doing your duties to protect the data and secure high octane performance out of the database.</p>
<p>Not only may it be very commonplace to experience this due to the nature of the job, but it can also get to feel that way when a new product is released. Suddenly, that icy island is further north into the Arctic Ocean and you are struggling to gasp for a bit of air in the frigid cold.</p>
<p>I am certain this may be some of what you feel as you try to take a look at Extended Events. It is a fancy, new technology and there is not a ton of time to get up to speed while trying to warm yourself against the development chill. As you stew about the situation, you begin to ponder, &#8220;How am I even supposed to know what an XE is, let alone what XEs are running on my server?&#8221; Never mind the confusion on what an XE is and that it is actually running or deployed sessions on the server. Don&#8217;t worry about the terminology just yet. <strong>What can we do to figure out what might be out there</strong>?</p>
<p>Well, that is where the trusty Google has come to help you. Thanks to a better than adequate ability to search the Internet, you landed on this page that has a script to help you explore what might be running as far as Extended Events on your server. You may be surprised to learn that you have more Extended Events Sessions running than you fathomed. Yes, SQL Server comes with some default sessions. Yes, some of these default sessions are more public than others. And yes, some of these</p>
<p><strong>Come on in out of the cold</strong>. Get off that arctic island and warm up with a little XE fun. This script is quite simple but will show you what you may have out there on your servers. Once you see what is there, hopefully your curiosity will get a little piqued and you will want to learn a little more (there is more of that here on this site too).</p>
<p>And now, for that script:</p>
<p><div id="wpshdo_11" class="wp-synhighlighter-outer"><div id="wpshdt_11" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_11"></a><a id="wpshat_11" class="wp-synhighlighter-title" href="#codesyntax_11"  onClick="javascript:wpsh_toggleBlock(11)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_11" onClick="javascript:wpsh_code(11)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_11" onClick="javascript:wpsh_print(11)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_11" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">DECLARE</span> @SessionName <span class="kw1">VARCHAR</span><span class="br0">&#40;</span><span class="nu0">128</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="sy0">NULL</span> <span class="co1">--'sp_server_diagnostics session' --NULL for all</span>
;
&nbsp;
<span class="kw1">SELECT</span> IS<span class="sy0">NULL</span><span class="br0">&#40;</span>ses.<span class="me1">name</span>,xse.<span class="me1">name</span><span class="br0">&#41;</span> <span class="kw1">AS</span> SessionName
		, <span class="kw1">CASE</span>
			<span class="kw1">WHEN</span> IS<span class="sy0">NULL</span><span class="br0">&#40;</span>ses.<span class="me1">name</span>,<span class="st0">''</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="st0">''</span>
			<span class="kw1">THEN</span> <span class="st0">'Private'</span>
			<span class="kw1">ELSE</span> <span class="st0">'Public'</span>
			<span class="kw1">END</span> <span class="kw1">AS</span> SessionVisibility
		, <span class="kw1">CASE</span>
			<span class="kw1">WHEN</span> IS<span class="sy0">NULL</span><span class="br0">&#40;</span>xse.<span class="me1">name</span>,<span class="st0">''</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="st0">''</span>
			<span class="kw1">THEN</span> <span class="st0">'NO'</span>
			<span class="kw1">ELSE</span> <span class="st0">'YES'</span>
			<span class="kw1">END</span> <span class="kw1">AS</span> SessionRunning
		, <span class="kw1">CASE</span>
			<span class="kw1">WHEN</span> IS<span class="sy0">NULL</span><span class="br0">&#40;</span>xse.<span class="me1">name</span>,<span class="st0">''</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="st0">''</span>
				<span class="sy0">AND</span> IS<span class="sy0">NULL</span><span class="br0">&#40;</span>ses.<span class="me1">name</span>,<span class="st0">''</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="st0">''</span>
			<span class="kw1">THEN</span> <span class="st0">'NO'</span>
			<span class="kw1">ELSE</span> <span class="st0">'YES'</span>
			<span class="kw1">END</span> <span class="kw1">AS</span> IsDeployed
	<span class="kw1">FROM</span> sys.<span class="me1">server_event_sessions</span> ses
	<span class="kw1">FULL</span> <span class="sy0">OUTER</span> <span class="sy0">JOIN</span> sys.<span class="me1">dm_xe_sessions</span> xse
		<span class="kw1">ON</span> xse.<span class="me1">name</span> <span class="sy0">=</span>ses.<span class="me1">name</span>
	<span class="kw1">WHERE</span> <span class="kw1">COALESCE</span><span class="br0">&#40;</span>@SessionName, ses.<span class="me1">name</span>, xse.<span class="me1">name</span><span class="br0">&#41;</span> <span class="sy0">=</span> IS<span class="sy0">NULL</span><span class="br0">&#40;</span>ses.<span class="me1">name</span>, xse.<span class="me1">name</span><span class="br0">&#41;</span>
	<span class="kw1">ORDER</span> <span class="kw1">BY</span> ses.<span class="me1">event_session_id</span>;
&nbsp;
GO</pre></div></div></p>
<p>Quick and simple, and full of that warming XE sensation. This script just shows you what is a private session versus public. What is a private session, you ask? Well, that happens to be all of those database audits you have deployed to your server. It also includes those little things like the “sp_server_diagnostics session” session (yes it sounds redundant but that is because session is also part of the name for that session).</p>
<p>This script will also show you what is deployed to the server versus what is running on the server (not all sessions have to be running). And to top it all off, I set it up so you can query for a specific session or for all sessions.</p>
<p>Try it out on one or more of your servers and let me know how it goes.</p>
<p>The post <a href="https://sqlsolutionsgroup.com/view-deployed-sessions/">What Sessions are Deployed?</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>An Experiment with Deadlocks</title>
		<link>https://sqlsolutionsgroup.com/an-experiment-with-deadlocks/</link>
		
		<dc:creator><![CDATA[Jason Brimhall]]></dc:creator>
		<pubDate>Tue, 21 Jul 2015 12:22:15 +0000</pubDate>
				<category><![CDATA[SQL Group]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[#microsftcertifedmaster]]></category>
		<category><![CDATA[#microsftpartner]]></category>
		<category><![CDATA[#SQLAB]]></category>
		<category><![CDATA[#SQlatino]]></category>
		<category><![CDATA[#SQlatinoamerica]]></category>
		<category><![CDATA[#sqldatabase]]></category>
		<category><![CDATA[#sqldeveloper]]></category>
		<category><![CDATA[#SQLgroupie]]></category>
		<category><![CDATA[#sqlimer]]></category>
		<category><![CDATA[#sqlimerbymay]]></category>
		<category><![CDATA[#sqlinjection]]></category>
		<category><![CDATA[#sqlinternals]]></category>
		<category><![CDATA[#sqlite]]></category>
		<category><![CDATA[#sqlite3]]></category>
		<category><![CDATA[#SQLLearning]]></category>
		<category><![CDATA[#SQLMagazine]]></category>
		<category><![CDATA[#sqlmanagementstudio]]></category>
		<category><![CDATA[#sqlmanager]]></category>
		<category><![CDATA[#Sqlmap]]></category>
		<category><![CDATA[#sqlrun]]></category>
		<category><![CDATA[#sqlsaturday2017]]></category>
		<category><![CDATA[#sqlsatvienna]]></category>
		<category><![CDATA[#sqlserver]]></category>
		<category><![CDATA[#SQLserver2012]]></category>
		<category><![CDATA[#sqlserver2014]]></category>
		<category><![CDATA[#sqlserver2017]]></category>
		<category><![CDATA[#sqlserver2022]]></category>
		<category><![CDATA[#SQLServeronLinux]]></category>
		<category><![CDATA[#SQLsolutionsgroup]]></category>
		<category><![CDATA[#SQLTraining]]></category>
		<category><![CDATA[#SQLYog]]></category>
		<category><![CDATA[deadlocks]]></category>
		<category><![CDATA[Extended Events]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Internals]]></category>
		<category><![CDATA[SQLPASS]]></category>
		<category><![CDATA[SQLSaturday]]></category>
		<category><![CDATA[SSG]]></category>
		<guid isPermaLink="false">http://sqlsolutionsgroup.com/?p=2460</guid>

					<description><![CDATA[<p>Everything can be fixed with a query hint (*cough* directive), right? If a certain process is consistently causing deadlocks, a simple ROWLOCK hint can be added to prevent it, right? Well, for whatever reason, there seems to be a myth out there that when deadlocks come a-knocking, then just throw this little directive at it and [&#8230;]</p>
<p>The post <a href="https://sqlsolutionsgroup.com/an-experiment-with-deadlocks/">An Experiment with Deadlocks</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Everything can be fixed with a query hint (*cough* directive), right? If a certain process is consistently causing deadlocks, a simple ROWLOCK hint can be added to prevent it, right?</p>
<p>Well, for whatever reason, there seems to be a myth out there that when deadlocks come a-knocking, then just throw this little directive at it and all will be well. Today, we get to test that and show what will continue to happen.</p>
<p>First, lets look at what the ROWLOCK actually means:</p>
<blockquote><p>Specifies that row locks are taken when page or table locks are ordinarily taken.</p></blockquote>
<p>This seems like a fabulous idea if the deadlocks are occurring against a table involving a massive update. Let’s take a look at a small update scenario involving just a handful of records.</p>
<p><div id="wpshdo_12" class="wp-synhighlighter-outer"><div id="wpshdt_12" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_12"></a><a id="wpshat_12" class="wp-synhighlighter-title" href="#codesyntax_12"  onClick="javascript:wpsh_toggleBlock(12)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_12" onClick="javascript:wpsh_code(12)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_12" onClick="javascript:wpsh_print(12)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_12" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">USE</span> tempdb;
GO
<span class="kw1">IF</span> <span class="kw2">OBJECT_ID</span><span class="br0">&#40;</span><span class="st0">'dbo.Test1'</span><span class="br0">&#41;</span> <span class="kw1">IS</span> <span class="sy0">NOT</span> <span class="sy0">NULL</span>
	<span class="kw1">DROP</span> <span class="kw1">TABLE</span> dbo.<span class="me1">Test1</span>;
<span class="kw1">IF</span> <span class="kw2">OBJECT_ID</span><span class="br0">&#40;</span><span class="st0">'dbo.Test2'</span><span class="br0">&#41;</span> <span class="kw1">IS</span> <span class="sy0">NOT</span> <span class="sy0">NULL</span>
	<span class="kw1">DROP</span> <span class="kw1">TABLE</span> dbo.<span class="me1">Test2</span>;
<span class="kw1">CREATE</span> <span class="kw1">TABLE</span> dbo.<span class="me1">Test1</span> <span class="br0">&#40;</span> col1 <span class="kw1">INT</span> <span class="br0">&#41;</span>;
<span class="kw1">CREATE</span> <span class="kw1">TABLE</span> dbo.<span class="me1">Test2</span> <span class="br0">&#40;</span> col2 <span class="kw1">INT</span> <span class="br0">&#41;</span>;
<span class="kw1">INSERT</span> <span class="kw1">INTO</span> dbo.<span class="me1">Test1</span>
	<span class="kw1">VALUES</span>	<span class="br0">&#40;</span> 1 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 2 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 3 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 4 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 5 <span class="br0">&#41;</span>;
<span class="kw1">INSERT</span> <span class="kw1">INTO</span> dbo.<span class="me1">Test2</span>
	<span class="kw1">VALUES</span>	<span class="br0">&#40;</span> 1 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 2 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 3 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 4 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 5 <span class="br0">&#41;</span>;
GO
<span class="kw1">BEGIN</span> <span class="kw1">TRANSACTION</span>;
<span class="kw1">UPDATE</span> dbo.<span class="me1">Test1</span>
	<span class="kw1">SET</span>	col1 <span class="sy0">=</span> col1 <span class="sy0">*</span> 10
	<span class="kw1">WHERE</span> col1 <span class="sy0">=</span> <span class="nu0">3</span>;
&nbsp;
<span class="coMULTI">/* query window 2*/</span>
&nbsp;
<span class="kw1">USE</span> tempdb;
<span class="kw1">BEGIN</span> <span class="kw1">TRANSACTION</span>;
<span class="kw1">UPDATE</span> dbo.<span class="me1">Test2</span>
	<span class="kw1">SET</span>	col2 <span class="sy0">=</span> col2 <span class="sy0">*</span> 20
	<span class="kw1">WHERE</span> col2 <span class="sy0">=</span> <span class="nu0">4</span>;
<span class="kw1">UPDATE</span> dbo.<span class="me1">Test1</span>
	<span class="kw1">SET</span>	col1 <span class="sy0">=</span> col1 <span class="sy0">*</span> 20
	<span class="kw1">WHERE</span> col1 <span class="sy0">=</span> <span class="nu0">3</span>;
<span class="kw1">COMMIT</span> <span class="kw1">TRANSACTION</span>;
&nbsp;
<span class="coMULTI">/* back to the first query window*/</span>
<span class="kw1">UPDATE</span> dbo.<span class="me1">Test2</span>
	<span class="kw1">SET</span>	col2 <span class="sy0">=</span> col2 <span class="sy0">*</span> 10
	<span class="kw1">WHERE</span> col2 <span class="sy0">=</span> <span class="nu0">4</span>;
<span class="kw1">COMMIT</span> <span class="kw1">TRANSACTION</span>;</pre></div></div></p>
<p>Looking at the code, we can see there are only five rows in each of the tables. In addition, an update will be performed to both col1 and col2 in each table for one specific row. So we are keeping this to a singleton type of update, and we are able to force a deadlock by using this setup. Not only do we see that a deadlock will occur consistently, we would see the following in the sys.dm_tran_locks DMV as well as in the deadlock graphs.</p>
<p><img decoding="async" src="https://jasonbrimhall.info/wp-content/uploads/2019/03/locks_held1-1024x521.png" /></p>
<p>In my environment, I used session 51 and 54 consistently for the deadlock repro. In each of the tests, each spid did obtain page locks as well as RID locks (row locks) that were waiting on each other in order to perform an Update. This is what we saw when I ran the setup without the ROWLOCK directive. What if I used the ROWLOCK directive (are you guessing already that there would be no change because the deadlock occurs on the lock held for the update that is waiting on the other update to complete?)? Let’s take a look at that too!</p>
<p><div id="wpshdo_13" class="wp-synhighlighter-outer"><div id="wpshdt_13" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_13"></a><a id="wpshat_13" class="wp-synhighlighter-title" href="#codesyntax_13"  onClick="javascript:wpsh_toggleBlock(13)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_13" onClick="javascript:wpsh_code(13)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_13" onClick="javascript:wpsh_print(13)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_13" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="coMULTI">/* what about using rowlock hint? let's try it */</span>
<span class="kw1">USE</span> tempdb;
GO
<span class="kw1">IF</span> <span class="kw2">OBJECT_ID</span><span class="br0">&#40;</span><span class="st0">'dbo.Test1'</span><span class="br0">&#41;</span> <span class="kw1">IS</span> <span class="sy0">NOT</span> <span class="sy0">NULL</span>
	<span class="kw1">DROP</span> <span class="kw1">TABLE</span> dbo.<span class="me1">Test1</span>;
<span class="kw1">IF</span> <span class="kw2">OBJECT_ID</span><span class="br0">&#40;</span><span class="st0">'dbo.Test2'</span><span class="br0">&#41;</span> <span class="kw1">IS</span> <span class="sy0">NOT</span> <span class="sy0">NULL</span>
	<span class="kw1">DROP</span> <span class="kw1">TABLE</span> dbo.<span class="me1">Test2</span>;
<span class="kw1">CREATE</span> <span class="kw1">TABLE</span> dbo.<span class="me1">Test1</span> <span class="br0">&#40;</span> col1 <span class="kw1">INT</span> <span class="br0">&#41;</span>;
<span class="kw1">CREATE</span> <span class="kw1">TABLE</span> dbo.<span class="me1">Test2</span> <span class="br0">&#40;</span> col2 <span class="kw1">INT</span> <span class="br0">&#41;</span>;
<span class="kw1">INSERT</span> <span class="kw1">INTO</span> dbo.<span class="me1">Test1</span>
	<span class="kw1">VALUES</span>	<span class="br0">&#40;</span> 1 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 2 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 3 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 4 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 5 <span class="br0">&#41;</span>;
<span class="kw1">INSERT</span> <span class="kw1">INTO</span> dbo.<span class="me1">Test2</span>
	<span class="kw1">VALUES</span>	<span class="br0">&#40;</span> 1 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 2 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 3 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 4 <span class="br0">&#41;</span>,
			<span class="br0">&#40;</span> 5 <span class="br0">&#41;</span>;
GO
<span class="kw1">BEGIN</span> <span class="kw1">TRANSACTION</span>;
<span class="kw1">UPDATE</span> dbo.<span class="me1">Test1</span> <span class="kw1">WITH</span> <span class="br0">&#40;</span>ROWLOCK<span class="br0">&#41;</span>
	<span class="kw1">SET</span>	col1 <span class="sy0">=</span> col1 <span class="sy0">*</span> 10
	<span class="kw1">WHERE</span> col1 <span class="sy0">=</span> <span class="nu0">3</span>;
&nbsp;
<span class="coMULTI">/* query window 2*/</span>
&nbsp;
<span class="kw1">USE</span> tempdb;
<span class="kw1">BEGIN</span> <span class="kw1">TRANSACTION</span>;
<span class="kw1">UPDATE</span> dbo.<span class="me1">Test2</span> <span class="kw1">WITH</span> <span class="br0">&#40;</span>ROWLOCK<span class="br0">&#41;</span>
	<span class="kw1">SET</span>	col2 <span class="sy0">=</span> col2 <span class="sy0">*</span> 20
	<span class="kw1">WHERE</span> col2 <span class="sy0">=</span> <span class="nu0">4</span>;
<span class="kw1">UPDATE</span> dbo.<span class="me1">Test1</span> <span class="kw1">WITH</span> <span class="br0">&#40;</span>ROWLOCK<span class="br0">&#41;</span>
	<span class="kw1">SET</span>	col1 <span class="sy0">=</span> col1 <span class="sy0">*</span> 20
	<span class="kw1">WHERE</span> col1 <span class="sy0">=</span> <span class="nu0">3</span>;
<span class="kw1">COMMIT</span> <span class="kw1">TRANSACTION</span>;
&nbsp;
<span class="coMULTI">/* back to the first query window*/</span>
<span class="kw1">UPDATE</span> dbo.<span class="me1">Test2</span> <span class="kw1">WITH</span> <span class="br0">&#40;</span>ROWLOCK<span class="br0">&#41;</span>
	<span class="kw1">SET</span>	col2 <span class="sy0">=</span> col2 <span class="sy0">*</span> 10
	<span class="kw1">WHERE</span> col2 <span class="sy0">=</span> <span class="nu0">4</span>;
<span class="kw1">COMMIT</span> <span class="kw1">TRANSACTION</span>;</pre></div></div></p>
<p>The only change to this setup is that the ROWLOCK directive has been added to the update statements. Examining the sys.dm_tran_locks DMV reveals the same locks being held as was seen without the directive. This shouldn’t be too big of a surprise since the updates are against a single row.</p>
<p>In addition to the same locks being held, we continue to experience the same deadlock problem. Using an Extended Events session to trap deadlock information (similar to the article previously discussed), we can pull out some pretty good info. Let’s examine some of the deadlock data trapped by an XE session.</p>
<p><div id="wpshdo_14" class="wp-synhighlighter-outer"><div id="wpshdt_14" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_14"></a><a id="wpshat_14" class="wp-synhighlighter-title" href="#codesyntax_14"  onClick="javascript:wpsh_toggleBlock(14)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_14" onClick="javascript:wpsh_code(14)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_14" onClick="javascript:wpsh_print(14)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_14" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">WITH</span>	cte	<span class="kw1">AS</span> <span class="br0">&#40;</span> <span class="kw1">SELECT</span> t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/@name)[1]'</span>, <span class="st0">'varchar(50)'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> event_name
							, t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/@timestamp)[1]'</span>,
													<span class="st0">'datetime2'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> StartTime
							, t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;duration&quot;]/value)[1]'</span>,
													<span class="st0">'bigint'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> duration
							, t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;database_name&quot;]/value)[1]'</span>,
													<span class="st0">'sysname'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> DBName
							, t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/action[@name=&quot;sql_text&quot;]/value)[1]'</span>,
													<span class="st0">'varchar(max)'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> sql_text
							, t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/action[@name=&quot;nt_username&quot;]/value)[1]'</span>,
													<span class="st0">'varchar(500)'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> nt_username
							, t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;mode&quot;]/value)[1]'</span>,
													<span class="st0">'varchar(15)'</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">' ('</span>
							<span class="sy0">+</span> t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;mode&quot;]/text)[1]'</span>,
													<span class="st0">'varchar(50)'</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">')'</span> <span class="kw1">AS</span> mode
							, t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;object_id&quot;]/value)[1]'</span>,
													<span class="st0">'integer'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> <span class="kw2">OBJECT_ID</span>
							, t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;resource_description&quot;]/value)[1]'</span>,
													<span class="st0">'varchar(max)'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> resource_description
							, t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;resource_owner_type&quot;]/text)[1]'</span>,
													<span class="st0">'varchar(max)'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> resource_owner_type
							, t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;resource_type&quot;]/text)[1]'</span>,
													<span class="st0">'varchar(max)'</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">' ('</span>
							<span class="sy0">+</span> t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;resource_type&quot;]/value)[1]'</span>,
													<span class="st0">'varchar(max)'</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">')'</span> <span class="kw1">AS</span> resource_type
							, t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/action[@name=&quot;server_principal_name&quot;]/value)[1]'</span>,
													<span class="st0">'varchar(max)'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> server_principal_name
							, t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/action[@name=&quot;session_id&quot;]/value)[1]'</span>,
													<span class="st0">'varchar(max)'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> session_id
							, t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/action[@name=&quot;client_pid&quot;]/value)[1]'</span>,
													<span class="st0">'integer'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> client_pid
							, t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/action[@name=&quot;client_app_name&quot;]/value)[1]'</span>,
													<span class="st0">'varchar(max)'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> client_app_name
							, t2.<span class="me1">event_data</span>
							,ROW_NUMBER<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw1">OVER</span> <span class="br0">&#40;</span><span class="kw1">ORDER</span> <span class="kw1">BY</span> t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/@timestamp)[1]'</span>,
													<span class="st0">'datetime2'</span><span class="br0">&#41;</span>
													,t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/@name)[1]'</span>, <span class="st0">'varchar(50)'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AS</span> Event_Seq
						<span class="kw1">FROM</span> sys.<span class="me1">fn_xe_file_target_read_file</span><span class="br0">&#40;</span><span class="st0">'C:<span class="es0">\D</span>atabase<span class="es0">\X</span>E<span class="es0">\D</span>eadlock*.xel'</span>,
																<span class="sy0">NULL</span>, <span class="sy0">NULL</span>, <span class="sy0">NULL</span><span class="br0">&#41;</span> t1
							<span class="sy0">CROSS</span> APPLY <span class="br0">&#40;</span> <span class="kw1">SELECT</span> <span class="kw1">CONVERT</span><span class="br0">&#40;</span>XML, t1.<span class="me1">event_data</span><span class="br0">&#41;</span>
										<span class="br0">&#41;</span> t2 <span class="br0">&#40;</span> event_data <span class="br0">&#41;</span>
				<span class="br0">&#41;</span>
	<span class="kw1">SELECT</span> c1.<span class="me1">event_name</span> <span class="kw1">AS</span> LockEvent, c2.<span class="me1">event_name</span> <span class="kw1">AS</span> GraphEvent
			, c1.<span class="me1">StartTime</span>
			, <span class="kw2">DATEADD</span><span class="br0">&#40;</span>MICROSECOND, c1.<span class="me1">duration</span>, <span class="kw1">CONVERT</span><span class="br0">&#40;</span>DATETIME2, <span class="br0">[</span>c1<span class="br0">]</span>.<span class="me1">StartTime</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AS</span> EndDate
			, c1.<span class="me1">duration</span>
			, c1.<span class="me1">DBName</span>
			, c1.<span class="me1">sql_text</span>
			, c1.<span class="me1">nt_username</span>
			, c1.<span class="me1">server_principal_name</span>
			, c1.<span class="me1">mode</span>
			, c1.<span class="kw2">OBJECT_ID</span>
			, c1.<span class="me1">resource_description</span>
			, c1.<span class="me1">resource_owner_type</span>
			, c1.<span class="me1">resource_type</span>
			, c1.<span class="me1">session_id</span>
			, c1.<span class="me1">client_pid</span>
			, c1.<span class="me1">client_app_name</span>
			, c1.<span class="me1">event_data</span>
			, graph.<span class="me1">query</span><span class="br0">&#40;</span><span class="st0">'.'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> EventDeadlockGraph
		<span class="kw1">FROM</span> cte c1
			<span class="kw1">INNER</span> <span class="sy0">JOIN</span> cte c2
				<span class="kw1">ON</span> c1.<span class="me1">Event_Seq</span> <span class="sy0">=</span> c2.<span class="me1">Event_Seq</span> <span class="sy0">-</span> <span class="nu0">1</span>
			<span class="sy0">CROSS</span> APPLY c2.<span class="me1">event_data</span>.<span class="me1">nodes</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;xml_report&quot;]/value)[last()]/*'</span><span class="br0">&#41;</span>
				<span class="kw1">AS</span> deadlock <span class="br0">&#40;</span> graph <span class="br0">&#41;</span>
		<span class="kw1">WHERE</span> c1.<span class="me1">event_name</span> <span class="sy0">=</span> <span class="st0">'lock_deadlock'</span>
			<span class="sy0">AND</span> c2.<span class="me1">event_name</span> <span class="sy0">=</span> <span class="st0">'xml_deadlock_report'</span>
		<span class="kw1">ORDER</span> <span class="kw1">BY</span> c1.<span class="me1">StartTime</span>;</pre></div></div></p>
<p>The results from this query will show us the deadlock graph, the event data, as well as several other pieces of data already parsed from the session data for you. And looking at the session data, one can see that the sql_text from each of the queries will demonstrate both the ROWLOCK directive and the directive-free versions of the query. In this query you can also see that I did a little black magic to match up the two event types from the event session (lock_deadlock and xml_deadlock_report). Then I was able to join the two together to produce one row per deadlock event and to see the sql_text with the deadlock graph on one row. Otherwise, the sql_text does not produce with the deadlock_report event. I leave the rest of the query to the reader to discover and question.</p>
<p><img decoding="async" src="https://jasonbrimhall.info/wp-content/uploads/2019/03/xe_results-1024x141.png" /></p>
<p>From the EventDeadlockGraph column, we could click the cell and take a close look at the XML generated for the deadlock event. Further, if I choose to save the xml as an XDL file and then reopen it in SSMS, I can see the deadlock graphical report as shown in the following.</p>
<p><img decoding="async" src="https://jasonbrimhall.info/wp-content/uploads/2019/03/graphical_report-1024x348.png" /></p>
<p>We see that row locks are still in effect for the update coming from both sides. This further supports that the directive really is just a waste of time in trying to combat this type of deadlock. This is one of those cases where the best option would be to optimize the code and work things out without trying to take a shortcut.</p>
<h3>Wrapping Up</h3>
<p>Look to optimize the code instead of trying to take a shortcut. In addition, take a look at the deadlocks, the locks held, and the code to get a better understanding of what is truly happening.</p>
<p>The post <a href="https://sqlsolutionsgroup.com/an-experiment-with-deadlocks/">An Experiment with Deadlocks</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>XE Output: Weaning yourself off of SQL Profiler, Part 2</title>
		<link>https://sqlsolutionsgroup.com/weaning-yourself-off-of-sql-profiler-part-2/</link>
		
		<dc:creator><![CDATA[Wayne Sheffield]]></dc:creator>
		<pubDate>Wed, 08 Jul 2015 10:01:40 +0000</pubDate>
				<category><![CDATA[Extended Events]]></category>
		<category><![CDATA[SQL Group]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[#microsftcertifedmaster]]></category>
		<category><![CDATA[#microsftpartner]]></category>
		<category><![CDATA[#SQLAB]]></category>
		<category><![CDATA[#SQlatino]]></category>
		<category><![CDATA[#SQlatinoamerica]]></category>
		<category><![CDATA[#sqldatabase]]></category>
		<category><![CDATA[#sqldeveloper]]></category>
		<category><![CDATA[#SQLgroupie]]></category>
		<category><![CDATA[#sqlimer]]></category>
		<category><![CDATA[#sqlimerbymay]]></category>
		<category><![CDATA[#sqlinjection]]></category>
		<category><![CDATA[#sqlinternals]]></category>
		<category><![CDATA[#sqlite]]></category>
		<category><![CDATA[#sqlite3]]></category>
		<category><![CDATA[#SQLLearning]]></category>
		<category><![CDATA[#SQLMagazine]]></category>
		<category><![CDATA[#sqlmanagementstudio]]></category>
		<category><![CDATA[#sqlmanager]]></category>
		<category><![CDATA[#Sqlmap]]></category>
		<category><![CDATA[#sqlrun]]></category>
		<category><![CDATA[#sqlsaturday2017]]></category>
		<category><![CDATA[#sqlsatvienna]]></category>
		<category><![CDATA[#sqlserver]]></category>
		<category><![CDATA[#SQLserver2012]]></category>
		<category><![CDATA[#sqlserver2014]]></category>
		<category><![CDATA[#sqlserver2017]]></category>
		<category><![CDATA[#sqlserver2022]]></category>
		<category><![CDATA[#SQLServeronLinux]]></category>
		<category><![CDATA[#SQLsolutionsgroup]]></category>
		<category><![CDATA[#SQLTraining]]></category>
		<category><![CDATA[#SQLYog]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[sql profiler]]></category>
		<category><![CDATA[SQLPASS]]></category>
		<category><![CDATA[SQLSaturday]]></category>
		<category><![CDATA[SSG]]></category>
		<guid isPermaLink="false">http://sqlsolutionsgroup.com/?p=2405</guid>

					<description><![CDATA[<p>In my last post, I shared a script that will take a running trace and show you the XE events that it relates to, and what columns are available within those XE events. Specifically, this was for converting a deadlock trace into an XE session; however the process is the same for converting any trace [&#8230;]</p>
<p>The post <a href="https://sqlsolutionsgroup.com/weaning-yourself-off-of-sql-profiler-part-2/">XE Output: Weaning yourself off of SQL Profiler, Part 2</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://sqlsolutionsgroup.com/wp-content/uploads/2015/06/NoProfiler.png"><img loading="lazy" decoding="async" class="alignright wp-image-2348 size-thumbnail" src="https://sqlsolutionsgroup.com/wp-content/uploads/2015/06/NoProfiler-150x150.png" alt="NoProfiler" width="150" height="150" /></a>In my <span style="color: #0000ff;"><a style="color: #0000ff;" href="https://sqlsolutionsgroup.com/wean-off-sql-profiler-part-1/">last post</a></span>, I shared a script that will take a running trace and show you the XE events that it relates to, and what columns are available within those XE events. Specifically, this was for converting a deadlock trace into an XE session; however the process is the same for converting any trace into an XE session. In today’s post, we’ll compare the deadlock trace and the new XE output by running both, creating a deadlock, and comparing the captured data. We’ll look at the data captured in the XE from both script and GUI, and look at a few other differences between running a trace and an XE session.</p>
<p>The first step is to grab the trace and XE scripts from the prior post at <span style="color: #0000ff;"><a style="color: #0000ff;" href="https://sqlsolutionsgroup.com/wean-off-sql-profiler-part-1/">https://sqlsolutionsgroup.com/wean-off-sql-profiler-part-1/</a></span>. Modify both scripts to put the output files in an appropriate place on your system. Run both of the scripts to start the trace and to create the XE session. Next, start the XE session with the following script:</p>
<p><div id="wpshdo_15" class="wp-synhighlighter-outer"><div id="wpshdt_15" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_15"></a><a id="wpshat_15" class="wp-synhighlighter-title" href="#codesyntax_15"  onClick="javascript:wpsh_toggleBlock(15)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_15" onClick="javascript:wpsh_code(15)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_15" onClick="javascript:wpsh_print(15)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_15" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">ALTER</span> EVENT <span class="kw1">SESSION</span> Deadlocks
<span class="kw1">ON</span> SERVER
<span class="kw1">STATE</span> <span class="sy0">=</span> <span class="kw1">START</span>;</pre></div></div></p>
<p>The next step is to create a deadlock. Open up a new query window, and run the following. Leave this query window open.</p>
<p><div id="wpshdo_16" class="wp-synhighlighter-outer"><div id="wpshdt_16" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_16"></a><a id="wpshat_16" class="wp-synhighlighter-title" href="#codesyntax_16"  onClick="javascript:wpsh_toggleBlock(16)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_16" onClick="javascript:wpsh_code(16)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_16" onClick="javascript:wpsh_print(16)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_16" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">USE</span> tempdb;
GO
<span class="kw1">IF</span> <span class="kw2">OBJECT_ID</span><span class="br0">&#40;</span><span class="st0">'dbo.Test1'</span><span class="br0">&#41;</span> <span class="kw1">IS</span> <span class="sy0">NOT</span> <span class="sy0">NULL</span> <span class="kw1">DROP</span> <span class="kw1">TABLE</span> dbo.<span class="me1">Test1</span>;
<span class="kw1">IF</span> <span class="kw2">OBJECT_ID</span><span class="br0">&#40;</span><span class="st0">'dbo.Test2'</span><span class="br0">&#41;</span> <span class="kw1">IS</span> <span class="sy0">NOT</span> <span class="sy0">NULL</span> <span class="kw1">DROP</span> <span class="kw1">TABLE</span> dbo.<span class="me1">Test2</span>;
<span class="kw1">CREATE</span> <span class="kw1">TABLE</span> dbo.<span class="me1">Test1</span> <span class="br0">&#40;</span>col1 <span class="kw1">INT</span><span class="br0">&#41;</span>;
<span class="kw1">CREATE</span> <span class="kw1">TABLE</span> dbo.<span class="me1">Test2</span> <span class="br0">&#40;</span>col2 <span class="kw1">INT</span><span class="br0">&#41;</span>;
<span class="kw1">INSERT</span> <span class="kw1">INTO</span> dbo.<span class="me1">Test1</span> <span class="kw1">VALUES</span> <span class="br0">&#40;</span>1<span class="br0">&#41;</span>,<span class="br0">&#40;</span>2<span class="br0">&#41;</span>,<span class="br0">&#40;</span>3<span class="br0">&#41;</span>,<span class="br0">&#40;</span>4<span class="br0">&#41;</span>,<span class="br0">&#40;</span>5<span class="br0">&#41;</span>;
<span class="kw1">INSERT</span> <span class="kw1">INTO</span> dbo.<span class="me1">Test2</span> <span class="kw1">VALUES</span> <span class="br0">&#40;</span>1<span class="br0">&#41;</span>,<span class="br0">&#40;</span>2<span class="br0">&#41;</span>,<span class="br0">&#40;</span>3<span class="br0">&#41;</span>,<span class="br0">&#40;</span>4<span class="br0">&#41;</span>,<span class="br0">&#40;</span>5<span class="br0">&#41;</span>;
GO
<span class="kw1">BEGIN</span> <span class="kw1">TRANSACTION</span>
<span class="kw1">UPDATE</span> dbo.<span class="me1">Test1</span> <span class="kw1">SET</span> col1 <span class="sy0">=</span> col1<span class="sy0">*</span>10 <span class="kw1">WHERE</span> col1<span class="sy0">=</span><span class="nu0">3</span>;</pre></div></div></p>
<p>Next, open up a second query window, and run the following code in that window:<div id="wpshdo_17" class="wp-synhighlighter-outer"><div id="wpshdt_17" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_17"></a><a id="wpshat_17" class="wp-synhighlighter-title" href="#codesyntax_17"  onClick="javascript:wpsh_toggleBlock(17)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_17" onClick="javascript:wpsh_code(17)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_17" onClick="javascript:wpsh_print(17)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_17" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">USE</span> tempdb;
<span class="kw1">BEGIN</span> <span class="kw1">TRANSACTION</span>;
<span class="kw1">UPDATE</span> dbo.<span class="me1">Test2</span> <span class="kw1">SET</span> col2 <span class="sy0">=</span> col2<span class="sy0">*</span>20 <span class="kw1">WHERE</span> col2 <span class="sy0">=</span> <span class="nu0">4</span>;
<span class="kw1">UPDATE</span> dbo.<span class="me1">Test1</span> <span class="kw1">SET</span> col1 <span class="sy0">=</span> col1<span class="sy0">*</span>20 <span class="kw1">WHERE</span> col1 <span class="sy0">=</span> <span class="nu0">3</span>;
<span class="kw1">COMMIT</span> <span class="kw1">TRANSACTION</span>;</pre></div></div></p>
<p>Finally, return to the first query window and run the following code, at which point one of the statements in one of the query windows will be deadlocked:<div id="wpshdo_18" class="wp-synhighlighter-outer"><div id="wpshdt_18" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_18"></a><a id="wpshat_18" class="wp-synhighlighter-title" href="#codesyntax_18"  onClick="javascript:wpsh_toggleBlock(18)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_18" onClick="javascript:wpsh_code(18)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_18" onClick="javascript:wpsh_print(18)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_18" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">UPDATE</span> dbo.<span class="me1">Test2</span> <span class="kw1">SET</span> col2 <span class="sy0">=</span> col2<span class="sy0">*</span>10 <span class="kw1">WHERE</span> col2 <span class="sy0">=</span> <span class="nu0">4</span>;
<span class="kw1">COMMIT</span> <span class="kw1">TRANSACTION</span>;</pre></div></div>

<span style="color: #ff0000;">Msg 1205, Level 13, State 45, Line 4</span></pre>
<pre><span style="color: #ff0000;">Transaction (Process ID 57) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.</span></pre>
<p>Now that we&#8217;ve created a deadlock, let’s compare the trace output data to the XE output data. First, let’s grab the data from the trace file with this script, which selects all of the non-null columns from the table valued function (remember to change the filename/path as appropriate):<div id="wpshdo_19" class="wp-synhighlighter-outer"><div id="wpshdt_19" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_19"></a><a id="wpshat_19" class="wp-synhighlighter-title" href="#codesyntax_19"  onClick="javascript:wpsh_toggleBlock(19)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_19" onClick="javascript:wpsh_code(19)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_19" onClick="javascript:wpsh_print(19)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_19" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">SELECT</span> t2.<span class="me1">TextData</span>, t2.<span class="me1">BinaryData</span>, t2.<span class="me1">NTUserName</span>, t2.<span class="me1">ClientProcessID</span>, t2.<span class="me1">ApplicationName</span>,
       t2.<span class="me1">LoginName</span>, t2.<span class="me1">SPID</span>, t2.<span class="me1">Duration</span>, t2.<span class="me1">StartTime</span>, t2.<span class="me1">EndTime</span>, t2.<span class="me1">ObjectID</span>,
       t2.<span class="me1">ServerName</span>, t2.<span class="me1">EventClass</span>, t2.<span class="me1">Mode</span>, t2.<span class="me1">DatabaseName</span>, t2.<span class="me1">Type</span>
<span class="kw1">FROM</span>   sys.<span class="me1">traces</span> t1
<span class="sy0">CROSS</span> APPLY sys.<span class="kw4">fn_trace_gettable</span> <span class="br0">&#40;</span><span class="kw1">path</span>, <span class="sy0">NULL</span><span class="br0">&#41;</span> t2
<span class="kw1">WHERE</span> t1.<span class="kw1">path</span> <span class="sy0">LIKE</span> <span class="st0">'C:<span class="es0">\S</span>QL<span class="es0">\T</span>races<span class="es0">\%</span>'</span></pre></div></div><a href="https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE09-XE-Collected-Trace-Data.png"><img loading="lazy" decoding="async" class="alignnone wp-image-2407 size-full" src="https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE09-XE-Collected-Trace-Data.png" alt="SSMS2014XE09-XE-Collected Trace Data" width="1164" height="188" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE09-XE-Collected-Trace-Data.png 1164w, https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE09-XE-Collected-Trace-Data-300x48.png 300w, https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE09-XE-Collected-Trace-Data-1024x165.png 1024w, https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE09-XE-Collected-Trace-Data-768x124.png 768w" sizes="(max-width: 1164px) 100vw, 1164px" /></a></p>
<p><a href="https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE10-XE-Collected-Trace-Data.png"><img loading="lazy" decoding="async" class="alignnone wp-image-2408 size-full" src="https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE10-XE-Collected-Trace-Data.png" alt="" width="1131" height="184" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE10-XE-Collected-Trace-Data.png 1131w, https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE10-XE-Collected-Trace-Data-300x49.png 300w, https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE10-XE-Collected-Trace-Data-1024x167.png 1024w, https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE10-XE-Collected-Trace-Data-768x125.png 768w" sizes="(max-width: 1131px) 100vw, 1131px" /></a></p>
<p><a href="https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE11-XE-Collected-Trace-Data.png"><img loading="lazy" decoding="async" class="alignnone wp-image-2406 size-full" src="https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE11-XE-Collected-Trace-Data.png" alt="" width="940" height="186" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE11-XE-Collected-Trace-Data.png 940w, https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE11-XE-Collected-Trace-Data-300x59.png 300w, https://sqlsolutionsgroup.com/wp-content/uploads/2015/07/SSMS2014XE11-XE-Collected-Trace-Data-768x152.png 768w" sizes="(max-width: 940px) 100vw, 940px" /></a></p>
<p>We now want to compare this to the data that was collected by the Extended Event session. In SSMS, expand the Management Tree, then the Extended Events tree, Session tree, and the Deadlocks tree:</p>
<p><img loading="lazy" decoding="async" class="alignnone" src="https://blog.waynesheffield.com/wayne/wp-content/uploads/2016/12/SSMS2014XE07-XE-Session-target.png" alt="" width="290" height="299" /></p>
<p>The event file target can now be seen. Double-click the file target to view the data, and you can see the events that fired for the deadlock. Note that you can right-click on the grid header, and choose additional columns to put into the grid – for this XE session, I like to add the database_name, resource_description, resource_owner, resource_type and xml_report columns.</p>
<p><img decoding="async" src="https://blog.waynesheffield.com/wayne/wp-content/uploads/2016/12/SSMS2014XE08-XE-Collected-Data.png" alt="SSMS2014XE08-XE-Collected-Data" /></p>
<p>By selecting one of the rows, all of the data will be available in the lower grid in a Name/Value format.</p>
<p>Let’s compare the XE output to the trace output, and ensure that the data captured by the trace is present in the XE output. The first trace column is TextData. In that, we see multiple bits of data: SPID, lock resource, and the deadlock graph in XML format. In the XE, the resource_description column has the lock resource, the xml_report column has the deadlock graph in XML format, and the session_id column has the SPID. Skipping the BinaryData column, the next column is the NTUserName. Here we can see that this is collected in the XE nt_username column. A minor difference is that the XE includes the domain name, and the trace doesn’t.</p>
<p>The ClientProcessID column maps to the client_pid column. Likewise, the ApplicationName maps to client_app_name, LoginName maps to server_principal_name, SPID maps to session_id, Duration maps to duration, StartTime maps to timestamp, ObjectID maps to object_id. The EventClass, Mode and Type columns maps via friendly names to the name, mode and resource_type columns. The only columns that aren’t explicitly in the XE results are the BinaryData, EndDate and ServerName columns. The EndDate can be calculated from the timestamp and duration columns, and we could have selected the server_instance_name in “Global Fields (Actions)” tab when configuring the XE session. So here, we can see that everything needed from the trace is available in the XE session.</p>
<p>For the next step, one might want to load the data into a table, and viewing it in the viewer doesn’t allow for this. Or maybe you are working on a server prior to SQL Server 2012, and the GUI isn’t available for you to use. The following script can be used to query the data from the file target (again, remember to change the file name/path as necessary):</p>
<p><div id="wpshdo_20" class="wp-synhighlighter-outer"><div id="wpshdt_20" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_20"></a><a id="wpshat_20" class="wp-synhighlighter-title" href="#codesyntax_20"  onClick="javascript:wpsh_toggleBlock(20)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_20" onClick="javascript:wpsh_code(20)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_20" onClick="javascript:wpsh_print(20)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_20" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">SELECT</span> <span class="kw2">OBJECT_NAME</span>,
       <span class="kw1">CONVERT</span><span class="br0">&#40;</span>XML, event_data<span class="br0">&#41;</span> <span class="kw1">AS</span> event_data
<span class="kw1">FROM</span>   sys.<span class="me1">fn_xe_file_target_read_file</span><span class="br0">&#40;</span><span class="st0">'C:<span class="es0">\S</span>QL<span class="es0">\X</span>E_Out<span class="es0">\D</span>eadlocks*.xel'</span>, <span class="sy0">NULL</span>, <span class="sy0">NULL</span>, <span class="sy0">NULL</span><span class="br0">&#41;</span>;</pre></div></div></p>
<p><img decoding="async" src="https://blog.waynesheffield.com/wayne/wp-content/uploads/2016/12/SSMS2014XE12-XE-target-file-query-results.png" alt="SSMS2014XE12-XE-target-file-query-results" /></p>
<p>As can be seen from the output, the data that we most want to see is stored as XML (when working with Extended Events, all of the data is stored as XML) in the event_data column, so I have converted this column to XML. At this point, you can click the XML output, and it will be opened up in text, allowing you to see all of the data as it is stored in the XML output.</p>
<p><img decoding="async" src="https://blog.waynesheffield.com/wayne/wp-content/uploads/2016/12/SSMS2014XE13-XE-target-file-event_data-results.png" alt="SSMS2014XE13-XE-target-file-event_data-results" /></p>
<p>From this point, it’s just a matter of modifying the query to return the columns that you are interested in.</p>
<p><div id="wpshdo_21" class="wp-synhighlighter-outer"><div id="wpshdt_21" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_21"></a><a id="wpshat_21" class="wp-synhighlighter-title" href="#codesyntax_21"  onClick="javascript:wpsh_toggleBlock(21)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_21" onClick="javascript:wpsh_code(21)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_21" onClick="javascript:wpsh_print(21)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_21" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">WITH</span> cte <span class="kw1">AS</span>
<span class="br0">&#40;</span>
<span class="kw1">SELECT</span>  t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/@name)[1]'</span>,<span class="st0">'varchar(50)'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> event_name,
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/@timestamp)[1]'</span>, <span class="st0">'datetime2'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> StartTime,
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;duration&quot;]/value)[1]'</span>, <span class="st0">'bigint'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> duration,
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;database_name&quot;]/value)[1]'</span>, <span class="st0">'sysname'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> DBName,
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/action[@name=&quot;nt_username&quot;]/value)[1]'</span>, <span class="st0">'varchar(500)'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> nt_username,
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;mode&quot;]/value)[1]'</span>, <span class="st0">'varchar(15)'</span><span class="br0">&#41;</span>  <span class="sy0">+</span> <span class="st0">' ('</span> <span class="sy0">+</span> 
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;mode&quot;]/text)[1]'</span>, <span class="st0">'varchar(50)'</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">')'</span> <span class="kw1">AS</span> mode,
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;object_id&quot;]/value)[1]'</span>, <span class="st0">'integer'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> <span class="kw2">OBJECT_ID</span>,
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;resource_description&quot;]/value)[1]'</span>, <span class="st0">'varchar(max)'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> resource_description,
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;resource_owner_type&quot;]/text)[1]'</span>, <span class="st0">'varchar(max)'</span><span class="br0">&#41;</span>  <span class="kw1">AS</span> resource_owner_type,
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;resource_type&quot;]/text)[1]'</span>, <span class="st0">'varchar(max)'</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">' ('</span> <span class="sy0">+</span>
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/data[@name=&quot;resource_type&quot;]/value)[1]'</span>, <span class="st0">'varchar(max)'</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">')'</span> <span class="kw1">AS</span> resource_type,
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/action[@name=&quot;server_principal_name&quot;]/value)[1]'</span>, <span class="st0">'varchar(max)'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> server_principal_name,
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/action[@name=&quot;session_id&quot;]/value)[1]'</span>, <span class="st0">'varchar(max)'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> session_id,
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/action[@name=&quot;client_pid&quot;]/value)[1]'</span>, <span class="st0">'integer'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> client_pid,
        t2.<span class="me1">event_data</span>.<span class="kw1">VALUE</span><span class="br0">&#40;</span><span class="st0">'(event/action[@name=&quot;client_app_name&quot;]/value)[1]'</span>, <span class="st0">'varchar(max)'</span><span class="br0">&#41;</span> <span class="kw1">AS</span> client_app_name,
        t2.<span class="me1">event_data</span>
<span class="kw1">FROM</span>    sys.<span class="me1">fn_xe_file_target_read_file</span><span class="br0">&#40;</span><span class="st0">'C:<span class="es0">\S</span>QL<span class="es0">\X</span>E_Out<span class="es0">\D</span>eadlocks*.xel'</span>, <span class="sy0">NULL</span>, <span class="sy0">NULL</span>, <span class="sy0">NULL</span><span class="br0">&#41;</span> t1
<span class="sy0">CROSS</span> APPLY <span class="br0">&#40;</span><span class="kw1">SELECT</span> <span class="kw1">CONVERT</span><span class="br0">&#40;</span>XML, t1.<span class="me1">event_data</span><span class="br0">&#41;</span><span class="br0">&#41;</span> t2<span class="br0">&#40;</span>event_data<span class="br0">&#41;</span>
<span class="br0">&#41;</span>
<span class="kw1">SELECT</span>  cte.<span class="me1">event_name</span>,
        cte.<span class="me1">StartTime</span>,
        <span class="kw2">DATEADD</span><span class="br0">&#40;</span>MICROSECOND, duration, <span class="kw1">CONVERT</span><span class="br0">&#40;</span>DATETIME2, <span class="br0">[</span>cte<span class="br0">]</span>.<span class="me1">StartTime</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AS</span> EndDate,
        cte.<span class="me1">duration</span>,
        cte.<span class="me1">DBName</span>,
        cte.<span class="me1">nt_username</span>,
        cte.<span class="me1">server_principal_name</span>,
        cte.<span class="me1">mode</span>,
        cte.<span class="kw2">OBJECT_ID</span>,
        cte.<span class="me1">resource_description</span>,
        cte.<span class="me1">resource_owner_type</span>,
        cte.<span class="me1">resource_type</span>,
        cte.<span class="me1">session_id</span>,
        cte.<span class="me1">client_pid</span>,
        cte.<span class="me1">client_app_name</span>,
        cte.<span class="me1">event_data</span> 
<span class="kw1">FROM</span>    cte;</pre></div></div></p>
<p>This query extracts the data from XE file target. It also calculates the end date, and displays both the internal and user-friendly names for the resource_type and mode columns – the internal values are what the trace was returning.</p>
<p>For a quick recap: <a href="https://sqlsolutionsgroup.com/wean-off-sql-profiler-part-1/">in Part 1</a>, you learned how to convert an existing trace into an XE session, identifying the columns and stepping through the GUI for creating the XE session. In part 2 you learned how to query both the trace and XE file target outputs, and then compared the two outputs and learned that all of the data in the trace output is available in the XE output.</p>
<p>The post <a href="https://sqlsolutionsgroup.com/weaning-yourself-off-of-sql-profiler-part-2/">XE Output: Weaning yourself off of SQL Profiler, Part 2</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Weaning yourself off of SQL Profiler (Part 1)</title>
		<link>https://sqlsolutionsgroup.com/wean-off-sql-profiler-part-1/</link>
					<comments>https://sqlsolutionsgroup.com/wean-off-sql-profiler-part-1/#comments</comments>
		
		<dc:creator><![CDATA[Wayne Sheffield]]></dc:creator>
		<pubDate>Tue, 09 Jun 2015 06:26:24 +0000</pubDate>
				<category><![CDATA[Extended Events]]></category>
		<category><![CDATA[SQL Group]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[#microsftcertifedmaster]]></category>
		<category><![CDATA[#microsftpartner]]></category>
		<category><![CDATA[#SQLAB]]></category>
		<category><![CDATA[#SQlatino]]></category>
		<category><![CDATA[#SQlatinoamerica]]></category>
		<category><![CDATA[#sqldatabase]]></category>
		<category><![CDATA[#sqldeveloper]]></category>
		<category><![CDATA[#SQLgroupie]]></category>
		<category><![CDATA[#sqlimer]]></category>
		<category><![CDATA[#sqlimerbymay]]></category>
		<category><![CDATA[#sqlinjection]]></category>
		<category><![CDATA[#sqlinternals]]></category>
		<category><![CDATA[#sqlite]]></category>
		<category><![CDATA[#sqlite3]]></category>
		<category><![CDATA[#SQLLearning]]></category>
		<category><![CDATA[#SQLMagazine]]></category>
		<category><![CDATA[#sqlmanagementstudio]]></category>
		<category><![CDATA[#sqlmanager]]></category>
		<category><![CDATA[#Sqlmap]]></category>
		<category><![CDATA[#sqlrun]]></category>
		<category><![CDATA[#sqlsaturday2017]]></category>
		<category><![CDATA[#sqlsatvienna]]></category>
		<category><![CDATA[#sqlserver]]></category>
		<category><![CDATA[#SQLserver2012]]></category>
		<category><![CDATA[#sqlserver2014]]></category>
		<category><![CDATA[#sqlserver2017]]></category>
		<category><![CDATA[#sqlserver2022]]></category>
		<category><![CDATA[#SQLServeronLinux]]></category>
		<category><![CDATA[#SQLsolutionsgroup]]></category>
		<category><![CDATA[#SQLTraining]]></category>
		<category><![CDATA[#SQLYog]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Script]]></category>
		<category><![CDATA[SQLPASS]]></category>
		<category><![CDATA[SQLSaturday]]></category>
		<category><![CDATA[SSG]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[XE]]></category>
		<guid isPermaLink="false">http://sqlsolutionsgroup.com/?p=2336</guid>

					<description><![CDATA[<p>In this brave, new world of Extended Events (XE, XEvents), I find myself with a mixture of scripts for troubleshooting issues – some use XE, and some use traces. We’ve all been told that XE is a much better system (it is much more lightweight, causing less of an issue with the server). In fact, [&#8230;]</p>
<p>The post <a href="https://sqlsolutionsgroup.com/wean-off-sql-profiler-part-1/">Weaning yourself off of SQL Profiler (Part 1)</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://sqlsolutionsgroup.com/wp-content/uploads/2015/06/NoProfiler.png"><img loading="lazy" decoding="async" class="alignright wp-image-2348 size-medium" src="https://sqlsolutionsgroup.com/wp-content/uploads/2015/06/NoProfiler-300x243.png" alt="NoProfiler" width="300" height="243" hspace="15" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2015/06/NoProfiler-300x243.png 300w, https://sqlsolutionsgroup.com/wp-content/uploads/2015/06/NoProfiler.png 560w" sizes="(max-width: 300px) 100vw, 300px" /></a>In this brave, new world of Extended Events (XE, XEvents), I find myself with a mixture of scripts for troubleshooting issues – some use XE, and some use traces. We’ve all been told that XE is a much better system (it is much more lightweight, causing less of an issue with the server). In fact, it is so much better that Microsoft has deprecated SQL Trace and SQL Profiler, and in the future, one will not be able to run any traces at all. Believe it or not, this is a good thing!</p>
<p><a href="https://blogs.lessthandot.com/index.php/uncategorized/youre-invited-to-t-sql-tuesday-67-extended-events/"><img loading="lazy" decoding="async" class="alignleft wp-image-1860 size-thumbnail" src="https://sqlsolutionsgroup.com/wp-content/uploads/2014/12/TSQL2sDay150x150-150x150.jpg" alt="TSQL2sDay150x150" width="150" height="150" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2014/12/TSQL2sDay150x150-150x150.jpg 150w, https://sqlsolutionsgroup.com/wp-content/uploads/2014/12/TSQL2sDay150x150.jpg 154w" sizes="(max-width: 150px) 100vw, 150px" /></a>It just so happens that today is the 67<sup>th</sup> installment of the monthly T-SQL Tuesday blogging event. T-SQL Tuesday, that wonderful monthly blogging party started by Adam Machanic where a selected host challenges the SQL Server universe to have a blog post about a specific topic. This wild frenzy of SQL Server blog posting occurs on the second Tuesday of each month. This month, it is being hosted by my friend (and the person with the highest amount of energy known to mankind) Jes Borland (<span style="color: #3366ff;"><a style="color: #3366ff;" href="https://blogs.lessthandot.com/index.php?disp=authdir&amp;author=420">b</a></span> / <span style="color: #3366ff;"><a style="color: #3366ff;" href="https://twitter.com/grrl_geek">t</a></span>), and the topic that she has chosen is Extended Events. Her specific challenge to the SQL Server universe is:</p>
<blockquote><p>I want to know (and others do, too) how you’ve solved problems with Extended Events. What sessions have you created? What unique way have you used predicates or targets? What challenges have you overcome?</p></blockquote>
<p>The biggest challenge that I have is not a technical challenge&#8230; it&#8217;s a personal challenge: actually getting started with XE. I have so many scripts for doing traces, that I just immediately use them instead of the better XE system. I really need to wean myself off of using Profiler / traces. Therefore, I’ve decided to start converting my trace scripts into XE scripts, and I&#8217;ll share with you how I go about doing it. Today, I’m going to look at my favorite trace script – a trace to capture deadlock information.</p>
<p>First off, let’s start with the trace script:</p>
<p><div id="wpshdo_22" class="wp-synhighlighter-outer"><div id="wpshdt_22" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_22"></a><a id="wpshat_22" class="wp-synhighlighter-title" href="#codesyntax_22"  onClick="javascript:wpsh_toggleBlock(22)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_22" onClick="javascript:wpsh_code(22)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_22" onClick="javascript:wpsh_print(22)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_22" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="co1">-- Create a trace to capture deadlocks</span>
<span class="kw1">DECLARE</span> @rc <span class="kw1">INTEGER</span>,
        @TraceID <span class="kw1">INTEGER</span>,
        @maxfilesize <span class="kw1">BIGINT</span>,
        @OutputFileName <span class="kw1">NVARCHAR</span><span class="br0">&#40;</span>256<span class="br0">&#41;</span>,
        @TraceStopTime <span class="kw1">DATETIME</span>,
        @<span class="kw1">ON</span> <span class="kw1">BIT</span>,
        @intfilter <span class="kw1">INT</span>,
        @bigintfilter <span class="kw1">BIGINT</span>;
&nbsp;
<span class="kw1">SET</span> @<span class="kw1">ON</span> <span class="sy0">=</span> <span class="nu0">1</span>;
<span class="kw1">SET</span> @maxfilesize <span class="sy0">=</span> <span class="nu0">10</span>; <span class="co1">--mb </span>
<span class="kw1">DECLARE</span> @FileName <span class="kw1">NVARCHAR</span><span class="br0">&#40;</span>256<span class="br0">&#41;</span>;
<span class="co1">-- added InstanceName for when server is running multiple instances</span>
<span class="kw1">SET</span> @FileName <span class="sy0">=</span> N<span class="st0">'C:<span class="es0">\S</span>QL<span class="es0">\T</span>races<span class="es0">\'</span> + CONVERT(sysname, SERVERPROPERTY('</span>InstanceName<span class="st0">')) + '</span>\<span class="st0">' +
               CONVERT(CHAR(8), GETDATE(), 112) + '</span>_<span class="st0">' +
               REPLACE(CONVERT(CHAR(8), GETDATE(), 114), '</span>:<span class="st0">', '</span><span class="st0">');
EXECUTE xp_create_subdir @FileName;               
SET @FileName = @FileName + N'</span>\<span class="st0">' + REPLACE(@@SERVERNAME, N'</span>\<span class="st0">', N'</span>_<span class="st0">') + '</span>_DeadlockTrace_<span class="st0">' + CONVERT(CHAR(8), GETDATE(), 112) + N'</span>_<span class="st0">' + REPLACE(CONVERT(CHAR(8), GETDATE(), 114), N'</span>:<span class="st0">', N'</span><span class="st0">') + N'</span>Z<span class="st0">';
PRINT @FileName;
SET @TraceStopTime = DATEADD(HOUR, 6, GETDATE());
EXEC @rc = sp_trace_create @TraceID output, 2, @FileName, @maxfilesize, @TraceStopTime;
&nbsp;
IF (@rc != 0) GOTO error
&nbsp;
-- Set the events
-- Event 148: Deadlock Graph
EXEC sp_trace_setevent @TraceID, 148, 1, @on;   -- TextData
EXEC sp_trace_setevent @TraceID, 148, 11, @on;  -- LoginName
EXEC sp_trace_setevent @TraceID, 148, 12, @on;  -- SPID
EXEC sp_trace_setevent @TraceID, 148, 14, @on;  -- StartTime
-- Event 25: Lock:Deadlock
EXEC sp_trace_setevent @TraceID, 25, 1, @on;    -- TextData
EXEC sp_trace_setevent @TraceID, 25, 2, @on;    -- BinaryData
EXEC sp_trace_setevent @TraceID, 25, 6, @on;    -- NTUserName
EXEC sp_trace_setevent @TraceID, 25, 9, @on;    -- ClientProcessID
EXEC sp_trace_setevent @TraceID, 25, 10, @on;   -- ApplicationName
EXEC sp_trace_setevent @TraceID, 25, 11, @on;   -- LoginName
EXEC sp_trace_setevent @TraceID, 25, 12, @on;   -- SPID
EXEC sp_trace_setevent @TraceID, 25, 13, @on;   -- Duration
EXEC sp_trace_setevent @TraceID, 25, 14, @on;   -- StartTime
EXEC sp_trace_setevent @TraceID, 25, 15, @on;   -- EndTime
EXEC sp_trace_setevent @TraceID, 25, 22, @on;   -- ObjectID
EXEC sp_trace_setevent @TraceID, 25, 32, @on;   -- Mode
EXEC sp_trace_setevent @TraceID, 25, 35, @on;   -- DatabaseName
EXEC sp_trace_setevent @TraceID, 25, 57, @on;   -- Type
-- Event 59: Lock:Deadlock Chain
EXEC sp_trace_setevent @TraceID, 59, 1, @on;    -- TextData
EXEC sp_trace_setevent @TraceID, 59, 2, @on;    -- BinaryData
EXEC sp_trace_setevent @TraceID, 59, 12, @on;   -- SPID
EXEC sp_trace_setevent @TraceID, 59, 14, @on;   -- StartTime
EXEC sp_trace_setevent @TraceID, 59, 22, @on;   -- ObjectID
EXEC sp_trace_setevent @TraceID, 59, 32, @on;   -- Mode
EXEC sp_trace_setevent @TraceID, 59, 35, @on;   -- DatabaseName
EXEC sp_trace_setevent @TraceID, 59, 57, @on;   -- Type
&nbsp;
&nbsp;
-- Set the Filters
-- Set the trace status to start
EXEC sp_trace_setstatus @TraceID, 1;
&nbsp;
-- display trace id for future references
SELECT TraceID=@TraceID;
GOTO finish;
&nbsp;
error: 
SELECT ErrorCode=@rc;
&nbsp;
finish: 
GO</span></pre></div></div></p>
<p>From this script, you can see that the trace is collecting data from three events (Deadlock Graph (148), Lock:Deadlock (25) and Lock:Deadlock Chain (59)) and several columns for each event. The next step is to convert all of this information into XE events / actions. For this, I’ll modify the script in BOL (at <a href="https://msdn.microsoft.com/en-us/library/ff878264.aspx" rel="noopener noreferrer">https://msdn.microsoft.com/en-us/library/ff878264.aspx</a>) to the following to return the XE events / actions for a specified running trace. Since the trace needs to be running, execute the above trace script to start the trace, then run the following code:</p>
<p><div id="wpshdo_23" class="wp-synhighlighter-outer"><div id="wpshdt_23" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_23"></a><a id="wpshat_23" class="wp-synhighlighter-title" href="#codesyntax_23"  onClick="javascript:wpsh_toggleBlock(23)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_23" onClick="javascript:wpsh_code(23)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_23" onClick="javascript:wpsh_print(23)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_23" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="co1">-- change the following value to the trace_id for the running trace to be converted to XE</span>
<span class="kw1">DECLARE</span> @trace_id <span class="kw1">INTEGER</span> <span class="sy0">=</span> <span class="nu0">2</span>;
&nbsp;
<span class="kw1">SELECT</span> <span class="kw1">DISTINCT</span>
        tb.<span class="me1">trace_event_id</span>,
        te.<span class="me1">name</span> <span class="kw1">AS</span> <span class="st0">'Event Class'</span>,
        em.<span class="me1">package_name</span> <span class="kw1">AS</span> <span class="st0">'Package'</span>,
        em.<span class="me1">xe_event_name</span> <span class="kw1">AS</span> <span class="st0">'XEvent Name'</span>,
        tb.<span class="me1">trace_column_id</span>,
        tc.<span class="me1">name</span> <span class="kw1">AS</span> <span class="st0">'SQL Trace Column'</span>,
        am.<span class="me1">xe_action_name</span> <span class="kw1">AS</span> <span class="st0">'Extended Events action'</span>
<span class="kw1">FROM</span>    sys.<span class="kw4">FN_TRACE_GETEVENTINFO</span><span class="br0">&#40;</span>@trace_id<span class="br0">&#41;</span> ei
        <span class="sy0">JOIN</span> sys.<span class="me1">trace_events</span> te
            <span class="kw1">ON</span> te.<span class="me1">trace_event_id</span> <span class="sy0">=</span> ei.<span class="me1">eventid</span>
        <span class="sy0">JOIN</span> sys.<span class="me1">trace_columns</span> tc  <span class="co1">-- all available trace columns</span>
            <span class="kw1">ON</span> tc.<span class="me1">trace_column_id</span> <span class="sy0">=</span> ei.<span class="me1">columnid</span>
        <span class="kw1">LEFT</span> <span class="sy0">OUTER</span> <span class="sy0">JOIN</span> sys.<span class="me1">trace_xe_event_map</span> em
            <span class="kw1">ON</span> em.<span class="me1">trace_event_id</span> <span class="sy0">=</span> te.<span class="me1">trace_event_id</span>
        <span class="kw1">LEFT</span> <span class="sy0">OUTER</span> <span class="sy0">JOIN</span> sys.<span class="me1">trace_event_bindings</span> tb
            <span class="kw1">ON</span> tb.<span class="me1">trace_event_id</span> <span class="sy0">=</span> em.<span class="me1">trace_event_id</span>
            <span class="sy0">AND</span> tc.<span class="me1">trace_column_id</span> <span class="sy0">=</span> tb.<span class="me1">trace_column_id</span>
        <span class="kw1">LEFT</span> <span class="sy0">OUTER</span> <span class="sy0">JOIN</span> sys.<span class="me1">trace_xe_action_map</span> am
            <span class="kw1">ON</span> am.<span class="me1">trace_column_id</span> <span class="sy0">=</span> tc.<span class="me1">trace_column_id</span>
<span class="kw1">ORDER</span> <span class="kw1">BY</span> tb.<span class="me1">trace_event_id</span>, tb.<span class="me1">trace_column_id</span>;</pre></div></div></p>
<p>These results may contain NULL values in the “Extended Events action” column. A NULL value here means that there is not a corresponding event action for that column. For my deadlock trace, I get the following results:</p>
<p><img decoding="async" src="https://blog.waynesheffield.com/wayne/wp-content/uploads/2016/11/SSMS2014XE00-TraceXExref.png" alt="SSMS2014XE00-TraceXExref" /></p>
<p>With this information, I can now jump into SSMS (2014) and use the New Session wizard to create a new XE session (Expand the Management and Extended Events nodes. Right click on Sessions and select New Session). I name the session “Deadlocks”, and click the “Events” page to select the events that I want to use.</p>
<p><img decoding="async" src="https://blog.waynesheffield.com/wayne/wp-content/uploads/2016/11/SSMS2014XE01-NewXESession.png" alt="SSMS2014XE01-NewXESession" /></p>
<p>Since all of the events that I’m looking for contain “Deadlock”, I search for this and 5 events are displayed. I double-click each of the three listed above (or select them and click the “&gt;” button) to move them to the “Selected Events” grid.</p>
<p><img decoding="async" src="https://blog.waynesheffield.com/wayne/wp-content/uploads/2016/11/SSMS2014XE02-SelectEvents.png" alt="SSMS2014XE02-SelectEvents" /></p>
<p>The next step is to configure the columns, so click the Configure button.</p>
<p><img decoding="async" src="https://blog.waynesheffield.com/wayne/wp-content/uploads/2016/11/SSMS2014XE03-ConfigureEvents.png" alt="SSMS2014XE03-ConfigureEvents" /></p>
<p>Select the lock_deadlock event, and on the “Global Fields (Actions)” tab select the client_app_name, client_pid, database_name, nt_username, server_principal_name and session_id columns.</p>
<p><img decoding="async" src="https://blog.waynesheffield.com/wayne/wp-content/uploads/2016/11/SSMS2014XE04-ConfigureEventColumns.png" alt="SSMS2014XE04-ConfigureEventColumns" /></p>
<p>Click on the “Event Fields” tab, and check the checkboxes for database_name and resource_description. Fields that show up in this tab with checkboxes have customizable actions, and don’t actually collect the information unless checked. Frequently this will be because these fields require an additional level of resource usage to gather this information.</p>
<p><img decoding="async" src="https://blog.waynesheffield.com/wayne/wp-content/uploads/2016/11/SSMS2014XE05-ConfigureEventColumns.png" alt="SSMS2014XE05-ConfigureEventColumns" /></p>
<p>Select the lock_deadlock_chain event, and select the session_id and database_name columns on the “Global Fields (Actions)” tab. Click on the “Event Fields” tab and check the checkbox for database_name and resource_description. Finally, select the xml_deadlock_report event, and select the server_principal_name and session_id columns on the “Global Fields (Actions)” tab.</p>
<p>Finally, click on the Data Storage page, and add an event_file target type. The file name defaults to the name that you gave the session earlier. I set the maximum size to 250mb and 5 rollover files. If you select to script to a new query window (HIGHLY recommended), you will have a script with all of the DDL necessary to create this XE.</p>
<p><img decoding="async" src="https://blog.waynesheffield.com/wayne/wp-content/uploads/2016/11/SSMS2014XE06-ConfigureDataStorage.png" alt="SSMS2014XE06-ConfigureDataStorage" /></p>
<p>At this point, there are two changes that I like to make. First, I like to make my scripts so that they won’t have an error, and if the XE session already exists then one will be generated. To make it bullet-proof, I add an IF EXISTS check at the top and drop the XE session if it already exists. Secondly, I like to call xp_create_subdir to create the directory that the script points to, just in case the directory doesn’t exist. Note that xp_create_subdir will be successful if the directory already exists, so I don’t check to ensure that the directory doesn’t exist before executing this procedure.</p>
<p>My final XE Deadlock script looks like:</p>
<p><div id="wpshdo_24" class="wp-synhighlighter-outer"><div id="wpshdt_24" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_24"></a><a id="wpshat_24" class="wp-synhighlighter-title" href="#codesyntax_24"  onClick="javascript:wpsh_toggleBlock(24)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_24" onClick="javascript:wpsh_code(24)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_24" onClick="javascript:wpsh_print(24)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_24" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">IF</span> <span class="sy0">EXISTS</span> <span class="br0">&#40;</span><span class="kw1">SELECT</span> 1 <span class="kw1">FROM</span> sys.<span class="me1">server_event_sessions</span> <span class="kw1">WHERE</span> name <span class="sy0">=</span> <span class="st0">'Deadlocks'</span><span class="br0">&#41;</span>
	<span class="kw1">DROP</span> EVENT <span class="kw1">SESSION</span> <span class="br0">[</span>Deadlocks<span class="br0">]</span> <span class="kw1">ON</span> SERVER;
GO
<span class="kw1">EXECUTE</span> xp_create_subdir <span class="st0">'C:<span class="es0">\S</span>QL<span class="es0">\X</span>E_Out'</span>;
GO
<span class="kw1">CREATE</span> EVENT <span class="kw1">SESSION</span> <span class="br0">[</span>Deadlocks<span class="br0">]</span>
<span class="kw1">ON</span> SERVER
<span class="kw1">ADD</span> EVENT sqlserver.<span class="me1">lock_deadlock</span><span class="br0">&#40;</span>
    <span class="kw1">SET</span> collect_database_name<span class="sy0">=</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span>,collect_resource_description<span class="sy0">=</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span>
	<span class="kw1">ACTION</span> 
	<span class="br0">&#40;</span>
			  sqlserver.<span class="me1">client_app_name</span>	<span class="co1">-- ApplicationName from SQLTrace</span>
			, sqlserver.<span class="me1">client_pid</span>	<span class="co1">-- ClientProcessID from SQLTrace</span>
			, sqlserver.<span class="me1">nt_username</span>	<span class="co1">-- NTUserName from SQLTrace</span>
			, sqlserver.<span class="me1">server_principal_name</span>	<span class="co1">-- LoginName from SQLTrace</span>
			, sqlserver.<span class="me1">session_id</span>	<span class="co1">-- SPID from SQLTrace</span>
	<span class="br0">&#41;</span>
<span class="br0">&#41;</span>,
<span class="kw1">ADD</span> EVENT sqlserver.<span class="me1">lock_deadlock_chain</span><span class="br0">&#40;</span>
    <span class="kw1">SET</span> collect_database_name<span class="sy0">=</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span>,collect_resource_description<span class="sy0">=</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span>
	<span class="kw1">ACTION</span> 
	<span class="br0">&#40;</span>
			  sqlserver.<span class="me1">session_id</span>	<span class="co1">-- SPID from SQLTrace</span>
	<span class="br0">&#41;</span>
<span class="br0">&#41;</span>,
<span class="kw1">ADD</span> EVENT sqlserver.<span class="me1">xml_deadlock_report</span><span class="br0">&#40;</span>
	<span class="kw1">ACTION</span> 
	<span class="br0">&#40;</span>
			  sqlserver.<span class="me1">server_principal_name</span>	<span class="co1">-- LoginName from SQLTrace</span>
			, sqlserver.<span class="me1">session_id</span>	<span class="co1">-- SPID from SQLTrace</span>
	<span class="br0">&#41;</span>
<span class="br0">&#41;</span>
<span class="kw1">ADD</span> TARGET package0.<span class="me1">event_file</span>
<span class="br0">&#40;</span>
	<span class="kw1">SET</span> filename <span class="sy0">=</span> <span class="st0">'C:<span class="es0">\S</span>QL<span class="es0">\X</span>E_Out<span class="es0">\D</span>eadlocks.xel'</span>,
		max_file_size <span class="sy0">=</span> 250,
		max_rollover_files <span class="sy0">=</span> 5
<span class="br0">&#41;</span>
<span class="kw1">WITH</span> <span class="br0">&#40;</span>STARTUP_STATE<span class="sy0">=</span><span class="kw1">OFF</span><span class="br0">&#41;</span>
;</pre></div></div></p>
<p>Now that you have this XE session scripted out, it can be easily installed on multiple servers. If you encounter a deadlock problem, you can easily start the XE session and let it run to trap your deadlocks. They will be persisted to a file dedicated for the deadlocks. You can use my Deadlock Shredder script at <a href="https://bit.ly/ShredDL">https://bit.ly/ShredDL</a> to read the deadlocks from the file and shred the deadlock XML into a tabular output.</p>
<p>Note that the default system_health XE session also captures deadlocks. I like to have a dedicated session for just deadlocks. As lightweight as XE is, sometimes it may benefit a server to turn off the system_health session. Additionally, Jonathan Kehayias has a script that will take a running trace and completely script out an XE session for it. This script can be found at <a href="https://www.sqlskills.com/blogs/jonathan/converting-sql-trace-to-extended-events-in-sql-server-2012/">https://www.sqlskills.com/blogs/jonathan/converting-sql-trace-to-extended-events-in-sql-server-2012/</a>. Even though this script is available, I like to figure things out for myself so that I can learn what is actually going on.</p>
<p><strong>Did you catch the note above where I mentioned that the default system_health XE captures deadlocks</strong><strong>?</strong> This means that if you are still enabling trace flags 1204 and/or 1222 to capture deadlock information in your error logs, you don’t need to do that anymore. Furthermore, by using this Deadlock XE, you can have the deadlocks persisted to a file where, in combination with my Deadlock Shredder script, it will be even easier to analyze the deadlocks than trying to figure it out from the captured information in the error logs.</p>
<p>I hope that this post will help someone with the conversion from using SQL Profiler to using XE instead. The process for converting other traces would be the same, so it can be easily adapted. I also hope that these deadlock scripts will be helpful to you!</p>
<p>In my next post, I will be comparing the results of the deadlock trace and the deadlock XE session.</p>
<p>And Jes – thanks for hosting this month! I’m really looking forward to seeing the roundup for this month.</p>
<p>The post <a href="https://sqlsolutionsgroup.com/wean-off-sql-profiler-part-1/">Weaning yourself off of SQL Profiler (Part 1)</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlsolutionsgroup.com/wean-off-sql-profiler-part-1/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
