Skip to content

Commit ccef0a8

Browse files
committed
Blog about troubleshooting Oracle's "Cannot find Offset SCN"
1 parent 76e5d4c commit ccef0a8

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
---
2+
layout: post
3+
title: Oracle does not contain SCN
4+
date: 2025-07-07 00:00:00 -0000
5+
tags: [ debezium, oracle, troubleshooting, debugging ]
6+
author: ccranfor
7+
---
8+
9+
Chances are if you're using the Debezium for Oracle connector, you've encountered the infamous exception about the SCN could not be found in your transaction logs.
10+
In this blog post, we'll not only talk about what this exception means, but the why, and troubleshooting steps you should take.
11+
12+
+++<!-- more -->+++
13+
14+
== What you should know...
15+
16+
Before we talk about what the exception means and how to troubleshoot it, it's important to have some understanding of some of the technical details we're going to be using later in the post.
17+
18+
=== What are SCNs?
19+
20+
System Change Numbers (SCNs) are Oracle's internal mechanism for ordering changes.
21+
You can think of them as _logical timestamps_ used to track the progression of changes across the database.
22+
Every commit, every change to a table, ever DDL operation -- all get assigned an SCN.
23+
24+
==== Important notes to consider about SCNs
25+
26+
* They are _monotonically increasing_, but not globally unique across contexts. For example, in Oracle RAC, multiple redo threads (which we'll discuss later) can have overlapping SCN ranges. In addition, Oracle is permitted to assign the same SCN to multiple changes.
27+
* They are crucial to Oracle LogMiner because Oracle uses SCNs to locate the start and end points of a mining session.
28+
* Debezium uses SCNs are resume positions during streaming, ensuring that changes are not lost or duplicated across connector restarts.
29+
30+
=== Redo Logs - Online versus Archived
31+
32+
Oracle writes every transaction to transaction logs _redo logs_.
33+
These logs come in two flavors:
34+
35+
==== Online Redo Logs
36+
37+
These are active, circular logs written in real-time by the Oracle Log Writer (LGWR) process.
38+
They are finite in size and are eventually overwritten once all changes within them are safely archived, if the database has archival enabled.
39+
40+
==== Archived Redo Logs
41+
42+
When archiving is enabled, Oracle copies full online redo logs to archive destinations before they are overwritten.
43+
These are essential for things like:
44+
45+
* Long-running queries or transactions
46+
* Point-in-time recovery
47+
* Downstream systems like Debezium that need historical log data
48+
49+
=== Redo Threads
50+
51+
Whether you've deployed Oracle using Standalone or if you're using Oracle RAC, each Oracle instance owns and writes to its own redo thread.
52+
While SCNs increment globally, each redo thread maintains a logical series of chronological changes that have occurred on that specific instance.
53+
In practice, this means:
54+
55+
* One redo thread (T1) may contain changes from transactions that logically happen _after_ those in another redo thread (T2), even if the SCNs seem interleaved.
56+
* Debezium and by extension LogMiner, needs access to logs across all redo threads to correctly reconstruct the global order of transactions in the database.
57+
* Missing or unarchived redo logs for _any redo thread_ can cause gaps, which Debezium guards against by performing log consistency check when Oracle performs a log switch.
58+
59+
== How to troubleshoot SCN not found?
60+
61+
There are several points during the Debezium connector lifecycle where the Oracle connector may report that it cannot find a specific SCN in the logs.
62+
Let's break down where this happens and how to troubleshoot each scenario.
63+
64+
=== Log position validation
65+
66+
When a Debezium Oracle connector starts, one of the first steps is validating that the resume position, based on the last known SCN in the offset, is still valid.
67+
68+
To do this, Debezium compares the stored offset SCN against the earliest available SCN in the database’s redo logs (online or archived).
69+
The logic is straightforward:
70+
71+
* If the earliest SCN ≤ offset SCN, the position is valid.
72+
* If the earliest SCN > offset SCN, the position is invalid, and Debezium throws an error stating the SCN cannot be found.
73+
74+
==== Why would the SCN become invalid?
75+
76+
There are several common causes:
77+
78+
* Short archive log retention
79+
** The Oracle archive policy may be purging logs faster than Debezium can process them.
80+
* Extended connector downtime
81+
** If the connector is offline longer than the log retention period, the required logs may no longer exist.
82+
* Skewed activity between captured and non-captured tables
83+
** The global SCN increases as transactions occur, even if Debezium isn’t capturing those tables. This can result in a stale SCN in the offsets.
84+
85+
==== What you can do
86+
87+
* Archive logs purged too early
88+
** Work with DBAs to increase the retention window or configure a secondary archive destination with longer retention.
89+
** Ensure Debezium has access to both online and archive logs from all redo threads.
90+
91+
* Connector is offline for too long
92+
** Ask DBAs to restore the missing archive logs if possible. Once restored, Debezium should resume without changes.
93+
** If restoration isn't possible:
94+
*** Manually update the connector offsets to a valid SCN that exists in the logs.
95+
*** Alternatively, clear the offset and history topics and restart the connector. You may choose to take a new full snapshot or use incremental snapshots.
96+
97+
* Disproportionate table activity
98+
** Configure a heartbeat using `heartbeat.interval.ms` and `heartbeat.action.query` to ensure regular SCN progression even if no captured changes occur.
99+
** Be sure the table used in the heartbeat query is included in the connector’s include list.
100+
101+
=== Redo thread consistency
102+
103+
Starting in Debezium 2.7, a more sophisticated consistency check was introduced to ensure log mining across all redo threads is reliable.
104+
This process is called **Redo Thread Consistency**.
105+
106+
If you've seen errors like the following, you've encountered this check in action.
107+
108+
[source,text]
109+
----
110+
Redo Thread 1 is inconsistent; an archive log with sequence 12345 is not available
111+
----
112+
113+
==== What Debezium checks
114+
115+
Before mining starts, Debezium queries the available logs and validates the following:
116+
117+
* At least one thread has a log containing the required SCN.
118+
* For each thread, log sequences must be continuous (no gaps), up to the latest sequence number in `V$THREAD`.
119+
* All redo threads must pass this check.
120+
* Threads in `OPEN` state (typically active instances) are held to stricter standards than those in `CLOSED` state.
121+
122+
If any redo thread fails this consistency check, Debezium pauses briefly, re-queries the logs, and retries.
123+
After 5 failed attempts (by default), it aborts with an SCN not found error.
124+
125+
==== How to troubleshoot
126+
127+
Start by reviewing the **INFO** level logs, that’s where Debezium reports which threads or sequences are inconsistent.
128+
If you're not seeing this, increase logging for the following class:
129+
130+
[source,text]
131+
----
132+
io.debezium.connector.oracle.logminer.LogFileCollector
133+
----
134+
135+
If your database is under heavy load or experiencing high log churn, the default retry strategy may not be sufficient.
136+
You can tune the retry behavior with these settings:
137+
138+
[source,json]
139+
----
140+
{
141+
"internal.log.mining.log.query.max.retries": "10",
142+
"internal.log.mining.log.backoff.initial.delay.ms": "1000",
143+
"internal.log.mining.log.backoff.max.delay.ms": "60000"
144+
}
145+
----
146+
147+
These options implement an exponential backoff: 1s, 2s, 4s, ... until either the logs become consistent, or the max retries are exhausted.
148+
149+
== Wrapping up
150+
151+
The error _"Online REDO LOG files or archive log files do not contain the offset SCN"_ can be frustrating, but it's usually a symptom of deeper log availability or coordination issues.
152+
By understanding:
153+
154+
* How SCNs relate to redo logs and LogMiner
155+
* The differences between online and archive logs
156+
* Debezium’s internal consistency checks
157+
158+
you can more effectively diagnose and prevent these issues.
159+
160+
When in doubt check:
161+
162+
* Offset SCN validity during startup
163+
* Log retention and thread coverage
164+
* Redo thread consistency at mining time
165+
* and heartbeat configurations to avoid staleness in idle streams.
166+
167+
With the right monitoring and configuration, these errors can become rare events rather than recurring blockers.

0 commit comments

Comments
 (0)