1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
|
Step 1: Create stream administration user in both databases.
----------ORCL
create user streamadmin identified by streamadmin default tablespace users;
----------TEST
create user streamadmin identified by streamadmin default tablespace users;
Step 2: Required grants to the user streamadmin.
----------on both of the databases(ORCL&TEST)
grant dba,select_catalog_role to streamadmin;
Grants the privileges needed by a user to be an administrator for streams
begin
dbms_streams_auth.grant_admin_privilege('streamadmin',true);
end;
Step 3: We will use default HR schema for setting up this replication for table countries
Step 4: Check database parameters required for setting up stream replication
check job_queue_processes parameter , it should not be 0. Also you can set e global_names parameter true, but if you create database links exact as oracle SIDs value true is not necessary.
Step 5: Enable supplemental logging on the tables of the HR user in both of the databases
----------on both of the databases(ORCL&TEST)
ALTER TABLE HR.countries ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;
Step 6: Create Database Links between the stream administrator users in the both databases.
Logon with streamadmin user
----------ORCL
CREATE DATABASE LINK TEST CONNECT TO STREAMADMIN IDENTIFIED BY streamadmin USING 'TEST';
----------TEST
CREATE DATABASE LINK ORCL CONNECT TO STREAMADMIN IDENTIFIED BY streamadmin USING 'ORCL';
Step 7: Create Stream Queues under the streamadmin user to apply and capture the database changes to be replicated.
This also needs to be run on both databases as streamadmin user.
----------on both of the databases(ORCL&TEST)
begin
dbms_streams_adm.set_up_queue(queue_table => 'apply_q', queue_name => 'apply_q', queue_user => 'streamadmin');
end;
begin
dbms_streams_adm.set_up_queue(queue_table => 'capture_q',queue_name => 'capture_q',queue_user => 'streamadmin');
end;
Step 8: Setup data capture on both the databases:
Logon with streamadmin user
----------on both of the databases(ORCL&TEST)
BEGIN
DBMS_STREAMS_ADM.add_table_rules
(table_name => 'HR.COUNTRIES'
,streams_type => 'CAPTURE'
,streams_name => 'CAPTURE_STREAM'
,queue_name => 'CAPTURE_Q'
,include_dml => TRUE
,include_ddl => TRUE
,inclusion_rule => TRUE
);
END;
Step 9: Setup data apply on both the databases:
Logon with streamadmin user
----------TEST
BEGIN
DBMS_STREAMS_ADM.add_table_rules (
TABLE_NAME => 'HR.COUNTRIES',
STREAMS_TYPE => 'APPLY',
STREAMS_NAME => 'APPLY_STREAM',
QUEUE_NAME => 'APPLY_Q',
INCLUDE_DML => TRUE,
INCLUDE_DDL => TRUE,
SOURCE_DATABASE => 'ORCL');
END;
----------on ORCL
BEGIN
DBMS_STREAMS_ADM.add_table_rules (
TABLE_NAME => 'HR.COUNTRIES',
STREAMS_TYPE => 'APPLY',
STREAMS_NAME => 'APPLY_STREAM',
QUEUE_NAME => 'APPLY_Q',
INCLUDE_DML => TRUE,
INCLUDE_DDL => TRUE,
SOURCE_DATABASE => 'TEST');
END;
Step 10: Setup propagation process on both the databases:
It is basically setting up related between the capture process on one database and apply process on the other database.
Logon with streamadmin user
----------on ORCL
BEGIN
DBMS_STREAMS_ADM.ADD_TABLE_PROPAGATION_RULES(
TABLE_NAME => 'HR.COUNTRIES',
STREAMS_NAME => 'ORCL_TO_TEST',
SOURCE_QUEUE_NAME =>'CAPTURE_Q',
DESTINATION_QUEUE_NAME => 'APPLY_Q@TEST',
INCLUDE_DML => TRUE,
INCLUDE_DDL => TRUE,
SOURCE_DATABASE => 'ORCL');
END;
----------on TEST
BEGIN
DBMS_STREAMS_ADM.add_table_propagation_rules(
TABLE_NAME => 'HR.COUNTRIES',
STREAMS_NAME => 'TEST_TO_ORCL',
SOURCE_QUEUE_NAME =>'CAPTURE_Q',
DESTINATION_QUEUE_NAME => 'APPLY_Q@ORCL',
INCLUDE_DML => TRUE,
INCLUDE_DDL => TRUE,
SOURCE_DATABASE => 'TEST');
END;
Step 11: Setup schema instantiation SCN on ORCL and TEST DBs
----------on TEST
DECLARE
ISCN NUMBER;
BEGIN
ISCN := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER();
DBMS_APPLY_ADM.set_table_instantiation_scn@ORCL(source_object_name => 'HR.COUNTRIES',source_database_name => 'TEST',instantiation_scn => ISCN);
END;
----------on ORCL
DECLARE
ISCN NUMBER;
BEGIN
ISCN := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER();
DBMS_APPLY_ADM.set_table_instantiation_scn@TEST(source_object_name => 'HR.COUNTRIES',source_database_name => 'ORCL',instantiation_scn => ISCN);
END;
Step 12: Start capture and apply process:
Setting the disable_on_error parameter to N allows the apply process to continue applying row LCRs even when it encounters errors. The default value is Y which disables the apply process automatically on the first error encountered.
----------on both DBs
BEGIN
DBMS_APPLY_ADM.SET_PARAMETER (APPLY_NAME => 'APPLY_STREAM', PARAMETER => 'DISABLE_ON_ERROR', VALUE => 'N');
DBMS_APPLY_ADM.START_APPLY (APPLY_NAME => 'APPLY_STREAM');
DBMS_CAPTURE_ADM.START_CAPTURE (CAPTURE_NAME => 'CAPTURE_STREAM');
END;
------------------------------------------------------------------------
Now you can test your replication 2-way replication which means all changes for HR.COUNTRIES from ORCL DB shipped to TEST DB and , all changes from TEST DB shipped to ORCL DB |
Partager