SQL Log File Won't Shrink: Why and How to Fix It
In this article
Your SQL Server log file won't shrink because DBCC SHRINKFILE can only remove the inactive part of the log, and something is keeping the active part pinned at the end of the file. Fix the reuse blocker first, then shrink, or the file just grows back.
Time 15 min · Steps 6 · Level Medium
Most people assume running DBCC SHRINKFILE on the transaction log should just make the file smaller. It only works when the log's active portion sits at the start of the file and the rest is free; if a transaction, a missing log backup, or replication is holding space, the shrink quietly does almost nothing. The fix is to find what is blocking log reuse, clear it, and only then shrink the file.
The steps that actually shrink a SQL log file
- Check what is blocking log reuse. Run SELECT name, log_reuse_wait, log_reuse_wait_desc FROM sys.databases and read the value for your database. It tells you the real reason the log is not clearing.
- Clear the wait it reports. For LOG_BACKUP, take a log backup; for ACTIVE_TRANSACTION, find and end the long-running transaction; for a replication or mirroring wait, resolve the stalled reader or remove the feature if it is no longer used.
- Back up the log if the database is in full recovery. In full or bulk-logged recovery the log never truncates on its own. A regular BACKUP LOG job is what marks space reusable.
- Run the shrink against the log file by name. Use DBCC SHRINKFILE (logical_log_name, target_size_in_MB), with the logical file name from sys.database_files, not the database name.
- Repeat backup then shrink if the first pass barely helps. Because the active part can sit in the middle of the file, one log backup plus one shrink may only free part of the space. Alternating backup and shrink a few times walks the active region toward the start.
- Verify the result. Check DBCC SQLPERF(LOGSPACE) for the used percentage, and confirm the physical file size on disk actually dropped.
Why DBCC SHRINKFILE seems to do nothing
A transaction log is a circular file: SQL Server writes sequentially, and after a backup or checkpoint marks old entries reusable, it wraps around and reuses that space. Shrinking can only remove space at the physical end of the file that is both free and after the active point. If the active virtual log files (VLFs) sit near the end, there is almost nothing for the shrink to trim, and the command returns with the file the same size. This is why the error is rarely the shrink command itself and nearly always the log_reuse_wait.
The waits you will meet most often: LOG_BACKUP means the database is in full recovery and no log backup has been taken, so nothing is reusable; ACTIVE_TRANSACTION means one long transaction is holding the log open; CHECKPOINT means the log has not yet been marked reusable and a manual CHECKPOINT may clear it. Replication, database mirroring, and an old, never-finished backup can also pin the log. The log_reuse_wait_desc column names the culprit directly, so you are not guessing.
What if the log just grows back after shrinking?
If the file shrinks today and balloons again next week, the shrink treated the symptom. The log grew for a reason: a missing log backup schedule, a nightly rebuild of huge indexes, or a single transaction that runs for hours. Find that reason with log_reuse_wait at the moment the file is growing, fix it, and then decide on a sensible permanent size. A log that is repeatedly shrunk and regrown suffers two costs: the file-system growth operations are slow, and thousands of tiny VLFs created by repeated autogrow events make log-related operations and restores slower too.
A reasonable target is a size the log reaches during a normal week plus headroom, sized once, and then left alone. If the database does not need point-in-time recovery, switching to simple recovery with ALTER DATABASE name SET RECOVERY SIMPLE makes the log truncate automatically at checkpoints and the growth problem largely disappears. Do not do this if you take log backups and need to restore to a point between full backups.
How to read the log's real size before and after
Two numbers get confused: the physical file size on disk and the used percentage inside it. DBCC SQLPERF(LOGSPACE) shows both per database. A 50 GB log file at 3 percent used is a shrink candidate; a 50 GB file at 90 percent used is being held open by something, and shrinking it now will fail no matter how many times you run the command. Always look at the used percentage first, then the wait, then shrink. The physical size also shows in the Files page of the database properties in SSMS, and in sys.database_files where you can confirm the logical file name the shrink command needs.
Commands worth knowing for a stuck log
For a long-running transaction, DBCC OPENTRAN shows the oldest one and its session, so you can decide whether to let it finish or kill the session. For a log that is huge but mostly free after you fixed the blocker, shrink in stages rather than asking for a tiny target in one shot; each backup-and-shrink cycle frees more of the tail. Never delete the .ldf file directly or detach and reattach hoping to drop the log, that path risks losing the database or breaking recovery. And avoid scheduling a nightly shrink of the log as routine maintenance; it is an emergency tool, not a habit.
Rule of thumb to remember: backup or clear first, shrink second, resize once. If you find yourself shrinking the same log file every week, the shrink is not the fix, the log_reuse_wait is.
Official source: Microsoft Support