The Oracle CDC connector allows for reading snapshot data and incremental data from Oracle database. This document describes how to setup the Oracle CDC connector to run SQL queries against Oracle databases.
Dependencies
------------
In order to setup the Oracle CDC connector, the following table provides dependency information for both projects using a build automation tool (such as Maven or SBT) and SQL Client with SQL JAR bundles.
Download [flink-sql-connector-oracle-cdc-2.2-SNAPSHOT.jar](https://repo1.maven.org/maven2/com/ververica/flink-sql-connector-oracle-cdc/2.2-SNAPSHOT/flink-sql-connector-oracle-cdc-2.2-SNAPSHOT.jar) and put it under `<FLINK_HOME>/lib/`.
You have to enable log archiving for Oracle database and define an Oracle user with appropriate permissions on all databases that the Debezium Oracle connector monitors.
Supplemental logging must be enabled for captured tables or the database in order for data changes to capture the <em>before</em> state of changed database rows.
The following illustrates how to configure this on the table/database level.
```sql
-- Enable supplemental logging for a specific table:
ALTER TABLE inventory.customers ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;
When working with the CDB + PDB model, you are expected to add an extra option `'debezium.database.pdb.name' = 'xxx'` in Flink DDL to specific the name of the PDB to connect to.
<td>Specify what connector to use, here should be <code>'oracle-cdc'</code>.</td>
</tr>
<tr>
<td>hostname</td>
<td>required</td>
<tdstyle="word-wrap: break-word;">(none)</td>
<td>String</td>
<td>IP address or hostname of the Oracle database server.</td>
</tr>
<tr>
<td>username</td>
<td>required</td>
<tdstyle="word-wrap: break-word;">(none)</td>
<td>String</td>
<td>Name of the Oracle database to use when connecting to the Oracle database server.</td>
</tr>
<tr>
<td>password</td>
<td>required</td>
<tdstyle="word-wrap: break-word;">(none)</td>
<td>String</td>
<td>Password to use when connecting to the Oracle database server.</td>
</tr>
<tr>
<td>database-name</td>
<td>required</td>
<tdstyle="word-wrap: break-word;">(none)</td>
<td>String</td>
<td>Database name of the Oracle server to monitor.</td>
</tr>
<tr>
<td>schema-name</td>
<td>required</td>
<tdstyle="word-wrap: break-word;">(none)</td>
<td>String</td>
<td>Schema name of the Oracle database to monitor.</td>
</tr>
<tr>
<td>table-name</td>
<td>required</td>
<tdstyle="word-wrap: break-word;">(none)</td>
<td>String</td>
<td>Table name of the Oracle database to monitor.</td>
</tr>
<tr>
<td>port</td>
<td>optional</td>
<tdstyle="word-wrap: break-word;">1521</td>
<td>Integer</td>
<td>Integer port number of the Oracle database server.</td>
</tr>
<tr>
<td>scan.startup.mode</td>
<td>optional</td>
<tdstyle="word-wrap: break-word;">initial</td>
<td>String</td>
<td>Optional startup mode for Oracle CDC consumer, valid enumerations are "initial"
and "latest-offset".
Please see <ahref="#startup-reading-position">Startup Reading Position</a>section for more detailed information.</td>
</tr>
<tr>
<td>debezium.*</td>
<td>optional</td>
<tdstyle="word-wrap: break-word;">(none)</td>
<td>String</td>
<td>Pass-through Debezium's properties to Debezium Embedded Engine which is used to capture data changes from Oracle server.
For example: <code>'debezium.snapshot.mode' = 'never'</code>.
See more about the <ahref="https://debezium.io/documentation/reference/1.5/connectors/oracle.html#oracle-connector-properties">Debezium's Oracle Connector properties</a></td>
### Can't perform checkpoint during scanning snapshot of tables
During scanning snapshot of database tables, since there is no recoverable position, we can't perform checkpoints. In order to not perform checkpoints, Oracle CDC source will keep the checkpoint waiting to timeout. The timeout checkpoint will be recognized as failed checkpoint, by default, this will trigger a failover for the Flink job. So if the database table is large, it is recommended to add following Flink configurations to avoid failover because of the timeout checkpoints:
<td>Name of the database that contain the row.</td>
</tr>
<tr>
<td>op_ts</td>
<td>TIMESTAMP_LTZ(3) NOT NULL</td>
<td>It indicates the time that the change was made in the database. <br>If the record is read from snapshot of the table instead of the change stream, the value is always 0.</td>
</tr>
</tbody>
</table>
The extended CREATE TABLE example demonstrates the syntax for exposing these metadata fields:
```sql
CREATE TABLE products (
db_name STRING METADATA FROM 'database_name' VIRTUAL,
schema_name STRING METADATA FROM 'schema_name' VIRTUAL,
table_name STRING METADATA FROM 'table_name' VIRTUAL,
operation_ts TIMESTAMP_LTZ(3) METADATA FROM 'op_ts' VIRTUAL,
**Note** : The Oracle dialect is case-sensitive, it converts field name to uppercase if the field name is not quoted, Flink SQL doesn't convert the field name. Thus for physical columns from oracle database, we should use its converted field name in Oracle when define an `oracle-cdc` table in Flink SQL.
The Oracle CDC connector is a Flink Source connector which will read database snapshot first and then continues to read change events with **exactly-once processing** even failures happen. Please read [How the connector works](https://debezium.io/documentation/reference/1.5/connectors/oracle.html#how-the-oracle-connector-works).
### Startup Reading Position
The config option `scan.startup.mode` specifies the startup mode for Oracle CDC consumer. The valid enumerations are:
-`initial` (default): Performs an initial snapshot on the monitored database tables upon first startup, and continue to read the latest binlog.
-`latest-offset`: Never to perform a snapshot on the monitored database tables upon first startup, just read from
the change since the connector was started.
_Note: the mechanism of `scan.startup.mode` option relying on Debezium's `snapshot.mode` configuration. So please do not use them together. If you specific both `scan.startup.mode` and `debezium.snapshot.mode` options in the table DDL, it may make `scan.startup.mode` doesn't work._
### Single Thread Reading
The Oracle CDC source can't work in parallel reading, because there is only one task can receive change events.
### DataStream Source
The Oracle CDC connector can also be a DataStream source. You can create a SourceFunction as the following shows: