<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Latches on SQL Server Scripts</title><link>https://www.sqlserver70.com/tags/latches/</link><description>Recent content in Latches on SQL Server Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>SQLServer70.com</copyright><lastBuildDate>Wed, 21 Oct 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.sqlserver70.com/tags/latches/index.xml" rel="self" type="application/rss+xml"/><item><title>Measure Internal Latch Contention with sys.dm_os_latch_stats</title><link>https://www.sqlserver70.com/post/measure-internal-latch-contention-with-sys-dm-os-latch-stats/</link><pubDate>Wed, 21 Oct 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/measure-internal-latch-contention-with-sys-dm-os-latch-stats/</guid><description>
&lt;p&gt;When LATCH_* waits show up near the top of &lt;code&gt;sys.dm_os_wait_stats&lt;/code&gt;, you know threads are waiting on non-buffer latches. You don't know which engine structure they're waiting for. &lt;code&gt;sys.dm_os_latch_stats&lt;/code&gt; splits those waits by latch class. The script below ranks the non-buffer classes that make up the first 95% of latch wait time and returns the seconds waited, the wait count, the percentage and the average wait for each class.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;The job is to turn a generic latch wait into a named structure, such as a filegroup, the log manager or the root of a B-tree. Non-buffer latch waits &lt;a href="https://learn.microsoft.com/en-us/sql/relational-databases/diagnose-resolve-latch-contention?view=sql-server-ver17"&gt;appear in wait stats as a LATCH_* wait type&lt;/a&gt;, and once they appear, &lt;code&gt;sys.dm_os_latch_stats&lt;/code&gt; &lt;a href="https://learn.microsoft.com/en-us/sql/relational-databases/diagnose-resolve-latch-contention?view=sql-server-ver17"&gt;gives the cumulative breakdown by class&lt;/a&gt;. A latch wait &lt;a href="https://learn.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-objects/sys-dm-os-latch-stats-transact-sql?view=sql-server-ver17"&gt;starts when a request cannot be granted immediately because another thread holds the latch in a conflicting mode&lt;/a&gt;.&lt;/p&gt;</description></item></channel></rss>