Extended Events: مفاهیم، Event Session و Targetها | Pro SQL Server 2019 Administration

Extended Events: مفاهیم، Event Session و Targetها

توسط admin | گروه SQL Server | 1405/05/20

نظرات 0

Extended Events: مفاهیم، Event Session و Targetها

Chapter 19 — Extended Events Concepts and Event Sessions

نویسنده: Peter A. Carter

زبان منبع: انگلیسی

محدوده: صفحات PDF 705 تا 721

تاریخ ترجمه: 2026-08-11

اعتبار ترجمه: ترجمه با کمک هوش مصنوعی

PAGE-705

فصل ۱۹ — Extended Events

Extended Events یک Framework سبک و قابل‌پیکربندی برای Event Monitoring در SQL Server است. Event Session Eventها را انتخاب، Actionهای Context را اضافه، Predicate را اعمال و داده را به Target می‌فرستد.

PAGE-706

Packages و Events

Artifactهای XEvent در Packageهایی مانند package0 و sqlserver سازماندهی می‌شوند. Eventها Channel/Category و Fieldهای مختلف دارند. Channelهای Admin، Operational، Analytic و Debug شدت/نوع مصرف را توصیف می‌کنند.

Table 19-1 — بازنمایی متن فنی جدول منبع
--- PDF PAGE 706 ---
700
Packages
A package is a container for the objects used within Extended Events. Here are the four 
types of SQL Server package:
•	
Package0: The default package, used for Extended Events system 
objects.
•	
Sqlserver: Used for SQL Server–related objects.
•	
Sqlos: Used for SQLOS-related objects.
•	
SecAudit: Used by SQL Audit; however, its objects are not exposed.
Events
An event is an occurrence of interest that you can trace. It may be a SQL batch 
completing, a cache miss, or a page split, or virtually anything else that can happen 
within the Database Engine, depending on the nature of the trace that you are 
configuring. Each event is categorized by channel and keyword (also known as 
category). A channel is a high-level categorization, and all events in SQL Server 2019 fall 
into one of the channels described in Table 19-1.
Table 19-1.  Channels
Channel
Description
Admin
Well-known events with well-known resolutions. For example, deadlocks, server 
starts, CPU thresholds being exceeded, and the use of deprecated features.
Operational
Used for troubleshooting issues. For example, bad memory being detected, 
an AlwaysOn Availability Group replica changing its state, and a long IO being 
detected are all events that fall within the Operational channel.
Analytic
High-volume events that you can use for troubleshooting issues such as 
performance. For example, a transaction beginning, a lock being acquired, and a 
file read completing are all events that fall within the Analytic channel.
Debug
Used by developers to diagnose issues by returning internal data. The events in 
the Debug channel are subject to change in future versions of SQL Server, so you 
should avoid them when possible.
Chapter 19  Extended Events
PAGE-707

Targets

Targetهای رایج
Targetکاربرد
event_fileفایل XEL؛ مناسب Capture پایدار
ring_bufferMemory Ring Buffer برای Session کوچک
histogramAggregation روی Field/Action
event_counterشمار Eventها
pair_matchingPair کردن Event آغاز/پایان

Target می‌تواند Synchronous یا Asynchronous باشد و انتخاب آن روی Overhead اثر دارد.

Table 19-2 — بازنمایی متن فنی جدول منبع
--- PDF PAGE 707 ---
701
Keywords, also known as categories, are much more fine grain. There are 88 
categories within SQL Server 2019. These categories can be listed, by running the query 
in Listing 19-1.
Listing 19-1.  Return List of Categories
SELECT DISTINCT map_value AS Category
FROM sys.dm_xe_map_values map
WHERE map.name = 'keyword_map'
ORDER BY map.map_value
Targets
A target is the consumer of the events; essentially, it is the device to which the trace data 
will be written. The targets available within SQL Server 2019 are detailed in Table 19-2.
Table 19-2.  Targets
Target
Synchronous/Asynchronous
Description
Event counter
Synchronous
Counts the number of events that occur during a 
session
Event file
Asynchronous
Writes the event output to memory buffers and 
then flushes them to disk
Event pairing
Asynchronous
Determines if a paired event occurs without its 
matching event, e.g., if a statement started but 
never completed
ETW*
Synchronous
Used to correlate Extended Events with operating 
system data
Histogram
Asynchronous
Counts the number of events that occur during a 
session, based on an action or event column
Ring buffer
Asynchronous
Stores data in a memory buffer, using First In First 
Out (FIFO) methodology
*Event Tracking for Windows
Chapter 19  Extended Events
PAGE-708

Actions و Predicates

Action داده Context مانند sql_text، session_id، database_name یا plan_handle را هنگام Event جمع می‌کند. Predicate قبل از Target Eventهای نامرتبط را Filter و حجم Capture را کم می‌کند.

PAGE-709

