SQL Server error logs: how to find, read and manage them

The SQL Server error log is a text file the Database Engine writes with startup, recovery, warning and error messages. Open it in SSMS under Management, SQL Server Logs, or run `EXEC sp_readerrorlog;`. If it has grown huge, cycle it with `sp_cycle_errorlog`; if old entries are missing, raise the number of log files kept.

Applies to:SQL Server2017, 2019, 2022, 2025 (Windows and Linux)
On this page

What it means

The SQL Server error log is a plain text file written by the Database Engine. It records startup and shutdown, database recovery, warnings, and assertion errors. Failed and successful logins appear there too, if login auditing is enabled. When an instance misbehaves, this is usually the first place to look.

SQL Server Agent keeps its own separate log (SQLAGENT.OUT). The transaction log (the .ldf file) is a different thing: it stores data changes, not diagnostic messages, and nothing here applies to it. For login failures specifically, see SQL Server error 18456.

A new error log starts every time the instance starts. The current file becomes ERRORLOG.1, the old ERRORLOG.1 becomes ERRORLOG.2, and so on.

Symptoms and causes

You are likely dealing with this problem if:

  • You don't know where the error log is or how to open it in SSMS.
  • The log is very large and slow to open in SSMS.
  • Older entries are gone, because only a limited number of archived logs are kept.
  • sp_readerrorlog fails with a permission error.

The usual causes, most common first:

The instance hasn't restarted for a long time
A new log file is only started on restart, so one file keeps growing. Many exceptions or assertions make it grow faster.
Default retention recycles old history
By default SQL Server keeps 6 archived logs plus the current one, and older ones are dropped. The maximum size of a single log file is unlimited by default (a value of 0).
Missing permission to read the log
Reading the log needs specific rights, and they changed in SQL Server 2022. People who relied on VIEW SERVER STATE may need an extra permission after upgrading.

How to fix it

Work through these in order. They start with the quickest, safest checks and move to deeper repairs; stop as soon as the problem is gone.

1.Open the log in SSMS

Easy

The Log File Viewer is the quickest way to read the log without writing any T-SQL.

  1. In SQL Server Management Studio, connect to the instance and expand it in Object Explorer.
  2. Expand Management, right-click SQL Server Logs, choose View, then SQL Server Log.
  3. The Log File Viewer opens. Pick older archived logs from the list if you need earlier history.

2.Read the log with sp_readerrorlog

Easy

Useful when SSMS is slow on a big file, or when you want to search for a word instead of scrolling.

  1. Read the current log.
    SQL
    EXEC sp_readerrorlog;
  2. Read the previous SQL Server Agent log. The first number is the log number (0 is current, 1 is ERRORLOG.1, and so on). The second is the product (1 for SQL Server, 2 for Agent).
    SQL
    EXEC sp_readerrorlog 1, 2;
  3. Filter the current SQL Server log on two search strings.
    SQL
    EXEC sp_readerrorlog 0, 1, 'database', 'start';

3.Check you have permission to read the log

ModerateChanges settings

A permission error from sp_readerrorlog or the viewer means your login lacks the required right.

Before you start: Changing permissions is a security change. Ask the person who administers the server, and grant only what is needed.

  1. On SQL Server 2019 and earlier, the login needs membership in the securityadmin role, or the VIEW SERVER STATE permission.
  2. On SQL Server 2022 and later, the login needs the securityadmin role, the VIEW ANY ERROR LOG permission, or VIEW SERVER STATE.
  3. Ask your SQL Server administrator to give your login one of these. VIEW ANY ERROR LOG is the narrowest option on 2022 and later.

4.Cycle a huge log without restarting

ModerateChanges settings

Cycling closes the current log and starts a fresh one, the same way a restart would, so the files stay a manageable size.

Before you start: Requires sysadmin. The current log becomes ERRORLOG.1 and the oldest archive is dropped once the retention limit is reached, so read or copy anything you need first.

  1. Connect as a sysadmin and run the procedure. It returns 0 on success and 1 on failure.
    SQL
    EXEC sp_cycle_errorlog;
  2. You can repeat this periodically whenever the current log gets too large.

5.Keep more history or cap the file size

ModerateChanges settings

If entries vanish too early, raise the number of archived logs. If single files grow too big, set a size limit.

Before you start: More archived logs and larger files use more disk space on the drive that holds the log folder.

  1. In SSMS, expand Management, right-click SQL Server Logs and choose Configure.
  2. Tick Limit the number of error log files and set the maximum number of archived files. The default is 6.
  3. Set Maximum size for error log file in KB if you want a cap. A value of 0 means unlimited.
  4. Click OK to save.

Check that it worked

  • EXEC sp_readerrorlog; returns rows without a permission error.
  • After cycling, the current log is short and the old one appears as ERRORLOG.1 in the Log File Viewer.
  • After changing retention, the viewer lists the number of archived logs you set once the instance has cycled enough times.

If it still fails

  • Check whether the right instance is selected: a server can run several instances, each with its own log.
  • If the log is empty of the event you expect, look in older archives, since a restart or cycle may have moved it.
  • For login problems, use the SQL Server error 18456 article. For Windows-side events, see Windows 11 error logs.
  • If a log still can't be read, ask your database administrator or Microsoft support to review the instance's permissions.

Questions

Is the SQL Server error log the same as the transaction log?

No. The error log is a text file of diagnostic messages. The transaction log (.ldf) records data changes for the database.

Does SQL Server Agent write to the same log?

No. Agent has its own log, SQLAGENT.OUT. You can read it with sp_readerrorlog by setting the second parameter to 2.

Sources

  1. Manage the error logOfficial · Microsoft Learn
  2. sys.sp_readerrorlog (Transact-SQL)Official · Microsoft Learn
  3. Configure SQL Server Error Logs (SQL Server Configuration Manager)Official · Microsoft Learn
  4. View the SQL Server Error Log (SSMS)Official · Microsoft Learn
  5. sp_cycle_errorlog (Transact-SQL)Official · Microsoft Learn