一直没有尝试过高级复制技术,闲来无聊。
1 配置:
主体定义数据库:test.com
主体数据库:back.com
高级复制过程:
1.处理数据库参数:(两台数据库都要配置)
1.1设置global_name为true。(global_name 由两部分组成。<sid> +<db_domain>.)
SQL> show parameter global_name
NAMETYPEVALUE
------------------------------------ ----------- --------
global_namesbooleanTRUE
如果为false 请更改
alter system set global_name=true scope=spfile; (写在spfile文件中。)
-----------------------------------------------------
1.2重新命名global_name
alter database rename global_name to <sid>.<domain_name>.
如:
alter database global_name to test.com;
更该完毕。
重起两台数据库。(两台数据都需要修改)
参数修改完毕。
2.开始用户配置:(两台数据库都要相同的配置)
2.1先配置复制数据测试用户。
用system用户操作:
create user test identified by test default tablespace users;
grant connect,resource to test;
2.2切换到test用户
conntest/test
create table test(id number,name varchar2(20),constraint test_id_pk primary key(id));(主键一定是要的);
2.3插入一些测试数据
insert into test values(1,’tttttttttt’);
insert into test values(2,’wwwwwwwww’);
insert into test values(3,’sssss’);
commit;
2.4用system用户创建public link;
在test上创建
create public database link “back.com” using ‘backdb’;
测试连通性:
select * from global_name@ back.com
GLOBAL_NAME
---------
BACK.COM
如果不通请检查tnsname.一定要通.不然后面就不用做了.
在back上创建
create public database link “back.com” using ‘backdb’;
测试连通性:
select * from global_name@ test.com
GLOBAL_NAME
---------
TEST.COM
如果不通请检查tnsname.一定要通.不然后面就不用做了.
3.配置复制管理用户.(两台数据库都要相同的配置)
3.1
conn system/tanfufa
SQL>create user repadmin identified by repadmin default tablespace users temporary tablespace temp;
User created.
SQL>execute dbms_defer_sys.register_propagator(‘repadmin‘);
PL/SQL procedure successfully completed.
SQL>grant execute any procedure to repadmin;
Grant succeeded.
SQL>execute dbms_repcat_admin.grant_admin_any_repgroup(‘repadmin‘);
PL/SQL procedure successfully completed.
SQL>execute dbms_repcat_admin.grant_admin_any_schema(username => ‘repadmin‘);
PL/SQL procedure successfully completed.
SQL>grant comment any table to repadmin;
Grant succeeded.
SQL>grant lock any table to repadmin;
Grant succeeded.
SQL>grant select any dictionary to repadmin;
Grant succeeded.
4. 用repadmin用户创建database link. (两台数据库都要相同的配置)
在testdb上创建:
create database link “back.com” connect to repadmin identified by repadmin.
测试连通性:
select * from global_name@ back.com
GLOBAL_NAME
---------
BACK.COM
如果不通请检查tnsname.一定要通.不然后面就不用做了.
在backdb上创建:
create database link “back.com” connect to repadmin identified by repadmin.
测试连通性:
select * from global_name@ test.com
GLOBAL_NAME
---------
TEST.COM
如果不通请检查tnsname.一定要通.不然后面就不用做了.
5.准备工作全部做完了.现在去喝咖啡.
6..复制实施进程:(特别注意以下在testdb数据库上操作)
6.1 conn repadmin/repadmin
SQL> execute dbms_repcat.create_master_repgroup(‘REP_MYTEST‘);
PL/SQL procedure successfully completed.
察看复制主体组相关信息:
SQL> select gname,master,status from dba_repgroup where gname=‘REP_MYTEST‘;
GNAMEMASTERSTATUS
--------------------------- ----------------------------------------------------
REP_MYTESTYQUIESCED
为主体组添加复制对象:
SQL> execute dbms_repcat.create_master_repobject (sname=>‘test‘,oname=>‘test‘, type=>‘TABLE‘,use_existing_object=>true,gname=>‘REP_MYTEST‘,copy_rows=>true);
PL/SQL procedure successfully completed.
察看复制主体组中复制对象的相关信息:
SQL>select sname,oname,status,gname from dba_repobject where gname=‘REP_MYTEST‘;
SNAMEONAMESTATUSGNAME
----------------------------- ------------------------------ ------------- ------------------------------
SCOTTDEPTVALIDREP_MYTEST
为复制对象生成复制支持:
SQL> execute dbms_repcat.generate_replication_support(‘test‘,‘test‘,‘TABLE‘);
PL/SQL procedure successfully completed.
再次察看复制主体组和对应的复制对象的相关信息:
SQL> select gname,master,status from dba_repgroup where gname=‘REP_MYTEST‘;
GNAMEMASTERSTATUS
--------------------------- ----------------------------------------------------
REP_MYTESTYQUIESCED
SQL> select sname,oname,status,gname from dba_repobject where gname=‘REP_MYTEST‘;
SNAMEONAMESTATUSGNAME
----------------------------- ------------------------------ ------------- ------------------------------
SCOTTDEPTVALIDREP_MYTEST
SCOTTDEPT$RPVALIDREP_MYTEST
SCOTTDEPT$RPVALIDREP_MYTEST
为复制主体组添加数据库主站点:
SQL>execute dbms_repcat.add_master_database(gname=>‘REP_MYTEST‘,
master=>‘backdb.geong.com‘,use_existing_objects=>true,copy_rows=>true, propagation_mode => ‘synchronous‘);
PL/SQL procedure successfully completed.
察看复制站点信息:
SQL> select gname,dblink,masterdef,master from dba_repsites where gname=‘REP_MYTEST‘;
GNAMEDBLINKMASTERDEFMASTER
------------ -------------------------------------------------- --------------
REP_MYTESTtestdb.geong.comYY
REP_MYTESTbackdb.geong.com NY
启动复制进程:
SQL> execute dbms_repcat.resume_master_activity(‘REP_MYTEST‘,true);
PL/SQL procedure successfully completed.
再次察看复制主体组相关信息:
SQL> select gname,master,status from dba_repgroup where gname=‘REP_MYTEST‘;
GNAMEMASTERSTATUS
--------------------------- ----------------------------------------------------
REP_MYTESTYNORMAL
注意:复制主体组的状态由QUIESCED变为NORMAL。
至此,这个复制过程实施完毕。可以进行相关的数据操作进行测试。
7.测试:
1.在test上删除修改插入数据,查看backdb变化.
2.在back上删除修改插入数据,查看testdb变化.
8.如果你需要添加表到组里面来请按照入下操作.
配置好后。如果需要添加表。
执行下命令:
exec dbms_repcat.suspend_master_activity(‘rep_mytest‘);
取消抑制。
execute dbms_repcat.create_master_repobject(sname=>‘reptest‘,oname=>‘test1‘
,type=>‘TABLE‘,use_existing_object=>true,gname=>‘REP_MYTEST‘,copy_rows=>true);
为组增加新表。
execute dbms_repcat.generate_replication_support(‘reptest‘,‘test1‘,‘TABLE‘)
增加支持。
execute dbms_repcat.resume_master_activity(‘REP_MYTEST‘,true);
启动进程