LATCH_EX
Published 28 March 2024
An operation is waiting for exclusive write access to modify a structure in memory. The structure is not related to buffers or transactions, but to some other process within SQL Server.
Latches are lightweight, performance-optimized mechanisms for data consistency within SQL Server. LATCH_* waits protect access to internal memory structures outside the buffer pool pages (non-buffer latches), and their use is determined by the SQL Server engine. The engine uses latch compatibility modes to manage concurrent attempts by multiple threads to acquire latches on the same structures.
On a system with high concurrency, it’s normal for incompatible latch requests to be forced to wait until other requests are complete. If latch contention and wait times affect CPU and throughput, you should investigate. For more information, including details of latch compatibility modes, see: Diagnosing and Resolving Latch Contention on SQL Server (Microsoft Download Center).
Investigating system issues
To determine whether latch contention is a system-wide issue:
- Check the Analysis page for consistently high values for these metrics:
Machine: processor time
Avg. CPU queue length
Check for SOS_SCHEDULER_YIELD waits in the Top waits table.
Investigating latch contention
- Query the DMV sys.dm_os_latch_stats to identify the dominant non-buffer latches in your system. See: Most common latch classes and what they mean for a suitable script and guidance.
Use a debugging tool to analyze SQL Server process memory dumps and identify system issues that might have caused contention. See: Debugging that latch timeout.