Description:

This wait type occurs when a thread is waiting for access to a non-page data structure so that it can modify the data structure. The thread cannot get access to the data structure because one or more other threads have it latched in share mode. The Latches Whitepaper in the sidebar on the right has a description of all latch modes and their compatibility with other latch modes.

(Books Online description: “Occurs when waiting for a EX (exclusive) latch. This does not include buffer latches or transaction mark latches. A listing of LATCH_* waits is available in sys.dm_os_latch_stats. Note that sys.dm_os_latch_stats groups LATCH_NL, LATCH_SH, LATCH_UP, LATCH_EX, and LATCH_DT waits together.”)

Questions/comments on this wait type? Click here to send Paul an email, especially if you have any information to add to this topic.

Added in SQL Server version:

Pre-2005/2005

Removed in SQL Server version:

N/A

Extended Events wait_type value:

The map_key value in sys.dm_xe_map_values is 36 in all versions through 2014 RTM. After 2014 RTM, you must check the DMV to get the latest value as some map_key values have changed in later builds.

Other information:

A latch is a lightweight synchronization mechanism that provides synchronization between threads trying to read or change a data structure in SQL Server. There are three types of latches:

  • Latches on pages being read from disk (these are covered by the PAGEIOLATCH_XX wait types – see the PAGEIOLATCH_SH wait type for more details)
  • Latches on pages already in memory (these are covered by the PAGELATCH_XX wait types – see the PAGELATCH_EX wait type for more details)
  • Latches on non-page data structures (i.e. everything else)

The LATCH_SH and LATCH_EX wait types occur when a thread requires access to a non-page data structure (e.g., page buffers in the buffer pool (latch type = BUFFER), or the data structure that represents a database’s data and log files (latch type = FGCB_ADD_REMOVE)).

A latch is only held for the duration of the operation, unlike a lock which may be held until a transaction commits. One example of locks and latches – imagine a table where an update query has caused lock escalation so that a table X lock is held on the table. As the query continues updating more records in the table, it won’t acquire any more locks, but any data and index pages that are updated in memory must be EX (exclusive) latched before the update can occur. The latch acts as the synchronization mechanism to prevent two threads updating the page at the same time, or a thread reading the page while another is in the middle of updating it. Another example is if you run a select query using NOLOCK – although the query will not acquire S (share) locks at any level in the table, the threads must acquire SH (share) latches on pages before they can be read, to synchronize with possible concurrent updaters.

Similar examples exist for all non-page data structures, but it’s easier to explain using page latches.

Non-page latch waits correspond to LATCH_SH and LATCH_EX waits in the output from the sys.dm_os_wait_stats DMV, but that DMV doesn’t show which exact latch is the contention point. You can look in the sys.dm_os_waiting_tasks DMV for latch waits occurring in real time (use this script), and that DMV will show the name of the latch being waited for. You can then look in the SQL Server Latch Classes Library for that latch and get more guidance. Alternatively, you can look in the sys.dm_os_latch_stats DMV to see which latches have had the most aggregate contention (use this script) and then get more guidance from the latches library. It’s impossible to troubleshoot non-page latch contention without knowing which latch is the contention point.

Note: Only look at latch statistics and be concerned about latch contention if LATCH_EX and/or LATCH_SH are one of the top waits on your server. It’s very easy to get pulled off on a wild-goose chase by looking at latch statistics first.

Known occurrences in SQL Server (list number matches call stack list):

  1. Waiting for the ACCESS_METHODS_DATASET_PARENT latch to get the next set of pages to scan (in this case, while scanning an index)
  2. Waiting for the DATABASE_MIRRORING_CONNECTION latch to send a message to a mirroring partner (in this case, the once-per-second ping to verify the partner is still available)
  3. Waiting for the LOG_MANAGER latch to grow the log file (in this case, while generating the LOP_BEGIN_XACT log record to start a transaction for modifying a record in a system table because a data file grew)

And many, many more stacks around the set of non-page latches.

