SQL Server 2014 – History of Growth and Shrink Events

shrinksql serversql server 2014

Is there a way to look at the complete history of growth and shrink events for the last weeks/months on SQL Server 2014 ? (New instances to support, noticed from the ticketing system that they have previous history of "log drive full", so would like to dig into the root cause before it happens again.)

This was useful: Identify File Growth Events . Came up with below query, but it doesn't show any of the "manual" log shrink events, just the "auto" events. Am I doing this the wrong way, any other place to look for past info ?

select
    te.name as event_name,
    tr.DatabaseName,
    tr.FileName,
    tr.IntegerData,
    tr.IntegerData2,
    tr.LoginName,
    tr.StartTime,
    tr.EndTime
--select * 
from 
sys.fn_trace_gettable(convert(nvarchar(255),(select value from sys.fn_trace_getinfo(0) where property=2)), 0) tr
inner join sys.trace_events te on tr.EventClass = te.trace_event_id
where 
tr.EventClass in (93, 95) --can't identify any other EventClass to add here
order by 
EndTime desc;

Best Answer

Is there a way to look at the complete history of growth and shrink events for the last weeks/months on SQL Server 2014

Yes there is a way, or should i say various ways to save the data collected from default trace as explained here Collecting the Information in the Default Trace

  1. We could query the default trace files and save aggregated values
  2. We could get the definition of the default trace and create a collection set, which can be used with Management Data Warehouse, which is built in with SQL Server.
  3. We could get the definition of the default trace and create a remote trace from another server and save the data to a database table
  4. We could use a robocopy script to copy the trace files from our server to a different folder or a remote machine, which will leave the files on disk for longer time, giving us the possibility to analyze them

Came up with below query, but it doesn't show any of the "manual" log shrink events, just the "auto" events. Am I doing this the wrong way, any other place to look for past info ?To capture the manual shrink events i use query like below:

SELECT 
    TextData,
    HostName,
    ApplicationName,
    LoginName, 
    StartTime  
FROM 
[fn_trace_gettable]('C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Log\log_75.trc', DEFAULT) 
WHERE TextData LIKE '%SHRINKFILE%'; ----- Location of default trace will be different ,so kindly check that accordingly

Probable reason you're query does not display manual grow or shrink events because you use events like (93, 95) which are for auto grow events