default trace enabled 服务器配置选项default trace enabled Server Configuration Option

适用对象:是SQL Server 否Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库APPLIES TO: yesSQL Server noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

使用 default trace enabled 选项可启用或禁用默认跟踪日志文件。Use the default trace enabled option to enable or disable the default trace log files. 默认跟踪功能提供了丰富持久的活动日志,并主要根据配置选项进行更改。The default trace functionality provides a rich, persistent log of activity and changes primarily related to the configuration options.

警告

此功能处于维护模式并且可能会在 Microsoft SQL Server 将来的版本中被删除。This feature is in maintenance mode and may be removed in a future version of Microsoft SQL Server. 请避免在新的开发工作中使用该功能,并着手修改当前还在使用该功能的应用程序。Avoid using this feature in new development work, and plan to modify applications that currently use this feature. 请改用扩展事件。Use Extended Events instead.

用途Purpose

默认跟踪可确保数据库管理员在问题首次出现时即具有诊断该问题所需的日志数据,从而为数据库管理员提供了故障排除帮助。Default trace provides troubleshooting assistance to database administrators by ensuring that they have the log data necessary to diagnose problems the first time they occur.

查看Viewing

默认跟踪日志可以通过 SQL Server ProfilerSQL Server Profiler 打开和检查,或者通过 Transact-SQLTransact-SQL 使用 fn_trace_gettable 系统函数来查询。The default trace logs can be opened and examined by SQL Server ProfilerSQL Server Profiler or queried with Transact-SQLTransact-SQL by using the fn_trace_gettable system function. SQL Server ProfilerSQL Server Profiler 可以像打开正常跟踪输出文件一样打开默认跟踪日志文件。can open the default trace log files just as it does normal trace output files. 默认情况下,默认跟踪日志以滚动更新跟踪文件的形式存储在 \MSSQL\LOG 目录中。The default trace log is stored by default in the \MSSQL\LOG directory using a rollover trace file. 默认跟踪日志文件的基本文件名是 log.trcThe base file name for the default trace log file is log.trc. SQL ServerSQL Server的典型安装中,默认跟踪启用并因而成为 TraceID 1。In a typical installation of SQL ServerSQL Server, the default trace is enabled and thus becomes TraceID 1. 如果在安装和创建其他跟踪后启用,该 TraceID 可以变成更大的数字。If enabled after installation and after creating other traces, the TraceID can become a larger number.

有关使用 SQL ServerSQL Server 事件探查器查看此跟踪文件的详细信息,请参阅打开跟踪文件 (SQL Server Profiler)For more information about using SQL ServerSQL Server Profiler to view this trace file, see Open a Trace File (SQL Server Profiler)

例如:Example:

以下语句将打开默认位置中的默认跟踪日志:The following statement opens the default trace log in the default location:

SELECT *   
FROM fn_trace_gettable  
('C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\LOG\log.trc', default);  
GO  
  

配置Configuring

如果将 default trace enabled 选项设置为 1,可启用“默认跟踪” 。When set to 1, the default trace enabled option enables Default Trace. 此选项的默认设置为 1 (ON)。The default setting for this option is 1 (ON). 值为 0 时将关闭跟踪。A value of 0 turns off the trace.

default trace enabled 选项是一个高级选项。The default trace enabled option is an advanced option. 如果使用 sp_configure 系统存储过程来更改该设置,则仅当 show advanced options 设置为 1 时才能更改 default trace enabled 选项。If you are using the sp_configure system stored procedure to change the setting, you can change the default trace enabled option only when show advanced options is set to 1. 该设置将立即生效,无需重新启动服务器。The setting takes effect immediately without a server restart.

另请参阅See Also

RECONFIGURE (Transact-SQL) RECONFIGURE (Transact-SQL)
服务器配置选项 (SQL Server) Server Configuration Options (SQL Server)
sp_configure (Transact-SQL)sp_configure (Transact-SQL)