# First 15 Minutes: CDC Troubleshooting

Page title: First 15 Minutes of a CDC Incident

> A repeatable first-15-minutes playbook to triage Change Data Capture incidents across Postgres, MySQL, Oracle, Kafka/Debezium, and common sinks.

Canonical page: <https://sandgraal.github.io/letstalkcdc/troubleshooting/>

A repeatable triage to stabilize incidents fast. Keep it pragmatic, measurable, and reversible.

## Quick Triage (5–8 minutes)

1. **Freeze changes** that make state drift: pause [backfills](https://sandgraal.github.io/letstalkcdc/glossary/#backfill), schema changes, and connector restarts.
2. **Define the failure mode**: *stuck* (no progress), *slow* (lag growing), *wrong* (duplicates, missing rows), or *crashing*.
3. **Bound the blast radius**: single table/tenant vs global; snapshot vs stream.
4. **Checkpoint evidence** (timestamps, connector name, offsets, group id). Don’t tail logs without writing down the top lines you see.
5. **Choose a safety**: if logs are at risk of rotating out, extend retention (WAL/binlog/redo) before touching the pipeline.

Goal: stop data loss, capture proof, buy time. Detailed checks below.

## Artifacts to Collect (Copy/Paste)

- Versions: source db, connector (Debezium), broker (Kafka/Redpanda), sink
- Connector config (sanitized): include snapshot mode, includes/excludes, heartbeat
- Exact error lines: 20–50 lines around the first failure
- Lag/offsets: consumer group lag and last committed LSN/GTID/SCN
- Log retention settings: WAL/binlog/redo retention and current oldest log

****Commands****

Kafka (Consumer Lag)

```
kafka-consumer-groups --bootstrap-server <host:port> \
  --describe --group <your-sink-group>
```

Connect (Connector Status)

```
curl -s http://<connect-host:8083>/connectors | jq
curl -s http://<connect-host:8083>/connectors/<name>/status | jq
```

## Stabilize First

- Ensure source logs retained ≥ time to fix + snapshot duration
- Enable DLQ (or equivalent) to prevent silent drops
- Reduce parallelism if source is choking (snapshot & stream task counts)
- If duplicates are appearing, convert sink writes to *idempotent* upserts (MERGE/UPSERT) immediately

## Postgres Quick Checks

****Configuration + Health****

```
-- WAL & slots
SHOW wal_level;                -- should be 'logical'
SHOW max_wal_senders;          -- >= number of replication clients
SHOW max_replication_slots;    -- >= slots in use
SELECT slot_name, active, restart_lsn, confirmed_flush_lsn
FROM pg_replication_slots;

-- retention & pressure
SHOW max_slot_wal_keep_size;   -- cap on WAL a slot may retain; -1 = unlimited
SELECT slot_name, wal_status,  -- on the primary
       pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained_by_slot
FROM pg_replication_slots;

-- lag (if using logical slot)
SELECT pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained_from_slot
FROM pg_replication_slots WHERE slot_name='<slot>';
```

****Common Symptoms → First Aid****

- *Snapshot stalls:* reduce fetch size; whitelist fewer tables; ensure long-running txns aren’t blocking.
- *Slot disk pressure:* sink caught behind → raise sink throughput or pause snapshot; never drop the slot without a plan. See the [replication slot runbook](https://sandgraal.github.io/letstalkcdc/postgres-replication-slots/).
- *Missing updates:* replica identity not full on keyless tables → set `REPLICA IDENTITY FULL` where needed.

## MySQL Quick Checks

****Configuration + Health****

```
-- binlog mode
SHOW VARIABLES LIKE 'binlog_format';       -- should be ROW
SHOW VARIABLES LIKE 'binlog_row_image';    -- FULL or MINIMAL (know your connector's needs)
SHOW VARIABLES LIKE 'gtid_mode';           -- ON preferred
SHOW MASTER STATUS;                         -- file/pos + executed GTID set

-- retention (8.0+)
SHOW VARIABLES LIKE 'binlog_expire_logs_seconds';

-- heartbeat/throughput
SHOW GLOBAL STATUS LIKE 'Binlog_cache_disk_use';
```

****Common Symptoms → First Aid****

- *Duplicates after restart:* sink not idempotent → change inserts to MERGE/UPSERT with stable pk + version.
- *Lost history:* binlogs expired during snapshot → extend expire window; restart from fresh snapshot. See the [MySQL and SQL Server runbooks](https://sandgraal.github.io/letstalkcdc/sql-server-mysql-cdc/).
- *DDL breakage:* add `include.schema.changes` (if supported) and verify sink DDL policy.

## Oracle Quick Checks

Background and tuning: [Vendor Nuances — Oracle CDC](https://sandgraal.github.io/letstalkcdc/oracle-notes/).

****Configuration + Health****

```
-- supplemental logging
SELECT supplemental_log_data_min, supplemental_log_data_all FROM v$database;
-- database log mode
SELECT log_mode FROM v$database;            -- ARCHIVELOG recommended for CDC
-- redo switch & archive status
SELECT sequence#, archived, status FROM v$log ORDER BY first_time DESC FETCH FIRST 5 ROWS ONLY;
-- confirm key columns logging for keyless tables (optional)
SELECT * FROM dba_log_groups WHERE LOG_GROUP_TYPE IN ('ALL COLUMN LOGGING','PRIMARY KEY LOGGING');
```

****Common Symptoms → First Aid****

- *High redo churn:* throttle snapshot/table set; ensure filters aren’t too broad.
- *Missed updates:* missing supplemental logging for key columns → add minimal or table-level logging, resnapshot.
- *Catalog mode mismatch after upgrade:* re-check connector’s catalog strategy defaults before restart.

## Kafka / Connect Quick Checks

****Status & Lag****

```
# list & inspect
curl -s http://<connect:8083>/connectors | jq
curl -s http://<connect:8083>/connectors/<name>/status | jq

# consumer lag (sink)
kafka-consumer-groups --bootstrap-server <host:port> \
  --describe --group <your-sink-group>

# safe restart of a sick task
curl -s -XPOST http://<connect:8083>/connectors/<name>/tasks/0/restart
```

****Common Symptoms → First Aid****

- *Connector crash loops:* identify first error, enable DLQ (`errors.tolerance=all` + DLQ topic), then fix offending table.
- *Slow ingestion:* increase tasks up to source limits; ensure topic partitions ≥ parallelism; watch sink bottlenecks first.
- *Out-of-order within key:* ensure producer uses key-aware partitioner; keep per-key ordering on the sink merge path.

## Sink Verification (Duplicates / Missing Rows)

### Duplicate Primary Keys

```
-- generic template (replace table/pk)
SELECT COUNT(*) AS rows,
       COUNT(DISTINCT pk) AS distinct_keys
FROM target_table;
```

### Latest-Wins Check

```
-- is the target behind the newest log position seen in history?
WITH last AS (
  SELECT key_col, MAX(source_lsn) AS last_lsn
  FROM history_table
  GROUP BY key_col
)
SELECT COUNT(*) AS stale
FROM target_table t
JOIN last l ON t.key_col = l.key_col
WHERE t.source_lsn < l.last_lsn;   -- expect 0
```

If duplicates or stale rows exist, convert the sink write to an idempotent MERGE keyed on the primary key and guarded on the source log position, then re-run the last N events.

## When to Escalate

- Source log gap detected (WAL/binlog/redo missing) and you can’t reconstruct from another source → plan a clean [resnapshot](https://sandgraal.github.io/letstalkcdc/snapshotting/).
- Schema/key change incompatible with current sink merge logic → schedule maintenance window for transform + backfill.
- Security/privileges prevent enabling required logging → involve DBAs (don’t keep retrying the connector).

## Build Troubleshooting Muscle Memory

Want to practice these scenarios in a safe lab environment? Check out our [**Failure Scenario Drills**](https://sandgraal.github.io/letstalkcdc/troubleshooting/failure-drills/) — hands-on exercises that let you intentionally break your CDC pipeline and learn how to fix it.

- **Backpressure simulation:** Shut down sink, observe lag metrics
- **DLQ exercise:** Inject bad data, trigger serialization errors
- **Schema drift:** Test incompatible column changes ([Schema Evolution](https://sandgraal.github.io/letstalkcdc/schema-evolution/))
- **Offset replay:** Wipe offsets, observe snapshot + stream behavior

Running these drills quarterly keeps your incident response sharp and validates your monitoring setup.

## Acceptance for “Stabilized”

- Consumer lag is flat or shrinking for 30 minutes
- Latest offsets/LSN/GTID/SCN are advancing
- DLQ is empty or only contains triaged, expected errors
- Duplicate-PK query shows **rows == distinct_keys**
- A controlled connector restart does *not* create new duplicates

---

CDC: The Missing Manual by Christopher Ennis (Let's Talk CDC), licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Attribution is required.
