SQL Log File Not Shrinking: Why and How to Fix It
In this article
Your SQL Server transaction log won't shrink because something is holding log space — usually an active transaction, log backups never being taken, or replication or availability group logs waiting to ship. DBCC SHRINKFILE only reclaims space that is already inactive and backed up, so you have to clear the log chain first, then shrink.
Time 20 min · Steps 6 · Level Medium
Why the Transaction Log Refuses to Shrink
The transaction log is a circular file: SQL Server writes to it, and once those parts are no longer needed, it marks them reusable. DBCC SHRINKFILE can only cut the file back to the point of the last active (still-needed) log record. If the log is 50 GB and the active portion ends at 45 GB, the file can shrink to roughly 45 GB and no further — no matter how many times you run the shrink. That's the detail most people get wrong: shrinking is not the problem, the log's active portion is.
What keeps a log record active: a long-running transaction that hasn't committed, a database in FULL recovery model with no log backups ever taken, transaction log backups waiting for a log mark, replication or Change Data Capture rows not yet delivered, or a database mirroring or availability group partner that hasn't received them yet. SQL Server also delays truncation briefly after a backup for safety.
How to Shrink the Log File, Step by Step
- Find what's holding the log. Run
DBCC OPENTRANon the database to spot a long-running transaction, and querysys.databasesfor the columnlog_reuse_wait_desc— it names the exact reason (for example ACTIVE_TRANSACTION, LOG_BACKUP, REPLICATION, AVAILABILITY_REPLICA). - Take a log backup if the database is in FULL recovery.
BACKUP LOG YourDb TO DISK = 'path\log.trn'. This truncates the inactive part of the log and is the single most common fix. If you never need point-in-time recovery, switching to SIMPLE recovery withALTER DATABASE YourDb SET RECOVERY SIMPLEmakes SQL Server reuse log space automatically. - Fix the underlying holder. If log_reuse_wait_desc says ACTIVE_TRANSACTION, find and either let finish or kill the blocking transaction. If it says REPLICATION or CDC, make sure the distributor or capture job is running. If it says AVAILABILITY_REPLICA, check the secondary replica's synchronisation.
- Check the file's actual size and used space.
DBCC SQLPERF(LOGSPACE)shows each database's log file size and the percentage of it in use. If used space is small, the shrink will work; if it's high, go back to step 1. - Shrink the log file by name, not by file number guesswork. Get the logical name from
sys.database_files(usually something like YourDb_log), then runDBCC SHRINKFILE(YourDb_log, 256)to target a size in megabytes — here 256 MB. - Verify and set a sensible maximum. Re-run
DBCC SQLPERF(LOGSPACE)to confirm the file is smaller, then considerALTER DATABASE YourDb MODIFY FILE (NAME = YourDb_log, MAXSIZE = 1GB)so a runaway transaction fails loudly instead of filling the disk.
What log_reuse_wait_desc Values Mean for Shrinking
The wait description tells you which fix applies before any shrink will stick:
| log_reuse_wait_desc | What's holding the log | Fix before shrinking |
|---|---|---|
| NOTHING | Log is truncated; space is reusable | Shrink should work now |
| LOG_BACKUP | FULL recovery, no log backup taken | Take a log backup |
| ACTIVE_TRANSACTION | Uncommitted or long transaction | Commit, roll back or kill it |
| REPLICATION / CDC | Rows not yet delivered to subscriber or capture table | Start or fix the distribution/capture job |
| AVAILABILITY_REPLICA / DATABASE_MIRRORING | Secondary partner hasn't hardened the log | Restore replica synchronisation |
| BACKUP | A data or log backup is running right now | Wait for it to finish |
Where Shrinking a Log Goes Wrong
Shrinking repeatedly is self-defeating. Every shrink followed by regrowth causes VLF fragmentation — the log gets chopped into thousands of small virtual log files, which slows crash recovery and log backups. If you must shrink once to reclaim a one-off bloat (say after a giant index rebuild), do it once, then let the file settle at its working size.
Don't set the log's max size too small, either. A transaction that needs more log than the file allows fails with error 9002 and the transaction rolls back. Size the log for your biggest regular maintenance job plus headroom, and check sys.dm_db_log_info for VLF counts — a healthy log has a manageable number of VLFs rather than thousands.
Never shrink the log by detaching the database and deleting the .ldf file. That can leave the database unrecoverable, and it removes the log SQL Server needs for crash recovery. The supported path is always: clear the reuse wait, back up, then DBCC SHRINKFILE.
Does truncating the log shrink the file?
No, and this trips up nearly everyone. Truncation (from a log backup or SIMPLE recovery) marks space inside the file as reusable — the file on disk stays exactly the same size. Shrinking (DBCC SHRINKFILE) is what returns disk space to the operating system. You need truncation first, then shrink; shrink alone on a log full of active records does nothing.
Why does the log grow right back after shrinking?
Because whatever grew it is still happening. If you're in FULL recovery with no scheduled log backups, the log grows forever — schedule regular log backups (typically every 15 minutes to a few hours, depending on how much data loss you can tolerate). If a nightly index rebuild or bulk load bloats it, switch the database to BULK_LOGGED for that window, or batch the work. Shrinking without removing the cause just repeats the cycle.
Official source: Microsoft Support