Configure a self-managed Oracle database for CDC

This page describes how to configure change data capture (CDC) to stream data from a self-managed Oracle database to a supported destination , such as BigQuery or Cloud Storage.

You can configure your self-managed Oracle database to work with the following CDC methods:

These methods specify how Datastream accesses your log files. For more information about the binary log reader and the LogMiner API, see Work with Oracle database redo log files .

For detailed instructions about how to configure your source Oracle database for each of these methods, see the sections that follow.

Configure your self managed Oracle database for binary log reader

To configure your self-managed Oracle database for use with the binary log reader CDC method, perform the following steps:

  1. Select one of the following methods to access your log files:

    • Automatic Storage Management (ASM): if you select this option, you need to create a dedicated ASM connection, and provide its details when you create your connection profile.
    • Database directories: if you select this option, you need to create database directory objects that point to the redo log files and the archived log files, and grant READ access to the directories to your database user:
     CREATE 
      
     DIRECTORY 
      
      DIRECTORY_NAME_1 
     
      
     as 
      
     ' ONLINE_REDO_LOGS_PATH 
    ' 
     ; 
     CREATE 
      
     DIRECTORY 
      
      DIRECTORY_NAME_2 
     
      
     as 
      
     ' ARCHIVED_REDO_LOGS_PATH 
    ' 
     ; 
     GRANT 
      
     READ 
      
     ON 
      
     DIRECTORY 
      
      DIRECTORY_NAME_1 
     
      
     to 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     READ 
      
     ON 
      
     DIRECTORY 
      
      DIRECTORY_NAME_2 
     
      
     to 
      
      USER_NAME 
     
     ; 
    

    Replace the following:

    • DIRECTORY_NAME_1 : the name of the directory for the online redo log files.
    • DIRECTORY_NAME_2 : the name of the directory for the archived redo log files.
    • ONLINE_REDO_LOGS_PATH : the path to the directory where online redo log files are to be stored.
    • ARCHIVED_REDO_LOGS_PATH : the path to the directory where archived log files are to be stored.
    • USER_NAME : the name of the database user to whom you want to grant READ access.

    If you select the binary log reader method and use database directories, you need to provide the redo log and archived log directory names when you create your stream.

  2. Verify that your database is running in ARCHIVELOG mode.

    To do so, sign in to your Oracle database and run the following command at the SQL prompt:

    SELECT LOG_MODE FROM V$DATABASE;

    1. If the result is ARCHIVELOG , then move on to the next step.
    2. If the result is NOARCHIVELOG , then you'll need to enable ARCHIVELOG mode for your database.
    3. Run the following commands when logged in as SYSDBA :

       SHUTDOWN 
        
       IMMEDIATE 
       ; 
       STARTUP 
        
       MOUNT 
       ; 
       ALTER 
        
       DATABASE 
        
       ARCHIVELOG 
       ; 
       ALTER 
        
       DATABASE 
        
       OPEN 
       ; 
      
    4. Archived log files consume disk space, so you'll want to configure the DB_RECOVERY_FILE_DEST_SIZE parameter for your database. Use this parameter to specify (in bytes) the hard limit on the total space to be used by target database recovery files. By setting this parameter, you can manage the tradeoff between protecting the database from running out of disk space and the stream failing because of log position loss.

  3. Define a data retention policy for your database by running these Oracle Recovery Manager (RMAN) commands:

     TARGET 
      
     / 
     CONFIGURE 
      
     RETENTION 
      
     POLICY 
      
     TO 
      
     RECOVERY 
      
     WINDOW 
      
     OF 
      
     4 
      
     DAYS 
     ; 
    

    We recommend that you retain backups and archive logs for a minimum of 4 days, and 7 days is recommended.

  4. Return to the SQL prompt of the database tool that you're using to configure the Oracle log file rotation policy. We recommend setting a maximum log file size of no more than 512MB.

  5. Enable supplemental log data . To do so, first enable minimal database-level supplemental logging by running the following command:

     ALTER 
      
     DATABASE 
      
     ADD 
      
     SUPPLEMENTAL 
      
     LOG 
      
     DATA 
     ; 
    

    Next, choose whether to turn on logging for specific tables or the entire database.

    To log changes only for specific tables, run the following command for each table that you want to replicate:

     ALTER 
      
     TABLE 
      
      SCHEMA 
     
     . 
      TABLE 
     
      
     ADD 
      
     SUPPLEMENTAL 
      
     LOG 
      
     DATA 
      
     ( 
     ALL 
     ) 
      
     COLUMNS 
     ; 
    

    Replace the following:

    • SCHEMA : the name of the schema that contains the table.
    • TABLE : the name of the table for which you want to log changes.

    To replicate most or all tables in your database, consider turning logging on for the entire database. Run the following command to enable supplemental log data for the entire database:

     ALTER 
      
     DATABASE 
      
     ADD 
      
     SUPPLEMENTAL 
      
     LOG 
      
     DATA 
      
     ( 
     ALL 
     ) 
      
     COLUMNS 
     ; 
    
  6. Grant the appropriate privileges directly to the user account that's used to connect to your database. Note that these grants don't work when assigned to a role, for example. To do so, run the following commands:

     GRANT 
      
     SELECT 
      
     ON 
      
     GV_$LOG 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     GV_$LOGFILE 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     GV_$ARCHIVED_LOG 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     GV_$INSTANCE 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     GV_$STANDBY_LOG 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     V_$INSTANCE 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     V_$PDBS 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     V_$TRANSPORTABLE_PLATFORM 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     V_$DATABASE 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     V_$PARAMETER 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     COL$ 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     DBA_OBJECTS 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     DBA_TABLESPACES 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     DBA_ENCRYPTED_COLUMNS 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     DBA_EXTENTS 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     CONNECT 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     CREATE 
      
     SESSION 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ANY 
      
     TABLE 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     READ 
      
     ON 
      
     DIRECTORY 
      
     ONLINELOG_DIR 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     READ 
      
     ON 
      
     DIRECTORY 
      
     ARCHIVELOG_DIR 
      
     TO 
      
      USER_NAME 
     
     ; 
    

    Replace USER_NAME with the name of the user account that you intend to use to connect to your database.

