Unable to recycle errorlog in SQL Server
Problem Description:
We were getting the following error and could not recycle the errorlog by running 'sp_cycle_errorlog' comamnd. And also we could not get downtime for restarting the sql instance and the error log size has gone to 6 GB.
Entry in errorlog:
Application saying: Msg 17049, Level 16, State 1, Procedure sp_cycle_errorlog, Line 9
Unable to cycle error log file from "C:\Program Files\ Microsoft SQL Server\MSSQL10_50 .MSSQLSERVER\MSSQL\Log\ERRORLOG" to "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Log\ERRORLOG.1" due to OS error '32(The process cannot access the file because it is being used by another process.)'. A process outside of SQL Server may be preventing SQL Server from reading the files. As a result, errorlog entries may be lost and it may not be possible to view some SQL Server errorlogs. Make sure no other processes have locked the file with write-only access."
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Unable to cycle error log file from "C:\Program Files\ Microsoft SQL Server\MSSQL10_50 .MSSQLSERVER\MSSQL\Log\ERRORLOG" to "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Log\ERRORLOG.1" due to OS error '32(The process cannot access the file because it is being used by another process.)'. A process outside of SQL Server may be preventing SQL Server from reading the files. As a result, errorlog entries may be lost and it may not be possible to view some SQL Server errorlogs. Make sure no other processes have locked the file with write-only access."
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Tried the following, but still we could not recycle the errorlog:
1. Stopped Tivoli Monitoring Agent to see if it was locking errorlog.
2. Checked if any other processes locking 'errorlog' by using process explorer.
3. Checked if any sql process was using xpreaderror log by this query
SELECT *
FROM sys.dm_exec_requests a
OUTER APPLY sys.dm_exec_sql_text(a.sql_handle) b
WHERE session_id > 50
and session_id <> @@spid AND( text = 'xp_readerrorlog' OR text = 'sp_cycle_errorlog')
ORDER BY start_time
Solution:FROM sys.dm_exec_requests a
OUTER APPLY sys.dm_exec_sql_text(a.sql_handle) b
WHERE session_id > 50
and session_id <> @@spid AND( text = 'xp_readerrorlog' OR text = 'sp_cycle_errorlog')
ORDER BY start_time
I found that Errorlog.2, Errorlog.3 were not there and probably deleted by someone. So, I copied Errorlog.4 as Errorlog.2, Errorlog.3. Then run the 'sp_cycle_errorlog' from new query window and now the sql server was able to recycle the error log.
Actually sql server was not able to find the previous errorlogs and could not rename it sequentially!
Hope it will help some one!
Thanks for reading!
Cheers
Veera
(Veerabahu Chockalingam)