Predicate Source/Comparator از Metadata XEvent قابل Query است. Filter مناسب مهم‌ترین راه کنترل Overhead است؛ Session پرحجم بدون Predicate می‌تواند Storage/CPU قابل توجه مصرف کند.

PAGE-710

Types, Maps و Sessions

sys.dm_xe_map_values مقادیر Map مانند Wait Type Codeها را به Description نگاشت می‌کند. Session container نهایی Event + Action + Predicate + Target است. Database نمونه Chapter19 برای مثال ساخته می‌شود.

PAGE-711

Tableهای Customer و داده آزمایشی Chapter19 ساخته می‌شوند تا Event Session روی INSERT/Statementها Activity قابل مشاهده داشته باشد.

PAGE-712

Tableهای Customer و داده آزمایشی Chapter19 ساخته می‌شوند تا Event Session روی INSERT/Statementها Activity قابل مشاهده داشته باشد.

PAGE-713

Tableهای Customer و داده آزمایشی Chapter19 ساخته می‌شوند تا Event Session روی INSERT/Statementها Activity قابل مشاهده داشته باشد.

PAGE-714

New Session Wizard — General

Session Name، Template، Startup State و Causality Tracking در صفحه General تنظیم می‌شود. Template نقطه شروع است و باید برای workload واقعی Filter شود.

Figure 19-1 — شکل/تصویر منبع، صفحه PDF 714
PAGE-715

Events

Events Page Eventهایی مانند sql_statement_completed، rpc_completed، error_reported یا lock/deadlock را انتخاب می‌کند. Event Fieldهای قابل Capture با هر Event متفاوت‌اند.

Figure 19-3 — شکل/تصویر منبع، صفحه PDF 715
PAGE-716

Global Fields / Actions

Actionهایی مثل sql_text، username، client_app_name و database_id به چند Event افزوده می‌شوند. Action زیاد Payload و Overhead را افزایش می‌دهد.

Figure 19-4 — شکل/تصویر منبع، صفحه PDF 716
PAGE-717

Predicate

Filter روی database_id، duration، username یا fieldهای دیگر باعث می‌شود فقط Eventهای هدف Capture شوند. Predicate بهتر است تا حد ممکن Selective باشد.

Figure 19-5 — شکل/تصویر منبع، صفحه PDF 717
PAGE-718

Event Fields

Fieldهای Event که intrinsic هستند در Event Fields نمایش داده می‌شوند. تفاوت Field و Action این است که Field بخشی از Event و Action Context اضافی است.

Figure 19-6 — شکل/تصویر منبع، صفحه PDF 718
PAGE-719

Data Storage

event_file معمولاً Target اصلی Production است. File Path، Max File Size و Rollover Count باید طوری تنظیم شوند که Disk پر نشود و History کافی باقی بماند.

Figure 19-6 — شکل/تصویر منبع، صفحه PDF 719
Table 19-3 — بازنمایی متن فنی جدول منبع
--- PDF PAGE 719 ---
713
On the Advanced page, we can specify the desired behavior in the event of memory 
pressure: whether single-event loss is acceptable, whether multiple-event loss is 
acceptable, or whether there should be no event loss at all. We can also set the minimum 
and maximum size for events and how memory partitioning should be applied. This 
is discussed in more detail in the following section. Additionally, we can configure 
dispatch latency. This indicates the maximum amount of time that an event remains in 
the buffers before it is flushed to disk.
Using T-SQL
You can also create event sessions via T-SQL using the CREATE EVENT SESSION DDL 
statement. The command accepts the arguments detailed in Table 19-3.
Figure 19-6.  The Data Storage page
Chapter 19  Extended Events

--- PDF PAGE 720 ---
714
The statement also accepts the WITH options, detailed in Table 19-4. The WITH 
statement is specified once, at the end of the CREATE EVENT SESSION statement.
Table 19-3.  Create Event Session Arguments
Argument
Description
event_session_name
The name of the event session that you are creating.
ADD EVENT | SET
Specified for every event that is added to the session, followed by the 
name of the event, in the format package.event. You can use the 
SET statement to set event-­specific customizations, such as including 
nonmandatory event fields.
ACTION
Specified after each ADD EVENT argument if global fields should be 
captured for that event.
WHERE
Specified after each ADD EVENT argument if the event should be 
filtered.
ADD TARGET | SET
Specified for each target that will be added to the session. You can use 
the SET statement to populate target-specific parameters, such as the 
filename parameter for the event_file target.
Table 19-4.  Create Event Session WITH Options
Option
Description
MAX_MEMORY
The maximum amount of memory that the event session can use 
for buffering events before dispatching them to the target(s).
EVENT_RETENTION_MODE
Specifies the behavior if the buffers become full. Acceptable values 
are ALLOW_SINGLE_EVENT_LOSS, which indicates that a single 
event can be dropped if all buffers are full; ALLOW_MULTIPLE_
EVENT_LOSS, which indicates that an entire buffer can be dropped 
if all buffers are full; and NO_EVENT_LOSS, which indicates that 
tasks that cause events to fire are to wait until there is space in the 
buffer.
(continued)
Chapter 19  Extended Events
PAGE-720

