Sunteți pe pagina 1din 14

Two-way stream replication configuration

Oracle 10g


Building a copy of Oracle bi-directional flow is a very complex process, I wrote the purpose of
this document is to try organized with the need to do the work, to help the DBA more effective
construction streaming replication environment.

1 scott mode to copy the example, generally as long as the install sample schema, there will be
the scott mode is selected when creating a database; exist in the schema, at least ensure that the
source library so that it can be initialized to the target library.

In the source and target database to create strmadmin flow management users, of course, you can
also choose other name. 2 library should create the streams use of table space, so that logmnr use
it:

CREATE TABLESPACE streams_tbs DATAFILE 'XXXXXX' SIZE 100M REUSE
AUTOEXTEND ON MAXSIZE UNLIMITED;

/ * The 10g r2 middle logmnr default SYSAUX tablespace * /

exec DBMS_LOGMNR_D.SET_TABLESPACE ('streams_tbs');

/ * Create the table space, and then to create strmadmin user * /

CREATE USER strmadmin IDENTIFIED BY strmadmin
Default TABLESPACE streams_tbs.
QUOTA UNLIMITED ON streams_tbs;

GRANT DBA TO strmadmin;

BEGIN
DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE (
grantee => 'strmadmin',
grant_privileges => true);
END;
/

/ * Check the user by the query dba_streams_administrator view is correct grant flow
management privileges * /

SQL> SELECT * FROM dba_streams_administrator;

The USERNAME LOC ACC
------------------------------------
Maclean YES YES
STRMADMIN YES YES

3 2 side database need to set reasonable instance initialization parameters, we 10g release2 as an
example:

Parameter name with the recommended values: _job_queue_interval = 1
Description: queue job of scanning parameters, the default is 5 5s scan time for what to consider
to: Set smaller _job_queue_interval is conducive the propagation job how to set up: alter system
set "_job_queue_interval = 1 scope = spfile;

/ * Note that the scope = spfile parameters need to restart the instance to enter into force * /

Parameter name with the recommended values: COMPATIBLE> = 10.2.0.0
Description: database version compatibility parameters, described previously, no longer expand
What are the considerations: 10g Release2 Streams new features require the parameter of at least
10.2.0.0 or higher how to set up: only upgrade from an earlier version to 10g R2 database need to
set the parameters,
alter system set compatible = "10.2.0.0" scope = spfile;

Parameter name with the recommended values: global_names = true
Description: Specifies whether the requirements of the database link name and the database
global name, the default is FALSE that is required to be consistent for what reasons: to help us
accurately identify the relationship between the database link and database, how to set up to
avoid misuse: alter system set global_names = true scope = spfile;

Parameter name with the recommended values: Job_queue_processes>
Description: Specifies the number of job queue processes instance (J000 ... J999).
What are the considerations: This parameter controls the maximum value of the job instances can
be run in parallel, should be set to a value greater than the configured propagations
Number of values, but also take into account there may be other how to set up database
operations: alter system set Job_queue_processes = 15;

