The parameters of xp_readerrorlog
I find that few people know xp_readerrorlog accepts parameters to help you mine information out of the SQL Error log (as well as the SQL Agent error log). The SQL Error log has a wealth of information. In this post, we’ll look at some of those parameters.
Running xp_readerrorlog without any parameters returns the current SQL Server error log (ERRORLOG). The first parameter specifies which log to return and the default is “0”:
xp_readerrorlog 1
This statement will return the contents of ERRORLOG.1.
However, if you put a value for a log file extension that does not exist, like 9 for ERRORLOG.9, you get:
Msg 22004, Level 16, State 1, Line 0
xp_readerrorlog() returned error 2, 'The system cannot find the file specified.'
For the second parameter, you specify which log to review. The default is 1 for the SQL Server database engine, but you can specify a 2 for the SQL Server agent. Anything larger than a 2 here will return an invalid parameter.
The 3rd and 4th parameters allow you to specify 2 search strings to search the log with. So to find the server process id assigned to SQL Server from the current error log using xp_readerrorlog, execute the following:
xp_readerrorlog 0, 1, “server”, “process ID”
and you get:
- Jay
Comments
- Anonymous
November 14, 2013
I have a SQL Server 2000 installation that is missing XP_READERRORLOG. Do you know how / where I should look to see how to get it installed? - Anonymous
November 14, 2013
Found it, SQL 2000 access is via: EXEC master..XP_READERRORLOGwhere SQL 2008 access is via: EXEC master.SYS.XP_READERRORLOG