这个是本人已经实验通过的了.很多都是向别人学习的.
oracle 10g
本例涉及两个站点.
1:lxp28.ruanko.com
2:lxp32.ruanko.com
注:主体定义站点指配置复制工作的站点
本例涉及的用户.
复制管理员:repadmin
应用用户:lxp
本例复制的对象:hw_test 数据表
本例的先决条件:你需要设置好相应的参数,job_queue_processes需要大于0,global_name=true,
一。在1上做的:
用户netca来配一个连接2的侦听 lxp32
sqlplus / as sysdba
察看global_name参数
SQL> show parameter global_name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
global_names boolean FALSE
SQL> alter system set global_names=true scope=both;
察看默认global_name,数据库域名
SQL> select * from global_name;
GLOBAL_NAME
--------------------------------------------------------------------------------
orc1.REGRESS.RDBMS.DEV.US.ORACLE.COM
修改global_name,数据库域名
SQL> alter database rename global_name to lxp28.ruanko.com scope=both;
SQL> shutdown immediate
SQL> startup
SQL> create user lxp identified by lxp default tablespace users;
SQL> grant connect,resource to lxp;
SQL> conn lxp/lxp
create table test(id number,name varchar2(20),constraint test_id_pk primary key(id)); (主键一定是要的,因为主键是判断两个数据库的差异);
建立管理数据库复制的用户repadmin,并赋权。
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> execute dbms_repcat_admin.grant_admin_any_schema(username => 'repadmin');
SQL> grant comment any table to repadmin;
SQL> grant lock any table to repadmin;
SQL> grant select any dictionary to repadmin;
用repadmin 创建database link 连接
SQL> conn repadmin/repadmin
SQL> create public database link "lxp32.ruanko.com" connect to repadmin identified by repadmin using 'lxp32';
Database link created.
SQL> select * from dual@lxp32;
D
-
X
二。在2上做的:
配一个连接2的侦听 lxp28
sqlplus / as sysdba
察看global_name参数
SQL> show parameter global_name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
global_names boolean FALSE
察看默认global_name,数据库域名
SQL> select * from global_name;
GLOBAL_NAME
--------------------------------------------------------------------------------
orc1.REGRESS.RDBMS.DEV.US.ORACLE.COM
修改global_name,数据库域名
SQL> alter database rename global_name to lxp28.ruanko.com scope=both;
SQL> shutdown immediate
SQL> startup
SQL> create user lxp identified by lxp default tablespace users;
SQL> grant connect,resource to lxp;
SQL> conn lxp/lxp
create table test(id number,name varchar2(20),constraint test_id_pk primary key(id)); (主键一定是要的,因为主键是判断两个数据库的差异);
建立管理数据库复制的用户repadmin,并赋权。
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> execute dbms_repcat_admin.grant_admin_any_schema(username => 'repadmin');
SQL> grant comment any table to repadmin;
SQL> grant lock any table to repadmin;
SQL> grant select any dictionary to repadmin;
用repadmin 创建database link 连接
SQL> conn repadmin/repadmin
SQL> create public database link "lxp28.ruanko.com" connect to repadmin identified by repadmin using 'lxp28';
Database link created.
SQL> select * from dual@lxp28;
D
-
X
三在回到1机上:
创建复制组:
SQL> execute dbms_repcat.create_master_repgroup('rep_hh');
PL/SQL procedure successfully completed.
SQL> select gname,master,status from dba_repgroup where gname='REP_HH';
GNAME M STATUS
------------------------------ - ---------
REP_HH Y QUIESCED
在复制组里加入复制对象
SQL> execute dbms_repcat.create_master_repobject(sname=>'lxp',oname=>'test',type=>'table',use_existing_object=>true,gname=>'rep_hh',copy_rows=>false);
sname 实现数据库复制的用户名称
oname 实现数据库复制的数据库对象名称
type 实现数据库复制的数据库对象类别。(支持的类别:表,索引,同义词,触发器,视图,过程,函数,程序包,程序包体)
use_existing_object true表示用主复制节点已经存在的数据库对象
gname 主复制组名
copy_rows true表示第一次开始复制时和主复制节点保持一致
PL/SQL procedure successfully completed.
SQL> select sname,oname,status,gname from dba_repobject where gname='REP_HH';
SNAME ONAME STATUS GNAME
------------------------------ ------------------------------ ---------- ------------------------------
HAWA HW_TEST VALID REP_HH
对复制对象产生复制支持
SQL> execute dbms_repcat.generate_replication_support('lxp','test','table');
(说明:产生支持lxp用户下test表复制的数据库触发器和程序包)
PL/SQL procedure successfully completed.
SQL> select gname, master, status from dba_repgroup where gname='REP_HH';
GNAME M STATUS
------------------------------ - ---------
REP_HH Y QUIESCED
SQL> select sname,oname,status,gname from dba_repobject where gname='REP_HH';
SNAME ONAME STATUS GNAME
------------------------------ ------------------------------ ---------- ------------------------------
lxp TEST VALID REP_HH
lxp TEST$RP VALID REP_HH
lxp TEST$RP VALID REP_HH
SQL>
添加主体复制节点
SQL> execute dbms_repcat.add_master_database
(gname=>'rep_hh',master=>'lxp32.ruanko.com',use_existing_objects=>true,
copy_rows=>false, propagation_mode => 'synchronous');
gname 主复制组名
master 加入主复制节点的另一个数据库
use_existing_object true表示用主复制节点已经存在的数据库对象
copy_rows false表示第一次开始复制时不用和主复制节点保持一致
propagation_mode 异步地执行
PL/SQL procedure successfully completed.
SQL> column masterdef format a10
SQL> column master format a10
SQL> column dblink format a25
SQL> column gname format a12
SQL> select gname, dblink, masterdef MASTERDEF, master MASTER from sys.dba_repsites where gname='REP_HH';
GNAME DBLINK MASTERDEF MASTER
------------ ------------------------- ---------- ----------
REP_HH lxp28.ruanko.com Y Y
REP_HH lxp32.ruanko.com N Y
四。登陆2机上,检查复制对象情况:
[oracle@www167 oracle]$ sqlplus repadmin/password
SQL> select * from global_name;
GLOBAL_NAME
--------------------------------------------------------------------------------
AUTHAA.COOLYOUNG.COM.CN
SQL> set linesize 120
SQL> select sname,oname,status,gname from dba_repobject where gname='REP_HH';
SNAME ONAME STATUS GNAME
------------------------------ ------------------------------ ---------- ------------------------------
lxp TEST VALID REP_HH
lxp TEST VALID REP_HH
lxp TEST VALID REP_HH
五回到1机上
在主体定义站点启动复制:
conn repadmin/repadmin
SQL> select * from global_name;
GLOBAL_NAME
-----------------------------------------------------------------------------
lxp28.ruanko.com
SQL> execute dbms_repcat.resume_master_activity('rep_hh',true);
PL/SQL procedure successfully completed.
六:在1或2机上
SQL>conn lxp/lxp
SQL>insert into test values(1,'zhao');
SQL>insert into test values(2,'yong');
SQL>commit;
再到1机或2机上的lxp用户上查
SQL>select * from test
ID NAME
---------- --------------------
1 zhao
2 yong
oracle 10g
本例涉及两个站点.
1:lxp28.ruanko.com
2:lxp32.ruanko.com
注:主体定义站点指配置复制工作的站点
本例涉及的用户.
复制管理员:repadmin
应用用户:lxp
本例复制的对象:hw_test 数据表
本例的先决条件:你需要设置好相应的参数,job_queue_processes需要大于0,global_name=true,
一。在1上做的:
用户netca来配一个连接2的侦听 lxp32
sqlplus / as sysdba
察看global_name参数
SQL> show parameter global_name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
global_names boolean FALSE
SQL> alter system set global_names=true scope=both;
察看默认global_name,数据库域名
SQL> select * from global_name;
GLOBAL_NAME
--------------------------------------------------------------------------------
orc1.REGRESS.RDBMS.DEV.US.ORACLE.COM
修改global_name,数据库域名
SQL> alter database rename global_name to lxp28.ruanko.com scope=both;
SQL> shutdown immediate
SQL> startup
SQL> create user lxp identified by lxp default tablespace users;
SQL> grant connect,resource to lxp;
SQL> conn lxp/lxp
create table test(id number,name varchar2(20),constraint test_id_pk primary key(id)); (主键一定是要的,因为主键是判断两个数据库的差异);
建立管理数据库复制的用户repadmin,并赋权。
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> execute dbms_repcat_admin.grant_admin_any_schema(username => 'repadmin');
SQL> grant comment any table to repadmin;
SQL> grant lock any table to repadmin;
SQL> grant select any dictionary to repadmin;
用repadmin 创建database link 连接
SQL> conn repadmin/repadmin
SQL> create public database link "lxp32.ruanko.com" connect to repadmin identified by repadmin using 'lxp32';
Database link created.
SQL> select * from dual@lxp32;
D
-
X
二。在2上做的:
配一个连接2的侦听 lxp28
sqlplus / as sysdba
察看global_name参数
SQL> show parameter global_name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
global_names boolean FALSE
察看默认global_name,数据库域名
SQL> select * from global_name;
GLOBAL_NAME
--------------------------------------------------------------------------------
orc1.REGRESS.RDBMS.DEV.US.ORACLE.COM
修改global_name,数据库域名
SQL> alter database rename global_name to lxp28.ruanko.com scope=both;
SQL> shutdown immediate
SQL> startup
SQL> create user lxp identified by lxp default tablespace users;
SQL> grant connect,resource to lxp;
SQL> conn lxp/lxp
create table test(id number,name varchar2(20),constraint test_id_pk primary key(id)); (主键一定是要的,因为主键是判断两个数据库的差异);
建立管理数据库复制的用户repadmin,并赋权。
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> execute dbms_repcat_admin.grant_admin_any_schema(username => 'repadmin');
SQL> grant comment any table to repadmin;
SQL> grant lock any table to repadmin;
SQL> grant select any dictionary to repadmin;
用repadmin 创建database link 连接
SQL> conn repadmin/repadmin
SQL> create public database link "lxp28.ruanko.com" connect to repadmin identified by repadmin using 'lxp28';
Database link created.
SQL> select * from dual@lxp28;
D
-
X
三在回到1机上:
创建复制组:
SQL> execute dbms_repcat.create_master_repgroup('rep_hh');
PL/SQL procedure successfully completed.
SQL> select gname,master,status from dba_repgroup where gname='REP_HH';
GNAME M STATUS
------------------------------ - ---------
REP_HH Y QUIESCED
在复制组里加入复制对象
SQL> execute dbms_repcat.create_master_repobject(sname=>'lxp',oname=>'test',type=>'table',use_existing_object=>true,gname=>'rep_hh',copy_rows=>false);
sname 实现数据库复制的用户名称
oname 实现数据库复制的数据库对象名称
type 实现数据库复制的数据库对象类别。(支持的类别:表,索引,同义词,触发器,视图,过程,函数,程序包,程序包体)
use_existing_object true表示用主复制节点已经存在的数据库对象
gname 主复制组名
copy_rows true表示第一次开始复制时和主复制节点保持一致
PL/SQL procedure successfully completed.
SQL> select sname,oname,status,gname from dba_repobject where gname='REP_HH';
SNAME ONAME STATUS GNAME
------------------------------ ------------------------------ ---------- ------------------------------
HAWA HW_TEST VALID REP_HH
对复制对象产生复制支持
SQL> execute dbms_repcat.generate_replication_support('lxp','test','table');
(说明:产生支持lxp用户下test表复制的数据库触发器和程序包)
PL/SQL procedure successfully completed.
SQL> select gname, master, status from dba_repgroup where gname='REP_HH';
GNAME M STATUS
------------------------------ - ---------
REP_HH Y QUIESCED
SQL> select sname,oname,status,gname from dba_repobject where gname='REP_HH';
SNAME ONAME STATUS GNAME
------------------------------ ------------------------------ ---------- ------------------------------
lxp TEST VALID REP_HH
lxp TEST$RP VALID REP_HH
lxp TEST$RP VALID REP_HH
SQL>
添加主体复制节点
SQL> execute dbms_repcat.add_master_database
(gname=>'rep_hh',master=>'lxp32.ruanko.com',use_existing_objects=>true,
copy_rows=>false, propagation_mode => 'synchronous');
gname 主复制组名
master 加入主复制节点的另一个数据库
use_existing_object true表示用主复制节点已经存在的数据库对象
copy_rows false表示第一次开始复制时不用和主复制节点保持一致
propagation_mode 异步地执行
PL/SQL procedure successfully completed.
SQL> column masterdef format a10
SQL> column master format a10
SQL> column dblink format a25
SQL> column gname format a12
SQL> select gname, dblink, masterdef MASTERDEF, master MASTER from sys.dba_repsites where gname='REP_HH';
GNAME DBLINK MASTERDEF MASTER
------------ ------------------------- ---------- ----------
REP_HH lxp28.ruanko.com Y Y
REP_HH lxp32.ruanko.com N Y
四。登陆2机上,检查复制对象情况:
[oracle@www167 oracle]$ sqlplus repadmin/password
SQL> select * from global_name;
GLOBAL_NAME
--------------------------------------------------------------------------------
AUTHAA.COOLYOUNG.COM.CN
SQL> set linesize 120
SQL> select sname,oname,status,gname from dba_repobject where gname='REP_HH';
SNAME ONAME STATUS GNAME
------------------------------ ------------------------------ ---------- ------------------------------
lxp TEST VALID REP_HH
lxp TEST VALID REP_HH
lxp TEST VALID REP_HH
五回到1机上
在主体定义站点启动复制:
conn repadmin/repadmin
SQL> select * from global_name;
GLOBAL_NAME
-----------------------------------------------------------------------------
lxp28.ruanko.com
SQL> execute dbms_repcat.resume_master_activity('rep_hh',true);
PL/SQL procedure successfully completed.
六:在1或2机上
SQL>conn lxp/lxp
SQL>insert into test values(1,'zhao');
SQL>insert into test values(2,'yong');
SQL>commit;
再到1机或2机上的lxp用户上查
SQL>select * from test
ID NAME
---------- --------------------
1 zhao
2 yong
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16111659/viewspace-663216/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/16111659/viewspace-663216/