Parameter name with the recommended values: PARALLEL_MAX_SERVERS
Description: Specifies the number of instance parallel processes for what to consider:
Streams environment, the capture process and apply process will be used in a number of parallel
processes.
The initialization parameter is set to the appropriate value (10 * CPU #) to ensure that there is
always enough available parallel processes;
One more capture or apply process, it is necessary for this parameter +2 plus capture or apply
process parallelism parallelism parameter.
How do I set it up:
alter system set PARALLEL_MAX_SERVERS = 40;

Parameter name with the recommended values: REMOTE_ARCHIVE_ENABLE
Description: Specifies whether to send the archive logs to a remote destination What are the
considerations: only downstream capture will be used, and does not expand

Parameter name with the recommended values: SGA_MAX_SIZE
Description: set a reasonable maximum SGA memory for what to consider: the common
parameters, not to proceed with

Parameter name with the recommended values: SGA_TARGET = 0
Description: disable out 10g Automatic Shared Memory Management.
What are the considerations: Oracle recommends to manually specify size of streams_pool and
shared_pool the stream environment without the use of automatic memory management features
in 10g how to set:
alter system set sga_target = 0;

Parameter name with the recommended values: Tuning STREAMS_POOL_SIZE
Description:
Specify the size of the Streams pool. Streams pool the cache queue message. In addition, the
flow cell will be used in parallel capture and apply internal communication.
The proposed reference V $ STREAMS_POOL_ADVICE view the information to determine the
optimal size to avoid spill overflow What are the considerations:
This parameter can be dynamically modified. If the parameter is zero, the instance in the process
of streams and jobs will not run. Streams pool size is limited by the following factors:
The degree of parallelism of the 1.capture process, each additional capture process is necessary
to increase the size of 10MB to the flow cell;
In addition, when the the capture parameters parallelism is greater than 1, it is necessary to
increase the size of 10Mb * parallelism Streams pool;
For example, if the degree of parallelism for a capture process parallelism is set to 3, you need to
increase 30Mb for the Streams pool.
The degree of parallelism of the 2.apply process for each additional one to apply the process
necessary to the for the Streams pool increased 1MB;
In addition, when the degree of parallelism apply process is greater than 1, the for the Streams
pool to increase the size of 1MB * parallelism;
For example, an apply process parallelism is set to 5, you need to increase 5Mb streams pool.
3.Logical Change Records (LCRS) is stored in the buffered queues in the buffer queue;
Appropriate to increase the Streams pool size to accommodate the the data replication amount of
data on the source and target libraries;
Oracle recommends a minimum in the low load database settings Streams pool is 256Mb, and is
set in the highly active OLTP environment to 500MB;
STREAMS Pool of the advice given by the V $ STREAMS_POOL_ADVISE view to further
adjust the size to a reasonable value to avoid excessive buffer queue overflow to disk.

www.oracledatabase12g.com



How do I set it up:
select * from v $ streams_pool_advice;
/ * Query v $ STREAMS_POOL_ADVICE view to understand the different streams_Pool_size
case estd_spill_time * /

alter system set streams_pool_size = 500M;

After completion of the above settings recommended restart the instance so that all parameters to
take effect, the two sides have to do.

Create additional log the (supplemental log), the stored procedure can use dbms_capture_adm
package prepare_schema_instantiation. The Scott schema under the object to the specified mode
to create additional log:

NAME
prepare_schema_instantiation ()
FUNCTION
prepare a schema for instantiation
PARAMETERS
schema_name - (IN) the name of the schema to prepare
supplemental_logging - (IN) supplemental logging level
('NONE', 'KEYS', or 'ALL')
NOTES
KEYS means PRIMARY KEY, UNIQUE INDEX, and FOREIGN KEY levels combined.
-------------------------------------------------- -------------------------- * /
The PROCEDURE prepare_schema_instantiation (
schema_name IN VARCHAR2,
supplemental_logging IN VARCHAR2 DEFAULT 'KEYS');

/ * Default supplemental_logging option key is the PRIMARY KEY, UNIQUE INDEX, and
FOREIGN KEY key
Create implicit additional log * /

/ * 10g or later prepare_xxx_instantiation stored procedure will implicitly create additional log
group
(In versions 10g and above, prepare_xxx_instantiation procedure implicitly creates supplemenal
log groups.
Type of supplemental logging that is enabled implicitly using this command can be checked
using the sql in the following link to the documentation. However, additional supplemental
logging might need to be enabled depending on the requirements as mentioned above).
By the following query to understand the properties of the additional log group:
SELECT SCHEMA_NAME
SUPPLEMENTAL_LOG_DATA_PK log_pk,
SUPPLEMENTAL_LOG_DATA_FK log_fk,
SUPPLEMENTAL_LOG_DATA_UI log_ui,
SUPPLEMENTAL_LOG_DATA_ALL log_all
FROM DBA_CAPTURE_PREPARED_SCHEMAS;

SCHEMA_NAME LOG_PK LOG_FK LOG_UI LOG_ALL
-------------------------------------------------- ------------
SCOTT IMPLICIT IMPLICIT IMPLICIT NO

5.
Created in the source library to the target library strmadmin users of Database Link:

conn strmadmin / strmadmin;
Connected.

create database link clinicb.rh3.oracle.com connect to strmadmin identified by strmadmin using
'clinicb.rh3.oracle.com';
Database link created.
/ * Clinicb.rh3.oracle.com global database name of the target library for the db_name clinicb,
rh3.oracle.com for your DOMAIN_NAME * /

Created in the target library to the source library strmadmin users of Database Link:

conn strmadmin / strmadmin;
Connected.

create database link clinica.rh2.oracle.com connect to strmadmin identified by strmadmin using
'clinica.rh2.oracle.com';
Database link created.

The / * clinica.rh2.oracle.com global database name of the source library, clinica database name,
rh2.oracle.com for your DOMAIN_NAME * /

6.
In the source library for the capture and apply to create a queue queue:

begin
dbms_streams_adm.set_up_queue (
queue_table => 'apply_srctab',
queue_name => 'apply_src',
queue_user => 'strmadmin');
end;
/
PL / SQL procedure successfully completed.

begin
dbms_streams_adm.set_up_queue (
queue_table => 'capture_srctab',
queue_name => 'capture_src',
queue_user => 'strmadmin');
end;
/
PL / SQL procedure successfully completed.

In the target library were created to capture and apply queue queue:

conn strmadmin / strmadmin @ clinicb.rh3.oracle.com
Connected.

begin
dbms_streams_adm.set_up_queue (
queue_table => 'apply_desttab',
queue_name => 'apply_dest',
queue_user => 'strmadmin');
end;
/

PL / SQL procedure successfully completed.

begin
dbms_streams_adm.set_up_queue (
queue_table => 'capture_desttab',
queue_name => 'capture_dest',
queue_user => 'strmadmin');
end;
/

PL / SQL procedure successfully completed.

8.
In the source library Clinica scott mode to create the capture Process:

conn strmadmin / strmadmin @ clinica.rh2.oracle.com
Connected.

begin
dbms_streams_adm.add_schema_rules (
schema_name => 'scott',
streams_type => 'capture',
streams_name => 'captures_src',
queue_name => 'capture_src',
include_dml => true
include_ddl => true
inclusion_rule => true);
end;
/
PL / SQL procedure successfully completed.

9.
In the source library Clinica create apply Process:

conn strmadmin / strmadmin @ clinica.rh2.oracle.com
Connected.

begin
dbms_streams_adm.add_schema_rules (
schema_name => 'scott',
streams_type => 'apply',
streams_name => 'applys_src',
queue_name => 'apply_src',
include_dml => true
include_ddl => true
source_database => 'clinicb.rh3.oracle.com');
end;
/

PL / SQL procedure successfully completed.

10 If you need to resolve the conflict in the source library processing, it is necessary to set the
conflict handlers can refer to the streams file link: conflict.htm

11 configured in the source library Clinica propagation process:

conn strmadmin / strmadmin @ clinica.rh2.oracle.com
Connected.

begin
dbms_streams_adm.add_schema_propagation_rules (
schema_name => 'scott',
streams_name => 'prop_src_to_dest',
source_queue_name => 'capture_src',
destination_queue_name => 'apply_dest@clinicb.rh3.oracle.com',
include_dml => true
include_ddl => true
source_database => 'clinica.rh2.oracle.com');
end;
/

PL / SQL procedure successfully completed.

12. Configuration the capture Process target library clinicb on:

conn strmadmin / strmadmin @ clinicb.rh3.oracle.com
Connected.

begin
dbms_streams_adm.add_schema_rules (
schema_name => 'scott',
streams_type => 'capture',
streams_name => 'captures_dest',
queue_name => 'capture_dest',
include_dml => true
include_ddl => true);
end;
/
PL / SQL procedure successfully completed.

13 to target library clinicb the SCN setting mode in the original library Clinica instantiation SCN
(schema instantiation of SCN):

conn strmadmin / strmadmin @ clinicb.rh3.oracle.com
Connected.

declare
v_scn number;
begin
v_scn: = dbms_flashback.get_system_change_number (the);
dbms_apply_adm.set_schema_instantiation_scn @ clinica.rh2.oracle.com (
source_schema_name => 'scott',
source_database_name => 'clinicb.rh3.oracle.com',
instantiation_scn => v_scn,
recursive => true);
end;
/

14 object library clinicb configuration apply Process:

conn strmadmin / strmadmin @ clinicb.rh3.oracle.com
Connected.

begin
dbms_streams_adm.add_schema_rules (
schema_name => 'scott',
streams_type => 'apply',
streams_name => 'applys_dest',
queue_name => 'apply_dest',
include_dml => true
include_ddl => true
source_database => 'clinica.rh2.oracle.com');
end;
/
PL / SQL procedure successfully completed.

15 in the target library configuration propagation process:

conn strmadmin / strmadmin @ clinicb.rh3.oracle.com
Connected.

begin
dbms_streams_adm.add_schema_propagation_rules (
schema_name => 'scott',
streams_name => 'prop_dest_to_src',
source_queue_name => 'capture_dest',
destination_queue_name => 'apply_src@clinica.rh2.oracle.com',
include_dml => true
include_ddl => true
source_database => 'clinicb.rh3.oracle.com');
end;
/
PL / SQL procedure successfully completed.

16 to initialize objects scott mode, the target library There are several ways to complete the
initialization. If the objects do not exist, in using the export / import import and export tools to
complete Instantiation objects already exists, the direct use of process of
dbms_apply_adm.set_schema_instantiation_scn storage.
The our environment scott mode already exists in the target library:

conn strmadmin / strmadmin @ clinica.rh2.oracle.com
Connected.

declare
v_scn number;
begin
v_scn: = dbms_flashback.get_system_change_number (the);
dbms_apply_adm.set_schema_instantiation_scn @ clinicb.rh3.oracle.com (
source_schema_name => 'scott',
source_database_name => 'clinica.rh2.oracle.com',
instantiation_scn => v_scn,
recursive => true);
end;
/
PL / SQL procedure successfully completed.

17 if you need to resolve conflicts in the target library processing, it is necessary to set the
Conflict the handlers can refer to the streams file link:
102/b14228/conflict.htm

18 to start the capture and apply processes in the target library:

Start Apply:
/ * Disable_on_erro parameter to 'N' to start the apply process encounters an error, even, apply
will continue to deal with the LCR * /

conn strmadmin / strmadmin @ clinicb.rh3.oracle.com
Connected.

begin
dbms_apply_adm.set_parameter (
apply_name => 'applys_dest',
parameter => 'disable_on_error',
value => 'N');
end;
/
PL / SQL procedure successfully completed.

exec dbms_apply_adm.start_apply (apply_name => 'applys_dest');
PL / SQL procedure successfully completed.

Start the capture Process in the target library:

exec dbms_capture_adm.start_capture (capture_name => 'captures_dest');

PL / SQL procedure successfully completed.

19. The same start capture and apply processes in the source library:

begin
dbms_apply_adm.set_parameter (
apply_name => 'applys_src',
parameter => 'disable_on_error',
value => 'N');
end;
/

PL / SQL procedure successfully completed.

exec dbms_apply_adm.start_apply (apply_name => 'applys_src');

PL / SQL procedure successfully completed.

Start capture in the source library:
exec dbms_capture_adm.start_capture (capture_name => 'captures_src');

PL / SQL procedure successfully completed.

20 bi-directional flow of the test copy was successful:

Test DDL statements:

SQL> conn scott / tiger @ clinica.rh2.oracle.com
Connected.
SQL> create table test_streams (t1 int);

Table created.

SQL> conn scott / tiger @ clinicb.rh3.oracle.com
Connected.
SQL> desc test_streams;
Name Null? Type
-------------------------------------------------- ---------------------------
T1 NUMBER (38)

SQL> create table anti_test (t1 int);

Table created.

SQL> conn scott / tiger @ clinica.rh2.oracle.com
Connected.
SQL> desc anti_test;
Name Null? Type
-------------------------------------------------- ---------------------------
T1 NUMBER (38)

/ * Ddl statement bidirectional replication * /

Test DML statement:
SQL> conn scott / tiger @ clinica.rh2.oracle.com
Connected.
SQL> desc emp;
Name Null? Type
-------------------------------------------------- ---------------------------
EMPNO NOT NULL NUMBER (4)
ENAME VARCHAR2 (10)
JOB VARCHAR2 (9)
MGR NUMBER (4)
HIREDATE DATE
SAL NUMBER (7,2)
COMM NUMBER (7,2)
DEPTNO NUMBER (2)

SQL> update emp set sal = sal +50;

14 rows updated.

SQL> commit;

Commit complete.

SQL> select sum (sal) from emp;

SUM (SAL)
----------
29725

SQL> conn scott / tiger @ clinicb.rh3.oracle.com
Connected.
SQL> select sum (sal) from emp;

SUM (SAL)
----------
29725

SQL> update emp set sal = sal +50;

14 rows updated.

SQL> commit;

Commit complete.

SQL> select sum (sal) from emp;

SUM (SAL)
----------
30425

SQL> conn scott / tiger @ clinica.rh2.oracle.com
Connected.
SQL> select sum (sal) from emp;

SUM (SAL)
----------
30425

/ * Dml statement bidirectional replication * /

to be continued .....

S-ar putea să vă placă și