Skip to content

Latest commit

 

History

History
100 lines (67 loc) · 3.33 KB

sp-readerrorlog-transact-sql.md

File metadata and controls

100 lines (67 loc) · 3.33 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs
sp_readerrorlog (Transact-SQL)
sp_readerrorlog allows you to read the contents of the SQL Server or SQL Server Agent error log file and filter on keywords.
pijocoder
jopilov
randolphwest
11/18/2024
sql
system-objects
reference
sp_readerrorlog_TSQL
sp_readerrorlog
sp_readerrorlog
TSQL

sp_readerrorlog (Transact-SQL)

[!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

Syntax

sp_readerrorlog
    [ [ @p1 = ] p1 ]
    [ , [ @p2 = ] p2 ]
    [ , [ @p3 = ] N'p3' ]
    [ , [ @p4 = ] N'p4' ]
[ ; ]

Arguments

[ @p1 = ] p1

The integer value of the log you want to view. @p1 is int, with a default of 0. 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.

[ @p2 = ] p2

The integer value for the product whose log you want to view. @p2 is int, with a default of NULL. Use 1 for SQL Server or 2 SQL Server Agent. If a value isn't specified, the SQL Server product is used.

[ @p3 = ] N'p3'

The string value for a string you want to filter on when viewing the error log. @p3 is nvarchar(4000), with a default of NULL.

[ @p4 = ] N'p4'

The string value for an extra string you want to filter on to further refine the search when viewing the error log. @p4 is nvarchar(4000), with a default of NULL. This parameter provides an extra filter to the first string search @p3.

Return code values

None.

Result set

Displays the content of the requested error log. If filter strings are used, only the lines that match those strings are displayed.

Remarks

Every time [!INCLUDE ssNoVersion] 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.

Permissions

[!INCLUDE sssql19-md] and earlier versions require VIEW SERVER STATE permission on the server.

[!INCLUDE sssql22-md] and later versions require VIEW ANY ERROR LOG permission on the server.

Examples

The following example cycles the [!INCLUDE ssNoVersion] error log.

A. Read the current SQL Server error log

EXECUTE sp_readerrorlog;

B. Show the previous SQL Server Agent error log

EXECUTE sp_readerrorlog 1, 2;

C. Find log messages that indicate a database is starting up

EXECUTE sp_readerrorlog 0, 1, 'database', 'start';

Related content