Technical Article

PoorDBA Tools - 1: DB Log Space used

,

Modify Paramters as required, defautl set to HTML, results to email body but option to add as attachment included. 

Set "fileID" to 1 for main data file checks, currently set to 2 for Log File checks. 

Set required percent used threshold, currently set at 15%.

You'll need to set this script as a step in a SQL Agent job, set on a schedule to run and evaluate.

---------------------------------------------------------
--Check and report on database log file usage over 15% --
--Henrico Bekker--
--Tested on 2012,2014 and 2016 SP1--
--Tools for Poor DBA's--
---------------------------------------------------------
IF 
(
Select
((CAST ( (fileproperty(name, 'SpaceUsed')*8)/1024 as float))
/(CAST ( (size * 8)/1024 as float)) )*100
as Used
From dbo.sysfiles
where fileid = 2
) > 15

begin
exec msdb.dbo.sp_send_dbmail
@profile_name = 'PoorDBAEmailProfile',
@recipients = 'PoorDBA@mail.com',
@subject = 'Database Log File Usage Exceed 15%',
@body_format='HTML',
@query_result_header=1,
@execute_query_database='model',
@query = 
'Select Filename,size, fileid, name,
((CAST ( (fileproperty(name, ''SpaceUsed'')*8)/1024 as float))
/(CAST ( (size * 8)/1024 as float)) 
)*100
as Used
From dbo.sysfiles
where fileid = 2',
@query_result_separator=' ',
@attach_query_result_as_file = 0, --set to 1 for true, this script will keep results in email body
@query_attachment_filename = 'LogFileSizeResult.txt' -- will only attach when prior parameter set TRUE
end

Rate

2.5 (4)

You rated this post out of 5. Change rating

Share

Share

Rate

2.5 (4)

You rated this post out of 5. Change rating