THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | Join | Help
in Search

Aaron Bertrand

Aaron is a senior consultant for SQL Sentry, Inc., makers of performance monitoring and event management software for SQL Server, Analysis Services, and Windows. He has been blogging here at sqlblog.com since 2006, focusing on manageability, performance, and new features; has been a Microsoft MVP since 1997; tweets as @AaronBertrand; and speaks frequently at user group meetings and SQL Saturday events.

Reviewing AutoGrow events from the default trace

Since I don't have the luxury of setting up event notifications on all my servers, in SQL Server 2005 I can use the default trace to monitor autogrow events... this helps to prepare for increased disk space usage, and also lets me know if my log backups are happening frequently enough.

This is probably covered in a ton of other places, but the question comes up enough that I thought I would add my quick & dirty methodology. Here is a quick method that grabs the folder for the default trace from sys.traces, then passes that folder into sys.fn_trace_gettable.

DECLARE @path NVARCHAR(260);

SELECT
  
@path = REVERSE(SUBSTRING(REVERSE([path]),
  
CHARINDEX('\', REVERSE([path])), 260)) + N'log.trc'
FROM    sys.traces
WHERE   is_default = 1;

SELECT
  
DatabaseName,
  
[FileName],
  
SPID,
  
Duration,
  
StartTime,
  
EndTime,
  
FileType = CASE EventClass
      
WHEN 92 THEN 'Data'
      
WHEN 93 THEN 'Log'
  
END
FROM
sys.fn_trace_gettable(@path, DEFAULT)
WHERE
  
EventClass IN (92,93)
ORDER BY
  
StartTime DESC;

 

Published Thursday, January 11, 2007 8:37 AM by AaronBertrand

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

oracledba said:

Good stuff.

June 2, 2008 11:53 AM
 

Ray said:

Great script! Thank you.

I did need to make one minor change. Had to enclose the path with double-quotes.

August 5, 2008 5:48 PM
 

Eoin said:

Excellent stuff

October 9, 2009 8:38 AM
 

SQLRocker said:

Right Click Database-Reports-Data Usage-Data/Log Files Autogrow/Autoshrink Events. Script is good for verification.

August 5, 2010 3:28 PM
 

Martin said:

You don't need to use xp_cmdshell for this. You can use

DECLARE @path NVARCHAR(260)

SELECT @path = REVERSE(SUBSTRING(REVERSE(path), CHARINDEX('\', REVERSE(path)), 260)) + N'log.trc'

FROM    sys.traces

WHERE   is_default = 1

SELECT COUNT(*)

FROM sys.fn_trace_gettable(@path, DEFAULT)

July 21, 2011 10:06 AM
 

AaronBertrand said:

Thanks Martin. In fact the code sample I gave uses DEFAULT as the second parameter and this leads to counting events up to n times (where n is the number of trace files) depending on which file the event occurs in. I've corrected that.

July 21, 2011 10:21 AM
 

opc.three said:

Agreed. No need to use xp_CmdShell. Thanks Aaron for the initial solution and idea. Thanks Martin, I have removed the use of xp_CmdShell from my monitor process, always a welcome chore.

October 24, 2011 3:15 PM
 

Garry Bargsley said:

Is there a way to see what size the TempDB grew by?  The settings in the SSMS GUI do not match the setting I get returned from sp_helpfile.  I am trying to figure out which one is being used when autogrow kicks in.

March 30, 2012 4:06 PM
 

SSIS: SQL Server Default Trace Logging past file rollover. | Willett Compute ? said:

April 29, 2012 11:48 AM

Leave a Comment

(required) 
(optional)
(required) 
Submit

About AaronBertrand

...about me...

This Blog

Syndication

Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement