Improved on the previous post some when I noticed that dbcc sqlperf(logspace) already gives you the log size in MB and also adds the log space used. Converting the floats to int in this manner may be kind of ugly, but it gets me close enough to the results I’m after – giving me sufficient data (database name, log file size, log space used, description why truncation may have to wait for each database in the database instance)Â to make decisions which logs to clean up.
Â
DECLARE @t TABLE([Database Name] nvarchar(50), [Log Size (MB)] int, [Log Space Used (%)] int, Status smallint);
INSERT INTO @t([Database Name], [Log Size (MB)], [Log Space Used (%)], Status) EXEC (‘dbcc sqlperf(logspace);’)
SELECT t2.Name AS [Datebase Name], t1.[Log Size (MB)], t1.[Log Space Used (%)], t2.[log_reuse_wait_desc] AS [Wait Desc]
FROM @t AS t1
INNER JOIN sys.databases AS t2
ON t1.[Database Name] = t2.[Name]
ORDER BY [Database Name]