|
|
IntroductionSchema to schema replication is an easy exercise, as it is quite automated. The only difficulty will be setting up the conflict handler. Convention and namesFor this exercise we will replicate the user scott schema from DB dev1 (site 1) to (dev2) site2
Action courseThe following table summarize the action course to create a schema to schema capture.
|
| -- Optional case Streams recommended
tablespace does not exists. adapt ${ORA_DATA} -- CREATE TABLESPACE streams LOGGING DATAFILE '$ORA_DATA/streams01.dbf' SIZE 100M REUSE AUTOEXTEND ON -- EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO' CREATE USER strmadmin IDENTIFIED BY strmadmin DEFAULT TABLESPACE streams TEMPORARY TABLESPACE temp; GRANT connect, resource, dba, aq_administrator_role TO strmadmin; GRANT select any table TO strmadmin; GRANT CREATE JOB TO strmadmin; GRANT select_catalog_role, select any dictionary TO strmadmin; exec dbms_streams_auth.grant_admin_privilege('STRMADMIN'); |
Create a dblink for the admin user site 1
| connect / as sysdba CREATE DATABASE LINK dev2.domain.com CONNECT TO strmadmin IDENTIFIED BY strmadmin USING 'dev2.domain.com; |
Create a dblink for the admin user site 2
| connect / as sysdba CREATE DATABASE LINK dev1.domain.com CONNECT TO strmadmin IDENTIFIED BY strmadmin USING 'dev1.domain.com ; |
Add supplemental logging (site 1 & 2)
| connect / as sysdba
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (primary key, unique, foreign key) COLUMNS; |
Create capture queue table on site_1
| exec DBMS_STREAMS_ADM.SET_UP_QUEUE( queue_table => 'cap_scott_1_qt', queue_name =>
'cap_scott_1_q' ); |
Create capture queue table on site_2
| exec DBMS_STREAMS_ADM.SET_UP_QUEUE( queue_table => 'cap_scott_2_qt', queue_name =>
'cap_scott2_q' ); |
| exec DBMS_STREAMS_ADM.ADD_SCHEMA_RULES(
schema_name => 'scott', streams_type => 'capture', streams_name => 'cap_scott_1', queue_name => 'cap_scott_1_q', include_dml => true, include_ddl => true, inclusion_rule => true); |
| exec DBMS_STREAMS_ADM.ADD_SCHEMA_RULES( schema_name =>
'scott', streams_type => 'capture', streams_name => 'cap_scott_2', queue_name => 'cap_scott_2_q', include_dml => true, include_ddl => true, inclusion_rule => true); |
Create Apply queue table (site 1 )
| exec DBMS_STREAMS_ADM.SET_UP_QUEUE( queue_table => 'app_scott_1_qt', queue_name =>
'app_scott_1_q' ); |
Create Apply queue table (site 2 )
| exec DBMS_STREAMS_ADM.SET_UP_QUEUE( queue_table => 'app_scott_2_qt', queue_name =>
'app_scott_2_q' ); |
Create apply process on site 1
| exec DBMS_STREAMS_ADM.ADD_SCHEMA_RULES(
schema_name => 'scott', streams_type => 'apply', streams_name => 'app_scott_1', queue_name => 'app_scott_1_q', include_dml => true, include_ddl => true, source_database => 'dev2.domain.com', /* note the name of the SID */ inclusion_rule => true); /* given with the domain name */ |
Create apply process on site 2
| exec DBMS_STREAMS_ADM.ADD_SCHEMA_RULES(
schema_name => 'scott', streams_type => 'apply', streams_name => 'app_scott_2', queue_name => 'app_scott_2_q', include_dml => true, include_ddl => true, source_database => 'dev1.domain.com', inclusion_rule => true); |
Create propagation process from site 1 to site 2
| exec DBMS_STREAMS_ADM.ADD_SCHEMA_PROPAGATION_RULES( schema_name =>
'scott', streams_name => 'prop_2_dev2', source_queue_name => 'cap_scott_1_q', destination_queue_name => 'app_scott_2_q@linux2.domain.com', include_dml => TRUE, include_ddl => TRUE, source_database => 'dev1.domain.com', inclusion_rule => TRUE, queue_to_queue => TRUE); |
Create propagation process from site 2 to site 1
| exec DBMS_STREAMS_ADM.ADD_SCHEMA_PROPAGATION_RULES( schema_name =>
'scott', streams_name => 'prop_2_dev1', source_queue_name => 'cap_scott_2_q', destination_queue_name => 'app_scott_1_q@linux1.domain.com', include_dml => TRUE, include_ddl => TRUE, source_database => 'dev2.domain.com', inclusion_rule => TRUE, queue_to_queue => TRUE); |
Prepare source instantiation (site 1 & 2)
| execute DBMS_CAPTURE_ADM.PREPARE_SCHEMA_INSTANTIATION( schema_name =>
'scott', supplemental_logging => 'keys'); |
instantiate site_1 with Scn of site_2
We instantiate the apply process using the current SCN of the capture site.
| DECLARE iscn number ; BEGIN select DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER() into iscn from dual@dev2.domain.com; DBMS_APPLY_ADM.SET_SCHEMA_INSTANTIATION_SCN( source_schema_name => 'scott', source_database_name => 'dev2.domain.com', instantiation_scn => iscn , recursive => true); END; / |
instantiate site_2 with Scn of site_1
We instantiate the apply process using the current SCN of the capture site.
| DECLARE iscn number ; BEGIN select DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER() into iscn from dual@dev1.domain.com; DBMS_APPLY_ADM.SET_SCHEMA_INSTANTIATION_SCN( source_schema_name => 'scott', source_database_name => 'dev1.domain.com', instantiation_scn => iscn , recursive => true); END; / |
| exec DBMS_CAPTURE_ADM.START_CAPTURE( capture_name => 'cap_scott_1'); |
| exec DBMS_CAPTURE_ADM.START_CAPTURE( capture_name => 'cap_scott_1'); |
| exec DBMS_APPLY_ADM.START_APPLY( apply_name => 'app_scott_1'); |
| exec DBMS_APPLY_ADM.START_APPLY( apply_name => 'app_scott_2); |