大网数据广告活动
数据库与应用安全

Manage the error log

· 52CE 我爱测

This article describes how to manage the SQL Server error log.

This article describes how to manage the SQL Server error log.

Original product version:   SQL Server
Original KB number:   2199578

Summary

The Microsoft SQL Server error log contains much valuable information that is generated by SQL Server. The error log contains informational messages, warnings, and information about critical events. The error log also contains information about user-generated messages and auditing information such as logon events (success and failure).

The error log is a valuable data point for SQL Server administrators. As an administrator, you must manage the size of the error logs so that you can use them when they're needed.

The error log file is initialized every time that the instance of SQL Server is started. If the instance of SQL Server hasn't been restarted for a long time, the error log file can grow large. If many exceptions (for example, access violations) or critical events (for example, SQL Server assertions) occur, these events can generate lots of information that is written to the SQL Server error log.

Reinitializing SQL Server error logs

You can use the sp_cycle_errorlog stored procedure to reinitialize the error logs periodically. For more information, see sp_cycle_errorlog (Transact-SQL).

Configuring the number and size of SQL Server Error Logs

For more information on how you can configure the size and number of SQL Server Error logs for an instance review Configure SQL Server Error Logs.

Reading the error logs

You can read the contents of the SQL Server or SQL Server Agent error log file and filter on keywords by using sp_read_errorlog. For example, you can find log messages in the current SQL Server error log that indicate a database is starting up by running the following command:

EXEC sp_readerrorlog 0, 1, 'database', 'start'

More information

For more information on configuring these values using T-SQL, see the following blog posts by Paul Randal and Jan Kare Lokna:

Third-party information disclaimer

Third-party information disclaimer

The third-party products that this article discusses are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, about the performance or reliability of these products.

Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / IT Pro troubleshooting
适用范围
See source applicability · Source date 11/05/2022
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。