Quick Answer
Too many virtual log files come from small autogrowth steps. Fix the count in 3 steps. Check the count with sys.dm_db_log_info. Shrink the log after a log backup and repeat until the count stops falling. Grow the file once to the size you need. In our test 88 VLFs dropped to 4 and one growth to 256 MB added 8.
Your database starts slowly or a restore takes longer than it should. Your log file contains hundreds of virtual log files because it grew in small steps.
This guide shows how to count VLFs, what our test showed for every growth step on SQL Server 2022 and the shrink and regrow steps that bring the count down.
How Many VLFs Does Your Log File Have?
Microsoft states the Database Engine divides the transaction log file into virtual log files. You cannot set the size or the number of VLFs. Every growth of the file decides how many new VLFs the engine adds.
Microsoft states many small growth steps create many VLFs. That can slow database startup, recovery, log backup and restore. It can also add latency to replication, change data capture and Always On redo. SQL Server logs message 9017 when a database starts with an excessive count after an instance start, an attach or a restore.
SELECT d.name, COUNT(*) AS vlf_count, SUM(l.vlf_size_mb) AS log_mb
FROM sys.databases AS d
CROSS APPLY sys.dm_db_log_info(d.database_id) AS l
WHERE d.name = N'YourDB'
GROUP BY d.name;
Replace YourDB with your database name. We built a FULL recovery database with a 1 MB log and a 1 MB growth and inserted 20,000 rows of about 2 KB.
| What we tested | Result on our test instance |
|---|---|
| Count after the inserts with 1 MB growth steps | 88 VLFs in 60.9 MB |
| Size of those VLFs | 36 VLFs of about 0.25 MB, then 52 VLFs of 1 MB |
| First DBCC SHRINKFILE after a log backup | Message that the logical log file at the end of the file is in use. Count fell to 74 VLFs in 46.9 MB |
| Second pass with a log backup, a small insert, a log backup and a shrink | 4 VLFs in 0.98 MB |
| One ALTER DATABASE growth to 256 MB from the 74 VLF log | 8 new VLFs of 26.12 MB, 82 in total |
| One growth to 256 MB from the 4 VLF log | 12 VLFs in total, 8 of them new |
Microsoft states growth below 1/8 of the current log size adds 1 VLF. Larger growth adds 4 VLFs under 64 MB, 8 VLFs from 64 MB to 1 GB and 16 VLFs above 1 GB. Our 1 MB growths added four VLFs while the log was small and one VLF after that, which matches the rule.
Microsoft also states SQL Server 2022 adds one VLF for growth of 64 MB or less. Our SQL Server 2022 instance added four VLFs for the first 1 MB growths. Count the VLFs of your own log and do not rely on the rule.
Heads Up
Few large VLFs cause problems too. Microsoft states a log built in a few big steps has a few huge VLFs. Check the count before you shrink and shrink only a log that has hundreds of VLFs.
Which Fix Matches Your Log?
| Your log | What it means | What to do |
|---|---|---|
| FULL recovery with log backups | The shrink works after a log backup | Use Method #1 |
| SIMPLE recovery | A checkpoint frees the inactive log | Execute CHECKPOINT, then use Method #1 |
| The shrink reports that the logical log file at the end is in use | The active log sits at the end of the file | Take another log backup and shrink again |
| The log cannot be reused yet | Another wait blocks the shrink | Check log_reuse_wait_desc first, then use Method #1 |
| The log was built in one or two big steps | The log has few large VLFs | Plan the growth size and skip the shrink |
Our guide on log_reuse_wait_desc in SQL Server lists every wait value and its fix.
What Does the VLF Fix Need on Your Server?
System Specifications
| Component | Requirement |
|---|---|
| Disk space | Free space for the log size you set in the regrow step |
| Backups | A valid restorable backup before the shrink, as Microsoft advises |
| Log backups | One log backup before every shrink pass in FULL recovery |
Software Specifications
| Item | Requirement |
|---|---|
| SQL Server version | SQL Server 2016 SP2 or later for sys.dm_db_log_info |
| Recovery model | FULL needs BACKUP LOG. SIMPLE needs CHECKPOINT |
| Statements | DBCC SHRINKFILE and ALTER DATABASE with MODIFY FILE |
| Tested on | SQL Server 2022 (RTM CU26) Express on Linux |
How Do You Reduce VLF Count in SQL Server?
Method #1: Shrink the Log and Grow It Once (Free, Needs Log Backups)
Use this method when the count reaches hundreds. Take a valid backup first. Microsoft states you need a restorable backup before you shrink and regrow the log.
BACKUP LOG YourDB TO DISK = N'D:\Backups\YourDB_log.trn';
DBCC SHRINKFILE (N'YourDB_log', 1);
-- Repeat the two statements above until the count stops falling
ALTER DATABASE YourDB MODIFY FILE (NAME = N'YourDB_log', SIZE = 256MB, FILEGROWTH = 256MB);
Our first pass returned the message that the logical log file at the end is in use and the count fell from 88 to 74. Our second pass after another log backup brought the count to 4 and the file to 0.98 MB. One ALTER DATABASE statement grew the file to 256 MB and added 8 VLFs.
In SIMPLE recovery execute CHECKPOINT in place of BACKUP LOG. Microsoft states the log truncates after a checkpoint in this model. Our guide on clearing the transaction log with DBCC SHRINKFILE lists more shrink problems.
Method #2: Set a Fixed Growth Size (Free, Stops the Count From Rising Again)
Use this method after the shrink. Microsoft states small growth values cause many VLFs and advises you to size the log near its final size with a relatively large growth increment. Check the current values first.
SELECT name, size*8/1024 AS size_mb, growth*8/1024 AS growth_mb
FROM sys.database_files
WHERE name = N'YourDB_log';
Our log showed 256 for size_mb and 256 for growth_mb after the statement in Method #1. Use these 3 rules for your own values.
- Size the log near its final size. Logs that never grow add no new VLFs.
- Use a fixed growth in MB. Microsoft names no single value. Match the value to your log backup volume.
- Check the count after every large load. Bulk loads can grow the log many times in one hour.
What Questions Come Up About VLF Count?
How Many VLFs Are Too Many in SQL Server?
Microsoft names no single limit. SQL Server logs message 9017 when it finds an excessive count at startup, attach or restore.
Does Shrinking the Log Reduce VLF Count?
Yes. Our log fell from 88 VLFs to 74 on the first pass and to 4 on the second pass.
Can You Shrink the Log in FULL Recovery?
Yes, after a log backup. Our first pass stopped with the message that the logical log file at the end is in use. Another log backup and shrink finished the job.
How Do You Check VLF Count in SQL Server 2022?
Query sys.dm_db_log_info as shown above. Microsoft points to this function and does not describe DBCC LOGINFO.
Will the Log Gain VLFs When You Grow It Again?
Yes. One growth to 256 MB added 8 VLFs in our test. Microsoft states growth from 64 MB to 1 GB adds 8 VLFs.
What Does Message 9017 Mean?
SQL Server logs it when a database starts with an excessive VLF count. Microsoft ties the message to small FILEGROWTH values.
About this guide
We checked this guide against Microsoft documentation on 4 Dec 2026. We executed the count, shrink and regrow tests on SQL Server 2022 (RTM CU26) Express on Linux.
Microsoft documents the topic in its transaction log architecture guide and on the sys.dm_db_log_info page.
