How To Safely Delete SQL Server ErrorLog Files


One of your SQL Server ErrorLog files has grown to a very large size.  You would like to delete it to free space on my hard drive.  Can the SQL Server ErrorLog file be safely deleted without harming SQL Server?

By default SQL Server stores seven ErrorLog files named:
  • ErrorLog
  • ErrorLog.1
  • ErrorLog.2
  • ErrorLog.3
  • ErrorLog.4
  • ErrorLog.5
  • ErrorLog.6

In SQL Server 2005 and later versions, the ErrorLog files are stored in the c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG folder.  The ErrorLog file contains the newest information; the ErrorLog.6 file contains the oldest information.

Every time SQL Server is restarted, the log files cycle as follows:
  • All data in the ErrorLog.6 file is deleted and a new ErrorLog file is created.
  • All data in the previous ErrorLog file is written to the ErrorLog.1 file. All data in the previous ErrorLog.1 file is written to the ErrorLog.2 file.
  • etc.

If one of the ErrorLog files has grown to a large size, the ErrorLog files can be manually cycled by running the sp_cycle_errorlog Stored Procedure. 

The data in the older ErrorLog files will be overwritten!  Copy the older ErrorLog files to some external media if they must be saved.

It is safe to delete the files, however, you should not ignore them, and solve the underlying issue.

Commentaires

Anonyme a dit…
Thanks Fabrice - very helpful.
eralper a dit…
Thank you for the information, I did not know the stored procedure which updates the log files and deletes the oldest one. Good to know managing the log files by code.