Why does a SQL Server database's transaction log keep growing under the FULL recovery model, and how do SIMPLE and BULK_LOGGED change that?
answer
- truncation needs a trigger
- log backup, not full backup
- log_reuse_wait_desc names the blocker
- SIMPLE truncates after a checkpoint
basics
~20 sUnder FULL, inactive log is reused only after a log backup, so without scheduled BACKUP LOG the log grows until the disk fills. SIMPLE truncates at checkpoints but allows no log backups; BULK_LOGGED minimally logs bulk work yet still needs log backups.
solid answer
~40 sThe recovery model is a per-database setting that decides when inactive log can be truncated. Under **FULL**, truncation happens only after a `BACKUP LOG`, so a FULL database with no log-backup job grows its log until the disk fills and updates fail with error 9002; a full backup does not free log space. **SIMPLE** truncates after each checkpoint, so the log stays small, but it allows no log backups, no point-in-time restore, and no availability groups or log shipping. **BULK_LOGGED** is FULL with minimal logging for bulk imports, `SELECT INTO` and index builds; it still needs log backups and gives up point-in-time restore for the log backups that cover bulk-logged work. When a log will not truncate, `log_reuse_wait_desc` in `sys.databases` names the blocker, such as `LOG_BACKUP`, `ACTIVE_TRANSACTION` or `AVAILABILITY_REPLICA`.
code
sql · 7 linesSELECT name, recovery_model_desc, log_reuse_wait_desc
FROM sys.databases
WHERE name = N'Payments';
ALTER DATABASE Payments SET RECOVERY FULL;
BACKUP DATABASE Payments TO DISK = N'D:\bak\Payments_full.bak'; -- starts the log chain
BACKUP LOG Payments TO DISK = N'D:\bak\Payments_log.trn'; -- lets inactive log be reusedgo deeper
Recall the three recovery models by name and that only FULL and BULK_LOGGED allow log backups and point-in-time recovery.
Explain what triggers log truncation in each model, why a full backup does not free log space, and how log_reuse_wait_desc tells you what is holding the log.
Show how you would handle error 9002 in production without breaking the log chain, and when a short BULK_LOGGED window is worth the restore risk.
Decide which databases deserve FULL recovery and log backups at all, and set the standard so new databases never run FULL without a log-backup job.
## What a recovery model decides Every SQL Server database writes changes to its **transaction log** before it changes data pages. The log is divided internally into **virtual log files (VLFs)**. Once the records in a VLF are no longer needed, the VLF can be **truncated**, which marks it reusable. Truncation never makes the physical file smaller; it only lets the file wrap around instead of growing. The **recovery model** is the database property (`ALTER DATABASE ... SET RECOVERY`) that decides what makes log records "no longer needed". Enterprise and Standard editions use FULL by default; Express uses SIMPLE. | Model | When inactive log is truncated | Log backups | Point-in-time restore | |---|---|---|---| | **FULL** | After a log backup | Required | Yes | | **BULK_LOGGED** | After a log backup | Required | Not into a log backup holding bulk-logged changes | | **SIMPLE** | After a checkpoint | Not supported | No | ## FULL: log backups free the space Under FULL recovery every change is fully logged and kept until a `BACKUP LOG` has copied it. That is what makes point-in-time restore and log-based features possible, and it is also why the log grows without bound when nobody schedules log backups. Two details catch people out: - A **full database backup does not truncate the log**. Only a log backup does (and not a `COPY_ONLY` one). - A brand-new FULL database behaves like SIMPLE until its first full backup starts the log chain, so the log looks fine for a while and then starts to grow once that first backup exists. When the log file cannot grow any more, SQL Server raises **error 9002**: the database stays online but can only be read, not updated, until log space is freed. ## SIMPLE: checkpoint truncation Under SIMPLE recovery, a checkpoint truncates the inactive log automatically, so log management is mostly hands-off. The price is that changes since the last full or differential backup are not protected. SIMPLE does not support: - `BACKUP LOG` and therefore log shipping - Always On availability groups (and the deprecated database mirroring) - restore to a point in time, or to the point of failure SIMPLE fits development databases, staging copies and data that can be reloaded from elsewhere. ## BULK_LOGGED: a temporary mode BULK_LOGGED is FULL with **minimal logging** for a set of operations: bulk imports (`bcp`, `BULK INSERT`, `INSERT ... SELECT` that qualifies), `SELECT INTO`, and index builds such as `CREATE INDEX` and `ALTER INDEX REBUILD`. Minimal logging records only what is needed to recover the transaction, not enough for point-in-time restore, so the log grows far less during a large load. The trade-offs: - Log backups are still required, and a log backup taken after bulk work captures the minimally logged changes, so it can be large. - You cannot restore to a point inside a log backup that contains bulk-logged changes; you can only restore to its end. - If the data files are damaged, a log backup of bulk-logged changes cannot be taken, so work since the last log backup is lost. The documented pattern is to switch to BULK_LOGGED just for the load, switch back to FULL, and take a log backup immediately. ## Finding why the log will not truncate The `log_reuse_wait_desc` column of `sys.databases` reports what truncation was waiting on at the last checkpoint. Common values: - `NOTHING`: space is reusable. - `CHECKPOINT`: no checkpoint since the last truncation, usually transient. - `LOG_BACKUP`: FULL or BULK_LOGGED database waiting for its next log backup. - `ACTIVE_TRANSACTION`: a long-running or open transaction holds the log in every recovery model, SIMPLE included. - `AVAILABILITY_REPLICA`: an availability-group secondary has not yet received or redone the log. ## Fixing a runaway log 1. Read `recovery_model_desc` and `log_reuse_wait_desc` for the database. 2. Remove the cause: schedule log backups, end the stuck transaction, or repair the lagging replica. 3. Only then, if the file is far larger than normal working size, shrink it once with `DBCC SHRINKFILE`, and size it for the real peak so it does not grow again in small steps. Switching to SIMPLE to "fix" a FULL database breaks the log chain; after switching back, a full or differential backup is needed before log backups mean anything again.
- Why can a newly created SQL Server database in FULL recovery keep a small log until its first full backup?Until a full backup (or, after a switch from SIMPLE, a full or differential backup) starts the log chain, there is nothing a log backup could extend, so SQL Server reuses log space much as it does under SIMPLE. Once that first backup exists, truncation waits for log backups, and that is often when an unmonitored log starts to grow.
- In SQL Server, log_reuse_wait_desc shows ACTIVE_TRANSACTION on a SIMPLE-recovery database. What does that mean, and what do you do?An open transaction holds the start of the active log, so even SIMPLE's checkpoint truncation cannot free anything after it. Find the oldest open transaction with DBCC OPENTRAN or sys.dm_tran_database_transactions, then commit, roll back or kill it; space becomes reusable at the next checkpoint. Changing the recovery model would not help.
- A full database backup truncates the log in the FULL recovery model.
- Shrinking the log file fixes a log that keeps growing.
- The SIMPLE recovery model means SQL Server writes no transaction log.
- BULK_LOGGED removes the need for log backups during bulk loads.
- Switching to SIMPLE and back to FULL leaves log backups restorable as before.