扩展事件工具Extended Events Tools

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database

您可以使用以下工具创建和管理 SQL ServerSQL Server 扩展事件会话:You can use the following tools to create and manage SQL ServerSQL Server Extended Events sessions:

  • 数据定义语言 (DDL) 语句。Data Definition Language (DDL) statements. 这些语句可用于创建和修改扩展事件会话。These enable you to create and modify an Extended Events session.

  • 动态管理视图、目录视图和系统表。Dynamic management views, catalog views and system tables. 这些视图和表可用于通过使用 Transact-SQLTransact-SQL 语句获取会话数据和元数据。These enable you to obtain session data and metadata by using Transact-SQLTransact-SQL statements. 这些系统表可帮助您确定用于 SQL 跟踪事件类和列的现有扩展事件等效项。The system tables help you determine the existing Extended Events equivalents for SQL Trace event classes and columns.

  • 对象资源管理器的 “扩展事件” 节点。The Extended Events node of Object Explorer. 该节点可用于启动、停止或删除会话,或者用于导入和导出会话模板。This enables you to start, stop or delete a session, or to import and export session templates.

  • SQL ServerSQL Server PowerShell 提供程序。The SQL ServerSQL Server PowerShell provider. 这是一个强大的工具,可用于创建、更改和管理扩展事件会话。This is a powerful tool that you can use to create, alter, and manage Extended Events sessions. 有关详细信息,请参阅 对扩展事件使用 PowerShell 提供程序For more information, see Use the PowerShell Provider for Extended Events.

  • SQL Server Management StudioSQL Server Management Studio 列中的一个值匹配。. 该工具可用于创建和执行在扩展事件主题中提供的代码示例。This enables you to create and execute the code samples that are provided in the Extended Events topics. 有关详细信息,请参阅 对象资源管理器For more information, see Object Explorer.

除了您创建的会话之外,在服务器上存在一个默认的系统运行状况会话。In addition to sessions that you create, a default system health session exists on the server. 该会话收集的系统数据可用于帮助解决性能问题。The session collects system data that you can use to help troubleshoot performance issues. 有关详细信息,请参阅 使用 system_health 会话For more information, see Use the system_health Session.

DDL 语句DDL Statements

请以下 DDL 语句可以创建、更改和删除扩展事件会话。Use the following DDL statements to create, change, and drop an Extended Events session.

名称Name 说明Description
CREATE EVENT SESSION (Transact-SQL)CREATE EVENT SESSION (Transact-SQL) 创建用于标识事件源、事件会话目标和事件会话参数的扩展事件会话对象。Creates an Extended Event session object that identifies the source of the events, the event session targets, and the event session parameters.
ALTER EVENT SESSION (Transact-SQL)ALTER EVENT SESSION (Transact-SQL) 启动或停止事件会话,或更改事件会话配置。Starts or stops an event session or changes an event session configuration.
DROP EVENT SESSION (Transact-SQL)DROP EVENT SESSION (Transact-SQL) 删除事件会话。Drops an event session.

目录视图Catalog Views

使用下面的目录视图可获取创建事件会话时所创建的元数据。Use the following catalog views to obtain the metadata that is created when you create an event session.

名称Name 说明Description
sys.server_event_sessions (Transact-SQL)sys.server_event_sessions (Transact-SQL) 列出所有事件会话定义。Lists all event session definitions.
sys.server_event_session_actions (Transact-SQL)sys.server_event_session_actions (Transact-SQL) 返回针对事件会话的每个事件执行的每个操作所对应的行。Returns a row for each action on each event of an event session.
sys.server_event_session_events (Transact-SQL)sys.server_event_session_events (Transact-SQL) 返回事件会话中每个事件所对应的行。Returns a row for each event in an event session.
sys.server_event_session_fields (Transact-SQL)sys.server_event_session_fields (Transact-SQL) 对在事件和目标上显式设置的每个可自定义列都返回一行。Returns a row for each customizable column that was explicitly set on events and targets.
sys.server_event_session_targets (Transact-SQL)sys.server_event_session_targets (Transact-SQL) 返回事件会话的每个事件目标所对应的行。Returns a row for each event target for an event session.

动态管理视图Dynamic Management Views

使用下面的动态管理视图可以获取会话元数据和会话数据。Use the following dynamic management views to obtain session metadata and session data. 将从目录视图中获取元数据,当启动并运行事件会话时即创建会话数据。The metadata is obtained from the catalog views, and the session data is created when you start and run an event session.

备注

直到会话启动,这些视图中才会包含会话数据。These views do not contain session data until a session starts.

名称Name 说明Description
sys.dm_os_dispatcher_pools (Transact-SQL)sys.dm_os_dispatcher_pools (Transact-SQL) 返回有关会话调度程序池的信息。Returns information about session dispatcher pools.
sys.dm_xe_objects (Transact-SQL)sys.dm_xe_objects (Transact-SQL) 对事件包显示的每个对象都返回一行。Returns a row for each object that is exposed by an event package.
sys.dm_xe_object_columns (Transact-SQL)sys.dm_xe_object_columns (Transact-SQL) 返回所有对象的架构信息。Returns the schema information for all the objects.
sys.dm_xe_packages (Transact-SQL)sys.dm_xe_packages (Transact-SQL) 列出向扩展事件引擎注册的所有包。Lists all the packages registered with the Extended Events engine.
sys.dm_xe_sessions (Transact-SQL)sys.dm_xe_sessions (Transact-SQL) 返回有关处于活动状态的扩展事件会话的信息。Returns information about an active Extended Events session.
sys.dm_xe_session_targets (Transact-SQL)sys.dm_xe_session_targets (Transact-SQL) 返回有关会话目标的信息。Returns information about session targets.
sys.dm_xe_session_events (Transact-SQL)sys.dm_xe_session_events (Transact-SQL) 返回有关会话事件的信息。Returns information about session events.
sys.dm_xe_session_event_actions (Transact-SQL)sys.dm_xe_session_event_actions (Transact-SQL) 返回有关事件会话操作的信息。Returns information about event session actions.
sys.dm_xe_map_values (Transact-SQL)sys.dm_xe_map_values (Transact-SQL) 提供一个从内部数字键到可读文本的映射。Provides a mapping of internal numeric keys to human-readable text.
sys.dm_xe_session_object_columns (Transact-SQL)sys.dm_xe_session_object_columns (Transact-SQL) 显示绑定到会话的对象的配置值。Shows the configuration values for objects that are bound to a session.

系统表System Tables

使用下面的系统表可以获取与 SQL 跟踪事件类和列的扩展事件等效项有关的信息。Use the following system tables to obtain information about the Extended Events equivalents for SQL Trace event classes and columns.

名称Name 说明Description
trace_xe_event_map (Transact-SQL)trace_xe_event_map (Transact-SQL) 映射到 SQL 跟踪事件类的每个扩展事件各占一行。Contains one row for each Extended Events event that is mapped to a SQL Trace event class.
trace_xe_action_map (Transact-SQL)trace_xe_action_map (Transact-SQL) 映射到 SQL 跟踪列 ID 的每个扩展事件操作各占一行。Contains one row for each Extended Events action that is mapped to a SQL Trace column ID.

另请参阅See Also

动态管理视图和函数 (Transact-SQL) Dynamic Management Views and Functions (Transact-SQL)
目录视图 (Transact-SQL) Catalog Views (Transact-SQL)
SQL Server 扩展事件表 (Transact-SQL) SQL Server Extended Events Tables (Transact-SQL)
使用 system_health 会话 Use the system_health Session
对扩展事件使用 PowerShell 提供程序Use the PowerShell Provider for Extended Events