Oracle Database Replication

Source: Internet
Author: User

We often hope to unify data stored in different regions for application. Now we can use the replication technology to solve this problem. However, Database Replication also requires some conditions.
First, the database must have the Advanced replication function. log on to the database as a system and view the v $ option view. If Advanced replication is TRUE, the Advanced replication function is supported. Otherwise, the Advanced replication function is not supported ).
If Advanced Replication is available, some parameter initialization is required for the database.
Db_domain = test.com.cn indicates the database domain name (the default is WORLD). Here, you can use your company domain name; global_names = true it requires database link) the name is the same as the name of the connected database. Now the global database name is db_name + ". "+ db_domain;
Parameters related to database job execution:
Job_queue_processes = 1;
Job_queue_interval = 60;
Distributed_transactions = 10;
Open_links = 4
The first line defines the number of initiation of the SNP process as n. The default value is 0, and the normal definition range is 0 ~ 36. You can configure different values based on the number of tasks. The second line defines the system to wake up the process every N seconds. The default value is 60 seconds. The normal range is 1 ~ 3600 seconds. In fact, the process enters the sleep state after the current task is executed. After a period of sleep, the general control of the system will wake it up. If you have modified these parameters, You need to restart the database to make the parameters take effect.
After completing the preliminary preparations, we will implement synchronous database replication.
Suppose there are two databases on the Internet: China and Japan ).
The specific configuration is as follows:
Database Name: China, Japan
Database domain name test.com.cn
Database sid numbers: China and Japan
Listener port 1521
Server IP address 10.1.0.100 10.1.0.200
Make sure that the two databases can access each other and set the database connection string in tnsnames. ora.

The database connection string on the Chinese side is in the following format:
Japan =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = 10.1.1.200) (PORT = 1521 ))
)
(CONNECT_DATA =
(SERVICE_NAME = Japan)
)
)
Run $ tnsping Japan and the following prompt appears:
Attempting to contact (ADDRESS = (PROTOCOL = TCP) (HOST = 10.1.1.200) (PORT = 1521 ))
OKn milliseconds)
Indicates that the chinese database can access the Japanese database. The configuration is the same in Japan. Make sure that $ tnsping China is available.
Change the global name of the database and create a public database link.

Log on to the China database as a system
SQL> alter database rename global_name to China.test.com.cn;
Log on to the Japan database as a system:
SQL> alter database rename global_name to Japan.test.com.cn;
Log on to the China database as a system.
SQL> create public database link Japan .test.com.cn using 'Japan ';
Test the global database name and public database connection.
SQL> select * from global_name@Japan.test.com.cn;
The returned result is Japan.test.com.cn.
Log on to the Japan database as a system:
SQL> create public database link China.test.com.cn using 'China ';
Test the global database name and public database connection.
SQL> select * from global_name@China.test.com.cn;
The returned result is China.test.com.cn.
Create a user repadmin who manages database replication and grant permissions.
Log on to the China database as a system:
SQL> create user repadmin identified by repadmin default tablespace users temporary tablespace temp;
SQL> execute dbms_defer_sys.register_propagator ('repadmin ');
SQL> grant execute any procedure to repadmin;
SQL> execute dbms_repcat_admin.grant_admin_any_repgroup ('repadmin ');
SQL> grant comment any table to repadmin;
SQL> grant lock any table to repadmin;

Log on to the Japan database as a system, run the preceding commands, manage the database replication user repadmin, and grant permissions.
Create a private database link under the user repadmin who copied the database.
Log on to the China database as repadmin.
SQL> create database link Japan.test.com.cn connect to repadmin identified

Run the above 1, 2, and 3 operations on the Japanese database.
Create the serial number of the primary keyword under the scott user of the Japan database to avoid conflicts with China.
SQL> create sequence dept_no increment by 1 start with 45 maxvalue 99 cycle nocache;
Insert initialization data under the scott user in the Japan database.
SQL> insert into dept values (dept_no.nextval, 'sales', 'Chicago ');
SQL> insert into dept values (dept_no.nextval, 'operations', 'boston ');
SQL> commit;
Create the scott_mg group to be copied and add it to the database object to generate support for object replication.
Log on to the China database as repadmin and create the master replication group scott_mg:
SQL> execute dbms_repcat.create_master_repgroup ('Scott _ mg ');
Add database objects to the replication group scott_mg:
SQL> execute dbms_repcat.create_master_repobject (sname => 'Scott ', oname => 'dept', type => 'table', use_existing_object => true, gname => 'Scott _ mg ');
Parameter description:
User name for Database Replication Using sname;
Oname indicates the name of the database object for database replication;
Type indicates the type of the database object to be copied;
Use_existing_object true indicates the existing database objects of the master replication node;
Gname: name of the master replication group;
Replication of database objects is supported:
SQL> execute dbms_repcat.generate_replication_support ('Scott ', 'dept', 'table ');
Make sure that the copied group and object have been added to the data dictionary of the database:
SQL> select gname, master, status from dba_repgroup;
SQL> select * from dba_repobject;
Create a master replication node:
Log on to the China database as repadmin and create the master replication node:
SQL> execute dbms_repcat.add_master_database
(Gname => 'Scott _ mg ', master => 'Japan .test.com.cn', use_existing_objects => true, copy_rows => false, propagation_mode => 'asynchronous ');
Parameter description:
Gname: name of the master replication group;
The master node is added to another database of the master replication node;
Use_existing_object true indicates the existing database objects of the master replication node;
Copy_rows false indicates that the first copy operation does not need to be consistent with the master copy node;
Propagation_mode asynchronous execution;
Make sure that the copied task queue has been added to the data dictionary of the database:
SQL> select * from user_jobs;
Change the status of the synchronization group from pause (quiesced) to normal (normal ):
Use repa


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.