Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
SQL

SQL Server: Fix a CDC Job Falling Behind After Log Truncate

- 24.11.26 - ErcanOPAK

🗄️ 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.

— Database Engineer

Related posts:

SQL Server: Fix a Foreign Key Constraint Allowing an Update That Should Have Failed Because It Was C...

SQL Server: Fix a Foreign Key Constraint Allowing an Update That Should Have Failed Because It Was C...

Not Null check on LEFT function with T-SQL

Not Null check on LEFT function with T-SQL

SQL Server: Why a Computed Column Can't Be Indexed Until You Mark It PERSISTED

SQL Server: Why a Computed Column Can't Be Indexed Until You Mark It PERSISTED

Views: 13
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

Asp.Net Core: Fix Rate Limiting Resetting on Every Deploy
Asp.Net Core: Fix Model Binding Ignoring a Renamed Query Param

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,080 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 868 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 672 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 585 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 562 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com