SHARE
Facebook X Pinterest WhatsApp

Automation of Error Log Cycling

Written By
thumbnail
Tanya Stolyar
Tanya Stolyar
Jun 5, 2000

SQL Server version: 7.0 +

As a DBA you may want to automate process of
cycling an errorlog file.
This script includes the following:
* stored
procedure ‘usp_dba_cyclelog’ .
* It purges an errorlog file if it’s size
larger then value
specified by @filesize parameter (Bytes)
* sends e-mail
to notify a recipient and attaches the
information about existing errorlog
files.
* you can specify the errorlog file location with
@errorlog
parameter. If it is not specified the

HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSSQLServerMSSQLServerParametersSQL
Arg1
is
used.

* scheduled task to call usp_dba_cyclelog’ stored
procedure.

Before executing the cyclelog.sql script you need to replace

* string <recipient_name> with the semicolon-separated list of
the
recipients of the mail.
* string <size_in_Bytes> with the proper
value
* string <db_name> with the database name where
the
‘usp_dba_cyclelog’ stored procedure will be created

Make sure that
SQL Mail and SQL Server Agent are running.

I got the information on
xp_getfiledetails & xp_enumerrorlogs from Brian
Knight
‘Undocumented
T-SQL Tricks With Logs’. Please refer to this article
regarding the security
issue of using these stored procedures.

Download cyclelog.SQL

Recommended for you...

Best Online Courses to Learn SQL
Ronnie Payne
Sep 23, 2022
Best Courses for Database Administrators
Ronnie Payne
Jul 22, 2022
Tip 74 – Changing Cost Threshold for Parallelism
Gregory Larsen
Feb 24, 2021
How Many Databases Can You Name?
Brad Jones
May 11, 2020
Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.