🗄️ SQL Server: Fix a CDC Job Falling Behind After Log Truncate
Change Data Capture relies on its own capture job continuously reading new entries from the transaction log before SQL Server’s regular log truncation, on checkpoint under simple recovery, or after a log backup under full recovery, removes them, and that capture job runs asynchronously on its own schedule rather than synchronously with every transaction. A spike in write volume, or the capture job’s Agent job being paused or failing silently, lets the log grow past what the capture job has actually consumed, and once a truncation point passes before it catches up, the unread log records are gone permanently rather than just delayed, leaving a silent gap in CDC’s change data for that table.
🔎 The Problem
-- Capture job's Agent job silently disabled or failing: EXEC sys.sp_cdc_help_jobs; -- job_type = 'capture', last run shows failures or far behind SELECT MAX(tran_begin_time) AS newest_captured_change FROM cdc.lsn_time_mapping; -- If this is hours behind sys.fn_cdc_get_max_lsn(), and a -- log backup or checkpoint has already truncated the gap -- between them, those change records cannot be recovered - -- CDC's change table will simply be missing that window
✅ Fix: Monitor Lag Against the Truncation Boundary
- Monitor the capture job’s actual lag using sys.sp_cdc_help_jobs and compare cdc.lsn_time_mapping’s newest entry against current time on a schedule, alerting well before the gap approaches how far back log truncation under the configured recovery model can reach.
- Keep the capture job’s SQL Server Agent job itself monitored for failures, not just its lag, since a stopped job and a slow job produce the exact same growing-lag symptom but need different fixes.
- Size the transaction log and log backup frequency with CDC’s consumption rate in mind, since a backup schedule tuned only for point-in-time recovery, with no regard for how far behind the capture job typically runs, can truncate change data it hasn’t read yet even in a technically healthy database.
🚨 Why This Is Dangerous
- A gap in captured changes doesn’t raise an error anywhere in CDC itself; downstream consumers like an ETL pipeline or a replication target simply never receive the missing rows, and the first sign of trouble is usually a data reconciliation mismatch discovered much later.
CDC’s capture job has to win a race against log truncation on every single transaction — falling behind doesn’t pause the race, it just means the log wins and the change is gone.



