8
ĐỒNG BỘ DATABASE GIỮA 2 SERVER Môi trường Thực hiện Database Version: 10g release 2 2 máy Windows Server 2003 Server 1: IP: 10.33.3.167; SM 255.0.0.0; GW 10.33.3.254 Server 1: IP: 10.33.3.169; SM 255.0.0.0; GW 10.33.3.254 Tên Database và TNS Server 1: DB1, db1 (source) 10.33.3.167 port 1521 Server 2: DB2, db2 (target) 10.33.3.169 port 1521 1. Thiết lập cả 2 thông số (db1, db2) cho cả hai database Vào Start Menu > All programs > Oracle OraDb10g_home2 > Configuration and Migration Tools > Net Configuration Assistant db1 Cửa sổ welcome hiện lên chọn Local Net Service Name configuration > Next > Add > Next. Tại ô Service Name điền DB1, tiếp tục Next chọn giao thức TCP rồi Next. Tại ô Host Name điền IP 10.33.3.169 và sử dụng Port mặc định 1521 tiếp tục Next đến Net Service Name nhập db1 Finish db2 tương tự như làm với db1 2. Enable ARCHIVELOG MODE trên cả 2 dabase SQL> shutdown immediate; SQL> startup mount; SQL> alter database archivelog; SQL> alter database open; SQL> archive log list; 3. Tạo Stream administrator User Source Database: DB1 SQL> conn sys@db1 as sysdba Enter password: Connected. SQL> create user strmadmin identified by strmadmin; User created. SQL> grant connect, resource, dba to strmadmin; Grant succeeded. SQL> begin dbms_streams_auth.grant_admin_privilege 2 (grantee => 'strmadmin', 3 grant_privileges => true);

ĐỒNG BỘ DATABASE GIỮA 2 SERVER

Embed Size (px)

Citation preview

Page 1: ĐỒNG BỘ DATABASE GIỮA 2 SERVER

ĐỒNG BỘ DATABASE GIỮA 2 SERVER Môi trường Thực hiện Database Version: 10g release 2 2 máy Windows Server 2003

Server 1: IP: 10.33.3.167; SM 255.0.0.0; GW 10.33.3.254

Server 1: IP: 10.33.3.169; SM 255.0.0.0; GW 10.33.3.254 Tên Database và TNS Server 1: DB1, db1 (source) 10.33.3.167 port 1521 Server 2: DB2, db2 (target) 10.33.3.169 port 1521 1. Thiết lập cả 2 thông số (db1, db2) cho cả hai database Vào Start Menu > All programs > Oracle – OraDb10g_home2 > Configuration and Migration Tools > Net Configuration Assistant

db1 Cửa sổ welcome hiện lên chọn Local Net Service Name configuration > Next > Add > Next. Tại ô Service Name điền DB1, tiếp tục Next chọn giao thức TCP rồi Next. Tại ô Host Name điền IP 10.33.3.169 và sử dụng Port mặc định 1521 tiếp tục Next đến Net Service Name nhập db1 và Finish

db2 tương tự như làm với db1 2. Enable ARCHIVELOG MODE trên cả 2 dabase SQL> shutdown immediate; SQL> startup mount; SQL> alter database archivelog; SQL> alter database open; SQL> archive log list; 3. Tạo Stream administrator User Source Database: DB1 SQL> conn sys@db1 as sysdba Enter password: Connected. SQL> create user strmadmin identified by strmadmin; User created. SQL> grant connect, resource, dba to strmadmin; Grant succeeded. SQL> begin dbms_streams_auth.grant_admin_privilege 2 (grantee => 'strmadmin', 3 grant_privileges => true);

Page 2: ĐỒNG BỘ DATABASE GIỮA 2 SERVER

4 end; 5 / PL/SQL procedure successfully completed. SQL> grant select_catalog_role, select any dictionary to strmadmin; Grant succeeded. Target Database: DB2 SQL> conn sys@db2 as sysdba Enter password: Connected. SQL> create user strmadmin identified by strmadmin; User created. SQL> grant connect, resource, dba to strmadmin; Grant succeeded. SQL> begin dbms_streams_auth.grant_admin_privilege 2 (grantee => 'strmadmin', 3 grant_privileges => true); 4 end; 5 / PL/SQL procedure successfully completed. SQL> grant select_catalog_role, select any dictionary to strmadmin; Grant succeeded. 4. Setup thông số INIT Source Database: DB1 SQL> conn sys@db1 as sysdba Enter password: Connected. SQL> alter system set global_names=true; System altered. SQL> alter system set streams_pool_size = 50 m; System altered. Target Database: DB2 SQL> conn sys@db2 as sysdba

Page 3: ĐỒNG BỘ DATABASE GIỮA 2 SERVER

Enter password: Connected. SQL> alter system set global_names=true; System altered. SQL> alter system set streams_pool_size = 50 m; System altered. 5. Tạo Database Link Target Database: DB1 SQL> conn strmadmin/strmadmin@db1 Connected. SQL> create database link db2 2 connect to strmadmin 3 identified by strmadmin 4 using 'DB2'; Database link created. Source Database: DB2 SQL> conn strmadmin/strmadmin@db2 Connected. SQL> create database link db1 2 connect to strmadmin 3 identified by strmadmin 4 using 'DB1'; Database link created. 6. Setup hàng đợi Source and Destination Source Database: DB1 SQL> conn strmadmin/strmadmin@db1 Connected. SQL> EXEC DBMS_STREAMS_ADM.SET_UP_QUEUE(); PL/SQL procedure successfully completed. Target Database: DB2 SQL> conn strmadmin/strmadmin@db2