CREATE EVENT SESSION Options

T-SQL Argumentها شامل MAX_MEMORY، EVENT_RETENTION_MODE، MAX_DISPATCH_LATENCY، MAX_EVENT_SIZE، MEMORY_PARTITION_MODE، TRACK_CAUSALITY و STARTUP_STATE هستند.

Table 19-4 — بازنمایی متن فنی جدول منبع
--- PDF PAGE 720 ---
714
The statement also accepts the WITH options, detailed in Table 19-4. The WITH 
statement is specified once, at the end of the CREATE EVENT SESSION statement.
Table 19-3.  Create Event Session Arguments
Argument
Description
event_session_name
The name of the event session that you are creating.
ADD EVENT | SET
Specified for every event that is added to the session, followed by the 
name of the event, in the format package.event. You can use the 
SET statement to set event-­specific customizations, such as including 
nonmandatory event fields.
ACTION
Specified after each ADD EVENT argument if global fields should be 
captured for that event.
WHERE
Specified after each ADD EVENT argument if the event should be 
filtered.
ADD TARGET | SET
Specified for each target that will be added to the session. You can use 
the SET statement to populate target-specific parameters, such as the 
filename parameter for the event_file target.
Table 19-4.  Create Event Session WITH Options
Option
Description
MAX_MEMORY
The maximum amount of memory that the event session can use 
for buffering events before dispatching them to the target(s).
EVENT_RETENTION_MODE
Specifies the behavior if the buffers become full. Acceptable values 
are ALLOW_SINGLE_EVENT_LOSS, which indicates that a single 
event can be dropped if all buffers are full; ALLOW_MULTIPLE_
EVENT_LOSS, which indicates that an entire buffer can be dropped 
if all buffers are full; and NO_EVENT_LOSS, which indicates that 
tasks that cause events to fire are to wait until there is space in the 
buffer.
(continued)
Chapter 19  Extended Events

--- PDF PAGE 721 ---
715
Option
Description
MAX_DISPATCH_LATENCY
The maximum amount of time that events can reside in the session 
buffers before being flushed to the target(s), specified in seconds.
MAX_EVENT_SIZE
The maximum possible size for event data from any single event. 
It can be specified in kilobytes or megabytes and should only be 
configured to allow events that are larger than the MAX_MEMORY 
setting.
MEMORY_PARTITION_MODE
Specifies where vent buffers are created. Acceptable values are 
NONE, which indicates that the buffers will be created within the 
instance; PER_NODE, which indicates that the buffers will be 
created for each NUMA node; and PER_CPU, which means that 
buffers will be created for each CPU.
TRACK_CAUSALITY
Specifies that an additional GUID and sequence number will be 
stored with each event so that events can be correlated.
STARTUP_STATE
Specifies if the session automatically starts when the instance 
starts. ON indicates it does, OFF indicates it does not.
Table 19-4.  (continued)
Caution  Using the NO_EVENT_LOSS option for EVENT_RETENTION_MODE can 
cause performance issues on your instance, because tasks may have to wait to 
complete until there is space in the event session’s buffers to hold the event data.
The script in Listing 19-5 demonstrates how you can use T-SQL to create a session 
called LogFileIO. This session is similar to the Database Log File IO Tracking template, 
provided through the GUI. The difference is that we are additionally capturing the 
sqlos.wait_completed event and the sqlserver.DatabaseName global field, which we 
are also filtering on this, so that only details of the Chapter19 transaction log are tracked.
The results of the trace will be written to a file called LogFileIO.xel in the C:\Logs 
folder (which needs to be pre-created). The STARTUP_STATE option is used to start the 
session.
Chapter 19  Extended Events
PAGE-721

NO_EVENT_LOSS می‌تواند Session را برای حفظ Event Block کند و در workload حساس خطر Performance دارد. ALLOW_SINGLE_EVENT_LOSS/ALLOW_MULTIPLE_EVENT_LOSS در برخی Monitoringها Trade-off بهتری است. Session باید با هدف و Overhead Budget مشخص طراحی شود.

امتیاز کاربران به این مقاله

☆☆☆☆☆

0 نفر امتیاز داده اند. میانگین: 0.0 از 5

 

0 نظر

نظر محترم شما در مورد مقاله های وب سایت برنامه نویسی و پایگاه داده

نظرات محترم شما در خدمات رسانی بهتر ما را یاری می نمایند. لطفا اگر مایل بودید یک نظر ما را مهمان فرمائید. آدرس ایمیل و وب سایت شما نمایش داده نخواهد شد.

0 / 500