Issues with reporting percent log space used, between DMV and DBCC
Using SQL Server 2012 SE 11.0.2100, I am getting two different sets of values when querying for log space between the DMV and the DBCC command. 

Querying using the DMV.

select instance_name as DBName, cntr_value as PercentLogUsed from sys.dm_os_performance_counters where counter_name = 'Percent Log Used' and instance_name <> '_Total' and instance_name <> 'mssqlsystemresource' and instance_name <> 'model' order by cntr_value desc

The results that I get from using this DMV are about 10% off from the results that I get when I use dbcc.

DBCC SQLPERF(logspace)

Why is this?




August 26th, 2013 1:53pm

Hello,

To provide exact answer i suppose we need to look how Percent log used in DMV and Logspace used % in DBCC is calculated .But viewing code of DBCC commands is not possible

What i found from BOL is

Log Space Used (%)in DBCC= Percentage of the log file currently occupied with transaction log information.

Percent Log Used in DMV : Percentage of space in the log that is in use.(This DMV is actually reports valuse which it takes from permon counters which is windows feature)

So I assume the way it is calculated  difference lies there.This is not exact answer but might help you

Free Windows Admin Tool Kit Click here and download it now
August 27th, 2013 2:21am

Hi Micheal,

Usually we can use DBCC SQLPERF (Transact-SQL) to returns the current size of the transaction log and the percentage of log space used for each database. Also we can get log space usage for all of our databases via the sys.dm_os_performance_counters DMV.

About the difference sets of values, it may be caused by  the precision and scale be preserved differently. As Shanky post, it is impossible to view the code of DBCC Commands. But when using the DMV statement from the following blog and dividing 'Log File(s) Used Size (KB) and 'Log File(s) Size (KB)' returning the log space usage manually, the sets of values is the same as the result set of DBCC SQLPERF. 

There is more detail about getting log space usage without using DBCC SQLPERF, you can refer to the following blog.
http://sqlblog.com/blogs/jonathan_kehayias/archive/2009/06/06/getting-log-space-usage-without-using-dbcc-sqlperf.aspx

Thanks,
Sofiya Li

August 27th, 2013 3:56am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics