首页 > 其他 > 详细

How to collect TLOG usage status automatically ?

时间:2020-02-16 19:42:06      阅读:56      评论:0      收藏:0      [点我收藏+]

Yes , in SQLSERVER, we use "DBCC sqlperf(logspace)" to check transaction logfile status.
But , for example , we collect it every one hour and save result to a special named table. as record ?
That is not easy but still can.

Here is script:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[getsqlperf]
AS
BEGIN
DECLARE @SQL2 VARCHAR(MAX)
DECLARE @createtable VARCHAR(MAX)
DECLARE @inserttable VARCHAR(MAX)
DECLARE @inserttable2 VARCHAR(MAX)
DECLARE @@tablename2 VARCHAR(MAX)

SELECT @SQL2 = (select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),‘-‘,‘‘),‘ ‘,‘‘),‘:‘,‘‘))
set @createtable=‘create table log‘+@SQL2+‘ (dbname varchar(20),logSizeMB float,logSpaceUsedPct float,Status int);‘
exec(@createtable)
set @inserttable=‘insert into log‘+@SQL2+‘ EXEC ("DBCC SQLPERF(LOGSPACE)")‘
set @inserttable2=(select replace(@inserttable,‘"‘,‘‘‘‘))
exec(@inserttable2)
END
GO

That script can generate a table which record logfile usage status. If you execute that script you could see the result.

execute one time:

技术分享图片

 

How to collect TLOG usage status automatically ?

原文:https://www.cnblogs.com/partition-liu/p/12318040.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!