Académique Documents
Professionnel Documents
Culture Documents
1)
APPLIES TO:
Oracle Server - Enterprise Edition - Version 9.2.0.1 and later
Information in this document applies to any platform.
PURPOSE
Oracle Streams enables the sharing of data and events in a data stream, either
within a database or from one database to another.
This article is intended to assist Replication DBAs in setting up and
configuring Oracle Streams Replication.
SCOPE
To be used by Oracle support analysts and replication DBAs to setup replication
using Streams in Oracle 9.2.x.
This article discusses the steps to setup Streams Replication from one Oracle
database to another.
The Global Database Name of the Source Database is V920.IDC.ORACLE.COM
The Global Database Name of the Destination Database is TEST920.IDC.ORACLE.COM
In the example setup, DEPT table belonging to SCOTT schema has been used for
demonstration purpose.
DETAILS
INTRODUCTION
------------Oracle 9.2 has introduced a more flexible and efficient way of implementing
replication using streams.
In a nutshell, replication using streams is implemented in the following way.
1) A background capture process is configured to capture changes made to
tables,schemas, or the entire database. The capture process captures
changes from the redo log and formats each captured change into a logical
change record (LCR).
The capture process uses logminer to mine the redo/archive logs to format LCRs.
2) The capture process enqueues LCR events into a queue that is specified.
3) This queue is scheduled to Propagate events from one queue to another in a
different database.
4) A background apply process dequeues the events and applies them at the
destination database.
STREAMS SETUP
To Bottom
EXECUTE
EXECUTE
EXECUTE
EXECUTE
EXECUTE
EXECUTE
EXECUTE
EXECUTE
ON
ON
ON
ON
ON
ON
ON
ON
DBMS_AQ TO STRMADMIN;
DBMS_AQADM TO STRMADMIN;
DBMS_FLASHBACK TO STRMADMIN;
DBMS_STREAMS_ADM TO STRMADMIN;
DBMS_CAPTURE_ADM TO STRMADMIN;
DBMS_APPLY_ADM TO STRMADMIN;
DBMS_RULE_ADM TO STRMADMIN;
DBMS_PROPAGATION_ADM TO STRMADMIN;
BEGIN
DBMS_AQADM.GRANT_SYSTEM_PRIVILEGE(
privilege => 'ENQUEUE_ANY',
grantee => 'STRMADMIN',
admin_option => FALSE);
END;
/
BEGIN
DBMS_AQADM.GRANT_SYSTEM_PRIVILEGE(
privilege => 'DEQUEUE_ANY',
grantee => 'STRMADMIN',
admin_option => FALSE);
END;
/
BEGIN
DBMS_AQADM.GRANT_SYSTEM_PRIVILEGE(
privilege => 'MANAGE_ANY',
grantee => 'STRMADMIN',
connect STRMADMIN/STRMADMIN
BEGIN
DBMS_STREAMS_ADM.SET_UP_QUEUE(
queue_table => 'STREAMS_QUEUE_TABLE',
queue_name => 'STREAMS_QUEUE',
queue_user => 'STRMADMIN');
END;
/
2.4 Add apply rules for the table at the destination database :
BEGIN
DBMS_STREAMS_ADM.ADD_TABLE_RULES(
table_name => 'SCOTT.DEPT',
streams_type => 'APPLY',
streams_name => 'STRMADMIN_APPLY',
queue_name => 'STRMADMIN.STREAMS_QUEUE',
include_dml => true,
include_ddl => true,
source_database => 'V920.IDC.ORACLE.COM');
END;
/
BEGIN
DBMS_APPLY_ADM.ALTER_APPLY(
apply_name => 'STRMADMIN_APPLY',
apply_user => 'SCOTT');
END;
/
2.6 If you do not wish the apply process to abort for every error that it
encounters, you can set the below paramter.
The default value is 'Y' which means that apply process would abort due to
any error.
When set to 'N', the apply process will not abort for any error that it
encounters, but the error details would be logged in DBA_APPLY_ERROR.
BEGIN
DBMS_APPLY_ADM.SET_PARAMETER(
apply_name => 'STRMADMIN_APPLY',
parameter => 'DISABLE_ON_ERROR',
value => 'N' );
END;
/
connect STRMADMIN/STRMADMIN
CREATE DATABASE LINK TEST920.IDC.ORACLE.COM connect to
STRMADMIN identified by STRMADMIN using 'TEST920.IDC.ORACLE.COM';
BEGIN
DBMS_STREAMS_ADM.SET_UP_QUEUE(
queue_name => 'STREAMS_QUEUE',
queue_table =>'STREAMS_QUEUE_TABLE',
queue_user => 'STRMADMIN');
END;
/
3.6 Add capture rules for the table at the source database:
BEGIN
DBMS_STREAMS_ADM.ADD_TABLE_RULES(
table_name => 'SCOTT.DEPT',
streams_type => 'CAPTURE',
streams_name => 'STRMADMIN_CAPTURE',
queue_name => 'STRMADMIN.STREAMS_QUEUE',
include_dml => true,
include_ddl => true,
source_database => 'V920.IDC.ORACLE.COM');
END;
/
3.7 Add propagation rules for the table at the source database.
This step will also create a propagation job to the destination database.
BEGIN
DBMS_STREAMS_ADM.ADD_TABLE_PROPAGATION_RULES(
table_name => 'SCOTT.DEPT',
streams_name => 'STRMADMIN_PROPAGATE',
source_queue_name => 'STRMADMIN.STREAMS_QUEUE',
destination_queue_name => 'STRMADMIN.STREAMS_QUEUE@TEST920.IDC.ORACLE.COM',
include_dml => true,
include_ddl => true,
source_database => 'V920.IDC.ORACLE.COM');
END;
/
Section 4 - Export, import and instantiation of tables from Source to Destination Database
-----------------------------------------------------------------------------------------------4.1 If the objects are not present in the destination database, perform an
export of the objects from the source database and import them into the
destination database
Export from the Source Database:
Specify the OBJECT_CONSISTENT=Y clause on the export command.
By doing this, an export is performed that is consistent for each
individual object at a particular system change number (SCN).
exp USERID=SYSTEM@V920.IDC.ORACLE.COM TABLES=SCOTT.DEPT FILE=tables.dmp
GRANTS=Y ROWS=Y LOG=exportTables.log OBJECT_CONSISTENT=Y
INDEXES=Y STATISTICS = NONE
4.2 If the objects are already present in the desination database, check that they are also
consistent at data level, otherwise the apply process may fail with error ORA-1403 when
apply a DML on a not consistent row. There are 2 ways of instanitating the objects
at the destination site.
1. By means of Metadata-only export/import :
Export from the Source Database by specifying ROWS=N
exp USERID=SYSTEM@V920.IDC.ORACLE.COM TABLES=SCOTT.DEPT FILE=tables.dmp
ROWS=N LOG=exportTables.log OBJECT_CONSISTENT=Y
Import into the destination database using IGNORE=Y
imp USERID=SYSTEM@TEST920.IDC.ORACLE.COM FULL=Y FILE=tables.dmp IGNORE=Y
LOG=importTables.log STREAMS_INSTANTIATION=Y
2. By Manaually instantiating the objects
Instantiate the objects at the destination database with this SCN value.
The SET_TABLE_INSTANTIATION_SCN procedure controls which LCRs for a table
are to be applied by the apply process.
If the commit SCN of an LCR from the source database is less than or
equal to this instantiation SCN , then the apply process discards the LCR.
Else, the apply process applies the LCR.
connect STRMADMIN/STRMADMIN@destination
BEGIN
DBMS_APPLY_ADM.SET_TABLE_INSTANTIATION_SCN(
source_object_name => 'SCOTT.DEPT',
source_database_name => 'V920.IDC.ORACLE.COM',
instantiation_scn => &iscn);
END;
Enter value for iscn: