Connect With MyTechMantra.com











"Receive newsletters and special offers about SQL Server, BizTalk and SharePoint from MyTechMantra. We respect your privacy and you can unsubscribe at any time."


How to Recycle SQL Server Error Log file without restarting SQL Server Service


Sept 15, 2014


Introduction

SQL Server Error Log is the best place for a Database Administrators to look for informational messages, warnings, critical events, database recover information, auditing information, user generated messages etc. SQL Server creates a new error log file everytime SQL Server Database Engine is restarted. This article explains how to recycle SQL Server Error Log file without restarting SQL Server Service.

Database administrator can recycle SQL Server Error Log file without restarting SQL Server Service by running DBCC ERRORLOG command or by running SP_CYCLE_ERRORLOG system stored procedure.

Note:- Starting SQL Server 2008 R2 you can also limit the size of SQL Server Error Log file. For more information see Limit SQL Server Error Log File Size in SQL Server. However, to increase the number of error log file see the following article for more information How to Increase Number of SQL Server Error Log Files.

Recycle SQL Server ErrorLog File using DBCC ERRORLOG Command

Execute the below TSQL code in SQL Server 2012 and later versions to set the maximum file size of individual error log files to 10 MB. SQL Server will create a new file once the size of the current log file reaches 10 MB. This helps in reducing the file from growing enormously large.

USE [master];
GO

DBCC ERRORLOG
GO

Recycle SQL Server Error Log File using SP_CYCLE_ERRORLOG System Stored Procedure

Use [master];
GO

SP_CYCLE_ERRORLOG
GO

Best Practice: It is highly recommended to create an SQL Server Agent Job to recycle SQL Server Error Log once a day or at least once a week.

Conclusion

This article explains how to Recycle SQL Server Error Log file without restarting SQL Server Service.


Share this Article


LEARN MORE...
 
Winners
White Papers
Product Reviews
Trending News
All Articles
Free Tools
 
Follow Us...

Related Articles…