title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic | f1_keywords | helpviewer_keywords | dev_langs | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sp_readerrorlog (Transact-SQL) |
sp_readerrorlog (Transact-SQL) |
pijocoder |
jopilov |
02/08/2022 |
sql |
system-objects |
reference |
|
|
|
[!INCLUDE SQL Server]
Allows you to read the contents of the SQL Server or SQL Server Agent error log file and filter on keywords.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
sp_readerrorlog
@p1 int = 0,
@p2 int = NULL,
@p3 nvarchar(4000) = NULL,
@p4 nvarchar(4000) = NULL
Is the integer (int) value of the log you want to view. The current error log has a value of 0, the previous is 1 (Errorlog.1), the one before previous is 2 (Errorlog.2), and so on.
Is the integer (int) value for the product whose log you want to view. Use 1 for SQL Server or 2 SQL Server Agent. If a value isn't specified, the SQL Server product is used
Is the string value for a string you want to filter on when viewing the error log. This value is nvarchar(4000) and has a default of NULL.
Is the string value for an additional string you want to filter on to further refine the search when viewing the error log. This value is nvarchar(4000) and has a default of NULL. This provides an additional filter to the first string search @p3.
No return code
Displays the content of the requested error log. If filter strings are used only the lines that match those strings are displayed.
Every time [!INCLUDEssNoVersion] 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_readerrorlog enables you to read any of these error log files as long as the files exist.
Execute permissions for sp_readerrorlog are restricted to members of the sysadmin fixed server role.
The following example cycles the [!INCLUDEssNoVersion] error log.
EXEC sp_readerrorlog;
exec sp_readerrorlog 1, 2;
exec sp_readerrorlog 0, 1, 'database', 'start'