Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1064173
  • 博文数量: 284
  • 博客积分: 8223
  • 博客等级: 中将
  • 技术积分: 3188
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-01 13:26
文章分类

全部博文(284)

文章存档

2012年(18)

2011年(33)

2010年(83)

2009年(147)

2008年(3)

分类: Oracle

2009-05-07 15:02:25

             好容易,折腾了两个星期才把高级复制配置成功,还有很多东西不清楚,不管了,作为总结,先把操作过程写下来,给所有人做个范例,特别感谢yangtk等大虾的无私奉献,抗议许多都没有自己尝试就直接转载的同仁,热情可贵,可就是害我在遇到问题baidu的时候付出了不少无用功。好,废话不多说,步骤如下,

1.       检查数据库参数:

要求:     global_names: TRUE

               Open_links:最小数5

修改命令:alter system set global_names=true;

查看参数:show parameter global_names;

2.       修改listener.ora

使双机能够互相使用@访问:

如这里,测试双机环境如下,

主机1 shenzhen 域名 shenzhen

主机2 beijing  域名:beijing

使得双方可以通过@shenzhen@beijing互相访问。

3.       在主机shenzhen上执行下面脚本:

a)         system用户登录并建立复制管理员rep

connect system/root@shenzhen;

create user rep identified by rep

default tablespace users

temporary tablespace temp;

b)        对复制管理员用户rep授予管理员权限;

Begin

dbms_repcat_admin.grant_admin_any_schema(username=>’rep’);

end;

/

grant comment any table to rep;

grant lock any table to rep;

//注册传播函数;

begin

dbms_defer_sys.register_propagator(username=>’rep’);

end;

/

Grant execute any procedure to rep;

c)        增加到beijing节点的公共链路;

Create public database link beijing using ‘beijing’;

d)        登录复制管理员用户,建立私有链路;

connect rep/rep@shenzhen

create database link beijing connect to rep identified by rep;

e)         每隔1分钟push一次任务将shenzhen节点上的事务推到beijing节点上去执行

Begin

dbms_defer_sys.schedule_push(

destination=>’beijing’,

       interval=>’sysdate+1/(60*24)’,

       next_date=>sysdate,

       stop_on_error=>FALSE,

       delay_seconds=>0,

       parallelism=>2);

END;

/

f)         注册接收者

Begin dbms_repcat_admin.register_user_repgroup(

Username=>’rep’,

Privilege_type=>’receiver’,

List_of_gnames=>NULL

);

end;

/

 

 

g)        每隔5分钟PURGE一次任务将shenzhen节点上已完成的事务退出队列

Begin dbms_defer_sys.schedule_purge(

next_date=>sysdate,

       interval=>’sysdate+5/(60*24)’,

       delay_seconds=>0,

       rollback_segment=>’’);

end;

/

h)        shenzhen主机上建立nari用户

connect system/root@shenzhen;

create user nari identified by nari default tablespace users temporary tablespace temp;

grant alter session to nari;

grant create cluster to nari;

grant create database link to nari;

grant create sequence to nari;

grant create session to nari;

grant create synonym to nari;

grant create table to nari;

grant create view to nari;

grant create procedure to nari;

grant create trigger to nari;

grant unlimited tablespace to nari;

grant create type to nari;

grant create any snapshot to nari;

grant alter any snapshot to nari;

i)          shenzhen主机上建立NARI下的dept表、tmp表;

connect nari/nari@shenzhen;

create table dept(

  deptno number primary key

);

create table tmp(

  deptno number primary key

);

commit;

 

4.       在主机beijing上执行下面脚本:

a)         system用户登录并建立复制管理员rep

connect system/root@beijing;

create user rep identified by rep

default tablespace users

temporary tablespace temp;

b)        对复制管理员用户rep授予管理员权限;

Begin

dbms_repcat_admin.grant_admin_any_schema(username=>’rep’);

end;

/

grant comment any table to rep;

grant lock any table to rep;

begin dbms_defer_sys.register_propagator(username=>’rep’);

end;

/

grant execute any procedure to rep;

c)        shenzhen节点建立公共链路;

Create public database link shenzhen using ‘shenzhen’;

d)        以复制用户对shenzhen节点建立私有链路;

conn rep/rep@beijing

create database link shenzhen connect to rep identified by rep;

 

e)         每隔1分钟push一次任务将beijing节点上的事务推到shenzhen节点上去执行

Begin

dbms_defer_sys.schedule_push(

destination=>’shenzhen’,

       interval=>’sysdate+1/(60*24)’,

       next_date=>sysdate,

       stop_on_error=>FALSE,

       delay_seconds=>0,

       parallelism=>2);

END;

/

f)         每隔5分钟PURGE一次任务将beijing节点上已完成的事务退出队列

