alter system set global_names=true scope=both; alter system set "_job_queue_interval"=1 scope=spfile;
3,stream数据库用户strmadmin及权限 @both db
create user STRMADMIN identified by STRM#123; ALTER USER STRMADMIN DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP QUOTA UNLIMITED ON USERS; GRANT CONNECT, RESOURCE, AQ_ADMINISTRATOR_ROLE,DBA to STRMADMIN; execute DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE('STRMADMIN');
hrdbprim = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.4.124.239)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = hrdbprim) ) ) hrdb = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.4.124.233)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = hrdb) ) )
conn strmadmin/STRM#123 BEGIN DBMS_STREAMS_ADM.SET_UP_QUEUE( queue_name => 'STREAMS_QUEUE', queue_table =>'STREAMS_QUEUE_TABLE', queue_user => 'STRMADMIN'); END; / conn sys/oracle as sysdba create public database link hrdb using 'hrdb'; conn strmadmin/STRM#123 create database link hrdb connect to strmadmin identified by STRM#123; @target db hrdb conn sys/oracle as sysdba create public database link HRDBPRIM using 'HRDBPRIM'; conn strmadmin/STRM#123 create database link HRDBPRIM connect to strmadmin identified by STRM#123;
b, @target hrdb 建stream队列
/* Step 2 - Connect as the Streams Administrator in the target site TARGET and create the streams queue */ conn strmadmin/STRM#123 BEGIN DBMS_STREAMS_ADM.SET_UP_QUEUE( queue_name => 'STREAMS_QUEUE', queue_table =>'STREAMS_QUEUE_TABLE', queue_user => 'STRMADMIN'); END; /c, @source db 建捕获(capture)和传播PROPAGATION 规则
/*Step 3 -Connected to source db, create CAPTURE and PROPAGATION rules */ conn strmadmin/STRM#123@source BEGIN DBMS_STREAMS_ADM.ADD_GLOBAL_PROPAGATION_RULES( streams_name => 'STRMADMIN_PROP', source_queue_name => 'STRMADMIN.STREAMS_QUEUE', destination_queue_name => 'STRMADMIN.STREAMS_QUEUE@hrdb', include_dml => true, include_ddl => true, source_database => 'HRDBPRIM'); END; / BEGIN DBMS_STREAMS_ADM.ADD_GLOBAL_RULES( streams_type => 'CAPTURE', streams_name => 'STRMADMIN_CAPTURE', queue_name => 'STRMADMIN.STREAMS_QUEUE', include_dml => true, include_ddl => true, source_database => 'hrdbprim'); END; /
/*Step 4 - Connected as STRMADMIN at TARGET, create APPLY rules */ conn STRMADMIN/STRMADMIN@TARGET BEGIN DBMS_STREAMS_ADM.ADD_GLOBAL_RULES( streams_type => 'APPLY', streams_name => 'STRMADMIN_APPLY', queue_name => 'STRMADMIN.STREAMS_QUEUE', include_dml => true, include_ddl => true, source_database => 'hrdbprim'); END; / BEGIN DBMS_APPLY_ADM.SET_PARAMETER( apply_name => 'STRMADMIN_APPLY', parameter => 'disable_on_error', value => 'n'); END; /
/*Step 7 - Take an export of the DB at SOURCE */ exp USERID=SYSTEM/1232@hrdbprim FULL=Y FILE=stream.dmp LOG=stream.log OBJECT_CONSISTENT=Y STATISTICS = NONE /*Step 8 - Transfer the export dump file to TARGET and import */ imp USERID=SYSTEM/2314@hrdb CONSTRAINTS=Y FULL=Y FILE=stream.dmp IGNORE=Y COMMIT=Y LOG=stream_imp.log STREAMS_INSTANTIATION=Y
F:启动apply和capture
/*Step 9 - Start Apply and capture */ conn strmadmin/STRM#123@hrdb BEGIN DBMS_APPLY_ADM.START_APPLY( apply_name => 'STRMADMIN_APPLY'); END; / conn strmadmin/STRM#123@hrdbprim BEGIN DBMS_CAPTURE_ADM.START_CAPTURE( capture_name => 'STRMADMIN_CAPTURE'); END; /
6,验证结果
@source db hrdbprim SQL> insert into w select * from dba_tables; 1211 rows created. SQL> commit; Commit complete. @target hrdb strmadmin@HRDB1(dtydb3)>/ COUNT(*) ---------- 0 strmadmin@HRDB1(dtydb3)>/ COUNT(*) ---------- 1211