SQL Log File Won't Shrink? Causes and Fixes
In this article
Your log file won't shrink because the active portion of the log is at the far end of the file, or the log has not been truncated. Run a log backup (in FULL recovery), then DBCC SHRINKFILE with TRUNCATEONLY before trying the regular shrink.
Time 10 min · Steps 6 · Level Advanced
Shrink the Log in Six Steps
- Check the recovery model. Run SELECT name, recovery_model_desc FROM sys.databases. FULL means the log only truncates after a log backup; SIMPLE truncates automatically at checkpoint.
- Back up the log if the database is FULL. Use BACKUP LOG YourDb TO DISK = 'path.bak'. Without this, the log is never marked reusable and the shrink does nothing.
- Run the shrink with TRUNCATEONLY first. DBCC SHRINKFILE (YourDb_log, TRUNCATEONLY) releases only free space at the tail of the file, which is often all you need.
- Shrink to a target size if needed. DBCC SHRINKFILE (YourDb_log, 512) targets 512 MB. Find the logical file name with SELECT name, size/128.0 AS SizeMB FROM sys.database_files WHERE type_desc = 'LOG'.
- Check the result. Re-run the file query and compare SizeMB. Also check log_reuse_wait_desc in sys.databases to see what is still holding space.
- Reset the log's growth size. After shrinking, set a sensible autogrowth value (for example 256 MB increments rather than a percentage) with ALTER DATABASE YourDb MODIFY FILE (NAME = YourDb_log, FILEGROWTH = 256MB). This stops the file ballooning again.
Find Out What Is Actually Holding the Log Space
The single most useful query is SELECT name, log_reuse_wait_desc FROM sys.databases. The value in log_reuse_wait_desc tells you why SQL Server cannot reuse the log space, and it names your real problem. LOG_BACKUP means a log backup is due; that is the common case in FULL recovery and the backup clears it. ACTIVE_TRANSACTION means a long-running transaction is holding the log; find it in the active sessions or transaction views and either let it finish or, if it is genuinely stuck, kill that session after checking with whoever owns it. REPLICATION or DATABASE_SNAPSHOT_CREATION means an external process is behind; the log cannot truncate until it catches up or is removed. NOTHING means the log is already reusable and a shrink should work now.
One more trap: the shrink only releases space after the highest used page, called the active virtual log file. If the used space sits at the end of the file, the shrink cannot release anything even when the log is mostly empty. Backing up the log a second time often rolls the active portion back to the start of the file, after which the shrink succeeds. This is why the sequence backup, shrink, backup again, shrink again is worth repeating a couple of times before concluding something else is wrong.
Each Cause and Its Fix
No log backup in FULL recovery
How to confirm: log_reuse_wait_desc shows LOG_BACKUP, and the log keeps growing despite checkpoints. Fix: switch to regular log backups on a schedule, or, if point-in-time recovery is not needed, switch the database to SIMPLE with ALTER DATABASE YourDb SET RECOVERY SIMPLE, then back up the log once more and shrink. Switching to SIMPLE breaks the backup chain, so take a full backup right after.
Long-running or orphaned transaction
How to confirm: log_reuse_wait_desc shows ACTIVE_TRANSACTION. Fix: find the session running the long transaction, let it complete if it is legitimate, or kill the session if it is orphaned. The log will truncate at the next checkpoint or log backup.
Replication, mirroring or an availability group is behind
How to confirm: log_reuse_wait_desc shows REPLICATION, AVAILABILITY_REPLICA or DATABASE_MIRRORING. Fix: get the secondary or the distribution agent caught up, or remove the database from that feature if it is no longer in use. The log truncates as soon as the lagging reader advances.
The active log sits at the end of the file
How to confirm: the shrink reports the file is already at its minimum or releases almost nothing, yet log_reuse_wait_desc shows NOTHING. Fix: take another log backup, shrink again, and repeat once or twice. If it still refuses, the reliable fallback is to checkpoint, back up the log, then shrink in a loop until the file comes down.
You are shrinking the wrong file or using the wrong name
How to confirm: DBCC SHRINKFILE errors with a message that the file ID or name is wrong. Fix: get the logical name from sys.database_files, not the physical file name on disk, and pass that logical name to DBCC SHRINKFILE. The logical name often differs from what you would guess.
Keep the Log From Growing Back
Shrinking is a one-time fix, and repeating it regularly is a bad habit: each shrink-and-grow cycle fragments the log and slows everything down. Decide what size the log actually needs by watching it through a normal business cycle, then pre-size it to that with ALTER DATABASE ... MODIFY FILE and leave it there. A fixed-size log with a sensible autogrowth increment is the steady state to aim for.
Also check what is filling it. Index rebuilds and bulk loads write heavily to the log; scheduling log backups more often during those windows keeps the log flat. In FULL recovery, a log backup every 15 to 30 minutes during heavy activity is a common pattern. If the database does not need point-in-time recovery, SIMPLE recovery removes the backup dependency entirely, and the log truncates at every checkpoint.
Menu names and dialog labels in SQL Server Management Studio can differ slightly between versions; the T-SQL commands above are the reliable path, and the Object Explorer shrink dialog simply calls the same commands.
Official source: Microsoft Support