Change Data Capture efficiently identifies and captures data that has
been added to, updated in, or removed from, Oracle relational tables and
makes this change data available for use by applications or
individuals. Often, data warehousing involves the extraction and transportation of relational data from one or more production databases into a data warehouse for analysis. Change Data Capture quickly identifies and processes only the data that has changed and makes the change data available for further use. Capturing Change Data Without Change Data CapturePrior to the introduction of Change Data Capture, there were a number of ways that users could capture change data, including table differencing and change-value selection. Table differencing
involves transporting a copy of an entire table from the source
(production) database to the staging database (where the change data is
captured), where an older version of the table already exists. Using the
SQL SELECT * FROM new_version MINUS SELECT * FROM old_version; Moreover, you can obtain the deleted rows and old versions of updated rows with the following query: SELECT * FROM old_version MINUS SELECT * FROM new_version; However, there are several problems with this method:
Change-value selection
involves capturing the data on the source database by selecting the new
and changed data from the source tables based on the value of a
specific column. For example, suppose the source table has a However, there are also several limitations with this method:
Change Data Capture does not depend on expensive and cumbersome table
differencing or change-value selection mechanisms. Instead, it captures
the change data resulting from Capturing Change Data with Change Data CaptureChange Data Capture can capture and publish committed change data in either of the following modes:
The following list describes the advantages of capturing change data with Change Data Capture:
Note that you cannot use any table that uses transparent data
encryption as a source table for synchronous Change Data Capture.
Asynchronous Change Data Capture supports transparent data encryption if
both the source and staging databases have A Change Data Capture system is based on the interaction of publishers and subscribers to capture and distribute change data, as described in the next section. Publish and Subscribe ModelMost Change Data Capture systems have one person who captures and publishes change data; this person is the publisher. There can be multiple applications or individuals that access the change data; these applications and individuals are the subscribers. Change Data Capture provides PL/SQL packages to accomplish the publish and subscribe tasks. The following sections describe the roles of the publisher and subscriber in detail. Subsequent sections describe change sources, more about modes of Change Data Capture, and change tables. PublisherThe publisher is usually a database administrator (DBA) who creates and maintains the schema objects that make up the Change Data Capture system. For all modes of Change Data Capture, except Distributed HotLog, there is typically one publisher on the staging database. For the Distributed HotLog mode of Change Data Capture there needs to be a publisher defined on the source and staging databases. The following list describes the source and staging databases and the objects of interest to Change Data Capture on each:
These are the main tasks performed by the publisher:
In Figure 16-1, the publisher determines that subscribers are interested in viewing change data from the The publisher decides to use the asynchronous AutoLog mode of capturing change data. On the Figure 16-1 Publisher Components in a Change Data Capture System ![]() Description of "Figure 16-1 Publisher Components in a Change Data Capture System" SubscribersThe subscribers are consumers of the published change data. A subscriber performs the following tasks:
A subscriber has the privileges of the user account under which the subscriber is running, plus any additional privileges that have been granted to the subscriber. In Figure 16-2, the subscriber is interested in a subset of columns that the publisher (in Figure 16-1) has published. Note that the publications shown in Figure 16-2, are represented as change tables in Figure 16-1; this reflects the different terminology used by subscribers and publishers, respectively. The subscriber creates a subscription, Figure 16-2 Subscriber Components in a Change Data Capture System ![]() Description of "Figure 16-2 Subscriber Components in a Change Data Capture System" Change Data Capture provides the following benefits for subscribers:
Change Sources and Modes of Change Data CaptureChange Data Capture provides synchronous and asynchronous modes for capturing change data. The following sections summarize how each mode of Change Data Capture is performed, and the change source associated with each mode of Change Data Capture. Synchronous Change Data CaptureThe synchronous mode uses triggers on the source database to capture change data. It has no latency because the change data is captured continuously and in real time on the source database. The change tables are populated when DML operations on the source table are committed. There is a single, predefined synchronous change source, While the synchronous mode of Change Data Capture adds overhead to the source database at capture time, this mode can reduce costs (as compared to attempting to extract change data using table differencing or change-value section) by simplifying the extraction of change data. Change tables for this mode of Change Data Capture must reside locally in the source database. Figure 16-3
illustrates the synchronous configuration. Triggers executed after DML
operations occur on the source tables populate the change tables in the
change sets within the Figure 16-3 Synchronous Change Data Capture Configuration ![]() Description of "Figure 16-3 Synchronous Change Data Capture Configuration" Asynchronous Change Data CaptureThe asynchronous modes capture change data from the database redo log files after changes have been committed to the source database. The asynchronous modes of Change Data Capture are dependent on the level of supplemental logging enabled at the source database. Supplemental logging adds redo logging overhead at the source database, so it must be carefully balanced with the needs of the applications or individuals using Change Data Capture. See "Asynchronous Change Data Capture and Supplemental Logging" for information on supplemental logging. The three modes of capturing change data are described in the following sections: Asynchronous HotLog ModeIn the asynchronous HotLog mode, change data is captured from the online redo log file on the source database. There is a brief latency between the act of committing source table transactions and the arrival of change data. There is a single, predefined HotLog change source, Change tables for this mode of Change Data Capture must reside locally in the source database. Figure 16-4 illustrates the asynchronous HotLog configuration. The Logwriter Process ( Figure 16-4 Asynchronous HotLog Configuration ![]() Description of "Figure 16-4 Asynchronous HotLog Configuration" Asynchronous Distributed HotLog ModeIn the asynchronous Distributed HotLog mode, change data is captured from the online redo log file on the source database. There is no predefined Distributed HotLog change source. Unlike other modes of Change Data Capture, the Distributed HotLog mode splits change data capture activities and objects across the source and staging database. Change sources are defined on the source database by the staging database publisher. A Distributed HotLog change source represents the current online redo log files of the source database. However, staging database publishers can define multiple Distributed HotLog change sources, each of which contains change sets on a different staging database. The source and staging database can be on different hardware platforms and be running different operating systems, however some restrictions apply. See "Summary of Supported Distributed HotLog Configurations and Restrictions" for information on these restrictions. Figure 16-5 illustrates the asynchronous Distributed HotLog configuration. The change source on the source database captures change data from the online redo log files and uses Streams to propagate it to the change set on the staging database. The change set on the staging database populates the change tables within the change set. There are two publishers required for this mode of Change Data Capture, one on the source database and one on the staging database. The source database publisher defines a database link on the source database to connect to the staging database as the staging database publisher. The staging database publisher defines a database link on the staging database to connect to the source database on the source database publisher. All publishing operations are performed by the staging database publisher. See "Performing Asynchronous Distributed HotLog Publishing" for details. Figure 16-5 Asynchronous Distributed HotLog Configuration ![]() Description of "Figure 16-5 Asynchronous Distributed HotLog Configuration" Asynchronous AutoLog ModeIn the asynchronous AutoLog mode, change data is captured from a set of redo log files managed by redo transport services. Redo transport services control the automated transfer of redo log files from the source database to the staging database. Using database initialization parameters (described in "Initialization Parameters for Asynchronous AutoLog Publishing"), the publisher configures redo transport services to copy the redo log files from the source database system to the staging database system and to automatically register the redo log files. Asynchronous AutoLog mode can obtain change data from either the source database online redo log or from source database archived redo logs. These options are known as asynchronous AutoLog online and asynchronous AutoLog archive.With the AutoLog online option, redo transport services is set up to copy redo data from the online redo log at the source database to the standby redo log at the staging database. Change sets are populated after individual source database transactions commit. There can only be one AutoLog online change source on a given staging database and it can contain only one change set.With the AutoLog archive option, redo transport services is set up to copy archived redo logs from the source database to the staging database. Change sets are populated as new archived redo log files arrive on the staging database. The degree of latency depends on the frequency of redo log file switches on the source database. The AutoLog archive option has a higher degree of latency than the AutoLog online option, but there can be as many AutoLog archive change sources as desired on a given staging database. There is no predefined AutoLog change source. The publisher provides information about the source database to create an AutoLog change source. See "Performing Asynchronous AutoLog Publishing" for details. Figure 16-6
shows a Change Data Capture asynchronous AutoLog online configuration
in which the LGWR process on the source database copies redo data to
both the online redo log file on the source database and to the standby
redo log files on the staging database as specified by the Note that the LGWR process uses Oracle Net to send redo data over the network to the remote file server (RFS) process. Transmitting redo data to a remote destination requires uninterrupted connectivity through Oracle Net. On the staging database, the RFS process writes the redo data to the standby redo log files. Then, Change Data Capture uses Oracle Streams downstream capture to populate the change tables in the change sets within the AutoLog change source. The source database and the staging database must be running on the same hardware, operating system, and Oracle version. Figure 16-6 Asynchronous Autolog Online Change Data Capture Configuration ![]() Description of "Figure 16-6 Asynchronous Autolog Online Change Data Capture Configuration" Figure 16-7
shows a typical Change Data Capture asynchronous AutoLog archive
configuration in which, when the redo log file switches on the source
database, archiver processes archive the redo log file on the source
database to the destination specified by the Note that the archiver processes use Oracle Net to send redo data over the network to the remote file server (RFS) process. Transmitting redo log files to a remote destination requires uninterrupted connectivity through Oracle Net. On the staging database, the RFS process writes the redo data to the copied log files. Then, Change Data Capture uses Oracle Streams downstream capture to populate the change tables in the change sets within the AutoLog change source. See Oracle Data Guard Concepts and Administration for more information regarding Redo Transport Services. Figure 16-7 Asynchronous AutoLog Archive Change Data Capture Configuration ![]() Description of "Figure 16-7 Asynchronous AutoLog Archive Change Data Capture Configuration" Change SetsA change set is a logical grouping of change data that is guaranteed to be transactionally consistent and that can be managed as a unit. A change set is a member of one (and only one) change source. Note: Change Data Capture change sources can contain one or more change sets with the following restrictions:
When a publisher includes two or more change tables in the same change set, subscribers can perform join operations across the tables represented within the change set and be assured of transactional consistency. Conceptually, a change set shares the same mode as its change source.
For example, an AutoLog change set is a change set contained in an
AutoLog change source. Publishers define change sets using the To keep the change tables in the change set from growing larger indefinitely, publishers can purge unneeded change data from change tables at the change set level. See "Purging Change Tables of Unneeded Data" for more information on purging change data. Valid Combinations of Change Sources and Change SetsTable 16-1 summarizes the valid combinations of change sources and change sets and indicates whether each is predefined or publisher-defined. In addition, it indicates whether the source database represented by the change source is local to or remote from the staging database, and whether the change source is used for synchronous or asynchronous Change Data Capture. Table 16-1 Summary of Change Sources and Change Sets
Change TablesA given change table contains the change data resulting from DML operations performed on a given source table. A change table consists of two things: the change data itself, which is stored in a database table; and the system metadata necessary to maintain the change table, which includes control columns. The publisher specifies the source columns that are to be included in
the change table. Typically, for a change table to contain useful data,
the publisher needs to include the primary key column in the change
table along with any other columns of interest to subscribers. For
example, suppose subscribers are interested in changes that occur to the
There are optional and required control columns. The required control columns are always included in a change table; the optional ones are included if specified by the publisher when creating the change table. Control columns are managed by Change Data Capture. See "Understanding Change Table Control Columns" and "Understanding TARGET_COLMAP$ and SOURCE_COLMAP$ Values" for detailed information on control columns. Getting Information About the Change Data Capture EnvironmentInformation about the Change Data Capture environment is provided in the static data dictionary views described in Table 16-2 and Table 16-3. Table 16-2 lists the views that are intended for use by publishers; the user must have the
Table 16-2 Views Intended for Use by Change Data Capture Publishers
Table 16-3 Views Intended for Use by Change Data Capture Subscribers
See Oracle Database Reference for complete information about these views. Preparing to Publish Change DataThis section describes the tasks the publisher should perform before starting to publish change data, information on creating publishers, information on selecting a mode in which to capture change data, instructions on setting up database links required for the asynchronous Distributed HotLog mode of Change Data Capture, and instructions on setting database initialization parameters required by Change Data Capture. A publisher should do the following before performing the actual steps for publishing:
Creating a User to Serve As a PublisherFor all modes of Change Database Capture, the staging database DBA creates a user to serve as a publisher for Change Data Capture. In addition, for the asynchronous Distributed HotLog mode of Change Data Capture, the source database DBA also creates a user to serve as a publisher. On the source database, this publisher's only task is to create a database link from the source database to the staging database. The The following sections describe how to set up a publisher as required for each mode of Change Data Capture. Note: If a publisher is dropped with a SQLDROP USER CASCADE
statement, then all Change Data Capture objects owned by that publisher
are dropped, except those that contain Change Data Capture objects owned
by other publishers.For example, suppose publisher CDCPUB1 owns the change set CDCPUB1_SET that contains the change table CDCPUB2.SALES_CT . Issuing a DROP USER CASCADE statement to drop CDCPUB1 does not result in the CDCPUB1_SET
change set being dropped. However, after all of the change tables
contained within the change set have been dropped, any publisher can
drop the CDCPUB1_SET change set with the DBMS_CDC_PUBLISH.DROP_CHANGE_SET subprogram.Granting Privileges and Roles to the PublisherRegardless of change data capture mode to be used, the staging database publisher must be granted the privileges and roles in the following list: For
asynchronous HotLog, Distributed HotLog, and AutoLog publishing, the
staging database publisher must be configured as an Oracle Streams
administrator and also be granted the
For asynchronous Distributed HotLog publishing, the source database publisher must be granted the Creating a Default Tablespace for the PublisherOracle recommends that when creating the publisher account on a staging database, the DBA specify a default tablespace for the publisher; the publisher should use this tablespace for any change tables he or she creates. Password Files and Setting the REMOTE_LOGIN_PASSWORDFILE ParameterYou need to ensure that a password file has been generated. This occurs automatically when using the Database Configuration Assistant. See Also: Oracle Database Administrator's Guide and "Database Configuration Assistant Considerations" for more information on setting passwordsDetermining the Mode in Which to Capture DataThese factors influence the decision on the mode in which to capture change data:
Table 16-4 summarizes these factors that influence the mode decision. Table 16-4 Factors Influencing Choice of Change Data Capture Mode Setting Initialization Parameters for Change Data Capture PublishingInitialization parameters must be set on the source or staging database, or both, for Change Data Capture to succeed. Which parameters to set depend on the mode in which Change Data Capture is publishing change data, and on whether the parameters are being set on the source or staging database. The following sections describe the database initialization parameter
settings for each mode of Change Data Capture. Sometimes the DBA is
directed to add a value to a current setting. (The DBA can use the SQL See Oracle Database Reference for general information about these database initialization parameters and Oracle Streams Concepts and Administration for more information about the database initialization parameters set for asynchronous publishing. Initialization Parameters for Synchronous PublishingSet the JAVA_POOL_SIZE = 50000000 Initialization Parameters for Asynchronous HotLog PublishingTable 16-5 lists the source database initialization parameters and their recommended settings for asynchronous HotLog publishing. Table 16-5 Source Database Initialization Parameters for Asynchronous HotLog Publishing
Initialization Parameters for Asynchronous Distributed HotLog PublishingTable 16-6 lists the source database initialization parameters and their recommended settings for asynchronous Distributed HotLog publishing when the source database is Oracle Database release 10.1.0, 10.2.0, or 11.1.0. Table 16-7 lists the source database initialization parameters and their recommended settings for asynchronous Distributed HotLog publishing when the source database is Oracle Database release 9.2. Table 16-8 lists the staging database initialization parameters and their recommended settings for asynchronous Distributed HotLog publishing. These are the same regardless of which Oracle database release is being used for the source database. Table 16-6 Source Database (10.1.0, 10.2.0, 11.1.0) Initialization Parameters for Asynchronous Distributed HotLog Publishing
Table 16-7 Source Database (9.2) Initialization Parameters for Asynchronous Distributed HotLog Publishing
Table 16-8 Staging Database (11.1.0) Initialization Parameters for Asynchronous Distributed HotLog Publishing
Initialization Parameters for Asynchronous AutoLog PublishingTable 16-9 lists the database initialization parameters and their recommended settings for the asynchronous AutoLog publishing source database and Table 16-10 lists the database initialization parameters and their recommended settings for the asynchronous AutoLog publishing staging database. Table 16-9 Source Database Initialization Parameters for Asynchronous AutoLog Publishing
Footnote 1 The integer value in this parameter can be any value between 1 and 10. In this manual, the values 1 and 2 are used. For each Footnote 2 In the format template, %t corresponds to the thread number, %s corresponds to the sequence number, and %r corresponds to the resetlogs ID. Together, these ensure that unique names are constructed for the copied redo log files. Each of these items must be present, but their ordering and format are flexible. Table 16-10 Staging Database Initialization Parameters for Asynchronous AutoLog Publishing
Footnote 1 The integer value in this parameter can be any value between 1 and 10. In this manual, the values 1 and 2 are used. For each Footnote 2 In the format template, %t corresponds to the thread number, %s corresponds to the sequence number, and %r corresponds to the resetlogs ID. Together, these ensure that unique names are constructed for the copied redo log files. Each of these items must be present, but their ordering and format are flexible. Adjusting Initialization Parameter Values When Oracle Streams Values ChangeAsynchronous Change Data Capture uses an Oracle Streams configuration for each change set. This Streams configuration consists of a Streams capture process and a Streams apply process, with an accompanying queue and queue table. Each Streams configuration uses additional processes, parallel execution servers, and memory. For details about the Streams architecture, see Oracle Streams Concepts and Administration. If anything in your configuration changes, initialization parameters may need to be adjusted. See Table 16-10, "Staging Database Initialization Parameters for Asynchronous AutoLog Publishing" for more information. Publishing Change DataThe following sections provide step-by-step instructions on performing the various types of publishing: Performing Synchronous PublishingFor synchronous Change Data Capture, the publisher must use the predefined change source, This example shows how to create a change set. If the publisher wants to use the predefined This example assumes that the publisher and the source database DBA are two different people. Note that for synchronous Change Data Capture, the source database and the staging database are the same. Step 1 Source Database DBA: Set the JAVA_POOL_SIZE parameter. The source database DBA sets the database initialization parameters, as described in "Setting Initialization Parameters for Change Data Capture Publishing". java_pool_size = 50000000 Step 2 Source Database DBA: Create and grant privileges to the publisher. The source database DBA creates a user (for example, CREATE USER cdcpub IDENTIFIED EXTERNALLY DEFAULT TABLESPACE ts_cdcpub QUOTA UNLIMITED ON SYSTEM QUOTA UNLIMITED ON SYSAUX; GRANT CREATE SESSION TO cdcpub; GRANT CREATE TABLE TO cdcpub; GRANT CREATE TABLESPACE TO cdcpub; GRANT UNLIMITED TABLESPACE TO cdcpub; GRANT SELECT_CATALOG_ROLE TO cdcpub; GRANT EXECUTE_CATALOG_ROLE TO cdcpub; GRANT ALL ON sh.sales TO cdcpub; GRANT ALL ON sh.products TO cdcpub; GRANT EXECUTE ON DBMS_CDC_PUBLISH TO cdcpub; Step 3 Staging Database Publisher: Create a change set. The publisher uses the The following example shows how to create a change set called BEGIN DBMS_CDC_PUBLISH.CREATE_CHANGE_SET( change_set_name => 'CHICAGO_DAILY', description => 'Change set for sales history info', change_source_name => 'SYNC_SOURCE'); END; / The change set captures changes from the predefined change source Step 4 Staging Database Publisher: Create a change table. The publisher uses the The publisher can set the The following example creates a change table that captures changes
that occur on a source table. The example uses the sample schema table BEGIN DBMS_CDC_PUBLISH.CREATE_CHANGE_TABLE( owner => 'cdcpub', change_table_name => 'products_ct', change_set_name => 'CHICAGO_DAILY', source_schema => 'SH', source_table => 'PRODUCTS', column_type_list => 'PROD_ID NUMBER(6), PROD_NAME VARCHAR2(50), PROD_LIST_PRICE NUMBER(8,2)', capture_values => 'both', rs_id => 'y', row_id => 'n', user_id => 'n', timestamp => 'n', object_id => 'n', source_colmap => 'y', target_colmap => 'y', options_string => 'TABLESPACE TS_CHICAGO_DAILY'); END; / This statement creates a change table named The See "Managing Change Tables" for more information. Step 5 Staging Database Publisher: Grant access to subscribers. The publisher controls subscriber access to change data by granting and revoking the GRANT SELECT ON cdcpub.products_ct TO subscriber1; The Change Data Capture synchronous system is now ready for Performing Asynchronous HotLog PublishingChange Data Capture uses Oracle Streams local capture to perform asynchronous HotLog publishing. (See Oracle Streams Concepts and Administration for information on Streams local capture.) For HotLog Change Data Capture, the publisher must use the predefined change source, Note that for asynchronous HotLog Change Data Capture, the source database and the staging database are the same. The following steps set up redo logging, Oracle Streams, and Change Data Capture for asynchronous HotLog publishing: Step 1 Source Database DBA: Set the database initialization parameters. The source database DBA sets the database initialization parameters, as described in "Setting Initialization Parameters for Change Data Capture Publishing". In this example, one change set will be defined and the current value of the compatible = 11.0 java_pool_size = 50000000 job_queue_processes = 2 parallel_max_servers = <current value> + 5 processes = <current value> + 7 sessions = <current value> + 2 streams_pool_size = <current value> + 21 MB undo_retention = 3600 Step 2 Source Database DBA: Alter the source database. The source database DBA performs the following three tasks. The
second is required. The first and third are optional, but recommended.
It is assumed that the database is currently running in
Step 3 Source Database DBA: Create and grant privileges to the publisher. The source database DBA creates a user, (for example, CREATE USER cdcpub IDENTIFIED EXTERNALLY DEFAULT TABLESPACE ts_cdcpub QUOTA UNLIMITED ON SYSTEM QUOTA UNLIMITED ON SYSAUX; GRANT CREATE SESSION TO cdcpub; GRANT CREATE TABLE TO cdcpub; GRANT CREATE TABLESPACE TO cdcpub; GRANT UNLIMITED TABLESPACE TO cdcpub; GRANT SELECT_CATALOG_ROLE TO cdcpub; GRANT EXECUTE_CATALOG_ROLE TO cdcpub; GRANT CREATE SEQUENCE TO cdcpub; GRANT DBA TO cdcpub; GRANT EXECUTE on DBMS_CDC_PUBLISH TO cdcpub; EXECUTE DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(GRANTEE => 'cdcpub'); Note that for HotLog Change Data Capture, the source database and the staging database are the same database. Step 4 Source Database DBA: Prepare the source tables. The source database DBA must prepare the source tables on the source database for asynchronous Change Data Capture by instantiating each source table. Instantiating each source table causes the underlying Oracle Streams environment to record the information it needs to capture each source table's changes. The source table structure and the column datatypes must be supported by Change Data Capture. See "Datatypes and Table Structures Supported for Asynchronous Change Data Capture" for more information. BEGIN DBMS_CAPTURE_ADM.PREPARE_TABLE_INSTANTIATION(TABLE_NAME => 'sh.products'); END; / Step 5 Staging Database Publisher: Create change sets. The publisher uses the The following example creates a change set called BEGIN DBMS_CDC_PUBLISH.CREATE_CHANGE_SET( change_set_name => 'CHICAGO_DAILY', description => 'Change set for product info', change_source_name => 'HOTLOG_SOURCE', stop_on_ddl => 'y', begin_date => sysdate, end_date => sysdate+5); END; / The change set captures changes from the predefined Step 6 Staging Database Publisher: Create the change tables that will contain the changes to the source tables. The publisher uses the The publisher creates one or more change tables for each source table to be published, specifies which columns should be included, and specifies the combination of before and after images of the change data to capture. The following example creates a change table on the staging database
that captures changes made to a source table on the source database. The
example uses the sample table BEGIN DBMS_CDC_PUBLISH.CREATE_CHANGE_TABLE( owner => 'cdcpub', change_table_name => 'products_ct', change_set_name => 'CHICAGO_DAILY', source_schema => 'SH', source_table => 'PRODUCTS', column_type_list => 'PROD_ID NUMBER(6), PROD_NAME VARCHAR2(50), PROD_LIST_PRICE NUMBER(8,2)', capture_values => 'both', rs_id => 'y', row_id => 'n', user_id => 'n', timestamp => 'n', object_id => 'n', source_colmap => 'n', target_colmap => 'y', options_string => 'TABLESPACE TS_CHICAGO_DAILY'); END; / This statement creates a change table named The The See "Managing Change Tables" for more information. Step 7 Staging Database Publisher: Enable the change set. Because asynchronous change sets are always disabled when they are created, the publisher must alter the change set to enable it. The Oracle Streams capture and apply processes are started when the change set is enabled. BEGIN DBMS_CDC_PUBLISH.ALTER_CHANGE_SET( change_set_name => 'CHICAGO_DAILY', enable_capture => 'y'); END; / Step 8 Staging Database Publisher: Grant access to subscribers. The publisher controls subscriber access to change data by granting and revoking the GRANT SELECT ON cdcpub.products_ct TO subscriber1; The Change Data Capture asynchronous HotLog system is now ready for Performing Asynchronous Distributed HotLog PublishingFor Distributed HotLog Change Data Capture, the staging database is remote from the source database. However, steps must be performed on both the source database and the staging database to set up database links, Oracle Streams, and Change Data Capture. Tasks must be performed by a source database DBA, a staging database DBA, and a publisher on each database, as follows:
This example assumes that the source database DBA, the staging database DBA, and the publishers are four different people. Step 1 Source Database DBA: Prepare the source database. The source database DBA performs the following tasks:
Step 2 Staging Database DBA: Set the database initialization parameters. The staging database DBA performs the following tasks:
Step 3 Source Database DBA: Alter the source database. The source database DBA performs the following three tasks. The
second is required. The first and third are optional, but recommended.
It is assumed that the database is currently running in
Step 4 Source Database DBA: Create and grant privileges to the publisher. The source database DBA creates a user, (for example, CREATE USER source_cdcpub IDENTIFIED EXTERNALLY QUOTA UNLIMITED ON SYSTEM QUOTA UNLIMITED ON SYSAUX; GRANT CREATE SESSION TO source_cdcpub; GRANT DBA TO source_cdcpub; GRANT CREATE DATABASE LINK TO source_cdcpub; GRANT EXECUTE on DBMS_CDC_PUBLISH TO source_cdcpub; GRANT EXECUTE_CATALOG_ROLE TO source_cdcpub; GRANT SELECT_CATALOG_ROLE TO source_cdcpub; EXECUTE DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE( GRANTEE=> 'source_cdcpub'); Step 5 Staging Database DBA: Create and grant privileges to the publisher. The staging database DBA creates a user, (for example, CREATE USER staging_cdcpub IDENTIFIED EXTERNALLY DEFAULT TABLESPACE ts_cdcpub QUOTA UNLIMITED ON SYSTEM; GRANT CREATE SESSION TO staging_cdcpub; GRANT CREATE TABLE TO staging_cdcpub; GRANT CREATE TABLESPACE TO staging_cdcpub; GRANT UNLIMITED TABLESPACE TO staging_cdcpub; GRANT SELECT_CATALOG_ROLE TO staging_cdcpub; GRANT EXECUTE_CATALOG_ROLE TO staging_cdcpub; GRANT CONNECT, RESOURCE, DBA TO staging_cdcpub; GRANT CREATE SEQUENCE TO staging_cdcpub; EXECUTE DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(grantee => 'staging_cdcpub'); GRANT CREATE DATABASE LINK TO staging_cdcpub; Step 6 Source Database Publisher: Create Database Link The source database publisher creates a link from the source database to the staging database. Because the CREATE DATABASE LINK staging_db CONNECT TO staging_cdcpub IDENTIFIED BY Stg395V3 USING 'staging_db'; For detailed information on database links, see Oracle Database Administrator's Guide. Step 7 Staging Database Publisher: Create Database Link The staging database publisher creates a link from the staging database to the source database. Again, because the CREATE DATABASE LINK source_db CONNECT TO source_cdcpub IDENTIFIED BY Lvh412A7 USING 'source_db'; Note that this database link must exist when creating, altering or dropping Distributed HotLog change sources, change sets and change tables. However, this database link is not required for change capture to occur. Once the required Distributed HotLog change sources, change sets and change tables are in place and enabled, this database link can be dropped without interrupting change capture. This database link would need to be re-created to create, alter or drop Distributed HotLog change sources, change sets and change tables. Step 8 Staging Database Publisher: Identify the change source database and create the change sources. The staging database publisher uses the Note that when Change Data Capture creates a change source, its associated Oracle Streams capture process is also created (but not started). The publisher creates the Distributed HotLog change source and specifies the database link defined from the staging database to the source database. The name of the database link is the same as the name of the source database: BEGIN DBMS_CDC_PUBLISH.CREATE_HOTLOG_CHANGE_SOURCE( change_source_name => 'CHICAGO', description => 'test source', source_database => 'source_db'); END; / Step 9 Staging Database Publisher: Create change sets. The publisher uses the Note that when Change Data Capture creates a change set, its associated Oracle Streams apply process is also created (but not started). The following example shows how to create a change set called BEGIN DBMS_CDC_PUBLISH.CREATE_CHANGE_SET( change_set_name => 'CHICAGO_DAILY', description => 'change set for product info', change_source_name => 'CHICAGO', stop_on_ddl => 'y'); END; / Step 10 Staging Database Publisher: Create the change tables. The publisher uses the The publisher creates one or more change tables for each source table to be published, specifies which columns should be included, and specifies the combination of before and after images of the change data to capture. The publisher can set the The following example creates a change table on the staging database
that captures changes made to a source table in the source database. The
example uses the sample table BEGIN DBMS_CDC_PUBLISH.CREATE_CHANGE_TABLE( owner => 'staging_cdcpub', change_table_name => 'products_ct', change_set_name => 'CHICAGO_DAILY', source_schema => 'SH', source_table => 'PRODUCTS', column_type_list => 'PROD_ID NUMBER(6), PROD_NAME VARCHAR2(50), PROD_LIST_PRICE NUMBER(8,2), JOB_ID VARCHAR2(10), DEPARTMENT_ID NUMBER(4)', capture_values => 'both', rs_id => 'y', row_id => 'n', user_id => 'n', timestamp => 'n', object_id => 'n', source_colmap => 'n', target_colmap => 'y', options_string => 'TABLESPACE TS_CHICAGO_DAILY'); END; / This example creates a change table named The See "Managing Change Tables" for more information. Step 11 Staging Database Publisher: Enable the change source. Because Distributed HotLog change sources are always disabled when they are created, the publisher must alter the change source to enable it. The Oracle Streams capture process is started when the change source is enabled. BEGIN DBMS_CDC_PUBLISH.ALTER_HOTLOG_CHANGE_SOURCE( change_source_name => 'CHICAGO', enable_source => 'Y'); END; / Step 12 Staging Database Publisher: Enable the change set. Because asynchronous change sets are always disabled when they are created, the publisher must alter the change set to enable it. The Oracle Streams apply processes is started when the change set is enabled. BEGIN DBMS_CDC_PUBLISH.ALTER_CHANGE_SET( change_set_name => 'CHICAGO_DAILY', enable_capture => 'y'); END; / Step 13 Staging Database Publisher: Grant access to subscribers. The publisher controls subscriber access to change data by granting and revoking the GRANT SELECT ON staging_cdcpub.products_ct TO subscriber1; The Change Data Capture Distributed HotLog system is now ready for Performing Asynchronous AutoLog PublishingChange Data Capture uses Oracle Streams downstream capture to perform asynchronous AutoLog publishing. The Change Data Capture staging database is considered a downstream database in the Streams environment. The asynchronous AutoLog online option uses Streams real-time downstream capture. The asynchronous AutoLog archive option uses Streams archived-log downstreams capture. See Oracle Streams Concepts and Administration for information on Streams downstream capture. For asynchronous AutoLog Change Data Capture, the publisher creates new change sources, as well as the change sets and the change tables that will contain the changes that are made to individual source tables. Steps must be performed on both the source database and the staging database to set up redo transport services, Streams, and Change Data Capture for asynchronous AutoLog publishing. Because the source database and staging database are usually on separate systems, this example assumes that the source database DBA, the staging database DBA, and the publisher are different people. Step 1 Source Database DBA: Prepare to copy redo log files from the source database. The source database DBA and the staging database DBA must set up redo transport services to copy redo log files from the source database to the staging database and to prepare the staging database to receive these redo log files, as follows:
Step 2 Staging Database DBA: Set the database initialization parameters. The staging database DBA sets the database initialization parameters on the staging database, as described in "Setting Initialization Parameters for Change Data Capture Publishing". In these examples, one change set will be defined and the current value for the The following is an example for the AutoLog online option: compatible = 11.0 global_names = true java_pool_size = 50000000 log_archive_dest_1="location=/oracle/dbs mandatory reopen=5 valid_for=(online_logfile,primary_role)" log_archive_dest_2="location=/usr/oracle/dbs mandatory valid_for=(standby_logfile,primary_role)" log_archive_dest_state_1=enable log_archive_dest_state_2=enable log_archive_format="arch_%s_%t_%r.dbf" job_queue_processes = 2 parallel_max_servers = <current_value> + 5 processes = <current_value> + 7 sessions = <current value> + 2 streams_pool_size = <current_value> + 21 MB undo_retention = 3600 The following is an example for the AutoLog archive option: compatible = 11.0 global_names = true java_pool_size = 50000000 log_archive_dest_1="location=/oracle/dbs mandatory reopen=5 valid_for=(online_logfile,primary_role)" log_archive_dest_2="location=/oracle/stdby mandatory valid_for=(standby_logfile,primary_role)" log_archive_dest_state_1=enable log_archive_dest_state_2=enable log_archive_format="arch_%s_%t_%r.dbf" job_queue_processes = 2 parallel_max_servers = <current_value> + 5 processes = <current_value> + 7 sessions = <current value> + 2 streams_pool_size = <current_value> + 21 MB undo_retention = 3600 Step 3 Source Database DBA: Alter the source database. The source database DBA performs the following three tasks. The
second is required. The first and third are optional, but recommended.
It is assumed that the database is currently running in
Step 4 Staging Database DBA: Create Standby Redo Log Files This step is only needed for the AutoLog online option. The staging database DBA must create the actual standby redo log files on the staging database:
Step 5 Staging Database DBA: Create and grant privileges to the publisher. The staging database DBA creates a user, (for example, CREATE USER cdcpub IDENTIFIED EXTERNALLY DEFAULT TABLESPACE ts_cdcpub QUOTA UNLIMITED ON SYSTEM QUOTA UNLIMITED ON SYSAUX; GRANT CREATE SESSION TO cdcpub; GRANT CREATE TABLE TO cdcpub; GRANT CREATE TABLESPACE TO cdcpub; GRANT UNLIMITED TABLESPACE TO cdcpub; GRANT SELECT_CATALOG_ROLE TO cdcpub; GRANT EXECUTE_CATALOG_ROLE TO cdcpub; GRANT DBA TO cdcpub; GRANT CREATE SEQUENCE TO cdcpub; GRANT EXECUTE on DBMS_CDC_PUBLISH TO cdcpub; EXECUTE DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(grantee => 'cdcpub'); Step 6 Source Database DBA: Build the LogMiner data dictionary. The source database DBA builds a LogMiner data dictionary at the source database so that redo transport services can transport this data dictionary to the staging database. This LogMiner data dictionary build provides the table definitions as they were just prior to beginning to capture change data. Change Data Capture automatically updates the data dictionary with any source table data definition language (DDL) operations that are made during the course of change data capture to ensure that the dictionary is always synchronized with the source database tables. When building the LogMiner data dictionary, the source database DBA
should get the SCN value of the data dictionary build. In Step 8, when
the publisher creates a change source, he or she will need to provide
this value as the SET SERVEROUTPUT ON VARIABLE f_scn NUMBER; BEGIN :f_scn := 0; DBMS_CAPTURE_ADM.BUILD(:f_scn); DBMS_OUTPUT.PUT_LINE('The first_scn value is ' || :f_scn); END; / The first_scn value is 207722 For asynchronous AutoLog publishing to work, it is critical that the source database DBA build the data dictionary (and the build completes) before the source tables are prepared. The source database DBA must be careful to follow Step 6 and Step 7 in the order they are presented here. See Oracle Streams Concepts and Administration for more information on the LogMiner data dictionary. Step 7 Source Database DBA: Prepare the source tables. The source database DBA must prepare the source tables on the source database for asynchronous Change Data Capture by instantiating each source table so that the underlying Oracle Streams environment records the information it needs to capture each source table's changes. The source table structure and the column datatypes must be supported by Change Data Capture. See "Datatypes and Table Structures Supported for Asynchronous Change Data Capture" for more information. BEGIN DBMS_CAPTURE_ADM.PREPARE_TABLE_INSTANTIATION( TABLE_NAME => 'sh.products'); END; / Step 8 Source Database DBA: Get the global name of the source database. In Step 8, the publisher will need to reference the global name of
the source database. The global name of the source database will be used
on the staging database to create the AutoLog change source. The source
database DBA can query the SELECT GLOBAL_NAME FROM GLOBAL_NAME; GLOBAL_NAME ---------------------------------------------------------------------------- HQDB Step 9 Staging Database Publisher: Identify each change source database and create the change sources. The publisher uses the The process of managing the capture system begins with the creation
of a change source. A change source describes the source database from
which the data will be captured, and manages the relationship between
the source database and the staging database. A change source always
specifies the SCN of a data dictionary build from the source database as
its The publisher gets the SCN of the data dictionary build and the
global database name from the source database DBA (as shown in Step 5
and Step 7, respectively). If the publisher cannot get the value to use
for the On the staging database, the publisher creates the AutoLog change source and specifies the global name as the BEGIN DBMS_CDC_PUBLISH.CREATE_AUTOLOG_CHANGE_SOURCE( change_source_name => 'CHICAGO', description => 'test source', source_database => 'HQDB', first_scn => 207722, online_log => 'y'); END; / To create an AutoLog archive change source: BEGIN DBMS_CDC_PUBLISH.CREATE_AUTOLOG_CHANGE_SOURCE( change_source_name => 'CHICAGO', description => 'test source', source_database => 'HQDB', first_scn => 207722); END; / Step 10 Staging Database Publisher: Create change sets. The publisher uses the Note that when Change Data Capture creates a change set, its associated Oracle Streams capture and apply processes are also created (but not started). The following example shows how to create a change set called BEGIN DBMS_CDC_PUBLISH.CREATE_CHANGE_SET( change_set_name => 'CHICAGO_DAILY', description => 'change set for product info', change_source_name => 'CHICAGO', stop_on_ddl => 'y'); END; / Step 11 Staging Database Publisher: Create the change tables. The publisher uses the The publisher creates one or more change tables for each source table to be published, specifies which columns should be included, and specifies the combination of before and after images of the change data to capture. The publisher can set the The following example creates a change table on the staging database
that captures changes made to a source table in the source database. The
example uses the sample table BEGIN DBMS_CDC_PUBLISH.CREATE_CHANGE_TABLE( owner => 'cdcpub', change_table_name => 'products_ct', change_set_name => 'CHICAGO_DAILY', source_schema => 'SH', source_table => 'PRODUCTS', column_type_list => 'PROD_ID NUMBER(6), PROD_NAME VARCHAR2(50), PROD_LIST_PRICE NUMBER(8,2)', JOB_ID VARCHAR2(10), DEPARTMENT_ID NUMBER(4)', capture_values => 'both', rs_id => 'y', row_id => 'n', user_id => 'n', timestamp => 'n', object_id => 'n', source_colmap => 'n', target_colmap => 'y', options_string => 'TABLESPACE TS_CHICAGO_DAILY'); END; / This example creates a change table named The See "Managing Change Tables" for more information. Step 12 Staging Database Publisher: Enable the change set. Because asynchronous change sets are always disabled when they are created, the publisher must alter the change set to enable it. The Oracle Streams capture and apply processes are started when the change set is enabled. BEGIN DBMS_CDC_PUBLISH.ALTER_CHANGE_SET( change_set_name => 'CHICAGO_DAILY', enable_capture => 'y'); END; / Step 13 Source Database DBA: Switch the redo log files at the source database. To begin capturing data, a log file must be archived. The source database DBA can initiate the process by switching the current redo log file: ALTER SYSTEM SWITCH LOGFILE; Step 14 Staging Database Publisher: Grant access to subscribers. The publisher controls subscriber access to change data by granting and revoking the SQL GRANT SELECT ON cdcpub.products_ct TO subscriber1; The Change Data Capture asynchronous AutoLog system is now ready for Subscribing to Change DataWhen a publisher creates a
change table, Change Data Capture assigns it a publication ID and
maintains a list of all the publication IDs in the The subscribers register their interest in one or more source tables, and obtain subscriptions to these tables. Assuming sufficient access privileges, the subscribers may subscribe to any source tables for which the publisher has created one or more change tables by doing one of the following:
The following steps provide an example to demonstrate both scenarios: Step 1 Find the source tables for which the subscriber has access privileges. The subscriber queries the SELECT * FROM ALL_SOURCE_TABLES; SOURCE_SCHEMA_NAME SOURCE_TABLE_NAME ------------------------------ ------------------------------ SH PRODUCTS Step 2 Find the change set names and columns for which the subscriber has access privileges. The subscriber queries the SELECT UNIQUE CHANGE_SET_NAME, COLUMN_NAME, PUB_ID FROM ALL_PUBLISHED_COLUMNS WHERE SOURCE_SCHEMA_NAME ='SH' AND SOURCE_TABLE_NAME = 'PRODUCTS'; CHANGE_SET_NAME COLUMN_NAME PUB_ID ---------------- ------------------ ------------ CHICAGO_DAILY PROD_ID 41494 CHICAGO_DAILY PROD_LIST_PRICE 41494 CHICAGO_DAILY PROD_NAME 41494 The subscriber calls the The following example shows how the subscriber identifies the change set of interest ( BEGIN DBMS_CDC_SUBSCRIBE.CREATE_SUBSCRIPTION( change_set_name => 'CHICAGO_DAILY', description => 'Change data for PRODUCTS', subscription_name => 'SALES_SUB'); END; / Step 4 Subscribe to a source table and the columns in the source table. The subscriber calls the A subscription can contain one or more source tables referenced by the same change set. In the following example, the subscriber wants to see the BEGIN DBMS_CDC_SUBSCRIBE.SUBSCRIBE( subscription_name => 'SALES_SUB', source_schema => 'SH', source_table => 'PRODUCTS', column_list => 'PROD_ID, PROD_NAME, PROD_LIST_PRICE', subscriber_view => 'SALES_VIEW'); END; / However, assume that for security reasons the publisher has not
created a single change table that includes all these columns. Suppose
that instead of the results shown in Step 2, the query of the SELECT UNIQUE CHANGE_SET_NAME, COLUMN_NAME, PUB_ID FROM ALL_PUBLISHED_COLUMNS WHERE SOURCE_SCHEMA_NAME ='SH' AND SOURCE_TABLE_NAME = 'PRODUCTS'; CHANGE_SET_NAME COLUMN_NAME PUB_ID ---------------- ------------------ ------------ CHICAGO_DAILY PROD_ID 34883 CHICAGO_DAILY PROD_NAME 34885 CHICAGO_DAILY PROD_LIST_PRICE 34883 CHICAGO_DAILY PROD_ID 34885 This returned data shows that the BEGIN DBMS_CDC_SUBSCRIBE.SUBSCRIBE( subscription_name => 'MULTI_PUB', publication_id => 34885, column_list => 'PROD_ID, PROD_NAME', subscriber_view => 'prod_idname'); DBMS_CDC_SUBSCRIBE.SUBSCRIBE( subscription_name => 'MULTI_PUB', publication_id => 34883, column_list => 'PROD_ID, PROD_LIST_PRICE', subscriber_view => 'prod_price'); END; / Note that each Step 5 Activate the subscription. The subscriber calls the A subscriber calls this procedure when finished subscribing to source
tables (or publications), and ready to receive change data. Whether
subscribing to one or multiple source tables, the subscriber needs to
call the The BEGIN DBMS_CDC_SUBSCRIBE.ACTIVATE_SUBSCRIPTION( subscription_name => 'SALES_SUB'); END; / Step 6 Get the next set of change data. The subscriber calls the BEGIN DBMS_CDC_SUBSCRIBE.EXTEND_WINDOW( subscription_name => 'SALES_SUB'); END; / If this is the subscriber's first call to the If no new change data has been added, then the subscription window remains unchanged. Step 7 Read and query the contents of the subscriber views. The subscriber uses the SQL SELECT PROD_ID, PROD_NAME, PROD_LIST_PRICE FROM SALES_VIEW; PROD_ID PROD_NAME PROD_LIST_PRICE ---------- -------------------------------------------------- --------------- 30 And 2 Crosscourt Tee Kids 14.99 30 And 2 Crosscourt Tee Kids 17.66 10 Gurfield& Murks Pleated Trousers 17.99 10 Gurfield& Murks Pleated Trousers 21.99 The subscriber view name, Step 8 Indicate that the current set of change data is no longer needed. The subscriber uses the For example: BEGIN DBMS_CDC_SUBSCRIBE.PURGE_WINDOW( subscription_name => 'SALES_SUB'); END; / Step 9 Repeat Steps 6 through 8. The subscriber repeats Steps 6 through 8 as long as the subscriber is interested in additional change data. The subscriber uses the BEGIN DBMS_CDC_SUBSCRIBE.DROP_SUBSCRIPTION( subscription_name => 'SALES_SUB'); END; / Managing Published DataThis section provides information about the management tasks involved in managing change sets and change tables. For the most part, these tasks are the responsibility of the publisher. However, to purge unneeded data from the change tables, both the publisher and the subscribers have responsibilities as described in "Purging Change Tables of Unneeded Data" The following topics are covered in this section: Managing Asynchronous Change SourcesThis section provides information about tasks that the publisher can perform to manage asynchronous change sources. The following topic is covered: Enabling And Disabling Asynchronous Distributed HotLog Change SourcesThe publisher can enable and disable asynchronous Distributed HotLog change sources. When a change source is disabled, it cannot process new change data until the change source is enabled. Asynchronous Distributed HotLog change sources are always created disabled. The publisher can enable the BEGIN DBMS_CDC_PUBLISH.ALTER_HOTLOG_CHANGE_SOURCE( change_source_name => 'PRODUCTS_SOURCE', enable_source => 'y'); END; / The Oracle Streams capture process for the change source is started
when the change source is enabled.The publisher can disable the An asynchronous Distributed HotLog change source and its change sets must be enabled separately in order to process change data and populate change tables. See "Enabling and Disabling Asynchronous Change Sets" for more information. Although a disabled change source cannot process new change data, it does not lose any change data, provided the necessary archived redo log files remain available until the change source and its changes sets are enabled and can process them. Oracle recommends that change sources and change sets be enabled as much as possible to avoid accumulating archived redo log files. See "Asynchronous Change Data Capture and Redo Log Files" for more information. Managing Asynchronous Change SetsThis section provides information about tasks that the publisher can perform to manage asynchronous change sets. The following topics are covered: Creating Asynchronous Change Sets with Starting and Ending DatesChange sets associated with asynchronous HotLog and AutoLog change sources can optionally specify starting and ending dates to limit the change data they capture. (Change sets associated with Distributed HotLog change sources cannot specify starting and ending dates). A change set with no starting date begins capture with the earliest available change data. A change set with no ending date continues capturing change data indefinitely. The following example creates a change set, BEGIN DBMS_CDC_PUBLISH.CREATE_CHANGE_SET( change_set_name => 'PRODUCTS_SET', description => 'Products Application Change Set', change_source_name => 'HQ_SOURCE', stop_on_ddl => 'Y', begin_date => sysdate+2); END; / Enabling and Disabling Asynchronous Change SetsThe publisher can enable and disable asynchronous change sets. When a change set is disabled, it cannot process new change data until the change set is enabled. Synchronous change sets are always created enabled. Asynchronous change sets are always created disabled. The publisher can enable the BEGIN DBMS_CDC_PUBLISH.ALTER_CHANGE_SET( change_set_name => 'PRODUCTS_SET', enable_capture => 'y'); END; / For asynchronous HotLog and AutoLog change sets, the Oracle Streams capture and apply processes are started when the change set is enabled. For asynchronous Distributed HotLog change sets, the Oracle Streams apply process is started when the change set is enabled. The publisher can disable the An asynchronous Distributed HotLog change source and its change sets must be enabled separately in order to process change data and populate change tables. See "Enabling And Disabling Asynchronous Distributed HotLog Change Sources" for more information. Although a disabled change set cannot process new change data, it does not lose any change data if the necessary archived redo log files remain available until the change set is enabled and processes them. Oracle recommends that change sets be enabled as much as possible to avoid accumulating archived redo log files. See "Asynchronous Change Data Capture and Redo Log Files" for more information. Change Data Capture can automatically disable an asynchronous change set if there is an internal capture error. The publisher must check the alert log for more information, take any necessary actions to adjust to the DDL or recover from the internal error, and explicitly enable the change set. See "Recovering from Errors Returned on Asynchronous Change Sets" for more information. Stopping Capture on DDL for Asynchronous Change SetsThe publisher can specify that a change set be automatically disabled by Change Data Capture if DDL is encountered. Some DDL commands can adversely affect capture, such as dropping a source table column that is being captured. If the change set stops on DDL, the publisher has a chance to analyze and fix the problem before capture proceeds. If the change set does not stop on DDL, internal capture errors are possible after DDL occurs. The publisher can specify whether a change set stops on DDL when
creating or altering the change set. The publisher can alter the BEGIN DBMS_CDC_PUBLISH.ALTER_CHANGE_SET( change_set_name => 'PRODUCTS_SET', stop_on_ddl => 'y'); END; / The publisher can alter the If a DDL statement causes processing to stop, a message is written to
the alert log indicating the DDL statement and change set involved. For
example, if a Change Data Capture received DDL for change set PRODUCTS_SET Change Data Capture received DDL and stopping: truncate table products Because they do not affect the
column data itself, the following DDL statements do not cause Change
Data Capture to stop capturing change data when the
These statements can be issued on the source database without concern
for their impact on Change Data Capture processing. For example, when
an Change Data Capture received DDL and ignoring: analyze table products compute statistics Recovering from Errors Returned on Asynchronous Change SetsErrors during asynchronous Change Data Capture are possible due to a variety of circumstances. If a change set stops on DDL, that DDL must be removed before capture can continue. If a change set does not stop on DDL, but a DDL change occurs that affects capture, it can result in an Oracle error. There are also system conditions that can cause Oracle errors, such as being out of disk space. In all these cases, the change set is disabled and marked as having an error. Subscriber procedures detect when a change set has an error and return the following message: ORA-31514: change set disabled due to capture error The publisher must check the alert log for more information and
attempt to fix the underlying problem. The publisher can then attempt to
recover from the error by calling The publisher can repeat this procedure as many times as necessary to resolve the problem. When recovery succeeds, the error is removed from the change set and the publisher can enable the asynchronous change set (as described in "Enabling and Disabling Asynchronous Change Sets"). The publisher should be aware that if there are multiple consecutive DDLs, the change set stops for each one separately. For example, suppose there are two consecutive DDLs. When the change set stops for the first DDL, the publisher must remove that DDL and then re-enable capture for the change set. The change set will then stop for the second DDL. The publisher must remove the second DDL and re-enable capture for the change set again. If more information is needed to resolve capture errors, the publisher can query the The following two scenarios demonstrate how a publisher might investigate and then recover from two different types of errors returned to Change Data Capture: An Error Due to Running Out of Disk SpaceThe publisher can view the contents of the alert log to determine which error is being returned for a given change set and which SCN is not being processed. For example, the alert log may contain lines such as the following (where LCR refers to a logical change record): Change Data Capture has encountered error number: 1688 for change set: CHICAGO_DAILY Change Data Capture did not process LCR with scn 219337 The publisher can determine the message associated with the error number specified in the alert log by querying the SQL> SELECT ERROR_MESSAGE FROM DBA_APPLY_ERROR WHERE APPLY_NAME = (SELECT APPLY_NAME FROM ALL_CHANGE_SETS WHERE SET_NAME ='CHICAGO_DAILY'); ERROR_MESSAGE -------------------------------------------------------------------------------- ORA-01688: unable to extend table LOGADMIN.CT1 partition P1 by 32 in tablespace TS_CHICAGO_DAILY After taking action to fix the problem that is causing the error, the
publisher can attempt to recover from the error. For example, the
publisher can attempt to recover the BEGIN DBMS_CDC_PUBLISH.ALTER_CHANGE_SET( change_set_name => 'CHICAGO_DAILY', recover_after_error => 'y'); END; / If the recovery does not succeed, then an error is returned and the publisher can take further action to attempt to resolve the problem. The publisher can retry the recovery procedure as many times as necessary to resolve the problem.
An Error Due to Stopping on DDLSuppose a SQL ERROR at line 1: ORA-31468: cannot process DDL change record ORA-06512: at "SYS.DBMS_CDC_PUBLISH", line 79 ORA-06512: at line 2 The alert log will contain lines similar to the following: Mon Jun 9 16:13:44 2003 Change Data Capture received DDL for change set PRODUCTS_SET Change Data Capture received DDL and stopping: truncate table products Mon Jun 9 16:13:50 2003 Change Data Capture did not process LCR with scn 219777 Streams Apply Server P001 pid=19 OS id=11730 stopped Streams Apply Reader P000 pid=17 OS id=11726 stopped Streams Apply Server P000 pid=17 OS id=11726 stopped Streams Apply Server P001 pid=19 OS id=11730 stopped Streams AP01 with pid=15, OS id=11722 stopped Because the BEGIN DBMS_CDC_PUBLISH.ALTER_CHANGE_SET( change_set_name => 'PRODUCTS_SET', recover_after_error => 'y', remove_ddl => 'y'); END; / After this procedure completes, the alert log will contain lines similar to the following: Mon Jun 9 16:20:17 2003 Change Data Capture received DDL and ignoring: truncate table products The scn for the truncate statement is 202998 Now, the publisher must enable the change set. All change data that occurred after the Managing Synchronous Change SetsThe publisher can enable and disable synchronous change sets. When a change set is disabled, it cannot process new change data until the change set is enabled. Enabling and Disabling Synchronous Change SetsSynchronous change sets are always created enabled. Asynchronous change sets are always created disabled. The publisher can enable the BEGIN DBMS_CDC_PUBLISH.ALTER_CHANGE_SET( change_set_name => 'PRODUCTS_SET', enable_capture => 'y'); END; / The publisher can disable the Managing Change TablesAll change table management tasks are the responsibility of the publisher with one exception: purging change tables of unneeded data. This task requires action from both the publisher and the subscriber to work most effectively. The following topics are discussed in this section: Creating Change TablesWhen creating change tables, the publisher should be aware that Oracle recommends the following:
Understanding Change Table Control ColumnsA change table consists of two things: the change data itself, which is stored in a database table, and the system metadata necessary to maintain the change table, which includes control columns. Table 16-11 describes the control columns for a change table, including the column name, datatype, mode, whether the column is optional or not, and a description. The mode indicates the type of Change Data Capture associated with the column. A value of A control column is considered optional if the publisher can choose to exclude it from a change table. Table 16-11
identifies which control columns are optional under what modes. All
optional control columns are specified with a parameter in the Table 16-11 Control Columns for a Change Table
Footnote 1 If you specify a query based on this column, specify the Footnote 2 You can use the Footnote 3 A bit mask is an array of binary values that indicate which columns in a row have been updated. Understanding TARGET_COLMAP$ and SOURCE_COLMAP$ ValuesThe Because the datatype of the Example 16-1 Sample TARGET_COLMAP$ VALUE FE110000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000 In Example 16-1, the first 'FE' is the low order byte and the last '00' is the high order byte. To correctly interpret the meaning of the values, you must consider which bits are set in each byte. The bits in the bitmap are counted starting at zero. The first bit is bit 0, the second bit is bit 1, and so on. Bit 0 is always ignored. For the other bits, if a particular bit is set to 1, it means that the value for that column has been changed. To interpret the string of bytes as presented in the Example 16-1, you read from left to right. The first byte is the string 'FE'. Broken down into bits (again from left to right) this string is "1111 1110", which maps to columns " 7,6,5,4 3,2,1,-" in the change table (where the hyphen represents the ignored bit). The first bit tells you if column 7 in the change table has changed. The right-most bit is ignored. The values in Example 16-1 indicate that the first 7 columns have a value present. This is typical - the first several columns in a change table are control columns. The next byte in Example 16-1 is the string '11'. Broken down into bits, this string is "0001 0001", which maps to columns "15,14,13,12 11,10,9,8" in the change table. These bits indicate that columns 8 and 12 are changed. Columns 9, 10, 11, 13, 14, 15, are not changed. The rest of the string is all '00', indicating that none of the other columns has been changed. A publisher can issue the following query to determine the mapping of column numbers to column names: SELECT COLUMN_NAME, COLUMN_ID FROM ALL_TAB_COLUMNS WHERE OWNER='PUBLISHER_STEWART' AND TABLE_NAME='MY_CT'; COLUMN_NAME COLUMN_ID ------------------------------ ---------- OPERATION$ 1 CSCN$ 2 COMMIT_TIMESTAMP$ 3 XIDUSN$ 4 XIDSLT$ 5 XIDSEQ$ 6 RSID$ 7 TARGET_COLMAP$ 8 C_ID 9 C_KEY 10 C_ZIP 11 COLUMN_NAME COLUMN_ID ------------------------------ ---------- C_DATE 12 C_1 13 C_3 14 C_5 15 C_7 16 C_9 17 Using Example 16-1,
the publisher can conclude that following columns were changed in the
particular change row in the change table represented by this Note that Change Data Capture generates values for all control
columns in all change rows, so the bits corresponding to control columns
are always set to 1 in every A common use for the values in the Values in the
Using Change MarkersThe following example illustrates how to use change markers. First, create the change set: BEGIN DBMS_CDC_PUBLISH.CREATE_CHANGE_SET ( CHANGE_SET_NAME => 'async_set1', CHANGE_SOURCE_NAME => 'HOTLOG_SOURCE', STOP_ON_DDL => 'N', BEGIN_DATE => SYSDATE, END_DATE => SYSDATE+5); PL/SQL procedure successfully completed Next, create the change table. Note that this should have the three DDL markers BEGIN DBMS_CDC_PUBLISH.CREATE_CHANGE_TABLE ( OWNER => 'tcdcpub', CHANGE_TABLE_NAME => 'cdc_psales_act', CHANGE_SET_NAME => 'async_set1', SOURCE_SCHEMA => 'tcdcpub', SOURCE_TABLE => 'cdc_psales', COLUMN_TYPE_LIST => 'PROD_IC NUMBER(6) NUMBER, TIME_ID DATE', CAPTURE_VALUES => 'both', RS_ID => 'N', ROW_ID => 'N', USER_ID => 'N', TIMESTAMP => 'N', OBJECT_ID => 'N', SOURCE_COLMAP => 'N', TARGET_COLMAP => 'Y', OPTIONS_STRING => NULL, DDL_MARKERS => 'Y'); END; / PL/SQL procedure successfully completed. describe cdc_psales_act; Name Null? Type --------------------------------------- OPERATION$ CHAR(2) CSCN$ NUMBER COMMIT_TIMESTAMP DATE XIDUSN$ NUMBER XIDSLT$ NUMBER XIDSEQ$ NUMBER TARGET_COLMAP$ RAW(128) DDLOPER$ NUMBER DDLDESC$ CLOB DDLPDOBJN$ NUMBER PROD_D NUMBER(6) CUST_ID NUMBER TIME_ID DATE Then, enable capture for the change set: BEGIN DBMS_CDC_PUBLISH.ALTER_CHANGE_SET ( CHANGE_SET_NAME => 'asynch_set1', ENABLE_CAPTURE => 'Y'); END; . PL/SQL procedure successfully completed Finally, issue a DDL statement and see if it is captured: ALTER TABLE cdc_psales DROP PARTITION Dec_06; SELECT ddloper$, DECODE(ddloper$, NULL, 'NULL', DBMS_CDC_PUBLISH.GET_DDLOPER(ddloper$)) AS DDL_OPER FROM cdc_psales_act WHERE DDLOPER$ IS NOT NULL ORDER BY cscn$; ddloper$ DDL_OPER --------------------------------- 512 Drop Partition 1 row selected. SELECT ddldesc$ FROM cdc_psales_act WHERE ddloper$ IS NOT NULL ORDER BY cscn; DDLDESC$ ------------------------ alter table cdc_psales drop partition Dec_06 1 row selected. Controlling Subscriber Access to Change TablesThe publisher grants
privileges to subscribers to allow them access to change tables. Because
privileges on source tables are not propagated to change tables, a
subscriber might have privileges to perform a The publisher controls subscriber access to change data by using the SQL The publisher must not grant any DML access (use of Purging Change Tables of Unneeded DataThis section describes purge operations. For optimum results, purge operations require action from the subscribers. Each subscriber indicates when he or she is done using change data, and then Change Data Capture or the publisher actually removes (purges) data that is no longer being used by any subscriber from the change table, as follows:
Thus, calls to the If Note that it is possible that a subscriber could fail to call Dropping Change TablesTo drop a change table, the publisher must call the ORA-31496 must use DBMS_CDC_PUBLISH.DROP_CHANGE_TABLE to drop change tables The ORA-31424 change table has active subscriptions If the publisher still wants to drop the change table, in spite of active subscriptions, he or she must call the Note: TheDROP USER CASCADE
statement will drop all the publisher's change tables, and if any other
users have active subscriptions to the (dropped) change table, these
will no longer be valid. In addition to dropping the change tables, the DROP USER CASCADE statement drops any change sources, change sets, and subscriptions that are owned by the user specified in the DROP USER CASCADE statement.Exporting and Importing Change Data Capture Objects Using Oracle Data PumpOracle Data Pump is the supported export and import utility for Change Data Capture. The following sections describe restrictions, provide examples, and describe publisher considerations for using Oracle Data Pump with Change Data Capture:
Restrictions on Using Oracle Data Pump with Change Data CaptureChange Data Capture change sources, change sets, change tables, and
subscriptions are exported and imported by the Oracle Data Pump
Examples of Oracle Data Pump Export and Import CommandsThe following are examples of Data Pump export and import commands that support Change Data Capture objects: > expdp DIRECTORY=dpump_dir FULL=y > impdp DIRECTORY=dpump_dir FULL=y STREAMS_CONFIGURATION=y See Oracle Database Utilities for information on Oracle Data Pump. Publisher Considerations for Exporting and Importing Change TablesThe following are publisher considerations for exporting and importing change tables:
The original level of export and import support available in Oracle9i Database is retained for backward compatibility. Synchronous change tables that reside in the Re-Creating AutoLog Change Data Capture Objects After an Import OperationAfter a Data Pump full database import operation completes for a database containing AutoLog Change Data Capture objects, the following steps must be performed to restore these objects:
Change data may be lost in the interval between a Data Pump full database export operation involving AutoLog Change Data Capture objects and their re-creation after a Data Pump full database import operation in the preceding step. This can be minimized by preventing changes to the source tables during this interval, if possible. Before re-creating an AutoLog Change Data Capture configuration after a Data Pump import operation, you must first drop the underlying objects: the table underlying a change table, subscriber views, a sequence used by the change set, and a Streams apply process, queue and queue table. Table 16-12 presents each underlying object and the method you use to drop it up after a Data Pump import operation. Table 16-12 Methods to Drop Objects After a Data Pump Import Operation
You can obtain the name of the sequence used by a change set by querying the You can obtain the names of the Streams objects by querying the Impact on Subscriptions When the Publisher Makes ChangesThe Change Data Capture environment is dynamic. The publisher can add and drop change tables at any time. The publisher can also add columns to and drop columns from existing change tables at any time. The following list describes how changes to the Change Data Capture environment affect subscriptions:
Table 16-13 Effects of Publisher Adding a Column to a Change Table
Considerations for Synchronous Change Data CaptureThe following sections provide information that the publisher should be aware of when using the synchronous mode of Change Data Capture: Restriction on Direct-Path INSERTSynchronous Change Data Capture does not support the direct-path When the publisher creates a change table in synchronous mode, Change
Data Capture creates triggers on the source table. Because a
direct-path Similarly, Change Data Capture cannot capture the inserted rows from
multitable insert and merge operations because these statements use a
direct-path See Oracle Database SQL Language Reference for more information regarding the direct-path Datatypes and Table Structures Supported for Synchronous Change Data CaptureSynchronous Change Data Capture supports columns of all built-in Oracle datatypes except the following:
In addition, virtual columns are not supported. Synchronous Change Data Capture does not support the following table structures:
Limitation on Restoring Source Tables from the Recycle BinIf the source table for a synchronous change table is dropped and then restored from the recycle bin, changes are no longer captured in that change table. The publisher must create a new synchronous change table to capture future changes to the restored source table. Considerations for Asynchronous Change Data CaptureThe following sections provide information that the publisher and the source and staging database DBAs should be aware of when using the asynchronous mode of Change Data Capture:
Asynchronous Change Data Capture and Redo Log FilesThe asynchronous mode of Change Data Capture uses redo log files, as follows:
For log files to be archived, the source databases for asynchronous Change Data Capture must run in ALTER DATABASE ARCHIVELOG; See Oracle Database Administrator's Guide for information about running a database in A redo log file used by Change Data Capture must remain available on the staging database until Change Data Capture has captured it. However, it is not necessary that the redo log file remain available until the Change Data Capture subscriber is done with the change data. To determine which redo log files are no longer needed by Change Data
Capture for a given change set, the publisher alters the change set's
Streams capture process, which causes Streams to perform some internal
cleanup and populates the
See the information on setting the first SCN for an existing capture process and on capture process checkpoints in Oracle Streams Concepts and Administration for more information. The Both the size of the redo log files and the frequency with which a log switch occurs can affect the generation of the archived log files at the source database. For Change Data Capture, the most important factor in deciding what size to make a redo log file is the tolerance for latency between when a change is made and when that change data is available to subscribers. However, because the Oracle Database software attempts a check point at each log switch, if the redo log file is too small, frequent log switches will lead to frequent checkpointing and negatively impact the performance of the source database. See Oracle Data Guard Concepts and Administration for step-by-step instructions on monitoring log file archival information. Substitute the terms source and staging database for the Oracle Data Guard terms primary database and archiving destinations, respectively. When using redo transport services to supply redo log files to an
AutoLog change source, gaps in the sequence of redo log files are
automatically detected and resolved. If a situation arises where it is
necessary to manually add a log file to an AutoLog change set, the
publisher can use instructions on explicitly assigning log files to a
downstream capture process described in the Oracle Streams Concepts and Administration.
These instructions require the name of the capture process for the
AutoLog change set. The publisher can obtain the name of the capture
process for an AutoLog change set from the Asynchronous Change Data Capture and Supplemental LoggingThe asynchronous modes of Change Data Capture work best with appropriate supplemental logging on the source database. (Supplemental logging is not used by synchronous Change Data Capture.) The source database DBA must enable some form of database-level supplemental logging. The following example enables minimal database-level supplemental logging: ALTER DATABASE ADD SUPPLEMENTAL LOG DATA; In addition, Oracle recommends that the source database DBA:
See Oracle Database Utilities for more information on the various types of supplemental logging. Asynchronous Change Data Capture and Oracle Streams ComponentsAsynchronous Change Data Capture generates components of Oracle Streams to capture change data and to populate change sets. These components must not be reused or shared for any other purposes. For example, the capture queue that Change Data Capture generates for a Distributed HotLog change source should not be used as the source queue for new user-created Streams propagations. For HotLog and AutoLog modes, each change set contains a Streams capture process, queue, queue table and apply process. The staging database publisher owns all of these objects.For Distributed HotLog mode, each change source resides on the source database and contains a Streams capture process, queue and queue table. Each change set resides on the staging database and contains a Streams apply process. When the first change set in a change source is created, Change Data Capture generates a queue and queue table on the staging database to be shared among all change sets in the change source. Change Data Capture also generates a Streams Propagation on the source database from the change source queue to the change set queue on the staging database. The source database publisher owns the source database objects and the staging database publisher owns the staging database objects. Figure 16-8
illustrates an example of how Streams components are used in an
asynchronous Distributed HotLog Change Data Capture environment. In this
example, there is a Distributed HotLog change source Figure 16-8 Streams Components in an Asynchronous Distributed HotLog Change Data Capture System ![]() Description of "Figure 16-8 Streams Components in an Asynchronous Distributed HotLog Change Data Capture System" Datatypes and Table Structures Supported for Asynchronous Change Data CaptureAsynchronous Change Data Capture supports columns of all built-in Oracle datatypes except the following:
In addition, virtual columns are not supported. Asynchronous Change Data Capture does not support the following table structures:
Restrictions for NOLOGGING and UNRECOVERABLE OperationsIf you use the See Oracle Database SQL Language Reference for information about the Implementation and System ConfigurationChange Data Capture comes packaged with the appropriate Oracle drivers already installed with which you can implement either asynchronous or synchronous data capture. The synchronous mode of Change Data Capture is included with the Standard Edition, but the asynchronous mode requires you have the Enterprise Edition. In addition, note that Change Data Capture uses Java. Therefore, when you install Oracle Database, ensure that Java is enabled. Change Data Capture places system triggers on the SQL To remove Change Data Capture from the database, the SQL script To reinstall Change Data Capture, the SQL script Database Configuration Assistant ConsiderationsAll of the predefined templates provided with the Database Configuration Assistant support the Oracle Change Data Capture feature. The predefined templates are:
If you choose the New Database option to build a custom database, note that Oracle JVM is selected by default in the Additional database configurations dialog box. Do not change this setting; Oracle Change Data Capture requires the Oracle JVM feature. Summary of Supported Distributed HotLog Configurations and RestrictionsThe following sections describe the supported configurations for the Distributed HotLog mode of Change Data Capture as well as the restrictions. Oracle Database Releases for Source and Staging DatabasesThe Distributed HotLog mode of Change Data Capture allows the following combinations of Oracle Database releases for the source and staging databases:
Note: When a release 9.2 or 10.1 Oracle Database serves as the source database for the Distributed HotLog mode of Change Data Capture, metadata for the source database is stored on the staging database, whereas metadata for an Oracle Database release 11.1 source database is stored on the source database. Therefore, to view the metadata for an Oracle Database release 9.2 or 10.1 source database, the publisher must query theCHANGE_SOURCES
data dictionary view on the staging database, and to view the metadata
for an Oracle Database release 11.1 source database, the publisher must
query the CHANGE_SOURCES data dictionary view on the source database.Upgrading a Distributed HotLog Change Source to Oracle Release 11.1As mentioned in the previous topic, the metadata for an Oracle Database release 11.1 Distributed HotLog change source is stored on the source database, but the metadata for a release 9.2 or 10.1 change source is stored on the staging database. When you upgrade a release 10.2 Oracle Database to release 11.1, then there is additional metadata movement required. When you upgrade a release 9.2 or 10.1 Oracle Database to release
11.1, Change Data Capture does not move the source database metadata
from the staging database to the source database as part of the upgrade
operation. However, the first time the change source is enabled after
the upgrade (using the If the publisher prefers to not alter the change source immediately after an upgrade, the change source metadata can remain on the staging database until a more appropriate time. Oracle recommends that the source database metadata not be left on the staging database indefinitely after an upgrade to Oracle Database release 11.1 so that information about the Distributed HotLog change source becomes available in the data dictionary views on the source database. Hardware Platforms and Operating SystemsThe Distributed HotLog mode of Change Data Capture supports the use of different hardware platforms or operating systems (or both) for the source and staging databases. Requirements for Multiple Publishers on the Staging DatabaseIf there are multiple publishers on the staging database for the Distributed HotLog mode of Change Data capture, and one publisher defines a change table in another publisher's Distributed HotLog change set, then Change Data Capture uses the database link established by publisher who created the change set to access the source database. Therefore, the database link to the source database established by the publisher who created the change set must be intact for the change table to be successfully created. If the change set publisher's database link is not present when creating a change table, an error is returned indicating that the connection description for the remote database was not found. Requirements for Database LinksThe database link from the source database to the staging database must exist for the life of a Distributed HotLog change source. The database link from the staging database to the source database must exist when creating, altering or dropping Distributed HotLog change sources, change sets and change tables. However, this database link is not required for change capture to occur. Once the required Distributed HotLog change sources, change sets and change tables are in place and enabled, this database link can be dropped without interrupting change capture. This database link would need to be re-created to create, alter or drop Distributed HotLog change sources, change sets and change tables. |
DBA's Home Page - A website for Oracle, Greenplum and PostgreSQL DBA's > DBA's Forum, Routine Tasks and Activities >