Last active
October 19, 2015 16:23
-
-
Save AndyMeps/59dae14f9f60f51d77c2 to your computer and use it in GitHub Desktop.
Logs database log file sizes to a table in the [master] schema for diagnostic / analytic purposes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE [master].[dbo].[LogFileUsage] ( | |
[Id] [int] IDENTITY(1,1) PRIMARY KEY NOT NULL | |
,[DatabaseName] [nvarchar](100) NOT NULL | |
,[LogSize] [real] NOT NULL | |
,[PercentageUsed] [real] NOT NULL | |
,[LogDateTime] [datetime] NOT NULL DEFAULT GETDATE() | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @temp TABLE ( | |
DatabaseName NVARCHAR(100) | |
,LogSize REAL | |
,PercentageUsed REAL | |
,Status INT | |
) | |
INSERT INTO @temp (DatabaseName, LogSize, PercentageUsed, Status) | |
EXEC('DBCC SQLPERF(LOGSPACE)') | |
INSERT INTO [master].[dbo].[LogFileUsage] | |
(DatabaseName | |
,LogSize | |
,PercentageUsed) | |
SELECT DatabaseName, LogSize, PercentageUsed FROM @temp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
Id | |
,DatabaseName | |
,LogSize | |
,(LogSize / 100) * PercentageUsed AS [PercentUsedInMB] | |
,PercentageUsed | |
,LogDateTime | |
FROM | |
[master].[dbo].[LogFileUsage] | |
WHERE | |
DatabaseName = '%' | |
ORDER BY | |
LogDateTime DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment