Viewing the Size of Log Files in SQL Server

Viewing the Size of Log Files in SQL Server
Viewing the Size of Log Files in SQL Server

Hello everyone,

In this article, I will provide information about viewing the size of log files in SQL Server.

In SQL Server we may want to view the size of log files in some cases.

You can easily do this with the help of the code below.

SELECT DB_NAME(mf.database_id) AS 'DB Name',
       name AS 'File Logical Name',
       'File Type' = CASE
                         WHEN type_desc = 'LOG' THEN
                             'Log File'
                         WHEN type_desc = 'ROWS' THEN
                             'Data File'
                         ELSE
                             type_desc
                     END,
       mf.physical_name AS 'File Physical Name',
       size_on_disk_bytes / 1024 AS 'Size(KB)',
       size_on_disk_bytes / 1024 / 1024 AS 'Size(MB)',
       size_on_disk_bytes / 1024 / 1024 / 1024 AS 'Size(GB)'
FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS divfs
    JOIN sys.master_files AS mf
        ON mf.database_id = divfs.database_id
           AND mf.file_id = divfs.file_id
WHERE CASE
          WHEN type_desc = 'LOG' THEN
              'Log File'
          WHEN type_desc = 'ROWS' THEN
              'Data File'
          ELSE
              type_desc
      END = 'Log File'
ORDER BY DB_NAME(mf.database_id);

When you run the code, you will get a result like the one below.

Viewing the Size of Log Files in SQL Server

As you can see, the size of the log files is displayed.

Good luck to everyone in business and life.

465 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!