info@techdevops.com
TechDevOps.com
Explore Tools
Experts in Microsoft SQL Server Operations, Performance, Replication, Cloud & Migrations



Cycle Error Logs
by BF (Senior MSSQL Operations - Enterprise, Cloud, Strategy)
2018-10-17








sp_cycle_errorlog (Transact-SQL)
- Closes the current error log file and cycles the error log extension numbers just like a server restart. The new error log contains version and copyright information and a line indicating that the new log has been created.
- Every time SQL Server is started, the current error log is renamed to errorlog.1; errorlog.1 becomes errorlog.2, errorlog.2 becomes errorlog.3, and so on. sp_cycle_errorlog enables you to cycle the error log files without stopping and starting the server.

sp_cycle_agent_errorlog (Transact-SQL)
- Closes the current SQL Server Agent error log file and cycles the SQL Server Agent error log extension numbers just like a server restart. The new SQL Server Agent error log contains a line indicating that the new log has been created.
- Every time SQL Server Agent is started, the current SQL Server Agent error log is renamed to SQLAgent.1; SQLAgent.1 becomes SQLAgent.2, SQLAgent.2 becomes SQLAgent.3, and so on. sp_cycle_agent_errorlog enables you to cycle the error log files without stopping and starting the server.
- This stored procedure must be run from the msdb database.



T-SQL:

Use Master
go
sp_cycle_errorlog
go

Use MSDB
go
sp_cycle_agent_errorlog


Recommendations:
- Schedule once daily in a SQL Job
- In SSMS, right click "SQL Server Logs", select Configure, set a max value required