LATCH_EX的更多相关文章

  1. SqlServer性能急剧下降,查看所有会话的状态及等待类型---Latch_Ex

    当某个数据库文件空间用尽,做自动增长的时候,同一时间点只能有一个用户人员可以做文件自动增长动作,其他任务必须等待,此时会出现Latch资源的等待.使用sp_helpdb查看业务数据库时发现:该数据库设 ...

  2. 资源等待类型sys.dm_os_wait_stats

    动态管理视图  sys.dm_os_wait_stats 返回执行的线程所遇到的所有等待的相关信息.可以使用该聚合视图来诊断 SQL Server 以及特定查询和批处理的性能问题. 列名 数据类型 说 ...

  3. sys.dm_db_wait_stats

    sys.dm_db_wait_stats 返回在操作期间执行的线程所遇到的所有等待的相关信息. 可以使用此聚合视图来诊断 Azure SQL Database 以及特定查询和批处理的性能问题. 执行查 ...

  4. [转载]sql server 等待类型

    下表列出各任务所遇到的等待类型. 等待类型 说明 ASYNC_DISKPOOL_LOCK 当尝试同步并行的线程(执行创建或初始化文件等任务)时出现. ASYNC_IO_COMPLETION 当某任务正 ...

  5. SQL Server 各任务所维护

    SQL Server 正在运行的代码查看 SELECT [Spid] = session_id , ecid , [Database] = DB_NAME(sp.dbid) , [User] = nt ...

  6. MYSQL一次性能优化实战经历[转]

    每次经历数据库性能调优,都是对性能优化的再次认识.对自己知识不足的有力验证,只有不断总结.学习才能少走弯路. 一.性能问题描述 应用端反应系统查询缓慢,长时间出不来结果.SQLServer数据库服务器 ...

  7. sql server 各种等待类型-转

    等待的类型 资源等待 当某个工作线程请求访问某个不可用的资源(因为该资源正在由其他某个工作线程使用,或者该资源尚不可用)时,便会发生资源等待.资源等待的示例包括锁等待.闩锁等待.网络等待以及磁盘 I/ ...

  8. 性能调优9:根据WaitType诊断性能

    SQL Server数据库接收到查询请求,从生成计划到执行计划的过程,等待次数和等待时间在一定程度上揭示了系统性能的压力,如果资源严重不足,就会成为性能的瓶颈.因此,对等待的监控非常有助于对系统性能进 ...

  9. Sys.dm_os_wait_stats Sys.dm_performance_counters

    wait_type waiting_tasks_count wait_time_ms max_wait_time_ms signal_wait_time_ms MISCELLANEOUS 0 0 0 ...

随机推荐

  1. [React] 03 - Intro: react.js in twelve demos

    Ref: React 入门实例教程 这算什么,react学习例子的十二门徒?哈哈 如何运行别人的react项目? Ref: [React全家桶入门之CODE]项目代码与使用方法 使用git克隆项目到本 ...

  2. 11代理模式Proxy

    一.什么是代理模式 Proxy模式又叫做代理模式,是构造型的设计 模式之一,它可以为其他对象提供一种代理(Proxy)以 控制对这个对象的访问. 所谓代理,是指具有与代理元(被代理的对象)具有 相同的 ...

  3. c++中SetEvent和ResetEvent的使用

    关于事件 事件(Event)是WIN32提供的最灵活的线程间同步方式,事件可以处于激发状态(signaled or true)或未激发状态(unsignal or false).根据状态变迁方式的不同 ...

  4. Unity3D Shader 半兰伯特光照模型

    //效果预览 //Shader代码 Shader "Unlit/HalfLambert" { Properties { _MainTex ("Texture", ...

  5. 适用于CentOS6.4的Win7双系统安装方式

    (文章在2013-11-16 15:56:31修改,此次修改幅度较大,之前的安装方式有问题,已经不推荐使用.笔者在此对各位读者表示深深的歉意!) 在之前的文章中我们实现了Win7+CentOS6.3双 ...

  6. nginx+tomcat 下POST响应参数过大无法显示完整及文件下载服务遇到过大文件无法下载解决办法

    在nginx里location里面设置 proxy_buffering off; 或者 proxy_buffering on; proxy_buffers 4 4k; proxy_busy_buffe ...

  7. 错误票据|2013年蓝桥杯B组题解析第七题-fishers

    错误票据 某涉密单位下发了某种票据,并要在年终全部收回. 因为工作人员疏忽,在录入ID号的时候发生了一处错误,造成了某个ID断号,另外一个ID重号. 你的任务是通过编程,找出断号的ID和重号的ID. ...

  8. IT资源关东煮第一期【来源于网络】

    IT资源关东煮第一期[来源于网络] 地址:http://geek.csdn.net/news/detail/128222

  9. ul li 的 float:left;

    如 ul li{float:left;} 出来的效果不仅是原本默认竖着排的元素变横排,还是往左边排,重点是元素是按顺序排的,如果float等于right,则不仅是往右排,且元素是倒着排的,如原来的a ...

  10. 配置zsh

    .zshrc export ZSH="/root/.oh-my-zsh" ZSH_THEME="robbyrussell" plugins=(git zsh-s ...