深入研究SQL Server扩展事件–事件配对目标

本文详细介绍了SQL Server扩展事件中的事件配对目标,用于匹配和丢弃成对发生的事件,如锁的获取和释放。事件配对是异步的,数据先存储在内存中,然后异步发送到目标。通过创建事件配对目标,可以有效地查找未发生的配对事件,例如未释放的锁。文章展示了如何配置TSQL语法以创建扩展事件会话和事件配对目标,并讨论了配置参数及其对性能和内存管理的影响。
摘要由CSDN通过智能技术生成

Extended event sessions can use multiple targets to store captured information. We should use different targets depending on the type of data we are capturing and the structure of the data outcome we desire. The available targets include the following: event counter, ring buffer, event file, histogram, event tracing for Windows (ETW), and Event Pairing.

扩展事件会话可以使用多个目标来存储捕获的信息。 我们应根据要捕获的数据类型和所需数据结果的结构使用不同的目标。 可用目标包括:事件计数器,环形缓冲区,事件文件,直方图,Windows事件跟踪(ETW)和事件配对

Event pairing matches two events using captured data. There are many types of events that occur in pairs, such as locks, where an example pair would be an acquired lock and released lock. We can utilize the event pairing target to find and determine when a specified paired event hasn’t occurred in the matching set. Working with our example, we can track when a lock was acquired, but not released.

事件配对使用捕获的数据匹配两个事件。 成对发生的事件有很多类型,例如锁,其中示例对将是获取的锁和释放的锁。 我们可以利用事件配对目标来查找和确定匹配集中未发生指定的配对事件。 通过我们的示例,我们可以跟踪何时获得但未释放锁。

After two events are paired, both of them are discarded. Discarding matching events frees space for still unmatched events and allows for easy overview. A great example is the Mahjong game, when two tiles of the same type are matched, they are removed.

在两个事件配对后,它们都将被丢弃。 丢弃匹配事件将为尚不匹配的事件释放空间,并允许轻松查看。 一个很好的例子是麻将游戏,当两个相同类型的图块匹配时,它们将被删除。

Event pairing is an asynchronous process. The data is first kept in the memory buffer, and then sent to the target asynchronously. Usually the events are not sent immediately and specifics of the memory mechanism result in a minimal delay. The data stored within the target will be lost when the SQL Server is restarted.

事件配对是一个异步过程。 数据首先保存在内存缓冲区中,然后异步发送到目标。 通常情况下,事件不会立即发送,并且存储机制的细节会导致延迟最小。 重新启动SQL Server时,目标中存储的数据将丢失。

Within the article, we will go true the creation of an Extended Events session; the configuration parameters of the Event Pairing target, and obtain meaningful data from it.

在本文中,我们将实现扩展事件会话的创建; 事件配对目标的配置参数,并从中获取有意义的数据。

We will start with creating a common extended events session. Its aim is to capture information for SQL Server locks. These events occur when a lock is acquired on an object or when a lock is released.

我们将从创建一个公共扩展事件会话开始。 其目的是捕获SQL Server锁的信息。 当在对象上获取锁或释放锁时,会发生这些事件。

 
CREATE EVENT SESSION [XE_collect_locks] ON SERVER 
ADD EVENT sqlserver.lock_acquired,
ADD EVENT sqlserver.lock_released
GO
 

Without creating a target for the extended event session, the data is only stored in memory and we can use the SQL Server Management Studio to access it. Shown is the captured data consisting of lock_acquired and lock_released events, each one of them representing a single lock action.

无需为扩展事件会话创建目标,数据仅存储在内存中,我们可以使用SQL Server Management Studio进行访问。 显示的是由lock_acquired和lock_released事件组成的捕获数据,其中每个事件代表一个锁定动作。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值