Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Shrink Log Not Working? The Real Fixes

· 5 min read · Home Tech

In this article
  1. The Six Steps That Fix a Stuck Log Shrink
  2. log_reuse_wait_desc Says Nothing: Why the Shrink Still Fails
  3. The Log Is in FULL Recovery and Never Gets Backed Up
  4. An Open Transaction Is Pinning the Log
  5. Replication, CDC or an Availability Group Keeps the Log Marked Active
  6. Why the Log Grows Right Back After a Successful Shrink
  7. What Shrinking the Log Repeatedly Actually Costs

Your log file won't shrink because DBCC SHRINKFILE can only remove the inactive, unused part of the log. If the log is waiting on a log backup, an open transaction, or replication, the space stays marked as in use and the shrink does nothing.

Time 15 min · Steps 6 · Level Medium

Run DBCC SHRINKFILE on the log's logical file name, not the database name, and check log_reuse_wait_desc first. Most failed shrinks come from one of two things: the file name is wrong, so the command errors out or shrinks the wrong file, or the log's space is genuinely still in use, so there is nothing for the shrink to release. The wait description tells you which case you're in before you touch anything.

The Six Steps That Fix a Stuck Log Shrink

  1. Find the log's logical name. Run SELECT name, size/128 AS size_mb FROM sys.database_files WHERE type_desc = 'LOG'. Use that name in the shrink, not the database name and not the physical file path.
  2. Check what is holding the log. Run SELECT name, log_reuse_wait_desc FROM sys.databases WHERE name = 'YourDB'. The value returned names the exact reason the log can't be reused; the sections below map each value to its fix.
  3. Take a log backup if recovery model is FULL. Under FULL or BULK_LOGGED recovery, the log only clears after a log backup: BACKUP LOG YourDB TO DISK = 'path\log.trn'. Without this step a shrink in FULL recovery almost never works.
  4. Clear the wait, then shrink. Fix the condition shown by log_reuse_wait_desc (open transaction, replication, mirroring, and so on), then run DBCC SHRINKFILE (log_logical_name, target_mb).
  5. Check the result. Re-run the query from step 1. If size_mb dropped, it worked. If not, re-check log_reuse_wait_desc, because a new wait can appear between attempts.
  6. Set a sane max size. After the shrink, consider ALTER DATABASE YourDB MODIFY FILE (NAME = log_logical_name, MAXSIZE = 2048MB) so a runaway log stops before it fills the disk again.

log_reuse_wait_desc Says Nothing: Why the Shrink Still Fails

When the wait is NOTHING, the log is clear and a shrink should work, so a failure here is almost always the command itself. The most common slip is passing the wrong logical file name, which either throws an error or shrinks a data file instead. Get the exact name from sys.database_files, including any underscores, and remember the name is case-sensitive on some collations. The other trap is asking for a target smaller than the space actually in use: if the log has 8 GB used, DBCC SHRINKFILE (log, 1024) will silently do nothing because it cannot cut below the used space. Shrink to the used size shown in step 1, or omit the target entirely to shrink to the minimum possible.

The Log Is in FULL Recovery and Never Gets Backed Up

A database in FULL recovery keeps every log record until a log backup truncates it, so the file grows forever and no shrink can release the space. Confirm with SELECT recovery_model_desc FROM sys.databases WHERE name = 'YourDB'. If you see FULL and you have no log backup job, you have two honest options. If you need point-in-time recovery, schedule regular log backups, for example every 15 minutes during business hours, and the log will stay small on its own. If you don't need point-in-time recovery, switch to SIMPLE: ALTER DATABASE YourDB SET RECOVERY SIMPLE, then take a log backup or checkpoint, then shrink. Switching to SIMPLE breaks the backup chain, so take a full backup right after.

An Open Transaction Is Pinning the Log

A long-running transaction that hasn't committed or rolled back forces SQL Server to keep every log record written after it started, and log_reuse_wait_desc shows ACTIVE_TRANSACTION. Confirm with DBCC OPENTRAN ('YourDB') and SELECT session_id, database_transaction_log_bytes_used FROM sys.dm_tran_database_transactions. If the open transaction belongs to a session that is stuck or abandoned, kill that session with KILL session_id, then take a log backup if the database is in FULL recovery, then shrink. If the transaction belongs to a live application, the fix is on the application side: the transaction needs to commit or roll back before any amount of shrinking will help.

Replication, CDC or an Availability Group Keeps the Log Marked Active

SQL Server holds log records until every feature that reads them is done, so a broken replication agent or an availability group replica that can't catch up keeps the log from clearing. The wait values to look for are REPLICATION, CDC and AVAILABILITY_REPLICA. For replication, check whether the Log Reader Agent or Distribution Agent has stopped or fallen behind, and start or fix it; the log clears once it catches up. For an availability group, look at the replica in the synchronising state and fix its connection or redo backlog. For CDC, the capture job must be running. Once the feature catches up, take a log backup in FULL recovery and shrink again. If the feature was decommissioned but left behind, the cleanup procedures for that feature mark the log records as distributable so the space frees.

Why the Log Grows Right Back After a Successful Shrink

If the shrink works but the file balloons again within hours, the shrink fixed the symptom and not the cause. Look for log_reuse_wait_desc returning to the same value repeatedly, or a burst of log growth from a one-off operation such as a huge index rebuild, a bulk load, or an accidental transaction left open overnight. Regular log growth events in FULL recovery usually mean the log backup schedule is too sparse; backing up every 15 minutes instead of once a day keeps far less log live at any moment. Frequent auto-growth also fragments the virtual log files, which slows everything down, so after fixing the cause it's worth shrinking once and pre-sizing the log to its normal steady size rather than letting it grow in small increments.

What Shrinking the Log Repeatedly Actually Costs

Every shrink-then-grow cycle creates virtual log file fragmentation, and a badly fragmented log slows writes, backups and crash recovery. Shrink the log once to reclaim space after fixing the underlying wait, then leave it alone. If disk space is the ongoing pressure, the better answers are more frequent log backups in FULL recovery, a switch to SIMPLE recovery where point-in-time restore isn't needed, or moving the log file to a drive with more room. Never shrink the log on a schedule as routine maintenance; treat it as a one-time cleanup after an incident.

Official source: Microsoft Support