SQL CDC stopped processing
This runbook helps you troubleshoot and recover SQL Server Change Data Capture (CDC) when it stops producing changes (for example when log scanning fails and CT tables stop updating).
It is designed for incident response:
- environment agnostic (no hard-coded DB names)
- copy/paste friendly SQL
- clear separation between read-only diagnosis and recovery actions
Decision flow
Section titled “Decision flow”If your documentation site has Mermaid enabled, this diagram will render. Otherwise it will show as a code block.
flowchart LR
A[CT tables not updating - integrations stalled] --> B[Confirm CDC stalled]
B --> C{sys.dm_cdc_errors shows 22859}
C -->|No| D[Continue diagnosis - jobs, permissions, cleanup pressure]
C -->|Yes| E[Restart capture job once]
E --> F{Recovered}
F -->|Yes| G[Verify and close incident]
F -->|No| H[Preserve CDC configuration]
H --> I[Reinitialize CDC for affected capture instance]
I --> G
Typical symptoms
Section titled “Typical symptoms”- No new rows in CDC change tables (CT tables)
- Downstream integrations stop triggering even though source data changes
sys.dm_cdc_errorscontains log scan errors (commonly 22859)sys.dm_cdc_log_scan_sessionsshows increasingerror_countor stalled progresscdc.lsn_time_mappingstops advancing
Why this happens (common root cause)
Section titled “Why this happens (common root cause)”CDC tracks progress using Log Sequence Numbers (LSNs). If the transaction log chain changes (restore, failover, log rebuild, truncation or maintenance), the CDC log reader may lose access to the expected LSN and get stuck retrying.
Typical outcome:
- error 22859 appears repeatedly
- capture job may keep running but makes no progress
- CT tables stop updating until CDC is reinitialized for affected capture instance(s)
Phase 0 — Confirm CDC is stalled (read-only)
Section titled “Phase 0 — Confirm CDC is stalled (read-only)”0.1 Verify CDC enabled at database level
Section titled “0.1 Verify CDC enabled at database level”SELECT name, is_cdc_enabledFROM sys.databasesWHERE name = DB_NAME();Expected: is_cdc_enabled = 1.
0.2 Verify LSN progress
Section titled “0.2 Verify LSN progress”SELECT TOP (20) start_lsn, tran_begin_time, tran_end_timeFROM cdc.lsn_time_mappingORDER BY tran_end_time DESC;If tran_end_time does not move forward while you know source data changes, CDC is stalled.
Phase 1 — Diagnose (read-only)
Section titled “Phase 1 — Diagnose (read-only)”1.1 Check CDC errors
Section titled “1.1 Check CDC errors”SELECT TOP (50) entry_time, error_number, error_severity, error_messageFROM sys.dm_cdc_errorsORDER BY entry_time DESC;Look for:
- repeated errors over time
error_number = 22859(Log Scan process failed)
If you would like to check the ct-tables content and decide when the latest row were created, use the following:
SELECT TOP 1 cdc_capture.__$start_lsn, lsn_mapping.tran_begin_time, lsn_mapping.tran_end_timeFROM [<DB>].[cdc].[<CaptureInstance_CT>] AS cdc_captureJOIN cdc.lsn_time_mapping AS lsn_mapping ON cdc_capture.__$start_lsn = lsn_mapping.start_lsnORDER BY cdc_capture.__$start_lsn ASC;1.2 Inspect log scan sessions
Section titled “1.2 Inspect log scan sessions”SELECT TOP (50) start_time, end_time, error_count, scan_phase, start_lsn, end_lsnFROM sys.dm_cdc_log_scan_sessionsORDER BY start_time DESC;CDC is considered stuck when:
error_countincreasesscan_phasedoes not progressstart_lsn/end_lsndo not advance across sessions
1.3 Check SQL Server Agent jobs (capture + cleanup)
Section titled “1.3 Check SQL Server Agent jobs (capture + cleanup)”List CDC-related jobs:
SELECT nameFROM msdb.dbo.sysjobsWHERE name LIKE 'cdc.%'ORDER BY name;Confirm:
- capture job exists and is not failing repeatedly
- cleanup job exists and is running on schedule
1.4 Identify capture instances and preserve configuration (REQUIRED)
Section titled “1.4 Identify capture instances and preserve configuration (REQUIRED)”This output is your “backup” for re-enabling CDC correctly.
SELECT ct.capture_instance, ct.source_schema, ct.source_name, ct.role_name, ct.filegroup_name, ct.captured_column_list, ct.supports_net_changesFROM cdc.change_tables AS ctORDER BY ct.source_schema, ct.source_name;Store this output safely before proceeding.
Phase 2 — Recovery
Section titled “Phase 2 — Recovery”Start with the least invasive option.
Option A — Restart the capture job (try once)
Section titled “Option A — Restart the capture job (try once)”Restart the capture job in SQL Server Agent UI.
If you restart via T-SQL, use the job name you discovered in Phase 1:
EXEC msdb.dbo.sp_start_job @job_name = N'<CDC_CAPTURE_JOB_NAME>';Then proceed to Phase 3 — Verification.
Option B — Reinitialize affected capture instance(s)
Section titled “Option B — Reinitialize affected capture instance(s)”B1) Disable CDC for the affected capture instance
Section titled “B1) Disable CDC for the affected capture instance”EXEC sys.sp_cdc_disable_table @source_schema = N'<RECORDED_SOURCE_SCHEMA>', @source_name = N'<RECORDED_SOURCE_TABLE>', @capture_instance = N'<RECORDED_CAPTURE_INSTANCE>';B2) Re-enable CDC using preserved configuration
Section titled “B2) Re-enable CDC using preserved configuration”EXEC sys.sp_cdc_enable_table @source_schema = N'<RECORDED_SOURCE_SCHEMA>', @source_name = N'<RECORDED_SOURCE_TABLE>', @role_name = N'<RECORDED_ROLE_NAME_OR_NULL>', @filegroup_name = N'<RECORDED_FILEGROUP_OR_NULL>', @captured_column_list = N'<RECORDED_CAPTURED_COLUMN_LIST_OR_NULL>', @supports_net_changes = <0_OR_1>;Notes:
- If a recorded value was NULL before, keep it NULL.
- Keep
supports_net_changesexactly as recorded (0or1).
Phase 3 — Verification
Section titled “Phase 3 — Verification”3.1 Confirm LSN mapping advances
Section titled “3.1 Confirm LSN mapping advances”SELECT TOP (20) start_lsn, tran_end_timeFROM cdc.lsn_time_mappingORDER BY tran_end_time DESC;Expected: tran_end_time moves forward over time.
3.2 Confirm errors stop increasing
Section titled “3.2 Confirm errors stop increasing”SELECT TOP (20) entry_time, error_number, error_messageFROM sys.dm_cdc_errorsORDER BY entry_time DESC;Expected: no repeated new 22859 entries after recovery.
3.3 Confirm CT tables receive new rows
Section titled “3.3 Confirm CT tables receive new rows”If you can safely observe or trigger a change in a captured source table, confirm the corresponding CT table receives new entries.
Optional: Controlled test change
Section titled “Optional: Controlled test change”If safe:
- perform a small, controlled update in a captured table
- verify the CT table gets a new row shortly after
Only do this if you have a safe procedure to avoid business impact.
Prevention / Monitoring
Section titled “Prevention / Monitoring”Recommended alerts
Section titled “Recommended alerts”- Capture job not running / repeated failures
- New errors in
sys.dm_cdc_errors(especially 22859) sys.dm_cdc_log_scan_sessions.error_count > 0for recent sessionscdc.lsn_time_mappinghas not updated within X minutes
Useful monitoring queries
Section titled “Useful monitoring queries”Recent sessions with errors:
SELECT TOP (20) start_time, end_time, error_count, scan_phase, start_lsn, end_lsnFROM sys.dm_cdc_log_scan_sessionsWHERE error_count > 0ORDER BY start_time DESC;Latest CDC errors:
SELECT TOP (20) entry_time, error_number, error_messageFROM sys.dm_cdc_errorsORDER BY entry_time DESC;LSN mapping freshness:
SELECT TOP (1) tran_end_timeFROM cdc.lsn_time_mappingORDER BY tran_end_time DESC;Operational guidance
Section titled “Operational guidance”- Plan restore/failover/log maintenance with CDC impact in mind
- After log chain impacting work, validate CDC (Phase 0 + Phase 1)
- Keep a periodic export of
cdc.change_tablesper environment (inventory)
CDC reference
Section titled “CDC reference”Key system objects:
| Object | Purpose |
|---|---|
cdc.change_tables | Metadata for all CDC-enabled tables |
cdc.captured_columns | Columns being tracked per capture instance |
cdc.lsn_time_mapping | Maps LSN values to wall-clock timestamps |
cdc.ddl_history | DDL changes on captured tables |
sys.databases (is_cdc_enabled) | Database-level CDC flag |
Check CDC status
Section titled “Check CDC status”Check whether CDC is enabled at the database level
Section titled “Check whether CDC is enabled at the database level”SELECT name AS DatabaseName, is_cdc_enabled AS CDC_Enabled, recovery_model_desc AS RecoveryModel, state_desc AS DatabaseStateFROM sys.databasesWHERE name = DB_NAME();Check whether CDC is enabled for a specific table
Section titled “Check whether CDC is enabled for a specific table”-- Method 1: sys.tablesSELECT OBJECT_NAME(object_id) AS TableName, is_tracked_by_cdc AS CDC_EnabledFROM sys.tablesWHERE OBJECT_NAME(object_id) = 'TargetTable'; -- Replace with your table name
-- Method 2: cdc.change_tablesSELECT ct.capture_instance, OBJECT_SCHEMA_NAME(ct.source_object_id) AS SchemaName, OBJECT_NAME(ct.source_object_id) AS TableName, ct.start_lsn, ct.supports_net_changesFROM cdc.change_tables ctWHERE OBJECT_NAME(ct.source_object_id) = 'TargetTable'; -- Replace with your table nameList all CDC-enabled tables
Section titled “List all CDC-enabled tables”SELECT ct.capture_instance, OBJECT_SCHEMA_NAME(ct.source_object_id) AS SchemaName, OBJECT_NAME(ct.source_object_id) AS SourceTableName, ct.start_lsn, ct.supports_net_changes, ct.role_name AS GatingRoleName, OBJECT_NAME(ct.object_id) AS ChangeTableName, ct.filegroup_name, ct.index_nameFROM cdc.change_tables ctORDER BY SchemaName, SourceTableName;List all CDC capture instances
Section titled “List all CDC capture instances”SELECT ct.capture_instance, OBJECT_SCHEMA_NAME(ct.source_object_id) AS SchemaName, OBJECT_NAME(ct.source_object_id) AS SourceTable, cc.column_name, cc.column_ordinal, cc.column_type, cc.is_computedFROM cdc.change_tables ctJOIN cdc.captured_columns cc ON ct.object_id = cc.object_idORDER BY ct.capture_instance, cc.column_ordinal;Enable CDC
Section titled “Enable CDC”Enable CDC on a database
Section titled “Enable CDC on a database”-- Must be run in the context of the target databaseUSE [YourDatabaseName];GO
EXEC sys.sp_cdc_enable_db;GO
-- VerifySELECT name, is_cdc_enabledFROM sys.databasesWHERE name = DB_NAME();Enable CDC on a table with default options
Section titled “Enable CDC on a table with default options”USE [YourDatabaseName];GO
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'targetTable', @role_name = NULL; -- NULL = no gating role, any db user can read CDC dataGOEnable CDC on a table with options
Section titled “Enable CDC on a table with options”EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'TargetTable', @role_name = N'roll_name', --roll name that can read the CDC data @supports_net_changes = 1, @captured_column_list = N'column1, column2, column3, column4'; -- the target columnsDisable CDC
Section titled “Disable CDC”Disable CDC for a specific table (all capture instances)
Section titled “Disable CDC for a specific table (all capture instances)”USE [YourDatabaseName];GO
EXEC sys.sp_cdc_disable_table @source_schema = N'dbo', @source_name = N'TargetTable', @capture_instance = N'all'; -- 'all' disables all instances for this tableGODisable a specific capture instance
Section titled “Disable a specific capture instance”USE [YourDatabaseName];GO
EXEC sys.sp_cdc_disable_table @source_schema = N'dbo', @source_name = N'TargetTable', @capture_instance = N'dbo_TargetTable_v1'; -- Only this instance is droppedGODisable CDC at the database level
Section titled “Disable CDC at the database level”USE [YourDatabaseName];GO
-- WARNING: This drops ALL change tables, ALL CDC metadata, and removes CDC Agent jobs.-- This action is IRREVERSIBLE without restoring from backup.EXEC sys.sp_cdc_disable_db;GOCDC retention and cleanup
Section titled “CDC retention and cleanup”Check current CDC retention settings
Section titled “Check current CDC retention settings”-- Check retention for capture and cleanup jobsEXEC sys.sp_cdc_help_jobs;GOChange CDC retention time
Section titled “Change CDC retention time”-- Default retention is 4320 minutes (3 days).-- Change to 10080 minutes (7 days):USE [YourDatabaseName];GO
EXEC sys.sp_cdc_change_job @job_type = N'cleanup', @retention = 10080; -- Minutes. 7 days = 10080; 14 days = 20160; 30 days = 43200GO
-- Verify the changeEXEC sys.sp_cdc_help_jobs;Configure the cleanup job
Section titled “Configure the cleanup job”USE [YourDatabaseName];GO
EXEC sys.sp_cdc_change_job @job_type = N'cleanup', @retention = 10080, -- 7 days in minutes @threshold = 5000; -- Max rows deleted per cleanup transaction -- Lower = less blocking; higher = faster cleanupGOCDC jobs and status
Section titled “CDC jobs and status”Check CDC capture job status
Section titled “Check CDC capture job status”-- View all CDC Agent jobs and their last run statusSELECT j.name AS JobName, j.enabled AS IsEnabled, jh.run_status, -- 0=Failed, 1=Succeeded, 2=Retry, 3=Canceled, 4=Running msdb.dbo.agent_datetime(jh.run_date, jh.run_time) AS LastRunTime, jh.run_duration, -- HHMMSS format jh.message AS LastMessageFROM msdb.dbo.sysjobs jJOIN msdb.dbo.sysjobhistory jh ON j.job_id = jh.job_id AND jh.step_id = 0 -- Step 0 = job-level outcomeWHERE j.name LIKE 'cdc.%'ORDER BY jh.run_date DESC, jh.run_time DESC;Check detailed CDC job parameters
Section titled “Check detailed CDC job parameters”USE [YourDatabaseName];GO
-- Returns capture and cleanup job configurationsEXEC sys.sp_cdc_help_jobs;GOOutput columns explained:
| Column | Job Type | Description |
|---|---|---|
maxtrans | Capture | Max transactions processed per scan cycle |
maxscans | Capture | Max log scan cycles per capture job execution |
continuous | Capture | 1 = run continuously; 0 = run once per Agent schedule |
pollinginterval | Capture | Seconds between log scans (when continuous = 1) |
retention | Cleanup | Minutes of change data to keep |
threshold | Cleanup | Max deletes per cleanup transaction |
Start and stop CDC jobs
Section titled “Start and stop CDC jobs”USE [YourDatabaseName];GO
-- Stop the capture jobEXEC sys.sp_cdc_stop_job @job_type = N'capture';GO
-- Stop the cleanup jobEXEC sys.sp_cdc_stop_job @job_type = N'cleanup';GO
-- Start the capture jobEXEC sys.sp_cdc_start_job @job_type = N'capture';GO
-- Start the cleanup jobEXEC sys.sp_cdc_start_job @job_type = N'cleanup';GO