Oracle® Streams Replication Administrator's Guide 10g Release 2 (10.2) Part Number B14228-04 |
|
|
View PDF |
This chapter explains concepts relating to Streams support for information sharing between Oracle databases and non-Oracle databases.
This chapter contains these topics:
To share DML changes from an Oracle source database to a non-Oracle destination database, the Oracle database functions as a proxy and carries out some of the steps that would normally be done at the destination database. That is, the LCRs intended for the non-Oracle destination database are dequeued in the Oracle database itself and an apply process at the Oracle database applies the changes to the non-Oracle database across a network connection through an Oracle Transparent Gateway. Figure 5-1 shows an Oracle database sharing data with a non-Oracle database.
Figure 5-1 Oracle to Non-Oracle Heterogeneous Data Sharing
You should configure the Oracle Transparent Gateway to use the transaction model COMMIT_CONFIRM
.
See Also:
Your Oracle-supplied gateway-specific documentation for information about using the transaction modelCOMMIT_CONFIRM
for your Oracle Transparent GatewayIn an Oracle to non-Oracle environment, the capture process functions the same way as it would in an Oracle-only environment. That is, it finds changes in the redo log, captures them based on capture process rules, and enqueues the captured changes as logical change records (LCRs) into an ANYDATA
queue. In addition, a single capture process can capture changes that will be applied at both Oracle and non-Oracle databases.
Similarly, the ANYDATA
queue that stages the captured LCRs functions the same way as it would in an Oracle-only environment, and you can propagate LCRs to any number of intermediate queues in Oracle databases before they are applied at a non-Oracle database.
See Also:
Oracle Streams Concepts and Administration for general information about capture processes, staging, and propagations
Chapter 1, "Understanding Streams Replication" for information about capture processes, staging, and propagations in a Streams replication environment
An apply process running in an Oracle database uses Heterogeneous Services and an Oracle Transparent Gateway to apply changes encapsulated in LCRs directly to database objects in a non-Oracle database. The LCRs are not propagated to a queue in the non-Oracle database, as they would be in an Oracle-only Streams environment. Instead, the apply process applies the changes directly through a database link to the non-Oracle database.
Note:
Oracle Streams apply processes do not support Generic Connectivity.See Also:
Oracle Streams Concepts and Administration for general information about apply processes
"Apply and Streams Replication" for information about apply processes in a Streams replication environment
This section describes the configuration of an apply process that will apply changes to a non-Oracle database.
When you create an apply process that will apply changes to a non-Oracle database, you previously must have configured Heterogeneous Services, the Oracle Transparent Gateway, and a database link, which will be used by the apply process to apply the changes to the non-Oracle database. The database link must be created with an explicit CONNECT
TO
clause.
When the database link is created and working properly, create the apply process using the CREATE_APPLY
procedure in the DBMS_APPLY_ADM
package and specify the database link for the apply_database_link
parameter. After you create an apply process, you can use apply process rules to specify which changes are applied at the non-Oracle database.
See Also:
Oracle Database Heterogeneous Connectivity Administrator's Guide for more information about Heterogeneous Services and Oracle Transparent Gateways
Oracle Database PL/SQL Packages and Types Reference for more information about the procedures in the DBMS_APPLY_ADM
package
Oracle Streams Concepts and Administration for information about specifying apply process rules
If you use substitute key columns for any of the tables at the non-Oracle database, then specify the database link to the non-Oracle database when you run the SET_KEY_COLUMNS
procedure in the DBMS_APPLY_ADM
package.
You must set the parallelism
apply process parameter to 1
, the default setting, when an apply process is applying changes to a non-Oracle database. Currently, parallel apply to non-Oracle databases is not supported. However, you can use multiple apply processes to apply changes a non-Oracle database.
If you use a DML handler to process row LCRs for any of the tables at the non-Oracle database, then specify the database link to the non-Oracle database when you run the SET_DML_HANDLER
procedure in the DBMS_APPLY_ADM
package.
See Also:
"Managing a DML Handler" and Oracle Streams Concepts and Administration for information about message processing options for an apply processIf you want to use a message handler to process user-enqueued messages for a non-Oracle database, then, when you run the CREATE_APPLY
procedure in the DBMS_APPLY_ADM
package, specify the database link to the non-Oracle database using the apply_database_link
parameter, and specify the message handler procedure using the message_handler
parameter.
See Also:
Oracle Streams Concepts and Administration for information about message processing options and managing message handlersCurrently, error handlers and conflict handlers are not supported when sharing data from an Oracle database to a non-Oracle database. If an apply error occurs, then the transaction containing the LCR that caused the error is moved into the error queue in the Oracle database.
When applying changes to a non-Oracle database, an apply process applies changes made to columns of only the following datatypes:
CHAR
VARCHAR2
NCHAR
NVARCHAR2
NUMBER
DATE
RAW
TIMESTAMP
TIMESTAMP
WITH
TIME
ZONE
TIMESTAMP
WITH
LOCAL
TIME
ZONE
INTERVAL
YEAR
TO
MONTH
INTERVAL
DAY
TO
SECOND
The apply process does not apply changes in columns of the following datatypes to non-Oracle databases: CLOB
, NCLOB
, BLOB
, BFILE
, LONG
, LONG
RAW
, ROWID
, UROWID
, and user-defined types (including object types, REF
s, varrays, and nested tables). The apply process raises an error when an LCR contains a datatype that is not listed, and the transaction containing the LCR that caused the error is moved to the error queue in the Oracle database.
Each Oracle Transparent Gateway might have further limitations regarding datatypes. For a datatype to be supported in an Oracle to non-Oracle environment, the datatype must be supported by both Streams and the Oracle Transparent Gateway being used.
See Also:
Oracle Database SQL Reference for more information about these datatypes
Your Oracle-supplied gateway-specific documentation for information about transparent gateways
When you specify that DML changes made to certain tables should be applied at a non-Oracle database, an apply process can apply only the following types of DML changes:
INSERT
UPDATE
DELETE
Note:
The apply process cannot apply DDL changes at non-Oracle databases.Before you start an apply process that applies changes to a non-Oracle database, complete the following steps to instantiate each table at the non-Oracle database:
Use the DBMS_HS_PASSTHROUGH
package or the tools supplied with the non-Oracle database to create the table at the non-Oracle database.
The following is an example that uses the DBMS_HS_PASSTHROUGH
package to create the hr.regions
table in the het.net
non-Oracle database:
CONNECT hr/hr DECLARE ret INTEGER; BEGIN ret := DBMS_HS_PASSTHROUGH.EXECUTE_IMMEDIATE@het.net ( 'CREATE TABLE regions (region_id INTEGER, region_name VARCHAR(50))'); END; / COMMIT;
See Also:
Oracle Database Heterogeneous Connectivity Administrator's Guide and your Oracle supplied gateway-specific documentation for more information about Heterogeneous Services and Oracle Transparent GatewayIf the changes that will be shared between the Oracle and non-Oracle database are captured by a capture process at the Oracle database, then prepare all tables that will share data for instantiation.
Create a PL/SQL procedure (or a C program) that performs the following actions:
Gets the current SCN using the GET_SYSTEM_CHANGE_NUMBER
function in the DBMS_FLASHBACK
package.
Invokes the ENABLE_AT_SYSTEM_CHANGE_NUMBER
procedure in the DBMS_FLASHBACK
package to set the current session to the obtained SCN. This action ensures that all fetches are done using the same SCN.
Populates the table at the non-Oracle site by fetching row by row from the table at the Oracle database and then inserting row by row into the table at the non-Oracle database. All fetches should be done at the SCN obtained using the GET_SYSTEM_CHANGE_NUMBER
function.
For example, the following PL/SQL procedure gets the flashback SCN, fetches each row in the hr.regions
table in the current Oracle database, and inserts them into the hr.regions
table in the het.net
non-Oracle database. Notice that flashback is disabled before the rows are inserted into the non-Oracle database.
SET SERVEROUTPUT ON CREATE OR REPLACE PROCEDURE insert_reg IS CURSOR c1 IS SELECT region_id, region_name FROM hr.regions; c1_rec c1 % ROWTYPE; scn NUMBER; BEGIN scn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER(); DBMS_FLASHBACK.ENABLE_AT_SYSTEM_CHANGE_NUMBER( query_scn => scn); /* Open c1 in flashback mode */ OPEN c1; /* Disable Flashback */ DBMS_FLASHBACK.DISABLE; LOOP FETCH c1 INTO c1_rec; EXIT WHEN c1%NOTFOUND; /* Note that all the DML operations inside the loop are performed with Flashback disabled */ INSERT INTO hr.regions@het.net VALUES ( c1_rec.region_id, c1_rec.region_name); END LOOP; COMMIT; DBMS_OUTPUT.PUT_LINE('SCN = ' || scn); EXCEPTION WHEN OTHERS THEN DBMS_FLASHBACK.DISABLE; RAISE; END; /
Make a note of the SCN returned.
If the Oracle Transparent Gateway you are using supports the Heterogeneous Services callback functionality, then you can replace the loop in the previous example with the following SQL statement:
INSERT INTO hr.region@het.net SELECT * FROM hr.region@!;
Note:
The user who creates and runs the procedure in the previous example must haveEXECUTE
privilege on the DBMS_FLASHBACK
package and all privileges on the tables involved.See Also:
Oracle Database Heterogeneous Connectivity Administrator's Guide and your Oracle-supplied gateway-specific documentation for information about callback functionality and your Oracle Transparent GatewaySet the instantiation SCN for the table at the non-Oracle database. Specify the SCN you obtained in Step 3 in the SET_TABLE_INSTANTIATION_SCN
procedure in the DBMS_APPLY_ADM
package to instruct the apply process to skip all LCRs with changes that occurred before the SCN you obtained in Step 3. Make sure you set the apply_database_link
parameter to the database link for the remote non-Oracle database.
See Also:
"Setting Instantiation SCNs at a Destination Database" and Oracle Database PL/SQL Packages and Types Reference for more information about theSET_TABLE_INSTANTIATION_SCN
procedureIn an Oracle to non-Oracle environment, you can specify rule-based transformations during capture or apply the same way as you would in an Oracle-only environment. In addition, if your environment propagates LCRs to one or more intermediate Oracle databases before they are applied at a non-Oracle database, then you can specify a rule-based transformation during propagation from a queue at an Oracle database to another queue at an Oracle database.
See Also:
Oracle Streams Concepts and Administration for more information about rule-based transformationsMessaging Gateway is a feature of the Oracle database that provides propagation between Oracle queues and non-Oracle message queuing systems. Messages enqueued into an Oracle queue are automatically propagated to a non-Oracle queue, and the messages enqueued into a non-Oracle queue are automatically propagated to an Oracle queue. It provides guaranteed message delivery to the non-Oracle messaging system and supports the native message format for the non-Oracle messaging system. It also supports specification of user-defined transformations that are invoked while propagating from an Oracle queue to the non-Oracle messaging system or from the non-Oracle messaging system to an Oracle queue.
See Also:
Oracle Streams Advanced Queuing User's Guide and Reference for more information about the Messaging GatewayIf the apply process encounters an unhandled error when it tries to apply an LCR at a non-Oracle database, then the transaction containing the LCR is placed in the error queue in the Oracle database that is running the apply process. The apply process detects data conflicts in the same way as it does in an Oracle-only environment, but automatic conflict resolution is not supported currently in an Oracle to non-Oracle environment. Therefore, any data conflicts encountered are treated as apply errors.
Chapter 19, "Single-Source Heterogeneous Replication Example" contains a detailed example that includes sharing data in an Oracle to non-Oracle Streams environment.
To capture and propagate changes from a non-Oracle database to an Oracle database, a custom application is required. This application gets the changes made to the non-Oracle database by reading from transaction logs, by using triggers, or by some other method. The application must assemble and order the transactions and must convert each change into a logical change record (LCR). Next, the application must enqueue the LCRs into a queue in an Oracle database using the DBMS_STREAMS_MESSAGING
package or the DBMS_AQ
package. The application must commit after enqueuing all LCRs in each transaction. Figure 5-2 shows a non-Oracle databases sharing data with an Oracle database.
Figure 5-2 Non-Oracle to Oracle Heterogeneous Data Sharing
Because the custom user application is responsible for assembling changes at the non-Oracle database into LCRs and enqueuing the LCRs into a queue at the Oracle database, the application is completely responsible for change capture. This means that the application must construct LCRs that represent changes at the non-Oracle database and then enqueue these LCRs into the queue at the Oracle database. The application can enqueue multiple transactions concurrently, but the transactions must be committed in the same order as the transactions on the non-Oracle source database.
See Also:
"Constructing and Enqueuing LCRs" for more information about constructing and enqueuing LCRsIf you want to ensure the same transactional consistency at both the Oracle database where changes are applied and the non-Oracle database where changes originate, then you must use a transactional queue to stage the LCRs at the Oracle database. For example, suppose a single transaction contains three row changes, and the custom application enqueues three row LCRs, one for each change, and then commits. With a transactional queue, a commit is performed by the apply process after the third row LCR, retaining the consistency of the transaction. If you use a nontransactional queue, then a commit is performed for each row LCR by the apply process. The SET_UP_QUEUE
procedure in the DBMS_STREAMS_ADM
package creates a transactional queue automatically.
Also, the queue at the Oracle database should be a commit-time queue. A commit-time queue orders LCRs by approximate commit system change number (approximate CSCN) of the transaction that includes the LCRs. Commit-time queues preserve transactional dependency ordering between LCRs in the queue, assuming that the application that enqueued the LCRs commit transactions in the correct order. Also, commit-time queues ensure consistent browses of LCRs in a queue.
See Also:
Oracle Streams Concepts and Administration for more information about transactional queues and commit-time queuesIn a non-Oracle to Oracle environment, the apply process functions the same way as it would in an Oracle-only environment. That is, it dequeues each LCR from its associated queue based on apply process rules, performs any rule-based transformation, and either sends the LCR to a handler or applies it directly. Error handling and conflict resolution also function the same as they would in an Oracle-only environment. So, you can specify a prebuilt update conflict handler or create a custom conflict handler to resolve conflicts.
The apply process should be configured to apply user-enqueued LCRs, not captured LCRs. So, the apply process should be created using the CREATE_APPLY
procedure in the DBMS_APPLY_ADM
package, and the apply_captured
parameter should be set to false
when you run this procedure. After the apply process is created, you can use procedures in the DBMS_STREAMS_ADM
package to add rules for LCRs to the apply process rule sets.
See Also:
Oracle Streams Concepts and Administration for more information about apply processes, rules, and rule-based transformations
There is no automatic way to instantiate tables that exist at a non-Oracle database at an Oracle database. However, you can perform the following general procedure to instantiate a table manually:
At the non-Oracle database, use a non-Oracle utility to export the table to a flat file.
At the Oracle database, create an empty table that matches the table at the non-Oracle database.
At the Oracle database, use SQL*Loader to load the contents of the flat file into the table.
See Also:
Oracle Database Utilities for information about using SQL*LoaderStreams supports data sharing between two non-Oracle databases through a combination of non-Oracle to Oracle data sharing and Oracle to non-Oracle data sharing. Such an environment would use Streams in an Oracle database as an intermediate database between two non-Oracle databases.
For example, a non-Oracle to non-Oracle environment can consist of the following databases:
A non-Oracle database named het1.net
An Oracle database named dbs1.net
A non-Oracle database named het2.net
A user application assembles changes at het1.net
and enqueues them into a queue in dbs1.net
. Next, the apply process at dbs1.net
applies the changes to het2.net
using Heterogeneous Services and an Oracle Transparent Gateway. Another apply process at dbs1.net
could apply some or all of the changes in the queue locally at dbs1.net
. One or more propagations at dbs1.net
could propagate some or all of the changes in the queue to other Oracle databases.