Home > Link, Microsoft SQL Server, MSBI, Optimization, Query, Script, SQL Mentalist, SQL PraRup, SQL Query, SQL Server, Technology,, TSQL, Vishal Pawar > BI SQL # 180 : SQL Server DBA Scripts : List log file information for all the databases on the server

BI SQL # 180 : SQL Server DBA Scripts : List log file information for all the databases on the server

Hi Geeks,

In this article we are going to cover How to List log file information for all the databases on the server.

In this post we are going to discuss following points:

  • Problem Statement of SQL Script:
  • Description of SQL Script:
  • SQL Script Output Column
  • SQL Script Code
  • SQL Script Output Screenshot
  • User Level to execute

Problem Statement of SQL Script:

How to find the log file information for all Databases on the server?

Description of SQL Script:

This Transact-SQL script uses the DMV sys.dm_os_performance_counters

To list log file information:

Allocated size in MB

used size in MB

free size in MB

percent of size used

count of VLF the log have been grown, shrink and truncated since last service start for all databases, similar to the DBCC SqlPerf(LogSpace) command.

SQL Script Output Column

image

SQL Script Code

SELECT PVT.DatabaseName
    ,CONVERT(NUMERIC(38, 1), PVT.[Log File(s) Size (KB)] / 
        1024.0) AS LogFileSizeMB
    ,CONVERT(NUMERIC(38, 1), PVT.[Log File(s) Used Size (KB)] / 
        1024.0) AS LogFileUsedMB
    ,CONVERT(NUMERIC(38, 1), (
            PVT.[Log File(s) Size (KB)] - PVT.
            [Log File(s) Used Size (KB)]
            ) / 1024.0) AS LogFileFreeMB
    ,PVT.[Percent Log Used] AS PercLogUsed
    ,PVT.[Log Growths] AS LogGrowths
    ,PVT.[Log Shrinks] AS LogShrinks
    ,PVT.[Log Truncations] AS LogTrunc
FROM (
    SELECT RTRIM(SUB.counter_name) AS CounterName
        ,RTRIM(SUB.instance_name) AS DatabaseName
        ,SUB.cntr_value AS CounterValue
    FROM [master].[sys].[dm_os_performance_counters] AS SUB
    WHERE SUB.[object_name] LIKE 'SQLServer:Databases%' 
        -- To be independed of instance name. 
        AND SUB.counter_name IN (
            'Log File(s) Size (KB)'
            ,'Log File(s) Used Size (KB)'
            ,'Percent Log Used'
            ,'Log Growths'
            ,'Log Shrinks'
            ,'Log Truncations'
            )
    ) AS OPC
PIVOT(SUM(OPC.CounterValue) FOR OPC.CounterName IN (
            [Log File(s) Size (KB)]
            ,[Log File(s) Used Size (KB)]
            ,[Percent Log Used]
            ,[Log Growths]
            ,[Log Shrinks]
            ,[Log Truncations]
            )) AS PVT
ORDER BY PVT.DatabaseName;

    SQL Script Output Screenshot

    image

    User Level to execute

      300

    Hope you will like How to List log file information for all the databases on the server.

    If you really like reading my blog and understood at least few thing then please don’t forget to subscribe my blog.

If you want daily link and analysis or interesting link go to following website which will give @ your inbox please subscribe our following link resource blog :

Link Resource Website

For More information related to BI World visit my Mentalist Blog

SQL Server Mentalist >> SQL Learning Blog

Business Intelligence Mentalist >> BI World

Infographic Mentalist >> Image worth explaining thousand Words

Microsoft Mentalist >> MVC,ASP.NET, WCF & LinQ

DBA Mentalist >>Advance SQL Server Blog

Microsoft BI Mentalist >> MS BI Development Update

Connect With me on

| FaceBook |Twitter | linkedIn| Google+ | WordPress | RSS |

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: