首先,我不是 DBA,但我必须执行一些 DBA 工作。我正在尝试使用读取扩展文件,
SELECT [object_name],[event_data],[file_name],[file_offset],[Event_Time]
FROM OPENQUERY(MyServer,'master.dbo.READ_AUDIT @P_RootFile_Name=''Path\DDL*.xel'',@P_File_Name=''Path\file.xel'',@P_Offsit=0')
我收到此错误,
The offset 0 is invalid for log file .xel Specify an offset that exists in the log file
如何计算 xel 文件的偏移量?
ALTER proc [dbo].[READ_AUDIT] @P_RootFile_Name NvarChar(260),@P_File_Name NvarChar(260)=NULL,@P_Offsit bigint =NULL
as
Select * from
(
select *,
DATEADD(mi, DATEDIFF(mi, GETUTCDATE(), GETDATE()), CONVERT (XML, event_data).value('(/event/@timestamp)[1]', 'datetime2')) Event_Time
from sys.fn_xe_file_target_read_file(@P_RootFile_Name, null, @P_File_Name, @P_Offsit)
) as T
order by T.Event_Time ASC
从这篇文章https://learn.microsoft.com/en-us/sql/relational-databases/system-functions/sys-fn-xe-file-target-read-file-transact-sql?view=sql-server -ver15
我发现 initial_file_name 和 initial_offset 最初应该为空