限制跟踪文件和表的大小Limit Trace File and Table Sizes

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions)

SQL 跟踪结果的大小依赖于跟踪中包括的事件类和 数据库引擎Database Engine 的用法。SQL Trace results vary in size depending on the event classes that are included in the trace and the way in which the 数据库引擎Database Engine is used. 如果跟踪经常出现的事件类,则可以通过设置最大文件大小或最大行数来最小化跟踪收集的数据量。If you trace event classes that occur frequently, you can minimize the amount of data that the trace collects by setting the maximum file size or the maximum number of rows. 通过指定最大文件大小或行数,可以确保跟踪文件或表不会增长到超出指定范围。By specifying the maximum file size or rows, you ensure that the trace file or table will not grow beyond the specified limit.

备注

如果将跟踪数据保存到已经存在的文件,则可以向该文件追加数据或覆盖该文件。If you save trace data to a file that already exists, you can append data to the file or overwrite the file. 如果选择向该文件追加数据,而此跟踪文件已经达到或超过指定的最大文件大小,则会通知您,并提示您可以增加最大文件大小或指定新文件。If you choose to append data to the file, and the trace file already meets or exceeds the specified maximum file size, you are notified and given the opportunity either to increase the maximum file size or specify a new file. 对跟踪表也是如此。The same is true for trace tables.

文件大小上限Maximum File Size

指定有最大文件大小的跟踪在达到最大文件大小时,会停止将跟踪信息保存到该文件。A trace that has a maximum file size stops saving trace information to the file after the maximum file size has been reached. 使用此选项可将事件分组成更小、更容易管理的文件。This option allows you to group events into smaller, more manageable files. 此外,限制文件大小使得无人参与的跟踪运行起来更加安全,因为跟踪会在达到最大文件大小后停止。In addition, limiting file size makes it safer to run unattended traces, because the trace stops when the maximum file size is reached. 可以为通过 Transact-SQL 存储过程或使用 SQL Server ProfilerSQL Server Profiler创建的跟踪设置最大文件大小。You can set the maximum file size for traces created by means of Transact-SQL stored procedures or by using SQL Server ProfilerSQL Server Profiler.

最大文件大小选项的上限为 1 GB。There is an upper limit of 1 gigabyte (GB) for the maximum file size option. 默认最大文件大小为 5 MB。The default maximum file size is 5 megabytes (MB).

启用文件滚动更新Enabling File Rollover

如果使用文件滚动更新选项,则在达到最大文件大小时, SQL ServerSQL Server 会关闭当前文件并创建一个新文件。The file rollover option causes SQL ServerSQL Server to close the current file and create a new file when the maximum file size is reached. 新文件与原文件同名,但是文件名后将追加一个整数以表示其序列。The new file has the same name as the previous file, but an integer is appended to the name to indicate its sequence. 例如,如果原始跟踪文件命名为 filename_1.trc,则下一跟踪文件为 filename_2.trc,依此类推。For example, if the original trace file is named filename_1.trc, the next trace file is filename_2.trc, and so on. 如果指定给新滚动更新文件的名称已经被现有文件使用,则将覆盖现有文件,除非现有文件为只读文件。If the name assigned to a new rollover file is already used by an existing file, the existing file is overwritten unless it is read only. 将跟踪数据保存到文件时,默认情况下启用文件滚动选项。The file rollover option is enabled by default when you are saving trace data to a file.

备注

如果启用了文件滚动更新选项,则在使用其他某种方法停止跟踪之前,跟踪将一直继续。With the file rollover option on, the trace continues until it is stopped by some other means. 若要停止在达到文件大小限制后进行跟踪,请禁用文件滚动更新选项。To stop the trace after you have reached the file size limit, disable the file rollover option.

设置跟踪文件的最大文件大小To set a maximum file size for a trace file

设置跟踪文件的最大文件大小 (SQL Server Profiler)Set a Maximum File Size for a Trace File (SQL Server Profiler)

最大行数Maximum Number of Rows

指定有最大行数的跟踪在达到最大行数时,会停止将跟踪信息保存到表。A trace with a maximum number of rows stops saving trace information to a table after the maximum number of rows has been reached. 每个事件构成一行,因此该参数可设置收集的事件数的范围。Each event constitutes one row, so this parameter sets a limit on the number of events that are gathered. 设置最大行数使得无人参与的跟踪运行起来更加方便。Setting the maximum number of rows makes it easier to run unattended traces. 例如,如果需要启动一个将跟踪数据保存到表的跟踪,同时希望在该表变得过大时停止跟踪,则可以使其自动停止。For example, if you need to start a trace that saves trace data to a table, but you want to stop the trace if the table becomes too large, you can do so automatically.

如果已指定并且达到了最大行数,将在运行 SQL Server ProfilerSQL Server Profiler 的同时继续运行跟踪,但不再记录跟踪信息。When the maximum number of rows is specified and the maximum number of rows has been reached, the trace continues to run while SQL Server ProfilerSQL Server Profiler is running, but the trace information is no longer recorded. SQL Server ProfilerSQL Server Profiler 将继续显示跟踪结果,直到跟踪停止。continues to display the trace results until the trace stops.

设置跟踪的最大行数To set a maximum number of rows for a trace

设置跟踪表的最大表大小 (SQL Server Profiler)Set a Maximum Table Size for a Trace Table (SQL Server Profiler)

另请参阅See Also

sp_trace_create (Transact-SQL)sp_trace_create (Transact-SQL)