sys.fn_xe_file_target_read_file (Transact-SQL)sys.fn_xe_file_target_read_file (Transact-SQL)

适用于: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

读取扩展事件异步文件目标创建的文件。Reads files that are created by the Extended Events asynchronous file target. 每行返回一个 XML 格式的事件。One event, in XML format, is returned per row.

警告

SQL Server 2008SQL Server 2008SQL Server 2008 R2SQL Server 2008 R2接受 .xel 和 .xem 格式生成的跟踪结果。and SQL Server 2008 R2SQL Server 2008 R2 accept trace results generated in XEL and XEM format. SQL Server 2012 (11.x)SQL Server 2012 (11.x) 扩展事件仅支持 .XEL 格式的跟踪结果。Extended Events only support trace results in XEL format. 我们推荐您使用 SQL Server Management Studio 来读取 XEL 格式的跟踪结果。We recommend that you use SQL Server Management Studio to read trace results in XEL format.

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

  
sys.fn_xe_file_target_read_file ( path, mdpath, initial_file_name, initial_offset )  

参数Arguments

路径path
要读取的文件的路径。The path to the files to read. 路径 可以包含通配符,并包含文件的名称。path can contain wildcards and include the name of a file. 路径nvarchar (260)path is nvarchar(260). 没有默认值。There is no default. 在 Azure SQL 数据库的上下文中,此值是 Azure 存储中文件的 HTTP URL。In the context of Azure SQL Database, this value is an HTTP URL to a file in Azure Storage.

mdpathmdpath
path 参数所指定的文件相对应的元数据文件的路径。The path to the metadata file that corresponds to the file or files specified by the path argument. mdpathnvarchar (260)mdpath is nvarchar(260). 没有默认值。There is no default. 从 SQL Server 2016 开始,可以将此参数指定为 null。Starting with SQL Server 2016, this parameter can be given as null.

备注

SQL Server 2012 (11.x)SQL Server 2012 (11.x) 不需要 mdpath 参数。does not require the mdpath parameter. 但是,为了在以前的 SQL Server 版本中生成的日志文件的向后兼容性,需要维护该参数。However, it is maintained for backward compatibility for log files generated in previous versions of SQL Server.

initial_file_nameinitial_file_name
要从 路径 中读取的第一个文件。The first file to read from path. initial_file_name (260) 为 nvarcharinitial_file_name is nvarchar(260). 没有默认值。There is no default. 如果指定 null 作为参数,则读取 路径 中找到的所有文件。If null is specified as the argument all the files found in path are read.

备注

initial_file_nameinitial_offset 均为成对参数。initial_file_name and initial_offset are paired arguments. 如果为其中一个参数指定值,则必须为另一个参数也指定值。If you specify a value for either argument you must specify a value for the other argument.

initial_offsetinitial_offset
用于指定之前读取的上一个偏移量并跳过该偏移量之前的所有事件(包括该偏移量处的事件)。Used to specify last offset read previously and skips all events up to the offset (inclusive). 事件枚举在指定偏移量后开始。Event enumeration starts after the offset specified. initial_offsetbigintinitial_offset is bigint. 如果指定 null 作为参数,将读取整个文件。If null is specified as the argument the entire file will be read.

返回的表Table Returned

列名称Column name 数据类型Data type 说明Description
module_guidmodule_guid uniqueidentifieruniqueidentifier 事件模块 GUID。The event module GUID. 不可为 null。Is not nullable.
package_guidpackage_guid uniqueidentifieruniqueidentifier 事件包 GUID。The event package GUID. 不可为 null。Is not nullable.
object_nameobject_name nvarchar(256)nvarchar(256) 事件的名称。The name of the event. 不可为 null。Is not nullable.
event_dataevent_data nvarchar(max)nvarchar(max) XML 格式的事件内容。The event contents, in XML format. 不可为 null。Is not nullable.
file_namefile_name nvarchar(260)nvarchar(260) 包含事件的文件的名称。The name of the file that contains the event. 不可为 null。Is not nullable.
file_offsetfile_offset bigintbigint 包含事件的块在文件中的偏移位置。The offset of the block in the file that contains the event. 不可为 null。Is not nullable.
timestamp_utctimestamp_utc datetime2datetime2 适用于SQL Server 2017 (14.x)SQL Server 2017 (14.x) 及更高版本和 Azure SQL 数据库Azure SQL DatabaseApplies to: SQL Server 2017 (14.x)SQL Server 2017 (14.x) and later and Azure SQL 数据库Azure SQL Database.

事件 (UTC 时区的日期和时间) 。The date and time (UTC timezone) of the event. 不可为 null。Is not nullable.

备注Remarks

通过在中执行 sys.fn_xe_file_target_read_file 读取大型结果集 Management StudioManagement Studio 可能会导致错误。Reading large result sets by executing sys.fn_xe_file_target_read_file in Management StudioManagement Studio may result in an error. 使用 " 结果显示文件 模式" (Ctrl + Shift + F) 将大型结果集导出到文件中,并改为使用其他工具读取文件。Use the Results to File mode (Ctrl+Shift+F) to export large result sets to a file and read the file with another tool instead.

权限Permissions

要求具有服务器的 VIEW SERVER STATE 权限。Requires VIEW SERVER STATE permission on the server.

示例Examples

A.A. 从文件目标检索数据Retrieving data from file targets

下面的示例从所有文件获取所有行。The following example gets all the rows from all the files. 在此示例中,文件目标和图元文件位于 C:\ 驱动器上的跟踪文件夹中。In this example the file targets and metafiles are located in the trace folder on the C:\ drive.

SELECT * FROM sys.fn_xe_file_target_read_file('C:\traces\*.xel', 'C:\traces\metafile.xem', null, null);  

另请参阅See Also

扩展事件动态管理视图 Extended Events Dynamic Management Views
(Transact-sql)的扩展事件目录视图 Extended Events Catalog Views (Transact-SQL)
扩展事件Extended Events