Sql-Server

什麼時候和誰縮小了 ldf 文件?

  • August 17, 2017

我正在嘗試查找有關何時以及誰縮小了 ldf 文件的資訊,但我無法在任何地方找到該資訊。

有人可以指出我正確的方向嗎?

Microsoft SQL Server 2008 R2 (SP2) - 10.50.4266.0 (X64) 
   Sep 26 2012 17:08:07 
   Copyright (c) Microsoft Corporation
   Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)

下面是使用 T-SQL 從預設跟踪返回資訊的範例查詢。

SELECT  
    trace.DatabaseName
   ,trace.ObjectName
   ,te.name AS EventName
   ,tsv.subclass_name
   ,trace.EventClass
   ,trace.EventSubClass
   ,trace.StartTime
   ,trace.EndTime
   ,trace.NTDomainName
   ,trace.NTUserName
   ,trace.HostName
   ,trace.ApplicationName
   ,trace.Spid
FROM (SELECT REVERSE(STUFF(REVERSE(path), 1, CHARINDEX(N'\', REVERSE(path)), '')) + N'\Log.trc' AS path
   FROM sys.traces WHERE is_default = 1) AS default_trace_path
CROSS APPLY fn_trace_gettable(default_trace_path.path, DEFAULT) AS trace
LEFT JOIN sys.trace_events AS te ON 
   trace.EventClass=te.trace_event_id
LEFT JOIN sys.trace_subclass_values AS tsv ON
   tsv.trace_event_id = EventClass
   AND tsv.subclass_value = trace.EventSubClass
ORDER BY trace.StartTime;

通過過濾WHERE TEXTDATA LIKE 'DBCC SHRINK%'你會發現所有的收縮事件。

引用自:https://dba.stackexchange.com/questions/183735