info@techdevops.com | 437-991-3573 | Data Engineering Services
TechDevOps.com
Resources Tools
Experts in Microsoft SQL Server on Windows, Linux, Containers | Clusters, Always On, FCI | Migrations, Cloud, Performance



Cycle Error Logs
by BF (Principal Consultant; Architecture; Engineering)
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