How high VLF counts kill your SQL Performance

Category: Performance
Item:  High VLF count

What is a Virtual Log File (VLF)?

The transaction log file is physically divided internally into several virtual log files (VLFs).

This number can grow base on how often the active transactions write to the disk and the auto-growth settings for the log file.

With high VLF counts, backups will run slower.

Some TSQL operations, such as UPDATE/DELETE will take longer.

SQL Engine service takes a long time to start.  Replication/AlwaysOn/Mirroring/Log shipping and other operations – all suffer.

How to identify the issue?

You can get information about the VLF count using DBCC LOGINFO.

For newer SQL Server versions (SQL Server 2016 SP2 and later),  you may use the query below that uses SQL Dynamic Management Functions (DMFs).

SELECT [name] AS 'Database Name',
COUNT(l.database_id) AS 'VLF Count',
SUM(CAST(vlf_active AS INT)) AS 'Active VLF',
COUNT(l.database_id)-SUM(CAST(vlf_active AS INT)) AS 'Inactive VLF',
SUM(vlf_size_mb) AS 'VLF Size (MB)',
SUM(vlf_active*vlf_size_mb) AS 'Active VLF Size (MB)',
SUM(vlf_size_mb)-SUM(vlf_active*vlf_size_mb) AS 'Inactive VLF Size (MB)'
FROM sys.databases s
CROSS APPLY sys.dm_db_log_info(s.database_id) l
GROUP BY [name]
ORDER BY COUNT(l.database_id)
Figure 1 – Query VLFs output.

 

When VLF under 100 – you can ignore

When between 100 – 200 – you can ignore, but better to fix

When above 400 – it’s getting urgent, so fix it.

When above 600 – slowdowns are happening, but it’s not easy to diagnose these. Fix.

When above 5000, fix now.

How to fix it?

  1. Fix database default growth settings.
  2. Shrink transaction log files, and pre-grow to set sizes.

More information

Pin Dave – How to Reduce High Virtual Log File (VLF) Count?
Aaron Bertrand –  Virtual Log File Monitoring in SQL Server 2017

Share this post

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

4.8/5

42

TESTIMONIALS

FREE Scripts to Instantly
Improve SQL Server Performance

3 FREE Scripts to Instantly
Improve SQL Server Performance

Learn how to increase Performance of SQL Server INSTANTLY with 3 free scripts.