SQL Server數(shù)據(jù)庫之查看SQL日志文件大小的命令
此文章主要向大家講述的是SQL Server數(shù)據(jù)庫之查看SQL日志文件大小命令:dbcc sqlperf(logspace),我們大家都熟知在DBA 日常管理工作中,其很重要一項工作就是監(jiān)視數(shù)據(jù)庫文件大小,及日志文件大小。
如果你管理數(shù)據(jù)庫的有很多的話,每天一個一個數(shù)據(jù)庫的去查看文件大小就太費神了,那就寫個SQL腳本吧,放到 SQL Agent 中,每天自動去查看各個數(shù)據(jù)庫DBA 日常管理工作中,很重要一項工作就是監(jiān)視數(shù)據(jù)庫文件大小,及日志文件大小。
如果你管理數(shù)據(jù)庫的有很多的話,每天一個一個數(shù)據(jù)庫的去查看文件大小就太費神了,那就寫個SQL腳本吧,放到 SQL Agent 中,每天自動去查看各個數(shù)據(jù)庫文件及日志文件的大小,然后再通過數(shù)據(jù)庫郵件,Email 到我們手中,豈不快哉!當然,可以把每天的記錄存放到數(shù)據(jù)庫中去,這樣數(shù)據(jù)庫及日志文件的增長趨勢,我們也就一目了然了。
這里,介紹下獲取數(shù)據(jù)庫日志文件大小的方法。其實很簡單,就是執(zhí)行 SQL Server DBCC 命令:dbcc sqlperf(logspace)
- dbcc sqlperf(logspace)
- Database Name Log Size (MB) Log Space Used (%) Status
- master 2.2421875 32.600174 0
- tempdb 0.4921875 39.285713 0
- model 0.4921875 41.07143 0
- msdb 2.2421875 30.901567 0
- pubs 0.7421875 49.934212 0
- Northwind 0.9921875 34.940945 0
- dbcc sqlperf(logspace)
可以獲取實例中每個數(shù)據(jù)庫日志文件大小,及使用情況。如果要保存SQL日志文件大小,則需要先創(chuàng)建一個數(shù)據(jù)表,然后動態(tài)執(zhí)行dbcc sqlperf(logspace)命令:
- create table dbo.LogSize
- (
- dbname nvarchar(50) not null
- ,logsize decimal(8,2) not null
- ,logused decimal(5,2) not null
- ,status int null
- )
- insert into dbo.LogSize
- execute('dbcc sqlperf(logspace) with no_infomsgs')
本篇文章來源于:開發(fā)學(xué)院 http://edu.codepub.com 原文鏈接:http://edu.codepub.com/2010/0508/22576.php