-------------------------------------------------- -----------------------------
master database:
operating system: Windows 2012
IP address: 192.168.160.122
database: Oracle 11.2.0.2. 0
the ORACLE_SID: orcl
Global_name: orcl
From the database:
Operating System: Windows 2012
IP address: 192.168.160.123
database: the Oracle 11.2.0.2.0
the ORACLE_SID: orcl
Global_name: orcl
alter system set deferred_segment_creation=false scope=both;
alter system set sec_case_sensitive_logon=false scope=both;
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
主数据库配置
archive log list;
select supplemental_log_data_min from v$database;
shutdown immediate;
startup mount;
alter database archivelog;
alter database add supplemental log data;
archive log list;
select supplemental_log_data_min from v$database;
alter database open;
设置参数
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=100M scope=spfile;
alter system set utl_file_dir='*' scope=spfile;
alter system set open_links=4 scope=spfile;
alter system set statistics_level='TYPICAL' scope=both;
alter system set utl_file_dir='*' scope=spfile;
alter system set "_job_queue_interval"=1 scope=spfile;
alter system set global_names=false scope=both;
shutdown immediate;
startup;
create user hytera identified by hytera account unlock;
grant connect to hytera;
grant RESOURCE to hytera;
grant dba to hytera;
--alter system set logmnr_max_persistent_sessions=1 scope=spfile;
create tablespace streams_tbs datafile 'D:\app\Administrator\oradata\orcl\streams_tbs.dbf' size 100M autoextend on maxsize unlimited;
create user strmadmin identified by strmadmin default tablespace streams_tbs account unlock quota unlimited on streams_tbs;
grant dba to strmadmin;
grant connect to strmadmin;
exec dbms_streams_auth.grant_admin_privilege('strmadmin');
begin
dbms_streams_auth.grant_admin_privilege(
grantee=>'strmadmin',
grant_privileges=>TRUE);
end;
/
tnsnames.ora
SZXTDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.160.123)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
conn strmadmin/strmadmin;
create database link SZXTDB connect to strmadmin identified by strmadmin using 'SZXTDB';
Creating Master stream queue
# strmadmin identity to log in the master database.
strmadmin Connect / strmadmin;
the begin
dbms_streams_adm.set_up_queue (
queue_table => 'source_queue_table', - queue table
queue_name => 'source_queue', - queue
queue_user => 'strmadmin'); - a user queue
End;
/
SELECT owner, queue_table , name from dba_queues where owner = ' STRMADMIN';
Create a data capture process, capture redo changes
connect strmadmin/strmadmin;
begin
dbms_streams_adm.add_schema_rules(
schema_name => 'hytera', --捕获用户名 非sys或者system
streams_type => 'capture',
streams_name => 'capture_stream',
queue_name => 'strmadmin.source_queue',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => 'ORCL',
inclusion_rule => true);
end;
/
select capture_name,queue_name,start_scn,status,capture_type from dba_capture;
Create a communication process corresponding to ogg inside datapump data transfer in the source database
communication process corresponding to the capture rules are needed to create the communication process table / schema / global's.
strmadmin Connect / strmadmin;
the begin
dbms_streams_adm.add_schema_propagation_rules (
schema_name => 'Hytera',
streams_name => 'source_to_target',
source_queue_name => 'strmadmin.SOURCE_QUEUE',
destination_queue_name => 'strmadmin.TARGET_QUEUE@szxtdb',
include_dml => to true,
include_ddl => to true,
source_database => 'ORCL',
inclusion_rule => to true,
queue_to_queue => to true);
End;
/
select propagation_name,status from all_propagation;
SCN manner directly instantiated
query scn number of source
select DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER () FROM dual;
Start capture process corresponds OGG inside EXT1
the BEGIN
DBMS_CAPTURE_ADM.START_CAPTURE (
capture_name => 'capture_stream');
the END;
/
Stop the capture process
the BEGIN
DBMS_CAPTURE_ADM.STOP_CAPTURE (
capture_name => 'capture_stream');
the END;
/
View capture process status
select capture_name, status from dba_capture;
表示实时传播lcr实时复制
begin
dbms_aqadm.alter_propagation_schedule(
queue_name => 'strmadmin.SOURCE_QUEUE',
destination => 'szxtdb',
destination_queue => 'TARGET_QUEUE',
latency => 0);
end;
/
-------------------------------------------------------------------------------------------------------------------------
备数据库配置
archive log list;
select supplemental_log_data_min from v$database;
shutdown immediate;
startup mount;
alter database archivelog;
alter database add supplemental log data;
archive log list;
select supplemental_log_data_min from v$database;
alter database open;
设置参数
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=100M scope=spfile;
alter system set utl_file_dir='*' scope=spfile;
alter system set open_links=4 scope=spfile;
alter system set statistics_level='TYPICAL' scope=both;
alter system set utl_file_dir='*' scope=spfile;
alter system set "_job_queue_interval"=1 scope=spfile;
alter system set global_names=false scope=both;
shutdown immediate;
startup;
--alter system set logmnr_max_persistent_sessions=1 scope=spfile;
create user hytera identified by hytera account unlock;
grant connect to hytera;
grant RESOURCE to hytera;
grant dba to hytera;
create tablespace streams_tbs datafile 'D:\app\Administrator\oradata\orcl\streams_tbs.dbf' size 100M autoextend on maxsize unlimited;
create user strmadmin identified by strmadmin default tablespace streams_tbs account unlock quota unlimited on streams_tbs;
grant dba to strmadmin;
grant connect to strmadmin;
exec dbms_streams_auth.grant_admin_privilege('strmadmin');
begin
dbms_streams_auth.grant_admin_privilege(
grantee=>'strmadmin',
grant_privileges=>TRUE);
end;
/
tnsnames.ora
SZXTDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.160.122)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
conn strmadmin/strmadmin;
create database link SZXTDB connect to strmadmin identified by strmadmin using 'SZXTDB';
Created by the library stream queue
# strmadmin identity to log in the master database.
strmadmin Connect / strmadmin;
the begin
dbms_streams_adm.set_up_queue (
queue_table => 'target_queue_table', - queue table
queue_name => 'target_queue', - queue
queue_user => 'strmadmin'); - a user queue
End;
/
SELECT owner, queue_table , name from dba_queues where owner = ' STRMADMIN';
Apply application process to create a queue on the destination side database corresponding to the rep1 process OGG
Connect strmadmin / strmadmin;
the begin
dbms_streams_adm.add_schema_rules (
schema_name => 'Hytera', - capturing the user name or non sys System
streams_type => 'Apply',
streams_name => 'target_apply_stream',
queue_name => 'strmadmin.TARGET_QUEUE',
include_dml => to true,
include_ddl => to true,
include_tagged_lcr => to false,
source_database => 'ORCL',
inclusion_rule => to true);
End;
/
select apply_name,queue_name,status from dba_apply;
Provided with the same source SCN number
source check
SELECT dbms_flashback.get_system_change_number () the FROM Dual;
Conn strmadmin / strmadmin;
the BEGIN
DBMS_APPLY_ADM.SET_SCHEMA_INSTANTIATION_SCN (
source_schema_name => 'Hytera',
source_database_name => 'ORCL',
instantiation_scn => 1097715) ;
the END;
/
Apply the destination application process corresponds to starting started OGG inside of rep1
the BEGIN
DBMS_APPLY_ADM.START_APPLY (
apply_name => 'target_apply_stream');
the END;
/
停止apply
BEGIN
DBMS_APPLY_ADM.STOP_APPLY(
apply_name => 'target_apply_stream');
END;
/
Check process status apply
the SELECT apply_name, queue_name, Status from dba_apply;
------------------------------------- -------------------------
View capture process status
select capture_name, status from dba_capture;
View apply process status
select apply_name, queue_name, status from dba_apply ;
Create a communication process equivalent to ogg inside datapump data transfer on the source database
select propagation_name, status from all_propagation;
select capture_name,status from dba_capture;
select apply_name,queue_name,status from dba_apply;
select capture_name,status from dba_capture;
select error_message from DBA_APPLY_ERROR;
Whether the source fetching process and the application process SCN number consistent stream replication is based on the redolog scn number of
select capture_name, queue_name, status, captured_scn , applied_scn from dba_capture;
Check whether the application process error
select apply_name, error_number, apply_captured, status from dba_apply;
------------------------------------------------------------------------------
Start capture process corresponds OGG inside EXT1
the BEGIN
DBMS_CAPTURE_ADM.START_CAPTURE (
capture_name => 'capture_stream');
the END;
/
Stop the capture process
the BEGIN
DBMS_CAPTURE_ADM.STOP_CAPTURE (
capture_name => 'capture_stream');
the END;
/
Apply the destination application process corresponds to starting started OGG inside of rep1
the BEGIN
DBMS_APPLY_ADM.START_APPLY (
apply_name => 'target_apply_stream');
the END;
/
停止apply
BEGIN
DBMS_APPLY_ADM.STOP_APPLY(
apply_name => 'target_apply_stream');
END;
/
--------------------------------------------------------------------------------
create tablespace hytera datafile 'D:\app\Administrator\oradata\orcl\hytera.dbf' size 100M autoextend on maxsize unlimited;
alter user hytera default tablespace hytera;
-------------------------------------------------- ------------------------------
configure bi-directional replication flow
Implementation of the source
to solve the problem ORA-26687
SELECT * FROM DBA_CAPTURE_PREPARED_TABLES;
BEGIN
DBMS_APPLY_ADM.SET_TABLE_INSTANTIATION_SCN (
source_object_name => 'hytera.t',
source_database_name => 'ORCL',
instantiation_scn => 1094239);
END;
/
select error_message from DBA_APPLY_ERROR; - stream copying error message
PURGE recyclebin;
解决 ORA-00942 问题
BEGIN
DBMS_APPLY_ADM.SET_PARAMETER(
apply_name => 'target_apply_stream',
parameter => 'disable_on_error',
value => 'n');
END;
/
--------------------------------------------------------------------------------
drop user hytera cascade;
create user hytera identified by hytera account unlock default tablespace hytera;
grant connect to hytera;
grant RESOURCE to hytera;
grant dba to hytera;