Skip to content

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

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
  • No new rows in CDC change tables (CT tables)
  • Downstream integrations stop triggering even though source data changes
  • sys.dm_cdc_errors contains log scan errors (commonly 22859)
  • sys.dm_cdc_log_scan_sessions shows increasing error_count or stalled progress
  • cdc.lsn_time_mapping stops advancing

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)”
SELECT name, is_cdc_enabled
FROM sys.databases
WHERE name = DB_NAME();

Expected: is_cdc_enabled = 1.

SELECT TOP (20)
start_lsn,
tran_begin_time,
tran_end_time
FROM cdc.lsn_time_mapping
ORDER BY tran_end_time DESC;

If tran_end_time does not move forward while you know source data changes, CDC is stalled.


SELECT TOP (50)
entry_time,
error_number,
error_severity,
error_message
FROM sys.dm_cdc_errors
ORDER 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_time
FROM [<DB>].[cdc].[<CaptureInstance_CT>] AS cdc_capture
JOIN cdc.lsn_time_mapping AS lsn_mapping
ON cdc_capture.__$start_lsn = lsn_mapping.start_lsn
ORDER BY cdc_capture.__$start_lsn ASC;
SELECT TOP (50)
start_time,
end_time,
error_count,
scan_phase,
start_lsn,
end_lsn
FROM sys.dm_cdc_log_scan_sessions
ORDER BY start_time DESC;

CDC is considered stuck when:

  • error_count increases
  • scan_phase does not progress
  • start_lsn / end_lsn do 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 name
FROM msdb.dbo.sysjobs
WHERE 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_changes
FROM cdc.change_tables AS ct
ORDER BY ct.source_schema, ct.source_name;

Store this output safely before proceeding.


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_changes exactly as recorded (0 or 1).

SELECT TOP (20)
start_lsn,
tran_end_time
FROM cdc.lsn_time_mapping
ORDER BY tran_end_time DESC;

Expected: tran_end_time moves forward over time.

SELECT TOP (20)
entry_time,
error_number,
error_message
FROM sys.dm_cdc_errors
ORDER BY entry_time DESC;

Expected: no repeated new 22859 entries after recovery.

If you can safely observe or trigger a change in a captured source table, confirm the corresponding CT table receives new entries.


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.


  • Capture job not running / repeated failures
  • New errors in sys.dm_cdc_errors (especially 22859)
  • sys.dm_cdc_log_scan_sessions.error_count > 0 for recent sessions
  • cdc.lsn_time_mapping has not updated within X minutes

Recent sessions with errors:

SELECT TOP (20)
start_time,
end_time,
error_count,
scan_phase,
start_lsn,
end_lsn
FROM sys.dm_cdc_log_scan_sessions
WHERE error_count > 0
ORDER BY start_time DESC;

Latest CDC errors:

SELECT TOP (20)
entry_time,
error_number,
error_message
FROM sys.dm_cdc_errors
ORDER BY entry_time DESC;

LSN mapping freshness:

SELECT TOP (1)
tran_end_time
FROM cdc.lsn_time_mapping
ORDER BY tran_end_time DESC;
  • 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_tables per environment (inventory)

Key system objects:

ObjectPurpose
cdc.change_tablesMetadata for all CDC-enabled tables
cdc.captured_columnsColumns being tracked per capture instance
cdc.lsn_time_mappingMaps LSN values to wall-clock timestamps
cdc.ddl_historyDDL changes on captured tables
sys.databases (is_cdc_enabled)Database-level CDC flag

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 DatabaseState
FROM sys.databases
WHERE 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.tables
SELECT
OBJECT_NAME(object_id) AS TableName,
is_tracked_by_cdc AS CDC_Enabled
FROM sys.tables
WHERE OBJECT_NAME(object_id) = 'TargetTable'; -- Replace with your table name
-- Method 2: cdc.change_tables
SELECT
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_changes
FROM cdc.change_tables ct
WHERE OBJECT_NAME(ct.source_object_id) = 'TargetTable'; -- Replace with your table name
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_name
FROM cdc.change_tables ct
ORDER BY SchemaName, SourceTableName;
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_computed
FROM cdc.change_tables ct
JOIN cdc.captured_columns cc
ON ct.object_id = cc.object_id
ORDER BY ct.capture_instance, cc.column_ordinal;

-- Must be run in the context of the target database
USE [YourDatabaseName];
GO
EXEC sys.sp_cdc_enable_db;
GO
-- Verify
SELECT name, is_cdc_enabled
FROM sys.databases
WHERE 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 data
GO
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 columns

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 table
GO
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 dropped
GO
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;
GO

-- Check retention for capture and cleanup jobs
EXEC sys.sp_cdc_help_jobs;
GO
-- 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 = 43200
GO
-- Verify the change
EXEC sys.sp_cdc_help_jobs;
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 cleanup
GO

-- View all CDC Agent jobs and their last run status
SELECT
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 LastMessage
FROM msdb.dbo.sysjobs j
JOIN msdb.dbo.sysjobhistory jh
ON j.job_id = jh.job_id
AND jh.step_id = 0 -- Step 0 = job-level outcome
WHERE j.name LIKE 'cdc.%'
ORDER BY jh.run_date DESC, jh.run_time DESC;
USE [YourDatabaseName];
GO
-- Returns capture and cleanup job configurations
EXEC sys.sp_cdc_help_jobs;
GO

Output columns explained:

ColumnJob TypeDescription
maxtransCaptureMax transactions processed per scan cycle
maxscansCaptureMax log scan cycles per capture job execution
continuousCapture1 = run continuously; 0 = run once per Agent schedule
pollingintervalCaptureSeconds between log scans (when continuous = 1)
retentionCleanupMinutes of change data to keep
thresholdCleanupMax deletes per cleanup transaction
USE [YourDatabaseName];
GO
-- Stop the capture job
EXEC sys.sp_cdc_stop_job @job_type = N'capture';
GO
-- Stop the cleanup job
EXEC sys.sp_cdc_stop_job @job_type = N'cleanup';
GO
-- Start the capture job
EXEC sys.sp_cdc_start_job @job_type = N'capture';
GO
-- Start the cleanup job
EXEC sys.sp_cdc_start_job @job_type = N'cleanup';
GO