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.
<!-- the dependency is available only for stable releases. -->
<version>2.1-SNAPSHOT</version>
</dependency>
```
### SQL Client JAR
**Download link is available only for stable releases.**
Download [flink-sql-connector-oracle-cdc-2.1-SNAPSHOT.jar](https://repo1.maven.org/maven2/com/ververica/flink-sql-connector-oracle-cdc/2.1-SNAPSHOT/flink-sql-connector-oracle-cdc-2.1-SNAPSHOT.jar) and put it under `<FLINK_HOME>/lib/`.
Setup Oracle
----------------
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.
1. Enable log archiving
(1.1). Connect to the database as DBA
```shells
sqlplus sys/password@host:port/SID AS SYSDBA
```
(1.2). Enable log archiving
```sql
alter system set db_recovery_file_dest_size = 10G;
alter system set db_recovery_file_dest = '/opt/oracle/oradata/recovery_area' scope=spfile;
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
```
<b>Notes:</b>
- Enable log archiving requires database restart, pay attention when try to do it
- The archived logs will occupy a large amount of disk space, so consider clean the expired logs the periodically
(1.3). Check whether log archiving is enabled
```sql
-- Should now "Database log mode: Archive Mode"
archive log list;
```
<b>Notes:</b>
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;
<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>
</tr>
</tbody>
</table>
</div>
Features
--------
### Exactly-Once Processing
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: