--prepare(2 servers)
conn / as sysdba
alter system set aq_tm_processes=2 scope=both;
alter system set global_names=true scope=both;
alter system set job_queue_processes=10 scope=both;
alter system set parallel_max_servers=20 scope=both;
alter system set undo_retention=3600 scope=both;
alter system set nls_date_format='YYYY-MM-DD HH24:MI:SS' scope=spfile;
alter system set streams_pool_size=25M scope=spfile;
alter system set utl_file_dir='*' scope=spfile;
alter system set open_links=4 scope=spfile;
-----------------------------------------------------------
--restart db(2 servers)
shutdown immediate
startup
------------------------------------------------------------
--create user:strmadmin (2 servers)
create tablespace tbs_stream datafile '/ora_data/tbs_stream01.dbf' size 100m autoextend on maxsize unlimited segment space management auto;
? 将logminer的数据字典从system表空间转移到新建的表空间,防止撑满system表空间
SQL> execute dbms_logmnr_d.set_tablespace('tbs_stream');
? 创建Stream管理用户
SQL> create user strmadmin identified by strmadmin default tablespace tbs_stream temporary tablespace temp;
? 授权Stream管理用户
SQL> grant connect,resource,dba,aq_administrator_role to strmadmin;
SQL> execute DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE('strmadmin');
-----------------------------------------------------------------
-- use supplemental log
? 启用Database 追加日志 (主、从数据库上操作)
SQL> alter database add supplemental log data;
? 检查是否被启用
SQL> Select supplemental_log_data_min from v$database;
-----------------------------------------------------------------
--create db tns
BJDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = zuoh)(PORT = 1521))
(CONNECT_DATA =
(SERVER = SHARED)
(SERVICE_NAME = bjdb)
)
)
hbDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.31.27)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = hbdb)
)
)
------------------------------------------------------------------
--create dblink
以strmadmin身份,登录主数据库。
SQL> connect strmadmin/strmadmin
建立数据库链
SQL> create database link hbdb connect to strmadmin identified by strmadmin using 'hbdb';
3.6.2创建从数据库数据库链
以strmadmin身份,登录从数据库。
SQL> connect strmadmin/strmadmin
建立数据库链
SQL> create database link bjdb connect to strmadmin identified by strmadmin using 'bjdb';
-----------------------------------------------------------
--create streams
conn strmadmin/strmadmin@bjdb
begin
dbms_streams_adm.set_up_queue(queue_table =>'bjdbc_queue_table',queue_name =>'bjdbc_queue');
dbms_streams_adm.set_up_queue(queue_table =>'bjdbr_queue_table',queue_name =>'bjdbr_queue');
end;
/
conn strmadmin/strmadmin@hbdb
begin
dbms_streams_adm.set_up_queue(queue_table =>'hbdbc_queue_table',queue_name =>'hbdbc_queue');
dbms_streams_adm.set_up_queue(queue_table =>'hbdbr_queue_table',queue_name =>'hbdbr_queue');
end;
/
---------------------------
conn strmadmin/strmadmin@bjdb
begin
dbms_streams_adm.add_schema_rules(
schema_name => 'aaa',
streams_type => 'capture',
streams_name => 'capture_bjdb',
queue_name => 'strmadmin.bjdbc_queue',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => null,
inclusion_rule => true);
end;
/
begin
dbms_streams_adm.add_schema_propagation_rules(
schema_name => 'aaa',
streams_name => 'bjdb_to_hbdb',
source_queue_name => 'strmadmin.bjdbc_queue',
destination_queue_name => 'strmadmin.hbdbr_queue@hbdb',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => 'bjdb',
inclusion_rule => true);
end;
/
begin
dbms_aqadm.alter_propagation_schedule(
queue_name => 'bjdbc_queue',
destination => 'hbdb',
latency => 0);
end;
/
begin
dbms_streams_adm.add_schema_rules(
schema_name =>'aaa',
streams_type =>'apply',
streams_name =>'apply_bjdb',
queue_name =>'strmadmin.bjdbr_queue',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => 'hbdb',
inclusion_rule => true);
end;
/
---------------------------------------------------------------------
conn strmadmin/strmadmin@hbdb
begin
dbms_streams_adm.add_schema_rules(
schema_name => 'aaa',
streams_type => 'capture',
streams_name => 'capture_hbdb',
queue_name => 'strmadmin.hbdbc_queue',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => null,
inclusion_rule => true);
end;
/
begin
dbms_streams_adm.add_schema_propagation_rules(
schema_name => 'aaa',
streams_name => 'hbdb_to_bjdb',
source_queue_name => 'strmadmin.hbdbc_queue',
destination_queue_name => 'strmadmin.bjdbr_queue@bjdb',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => 'hbdb',
inclusion_rule => true);
end;
/
declare
iscn number;
begin
iscn:=dbms_flashback.get_system_change_number();
dbms_apply_adm.set_schema_instantiation_scn@bjdb(
source_schema_name => 'aaa',
source_database_name => 'hbdb',
instantiation_scn => iscn);
end;
/
begin
dbms_streams_adm.add_schema_rules(
schema_name =>'aaa',
streams_type =>'apply',
streams_name =>'apply_hbdb',
queue_name =>'strmadmin.hbdbr_queue',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => 'bjdb',
inclusion_rule => true);
end;
/
---------------------------------------------------------
--sync on bjdb server
exp userid=aaa/aaa@bjdb file='/ora_data/aaa.dmp' object_consistent=y rows=y
imp userid=system/capitek@hbdb file='/ora_data/aaa.dmp' ignore=y commit=y log='/ora_data/aaa.log' streams_instantiation=y fromuser=aaa touser=aaa
--sync on hbdb server
exp userid=aaa/aaa@hbdb file='/ora_data/aaa.dmp' object_consistent=y rows=y
imp userid=system/capitek@bjdb file='/ora_data/aaa.dmp' ignore=y commit=y log='/ora_data/aaa.log' streams_instantiation=y fromuser=aaa touser=aaa
--or
declare
iscn number;
begin
iscn:=dbms_flashback.get_system_change_number();
dbms_apply_adm.set_schema_instantiation_scn@hbdb(source_schema_name => 'aaa',source_database_name => 'bjdb',instantiation_scn => iscn);
end;
----------------------------------
--start 2 dbs sync
conn strmadmin/strmadmin@hbdb
begin
dbms_apply_adm.start_apply('apply_hbdb');
end;
/
-------------------------------------------------
conn strmadmin/strmadmin@bjdb
begin
dbms_capture_adm.start_capture('capture_bjdb');
dbms_propagation_adm.start_propagation('bjdb_to_hbdb');
dbms_apply_adm.start_apply('apply_bjdb');
end;
/
----------------------------------------------------------
conn strmadmin/strmadmin@hbdb
begin
dbms_capture_adm.start_capture('capture_hbdb');
dbms_propagation_adm.start_propagation('hbdb_to_bjdb');
end;
/
-----------------------------------------------------
--test sql
select mdn, imsi from mdn_imsi;
insert into mdn_imsi (mdn,imsi) values ('bbbbb','bbbbb');
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9240380/viewspace-617908/ ,如需转载,请注明出处,否则将追究法律责任。