snippetsqlMinor
How to check the growth of database
Viewed 0 times
thedatabasegrowthhowcheck
Problem
I would like to know how to check the growth of entire database and individual data files.
Also, what to suggest to the client if the database is growing rapidly?
Also, what to suggest to the client if the database is growing rapidly?
Solution
You can query the default trace to get information about recent growth events.
You can also use Event Notifications to be notified on
DECLARE @path nvarchar(260) = (
SELECT REVERSE(SUBSTRING(REVERSE(path), CHARINDEX('\', REVERSE(path)), 260)) +'log.trc'
FROM sys.traces
WHERE is_default = 1)
SELECT gt.DatabaseID,
gt.FileName,
COUNT(*) AS NumberOfEvents,
CASE WHEN te.name LIKE'%Grow' THEN 1 ELSE 0 END AS is_growth_event
FROM sys.fn_trace_gettable(@path, DEFAULT) gt
JOIN sys.trace_events te ON gt.EventClass = te.trace_event_id
WHERE te.name in ('Data File Auto Grow','Log File Auto Grow','Data File Auto Shrink','Log File Auto Shrink')
GROUP BY gt.DatabaseID,
gt.FileName,
te.nameYou can also use Event Notifications to be notified on
DATA_FILE_AUTO_GROW,LOG_FILE_AUTO_GROW without having to poll the trace.Code Snippets
DECLARE @path nvarchar(260) = (
SELECT REVERSE(SUBSTRING(REVERSE(path), CHARINDEX('\', REVERSE(path)), 260)) +'log.trc'
FROM sys.traces
WHERE is_default = 1)
SELECT gt.DatabaseID,
gt.FileName,
COUNT(*) AS NumberOfEvents,
CASE WHEN te.name LIKE'%Grow' THEN 1 ELSE 0 END AS is_growth_event
FROM sys.fn_trace_gettable(@path, DEFAULT) gt
JOIN sys.trace_events te ON gt.EventClass = te.trace_event_id
WHERE te.name in ('Data File Auto Grow','Log File Auto Grow','Data File Auto Shrink','Log File Auto Shrink')
GROUP BY gt.DatabaseID,
gt.FileName,
te.nameContext
StackExchange Database Administrators Q#7788, answer score: 7
Revisions (0)
No revisions yet.