Page 4: ĐỒNG BỘ DATABASE GIỮA 2 SERVER

Connected. SQL> EXEC DBMS_STREAMS_ADM.SET_UP_QUEUE(); PL/SQL procedure successfully completed. 7. Setup Schema for streams Schema: SCOTT Table: Taj Chú ý: Mặc định schema Scott là ở trạng thái Lock trong Oracle 10g => Unlock cho schema Scott Source Database: DB1 SQL> conn sys@db1 as sysdba Enetr password: Connected. SQL> alter user scott account unlock identified by tiger; User altered. SQL> conn scott/tiger@db1 Connected. SQL> create table TAJ ( no number primary key,name varchar2(20),ddate date); Table created. Target Database: DB2 SQL> conn sys@db2 as sysdba Enter password: Connected. SQL> alter user scott account unlock identified by tiger; User altered. SQL> conn scott/tiger@db2 Connected. SQL> create table TAJ ( no number primary key,name varchar2(20),ddate date); Table created. 8. Setup Supplemental logging ở source database Source Database: DB1

Page 5: ĐỒNG BỘ DATABASE GIỮA 2 SERVER

SQL> conn scott/tiger@db1 Connected. SQL> alter table taj 2 add supplemental log data (primary key,unique) columns; Table altered. 9. Cấu hình quá trình Capture ở source database Source Database: DB1 SQL> conn strmadmin/strmadmin@db1 Connected. SQL> begin dbms_streams_adm.add_table_rules 2 ( table_name => 'scott.taj', 3 streams_type => 'capture', 4 streams_name => 'capture_stream', 5 queue_name=> 'strmadmin.streams_queue', 6 include_dml => true, 7 include_ddl => true, 8 inclusion_rule => true); 9 end; 10 / PL/SQL procedure successfully completed. 10. Cấu hình quá trình Propagation Source Database: DB1 SQL> conn strmadmin/strmadmin@db1 Connected. SQL> begin dbms_streams_adm.add_table_propagation_rules 2 ( table_name => 'scott.taj', 3 streams_name => 'DB1_TO_DB2', 4 source_queue_name => 'strmadmin.streams_queue', 5 destination_queue_name => 'strmadmin.streams_queue@DB2', 6 include_dml => true, 7 include_ddl => true, 8 source_database => 'DB1', 9 inclusion_rule => true); 10 end; 11 / PL/SQL procedure successfully completed. 11. Set the instantiation system change number (SCN) Source Database: DB1

Page 6: ĐỒNG BỘ DATABASE GIỮA 2 SERVER

SQL> CONN STRMADMIN/STRMADMIN@DB1 Connected. SQL> declare 2 source_scn number; 3 begin 4 source_scn := dbms_flashback.get_system_change_number(); 5 dbms_apply_adm.set_table_instantiation_scn@DB2 6 ( source_object_name => 'scott.taj', 7 source_database_name => 'DB1', 8 instantiation_scn => source_scn); 9 end; 10 / PL/SQL procedure successfully completed. 12. Cấu hình quá trình apply ở destination database Target Database: DB2 SQL> conn strmadmin/strmadmin@db2 Connected. SQL> begin dbms_streams_adm.add_table_rules 2 ( table_name => 'scott.taj', 3 streams_type => 'apply', 4 streams_name => 'apply_stream', 5 queue_name => 'strmadmin.streams_queue', 6 include_dml => true, 7 include_ddl => true, 8 source_database => 'DB1', 9 inclusion_rule => true); 10 end; 11 / PL/SQL procedure successfully completed. 13. Start the capture and apply processes Source Database: DB1 SQL> conn strmadmin/strmadmin@db1 Connected. SQL> begin dbms_capture_adm.start_capture 2 ( capture_name => 'capture_stream'); 3 end; 4 / PL/SQL procedure successfully completed. Target Database: DB2 SQL> conn strmadmin/strmadmin@db2

Page 7: ĐỒNG BỘ DATABASE GIỮA 2 SERVER

Connected. SQL> begin dbms_apply_adm.set_parameter 2 ( apply_name => 'apply_stream', 3 parameter => 'disable_on_error', 4 value => 'n'); 5 end; 6 / PL/SQL procedure successfully completed. SQL> begin 2 dbms_apply_adm.start_apply 3 ( apply_name => 'apply_stream'); 4 end; 5 / PL/SQL procedure successfully completed. Chú ý: Môi trường cho việc sao chép đồng bộ là đã sẵn sàng is ready 14. Test kết quả Target Database: DB1 SQL> conn scott/tiger@db1 Connected. SQL> --DDL operation SQL> alter table taj add (flag char(1)); Table altered. SQL> --DML operation SQL> begin 2 insert into taj values (1,'first_entry',sysdate,1); 3 commit; 4 end; 5 / PL/SQL procedure successfully completed. SQL> conn scott/tiger@db2 Connected. SQL> --TEST DDL operation SQL> desc taj Name Null? Type ----------------------------------------- -------- ---------------------------- NO NOT NULL NUMBER NAME VARCHAR2(20) DDATE DATE

Page 8: ĐỒNG BỘ DATABASE GIỮA 2 SERVER

FLAG CHAR(1) SQL> --TEST DML operation SQL> select * from taj; NO NAME DDATE F ---------- -------------------- --------- - 1 first_entry 24-JAN-08 1