# Vendor Nuances — Oracle CDC

> Oracle Change Data Capture: prerequisites, quick checks, performance knobs, and troubleshooting playbook for log-based CDC (LogMiner/replication readers).

Canonical page: <https://sandgraal.github.io/letstalkcdc/oracle-notes/>

> **Known errata for this page (1)**
>
> - **Corrected: an Oracle SCN alone is not a safe guard** (updated 2026-10-12)
>
>   The first-aid list said to guard the sink on the source log position (SCN), and the latest-wins check took `MAX(source_scn)` per key. The partitioning and materialization pages already say that an Oracle `scn` can repeat across changes in one transaction, so a single SCN can tie. The guard and the check now use a (position, tie-break) pair, where the tie-break is `rs_id` and `ssn` or your own within-transaction ordinal (verify the ordering semantics for your Debezium version). The SCN and commit timestamp the page asks you to expose are for lag metrics only, never for ordering. The tie-break is a single orderable column: if you use both `rs_id` and `ssn`, compare them as separate columns (`rs_id` is a string) and do not concatenate them as text. The Oracle quickstart's acceptance line said latest-wins by SCN alone and now says (SCN, tie-break). The Oracle SQL on the page is now labelled as not run against an Oracle database.
>
> [See all corrections and caveats](https://sandgraal.github.io/letstalkcdc/errata/)

[← Back to Quickstarts](https://sandgraal.github.io/letstalkcdc/quickstarts/)

# Vendor Nuances — Oracle (Log-Based CDC)

Practical prerequisites, quick checks, performance knobs, and a “first-aid” section for common failures.

## What you must have before turning on CDC

- **Database in ARCHIVELOG** mode (recommended for CDC resiliency).
- **Supplemental logging** enabled (database-level minimal; table-level as needed for keys/columns used in merges).
- **Privileges**: read data dictionary views, redo/archive logs, target tables; ability to create log groups if required.
- **Redo retention** sized for snapshot + catch-up window (avoid log switch storms during backfills).
- **Stable primary keys** (or explicit “replica identity full” equivalents via table log groups for keyless tables).

## Quick Health Checks (copy/paste)

**Untested: not run against an Oracle database.** This repository has no Oracle in its test setup; try these on a test instance first.

### Archivelog & Redo Status

```
SELECT log_mode FROM v$database;
SELECT sequence#, bytes/1024/1024 MB, archived, status
FROM v$log ORDER BY first_time DESC FETCH FIRST 10 ROWS ONLY;
```

### Supplemental Logging

```
-- database-wide
SELECT supplemental_log_data_min, supplemental_log_data_all FROM v$database;

-- table-level (confirm keys/columns logged for merges on keyless tables)
SELECT owner, table_name, log_group_name, always, log_group_type
FROM dba_log_groups
ORDER BY owner, table_name;
```

### Current Redo Pressure

```
SELECT TO_CHAR(first_time,'YYYY-MM-DD HH24:MI') AS first_time,
       COUNT(*) AS switches
FROM v$log_history
WHERE first_time > SYSDATE - 1/24   -- last hour
GROUP BY TO_CHAR(first_time,'YYYY-MM-DD HH24:MI')
ORDER BY 1 DESC;
```

## Connector Snapshot Sanity

- Scope restricted: include only necessary schemas/tables.
- Long-running transactions identified (they can stall snapshot start).
- Redo retention ≥ expected snapshot duration.
- If tables lack PKs, ensure table-level log groups capture enough columns for deterministic merges.

### Nice-to-have SQL for big snapshots

**Untested: not run against an Oracle database.**

```
-- largest tables by size
SELECT owner, segment_name, bytes/1024/1024 MB
FROM dba_segments
WHERE segment_type='TABLE'
ORDER BY bytes DESC FETCH FIRST 20 ROWS ONLY;
```

## Performance Knobs (choose carefully, measure after each change)

- **Redo log size & count:** larger logs reduce switch frequency during snapshots; too large can delay archiving.
- **Filter scope:** narrow includes to reduce LogMiner workload and topic chatter.
- **Task/worker parallelism:** increase only if the source and sink can keep up; watch redo/CPU.
- **Batch/fetch sizing:** tune connector fetch/commit sizes to match sink merge throughput.
- **LOB handling:** consider excluding or routing large LOB tables to a separate flow; they dominate redo and bandwidth.

## Common Failure → First Aid

- *Duplicates after restarts:* switch the sink to **idempotent** `MERGE/UPSERT` keyed by a primary key and guarded on the (position, tie-break) pair: the source log position (SCN) plus a single orderable tie-break column; if you use both `rs_id` and `ssn`, compare them as separate columns (`rs_id` is a string), as the [merge cookbook](https://sandgraal.github.io/letstalkcdc/merge-cookbook/) note explains: do not concatenate them as text. The tie-break is needed because the SCN can repeat across changes in one transaction (see [Making Sinks Bulletproof](https://sandgraal.github.io/letstalkcdc/partitioning/#recon)); then replay last N events.
- *Missed updates:* enable table-level supplemental logging for key columns (or all columns for keyless) and re-snapshot.
- *Dictionary mismatch / DDL errors:* pause, capture the DDL, align connector schema evolution settings, then resume from a safe SCN.
- *Redo switch storm:* reduce snapshot scope or increase redo log size; avoid concurrent heavy maintenance jobs.
- *SCN gaps / “log not found”:* extend archive retention; if a gap exists, plan a clean re-snapshot of affected tables.

## Observability

- Expose SCN / commit timestamp per event (headers/columns) all the way to the sink (for lag metrics only, never for ordering).
- Emit connector task metrics (lag, batches/sec, records/sec) and alert on flatlining progress.
- Dead-letter queue (DLQ) enabled with payload + error string for triage.

### Duplicate / Latest-wins Checks (sink)

**Untested: not run against an Oracle database.** The latest-wins query ranks by the (position, tie-break) pair, not by the SCN alone; `tie_break` stands for a single orderable column; if you use both `rs_id` and `ssn`, compare them as separate columns (`rs_id` is a string), as the [merge cookbook](https://sandgraal.github.io/letstalkcdc/merge-cookbook/) note explains: do not concatenate them as text. It can also be your own within-transaction ordinal (verify the ordering semantics for your Debezium version).

```
-- generic duplicate check (replace target & pk)
SELECT COUNT(*) AS rows, COUNT(DISTINCT pk) AS distinct_keys FROM target;

-- latest-wins per key by (position, tie-break), never by SCN alone
-- (replace names; tie_break = one orderable column, e.g. your own ordinal;
-- never rs_id and ssn concatenated as text)
SELECT business_id, source_scn AS last_scn, tie_break AS last_tie_break, events
FROM (
  SELECT business_id, source_scn, tie_break,
         COUNT(*) OVER (PARTITION BY business_id) AS events,
         ROW_NUMBER() OVER (PARTITION BY business_id
                            ORDER BY source_scn DESC, tie_break DESC) AS rn
  FROM history_or_stage
)
WHERE rn = 1;
```

## Upgrade Checklist

- Read the connector release notes for breaking changes (catalog strategies, snapshot defaults, DDL handling).
- Test on a staging database with archived logs; verify no duplicate PKs after a controlled restart.
- Capture before/after redo switch rates and connector lag to spot regressions early. Weighing a commercial reader instead? The [Oracle GoldenGate lab](https://sandgraal.github.io/letstalkcdc/cloud-labs/goldengate/) covers that route.

## Acceptance Criteria

- Database in `ARCHIVELOG`; supplemental logging verified at DB and required tables
- Snapshot finishes without schema conflicts; archived logs cover entire snapshot window
- Controlled connector restart produces **no duplicate PKs** in the sink
- Steady-state redo switch rate and connector lag are within SLOs
- DLQ empty (or only known test errors) for 30 minutes

---

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.