Configure your self managed Oracle database for LogMiner

  1. Verify that your database is running in ARCHIVELOG mode.

    To do so, sign in to your Oracle database and run the following command at the SQL prompt:

    SELECT LOG_MODE FROM V$DATABASE;

    1. If the result is ARCHIVELOG , then move on to step 2.
    2. If the result is NOARCHIVELOG , then you'll need to enable ARCHIVELOG mode for your database.
    3. Run the following commands when logged in as SYSDBA :

       SHUTDOWN 
        
       IMMEDIATE 
       ; 
       STARTUP 
        
       MOUNT 
       ; 
       ALTER 
        
       DATABASE 
        
       ARCHIVELOG 
       ; 
       ALTER 
        
       DATABASE 
        
       OPEN 
       ; 
      
    4. Archived log files consume disk space, so you'll want to configure the DB_RECOVERY_FILE_DEST_SIZE parameter for your database. Use this parameter to specify (in bytes) the hard limit on the total space to be used by target database recovery files. By setting this parameter, you can manage the tradeoff between protecting the database from running out of disk space and the stream failing because of log position loss.

  2. Define a data retention policy for your database by running these Oracle Recovery Manager (RMAN) commands:

     TARGET 
      
     / 
     CONFIGURE 
      
     RETENTION 
      
     POLICY 
      
     TO 
      
     RECOVERY 
      
     WINDOW 
      
     OF 
      
     4 
      
     DAYS 
     ; 
    

    We recommend that you retain backups and archive logs for a minimum of 4 days, and 7 days is recommended.

  3. Return to the SQL prompt of the database tool that you're using to configure the Oracle log file rotation policy. We recommend setting a maximum log file size of no more than 512MB.

  4. Enable supplemental log data . To do so, first enable minimal database-level supplemental logging by running the following command:

     ALTER 
      
     DATABASE 
      
     ADD 
      
     SUPPLEMENTAL 
      
     LOG 
      
     DATA 
     ; 
    

    Next, choose whether to turn on logging for specific tables or the entire database.

    To log changes only for specific tables, run the following command for each table that you want to replicate:

     ALTER 
      
     TABLE 
      
      SCHEMA 
     
     . 
      TABLE 
     
      
     ADD 
      
     SUPPLEMENTAL 
      
     LOG 
      
     DATA 
      
     ( 
     ALL 
     ) 
      
     COLUMNS 
     ; 
    

    Replace the following:

    • SCHEMA : the name of the schema that contains the table.
    • TABLE : the name of the table for which you want to log changes.

    To replicate most or all tables in your database, consider turning logging on for the entire database. Run the following command to enable supplemental log data for the entire database:

     ALTER 
      
     DATABASE 
      
     ADD 
      
     SUPPLEMENTAL 
      
     LOG 
      
     DATA 
      
     ( 
     ALL 
     ) 
      
     COLUMNS 
     ; 
    
  5. Grant the appropriate privileges directly to the user account that's used to connect to your database. Note that these grants don't work when assigned to a role, for example. To do so, run the following commands:

     GRANT 
      
     EXECUTE_CATALOG_ROLE 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     CONNECT 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     CREATE 
      
     SESSION 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     SYS 
     . 
     V_$DATABASE 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     SYS 
     . 
     V_$LOG 
      
     TO 
      
      USER_NAME 
     
     ; 
      
     -- for primary databases 
     GRANT 
      
     SELECT 
      
     ON 
      
     SYS 
     . 
     V_$STANDY_LOG 
      
     TO 
      
      USER_NAME 
     
     ; 
      
     -- for standby databases 
     GRANT 
      
     SELECT 
      
     ON 
      
     SYS 
     . 
     V_$LOGFILE 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     SYS 
     . 
     V_$ARCHIVED_LOG 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     SYS 
     . 
     V_$LOGMNR_CONTENTS 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     SYS 
     . 
     V_$PARAMETER 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     EXECUTE 
      
     ON 
      
     DBMS_LOGMNR 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     EXECUTE 
      
     ON 
      
     DBMS_LOGMNR_D 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ANY 
      
     TRANSACTION 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ANY 
      
     TABLE 
      
     TO 
      
      USER_NAME 
     
     ; 
    

    If your database uses Transparent Data Encryption (TDE), grant the following permissions:

     GRANT 
      
     SELECT 
      
     ON 
      
     DBA_TABLESPACES 
      
     TO 
      
      USER_NAME 
     
     ; 
     GRANT 
      
     SELECT 
      
     ON 
      
     DBA_ENCRYPTED_COLUMNS 
      
     TO 
      
      USER_NAME 
     
     ; 
    

    If your organization doesn't permit granting the GRANT SELECT ANY TABLE permission, use the solution described in the Oracle change data capture (CDC) section of the Datastream FAQ page.

    If your source database is Oracle 12c or newer, then grant the following additional privilege:

     GRANT 
      
     LOGMINING 
      
     TO 
      
      USER_NAME 
     
     ; 
    
  6. Grant the user account SELECT access to the DBA_EXTENTS view in your database. This privilege lets you use the ROWID based backfill for your Oracle source:

     GRANT 
      
     SELECT 
      
     ON 
      
     DBA_EXTENTS 
      
     TO 
      
      USER_NAME 
     
     ; 
    

What's next

Design a Mobile Site
View Site in Mobile | Classic
Share by: