liveBook · Manning

Log truncation

As explained in 100 SQL Server Mistakes and How to Avoid Them

Log truncation is the process of marking obsolete transaction-log portions for reuse after they are no longer required for recovery or other database operations.

Log truncation marks transaction-log portions for reuse after they are no longer needed. A common mistake is choosing SIMPLE recovery for every production OLTP database merely because the log might fill the disk. With FULL recovery, regular transaction-log backups normally prevent continuous growth; if a backup does not truncate the log, investigate the reuse blocker instead of changing recovery models. section 12.7

Check the reason before prescribing a fix:

  • Run the log-reuse diagnostic query and look for transient blockers such as a missing checkpoint, an active backup or restore, or a database snapshot. section 12.7
  • Investigate repeated ACTIVE_TRANSACTION waits: long-running transactions can grow the log and also contribute to lock contention or deadlocks. section 12.7
  • Treat persistent REPLICATION or AVAILABILITY_REPLICA waits as signs that transactions are still being applied to secondary databases. section 12.7
Listing 12.6 Exploring the reason the log was not truncated
SELECT
     name
   , log_reuse_wait_desc
FROM sys.databases ;

Use the sys.databases query to identify why the previous truncation attempt did not release log space. section 12.7

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Explains reuse blockers and diagnostic queries, but stops short of detailed truncation internals.
Examples
Uses production OLTP log growth, failed truncation attempts, and sys.databases diagnostics as concrete examples.
What it assumes
Assumes basic transaction-log and recovery-model knowledge while demonstrating how to investigate reuse waits.
What you can do after
Diagnose truncation delays with SQL and investigate recurring blockers before changing recovery models.
How it connects
Connects log truncation with recovery models, transaction-log backups, checkpoints, long-running transactions, replication, and availability replicas.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.