Begin dbms_defer_sys.schedule_purge(

next_date=>sysdate,

       interval=>’sysdate+5/(60*24)’,

       delay_seconds=>0,

       rollback_segment=>’’);

end;

/

g)        注册接收者

Begin dbms_repcat_admin.register_user_repgroup(

Username=>’rep’,

Privilege_type=>’receiver’,

List_of_gnames=>NULL

);

end;

/

 

h)        beijing主机上建立nari用户

connect system/root@beijing;

create user nari identified by nari default tablespace users temporary tablespace temp;

grant alter session to nari;

grant create cluster to nari;

grant create database link to nari;

grant create sequence to nari;

grant create session to nari;

grant create synonym to nari;

grant create table to nari;

grant create view to nari;

grant create procedure to nari;

grant create trigger to nari;

grant unlimited tablespace to nari;

grant create type to nari;

grant create any snapshot to nari;

grant alter any snapshot to nari;

i)          beijing主机上建立NARI下的dept表、tmp表;

connect nari/nari@beijing;

create table dept(

  deptno number primary key

);

create table tmp(

  deptno number primary key

);

commit;

 

 

5.       在主机shenzhen上执行下面脚本:

a)         rep用户登录;

conn rep/rep@shenzhen;

b)        建立对称复制组“SCOTT

Begin dbms_repcat.create_master_repgroup(gname=>’SCOTT’,qualifier=>’’,group_comment=>’’);

End;

/

c)        DEPT\TMP表加入到对称复制组“SCOTT”中

Begin

dbms_repcat.create_master_repobject(gname=>’”SCOTT”’, type=>’TABLE’,

oname=>’DEPT’,sname=>’nari’,use_existing_object=>TRUE,

copy_rows=>TRUE);

End;

/

Begin

dbms_repcat.create_master_repobject(gname=>’”SCOTT”’, type=>’TABLE’,

oname=>’TMP’,sname=>’nari’,use_existing_object=>TRUE,

copy_rows=>TRUE);

End;

/

d)        把主数据库“Beijing”加入到对称复制组“SCOTT”中

Begin

Dbms_repcat.add_master_database(gname=>’”SCOTT”’,master=>’beijing’,use_existing_objects=>TRUE, copy_rows=>TRUE, propagation_mode=>’ASYNCHRONOUS’);

End;

/

(ORA-4052 查找远程对象SYS.SYS.BEIJING出错)

(ORA-23308:对象nari.DEPT不存在或无效 ORA-02055:分布式更新操作失效,要求回退:

遇到该问题后,新建表CC,新建复制组T,所有问题解决;原因在于建表过程,建表时,应使用目前说明的语句,不要使用alter 。。。modify语句,不能有NUMBER(2)这样的描述,先不要insert 数据进入)

e)         生成复制支持表DEPT

Begin dbms_repcat.generate_replication_support(sname=>’nari’,

Oname=>’DEPT’,type=>’TABLE’,min_communication=>TRUE);

End;

/

f)         生成复制支持表TMP

Begin dbms_repcat.generate_replication_support(sname=>’nari’,

Oname=>’TMP’,type=>’TABLE’,min_communication=>TRUE);

End;

/

g)        启动对称复制组SCOTT

Begin dbms_repcat.resume_master_activity(gname=>’”SCOTT”’);

End;

/

Commit;

执行完后,使用system用户登录系统并查询状态;

Conn system/root@shenzhen

Select gname,status from sys.dba_repcat ;

如果看到当前复制组的状态为NORMAL表明可以进行DML操作;

同时,如果工作正常的话,应该使用如下命令,看不到log

Select count(*) from sys.dba_repcatlog;

(如果为quiesced

Begin dbms_repcat.resume_master_activity(’”SCOTT”’,true);

End;

/

会发现配置主站变成NORMAL,但是另外一个主站仍然为quiesced,该站不能执行启动复制组的操作

可以查询该站的job

select job,this_date,next_date,what from user_jobs;

使用命令exec dbms_job.run(job_number);

Job_number为该主机的最后一个job号,可以启动相应job,发现相应数据就会被同步;而且执行该操作后,该主机也会从quiesced变成NORMAL

)

 

特别:

1.       如果想停止复制对称组运行:

execute  dbms_repcat.suspend_master_activity(gname=>’SCOTT’);注意,需要rep用户;

在执行复制使用,

Begin dbms_repcat.resume_master_activity(gname=>’”SCOTT”’);

End;

 

2.       如果想删除复制组:

execute  dbms_repcat.drop_master_repgroup(gname => 'SCOTT', drop_contents => false, all_sites => false);

 

3.   在复制组scott_mg里删除数据库对象。
execute dbms_repcat.drop_master_repobject ('testuser','dept','table');

 

4.   重新使同步组的状态由停顿(quiesced )改为正常(normal)
execute dbms_repcat.resume_master_activity('scott_mg',false);

 

阅读(1717) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~