SQL Log File Won't Shrink? Here's Why and the Fix
In this article
A SQL Server log file won't shrink because the active portion of the log can't move, or because the recovery model keeps every transaction in the log until it's backed up. In most cases you fix it by backing up the log (or switching to SIMPLE recovery), then running DBCC SHRINKFILE on the log file only.
Time 15 min · Steps 6 · Level Medium
Why the Log Refuses to Shrink
DBCC SHRINKFILE can only remove the inactive part of the log — the part that comes before the oldest transaction SQL Server still needs. If the active part sits at the far end of the file, there is nothing to trim, and the command finishes with the file at the same size. The log also only shrinks in whole virtual log files (VLFs), so a small amount of used space at the wrong spot can block shrinking of a multi-gigabyte file.
The most common cause is the FULL recovery model without log backups. In FULL recovery, every transaction stays in the log until you back the log up, so the file grows and stays grown. Other causes are a long-running open transaction, replication or mirroring holding old log records, or a database stuck in a state that never clears the log.
The Shrink Sequence That Works
- Check the recovery model. Run
SELECT name, recovery_model_desc FROM sys.databases WHERE name = 'YourDB';. If it says FULL and you don't take log backups, that's your culprit. - Back up the transaction log. In FULL recovery, run
BACKUP LOG YourDB TO DISK = 'path\log.bak';. This marks the log space inactive. If you don't need point-in-time recovery, switch withALTER DATABASE YourDB SET RECOVERY SIMPLE;instead, which lets the log clear automatically. - Find what's holding the log. Run
SELECT name, log_reuse_wait_desc FROM sys.databases WHERE name = 'YourDB';. A value like ACTIVE_TRANSACTION, LOG_BACKUP, or REPLICATION tells you what to clear first — shrinking won't work until it says NOTHING or a benign reason. - Get the log file's logical name. Run
SELECT name, size/128 AS SizeMB FROM YourDB.sys.database_files WHERE type_desc = 'LOG';and note the name in the first column. - Shrink the log file only. Run
USE YourDB; DBCC SHRINKFILE (LogFileName, 256);where 256 is the target size in MB. Never shrink to the minimum just because you can — pick a size the log actually needs. - Verify and prevent regrowth. Re-run the query from step 4 to confirm the size dropped. Then check autogrowth settings in database properties so the file grows in sensible increments rather than by tiny percentages.
Menu paths in SQL Server Management Studio can differ slightly by version, but the T-SQL commands above are stable across versions.
What log_reuse_wait_desc Tells You
This one column solves most "why won't it shrink" cases, so read it before touching anything:
- NOTHING — the log is clear; shrinking should now work.
- LOG_BACKUP — take a log backup, then shrink.
- ACTIVE_TRANSACTION — a long-running transaction is holding the log. Find it with
DBCC OPENTRANorsys.dm_tran_database_transactionsand either let it finish or, if it's orphaned, kill the session. - REPLICATION / DATABASE_MIRRORING / AVAILABILITY_REPLICA — a secondary or subscriber hasn't consumed the log records yet. Fix the partner, and the log clears on its own.
After clearing the wait reason, you may need to back up the log once more, then run DBCC SHRINKFILE again — sometimes two passes are needed because the first backup only marks the space reusable.
The Misconception About Shrinking
Many people believe shrinking is a maintenance task you should run regularly. It isn't. Shrinking the log, having it grow again, and shrinking it again fragments the log into many small virtual log files, which slows down every transaction that writes to it. Shrink is a one-time operation for reclaiming space after an exceptional event — a one-off bulk load, a switch to SIMPLE recovery, or a runaway transaction that's been fixed.
The correct long-term pattern is: pick a log size that fits your normal workload, let the file stay at that size, and back up the log on a schedule if you're in FULL recovery. A log that isn't growing is a healthy log.
When the File Still Won't Budge
If log_reuse_wait_desc says NOTHING and DBCC SHRINKFILE still reports no reduction, the active VLF is likely at the end of the file. Back up the log, shrink, back up again, and shrink again — the repeated backup cycle moves the active VLF toward the start of the file. In stubborn cases, several cycles of BACKUP LOG followed by DBCC SHRINKFILE will eventually release the space.
Also confirm you're shrinking the right file. DBCC SHRINKFILE takes the logical file name, not the physical path, and running it against the data file when you meant the log file is a common slip. The query in step 4 shows both files side by side so you can tell them apart.
One caution: if the database is a replica in an availability group, or a publisher in replication, don't switch it to SIMPLE recovery to force a shrink — that breaks the feature that's holding the log. Fix the downstream consumer instead.
Official source: Microsoft Support