Viewing the Size of Log Files in SQL Server
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.
As you can see, the size of the log files is displayed.
Good luck to everyone in business and life.