T-SQL script to Recycle SQL Server error logs manually

Updated: Dec 30, 2021

SQL Server allows you to automatically recycle error logs and this is great because it gives you more of a hands-off approach. However, if you require to do it manually, you can use the stored procedure sp_cycle_errorlog as shown below.

Once you execute the following T-SQL script, it creates a new error log file and start recording latest entries into it.

Use Master
EXEC sp_cycle_errorlog

Similarly, the following script recycles the SQL Server agent error log file.

USE msdb ; 
EXEC dbo.sp_cycle_agent_errorlog ;  

If you are looking to manage SQL Server logs effectively, refer to the article - https://www.sqlshack.com/how-to-manage-sql-server-logs-effectively/

15 views0 comments