Efficient Log File Growth Monitoring : Stay Informed with Real-time Email Alerts
DECLARE @LogFileSizeMB INT
DECLARE @ThresholdMB INT
-- Set the threshold value for log file size in megabytes
SET @ThresholdMB = 1024 -- Adjust the value as per your requirement
-- Get the current log file size in megabytes
SELECT @LogFileSizeMB = size * 8 / 1024
FROM sys.database_files
WHERE type = 1 -- Log file type (0 = data file, 1 = log file)
-- Check if the log file size exceeds the threshold
Recommended by LinkedIn
IF @LogFileSizeMB > @ThresholdMB
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'YourDatabaseMailProfile',
@recipients = 'your-email@example.com',
@subject = 'Log File Size Alert',
@body = 'The log file size has exceeded the threshold.'
-- You can also take additional actions, such as logging the alert to a table or executing other scripts.
-- Implement the necessary actions as per your requirements.
END
As always, please do share your feedback, comments or thoughts!
Thanks for reading :)