简体   繁体   English

如何在SQL Server中跟踪日志文件大小的演变?

[英]How to trace log file size evolution in SQL Server?

What I want to know, is how to follow the evolution of log file size in time? 我想知道的是,如何及时跟踪日志文件大小的演变? Does SSMS provide a tool to do so? SSMS是否提供了这样做的工具?

The option of writing a script that checks from time to time the size of the file is indeed doable, but before getting in, can anyone please tell if such a tool exists already in SSMS? 编写一个不时检查文件大小的脚本的选项确实可行,但在进入之前,有人可以告诉SSMS中是否已存在这样的工具吗?

Thank you, 谢谢,

I use the following script (powershell) when I need to do this: 当我需要这样做时,我使用以下脚本(powershell):

$doforever = 1

$cn2 = new-object system.data.SqlClient.SQLConnection("Data Source=somedatasource;Integrated Security=false;Initial Catalog=master;User  ID=sa;Password=somepasswordimnottelling");
$cmd = new-object system.data.sqlclient.sqlcommand("dbcc sqlperf(logspace)", $cn2);
$cn2.Open();

do 
{
$ds=New-Object system.Data.DataSet
$da=New-Object system.Data.SqlClient.SqlDataAdapter($cmd)
[void]$da.fill($ds)

$ds.tables[0] | out-string | %{$_.split("`n")}| %{$_ -replace("\s+",",")}|%{"{0},{1}" -f (get-date -format 'dd/MM/yyyy HH:mm:ss'),$_} | add-content -path c:\perflogs\admin\logsize.csv

sleep -s 300
}
while ($doForever -eq 1)

Quick and dirty - I know it can be refined :) 快速又脏 - 我知道它可以改进:)

It won't give you exact values of log file size in time, but you can use trace to filter 'grow log file' events. 它不会及时为您提供日志文件大小的确切值,但您可以使用trace来过滤“增长日志文件”事件。 This should also appear in default trace (enabled by default :)). 这也应该出现在默认跟踪中(默认情况下启用:))。 I know this applies to SQL Server 2005 and 2008, not sure about other editions (and I don't know which one do you use). 我知道这适用于SQL Server 2005和2008,不确定其他版本(我不知道你使用哪一个)。 You'd use ::fn_trace_gettable function for this. 你可以使用::fn_trace_gettable函数。 As a parameter you specify default trace files location (it automatically parses all the files in a directory, you just need to give "log.trc" as filename. 作为参数,您可以指定默认跟踪文件位置(它会自动解析目录中的所有文件,您只需要将“log.trc”作为文件名。

There is a tool available in SQL Server 2008 and later called Data Collector. SQL Server 2008中有一个工具,后来称为Data Collector。 If you have enabled Data Collection on your server you can track historical Data and Log file changes as well as observe auto-growth events for specific databases. 如果已在服务器上启用了数据收集,则可以跟踪历史数据和日志文件更改,以及观察特定数据库的自动增长事件。

MSDN Data Collector MSDN数据收集器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM