高级复制之主站点与物化视图站点之间的数据复制(基于物化视图的配置方式)
基于版本10g(10.2.0.1)的高级复制-基于物化视图的配置方式
官方文档参考:http://docs.oracle.com/cd/E11882_01/server.112/e10707/rarrepsite.htm#REPMA002
主站点global_name:
SQL> select * from global_name;
GLOBAL_NAME
--------------------------------------------------------------------------------
DSOURCE.REGRESS.RDBMS.DEV.US.ORACLE.COM
物化视图站点global_name:
SQL> select * from global_name;
GLOBAL_NAME
--------------------------------------------------------------------------------
DTARGET.REGRESS.RDBMS.DEV.US.ORACLE.COM
1.主站点配置:
1)创建复制管理用户,并授予权限:
conn system/oracle
CREATE USER repadmin IDENTIFIED BY repadmin;
exec DBMS_REPCAT_ADMIN.GRANT_ADMIN_ANY_SCHEMA(username=>'repadmin');
GRANT COMMENT ANY TABLE TO repadmin;
GRANT LOCK ANY TABLE TO repadmin;
GRANT SELECT ANY DICTIONARY TO repadmin;
2)注册propagator:
exec DBMS_DEFER_SYS.REGISTER_PROPAGATOR(username=>'repadmin');
注:如果出现ORA-23394: duplicate propagator错误,说明之前注册过,处理方法如下:
a.查询注册信息:select * from system.def$_propagator;
b.注销原来的注册信息:exec DBMS_DEFER_SYS.UNREGISTER_PROPAGATOR(username=>'apadmin');
3)注册receiver:
BEGIN
DBMS_REPCAT_ADMIN.REGISTER_USER_REPGROUP (
username => 'repadmin',
privilege_type => 'receiver',
list_of_gnames => NULL);
END;
/
4)Schedule purge:
CONNECT repadmin/repadmin
BEGIN
DBMS_DEFER_SYS.SCHEDULE_PURGE (
next_date => SYSDATE,
interval => 'SYSDATE + 1/1440',
delay_seconds => 0);
END;
/
5)创建主站点代理管理用户,并注册相关权限:
CONNECT system/oracle
CREATE USER proxy_mviewadmin IDENTIFIED BY proxy_mviewadmin;
BEGIN
DBMS_REPCAT_ADMIN.REGISTER_USER_REPGROUP (
username => 'proxy_mviewadmin',
privilege_type => 'proxy_snapadmin',
list_of_gnames => NULL);
END;
/
GRANT SELECT_CATALOG_ROLE TO proxy_mviewadmin;
6)创建主站点代理刷新用户,并注册相关权限:
CREATE USER proxy_refresher IDENTIFIED BY proxy_refresher;
GRANT CREATE SESSION TO proxy_refresher;
GRANT SELECT ANY TABLE TO proxy_refresher;
7)创建测试用户及测试表:
CREATE USER mv IDENTIFIED BY mv;
grant dba to mv;
GRANT
CREATE SESSION,
CREATE TABLE,
CREATE PROCEDURE,
CREATE SEQUENCE,
CREATE TRIGGER,
CREATE VIEW,
CREATE SYNONYM,
ALTER SESSION,
CREATE MATERIALIZED VIEW,
ALTER ANY MATERIALIZED VIEW,
CREATE DATABASE LINK
TO mv;
conn mv/mv
create table t(id number primary key);
8)创建物化视图日志:
conn mv/mv
CREATE MATERIALIZED VIEW LOG ON mv.t;
9)创建主组:
CONNECT repadmin/repadmin
BEGIN
DBMS_REPCAT.CREATE_MASTER_REPGROUP (
gname => 'mv_repg');
END;
/
10)添加对象到主组:
BEGIN
DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
gname => 'mv_repg',
type => 'TABLE',
oname => 't',
sname => 'mv',
use_existing_object => TRUE,
copy_rows => FALSE);
END;
/
11)生成复制支持:
BEGIN
DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT (
sname => 'mv',
oname => 't',
type => 'TABLE',
min_communication => TRUE);
END;
/
12)开始复制:
BEGIN
DBMS_REPCAT.RESUME_MASTER_ACTIVITY (
gname => 'mv_repg');
END;
/
查询主组状态:
SQL> select gname,master,status from dba_repgroup where gname='MV_REPG';
GNAME M STATUS
------------------------------ - ---------
MV_REPG Y NORMAL
2.物化视图站点配置:
1)创建物化视图站点管理用户,并授予相关权限:
conn system/oracle
CREATE USER mviewadmin IDENTIFIED BY mviewadmin;
BEGIN
DBMS_REPCAT_ADMIN.GRANT_ADMIN_ANY_SCHEMA (
username => 'mviewadmin');
END;
/
GRANT COMMENT ANY TABLE TO mviewadmin;
GRANT LOCK ANY TABLE TO mviewadmin;
GRANT SELECT ANY DICTIONARY TO mviewadmin;
2)创建传输用户,并授予相关权限:
CREATE USER propagator IDENTIFIED BY propagator;
BEGIN
DBMS_DEFER_SYS.REGISTER_PROPAGATOR (
username => 'propagator');
END;
/
注:如果出现ORA-23394: duplicate propagator错误,说明之前注册过,处理方法如下:
a.查询注册信息:select * from system.def$_propagator;
b.注销原来的注册信息:exec DBMS_DEFER_SYS.UNREGISTER_PROPAGATOR(username=>'apadmin');
3)创建刷新用户,并授予相关权限:
CREATE USER refresher IDENTIFIED BY refresher;
GRANT CREATE SESSION TO refresher;
GRANT ALTER ANY MATERIALIZED VIEW TO refresher;
4)注册reciver:
BEGIN
DBMS_REPCAT_ADMIN.REGISTER_USER_REPGROUP (
username => 'mviewadmin',
privilege_type => 'receiver',
list_of_gnames => NULL);
END;
/
5)创建到主站点的public db link:
conn system/oracle
CREATE PUBLIC DATABASE LINK DSOURCE.REGRESS.RDBMS.DEV.US.ORACLE.COM USING 'DSOURCE';
6)使用物化视图管理用户创建到主站点的db link:
conn mviewadmin/mviewadmin
CREATE DATABASE LINK DSOURCE.REGRESS.RDBMS.DEV.US.ORACLE.COM
CONNECT TO proxy_mviewadmin IDENTIFIED BY proxy_mviewadmin;
7)创建propagator/receiver db link:
CONNECT propagator/propagator
CREATE DATABASE LINK DSOURCE.REGRESS.RDBMS.DEV.US.ORACLE.COM
CONNECT TO repadmin IDENTIFIED BY repadmin;
8)Schedule purge:
CONNECT mviewadmin/mviewadmin
BEGIN
DBMS_DEFER_SYS.SCHEDULE_PURGE (
next_date => SYSDATE,
interval => 'SYSDATE + 1/1440',
delay_seconds => 0,
rollback_segment => '');
END;
/
9)Schedule push
BEGIN
DBMS_DEFER_SYS.SCHEDULE_PUSH (
destination => 'DSOURCE.REGRESS.RDBMS.DEV.US.ORACLE.COM',
interval => 'SYSDATE + 1/1440',
next_date => SYSDATE,
stop_on_error => FALSE,
delay_seconds => 0,
parallelism => 0);
END;
/
10)创建代理用户,并授予相关权限:
CONNECT system/oracle
CREATE USER proxy_mviewadmin IDENTIFIED BY proxy_mviewadmin;
BEGIN
DBMS_REPCAT_ADMIN.REGISTER_USER_REPGROUP (
username => 'proxy_mviewadmin',
privilege_type => 'proxy_snapadmin',
list_of_gnames => NULL);
END;
/
GRANT SELECT_CATALOG_ROLE TO proxy_mviewadmin;
11)创建代理刷新用户,并授予相关权限:
CREATE USER proxy_refresher IDENTIFIED BY proxy_refresher;
GRANT CREATE SESSION TO proxy_refresher;
GRANT SELECT ANY TABLE TO proxy_refresher;
12)创建测试用户,并授予相关权限:
CREATE USER mv IDENTIFIED BY mv;
grant dba to mv;
GRANT
CREATE SESSION,
CREATE TABLE,
CREATE PROCEDURE,
CREATE SEQUENCE,
CREATE TRIGGER,
CREATE VIEW,
CREATE SYNONYM,
ALTER SESSION,
CREATE MATERIALIZED VIEW,
ALTER ANY MATERIALIZED VIEW,
CREATE DATABASE LINK
TO mv;
13)创建数据库链路:
conn mv/mv
CREATE DATABASE LINK DSOURCE.REGRESS.RDBMS.DEV.US.ORACLE.COM
CONNECT TO proxy_refresher IDENTIFIED BY proxy_refresher;
14)创建物化视图组:
CONNECT mviewadmin/mviewadmin
BEGIN
DBMS_REPCAT.CREATE_MVIEW_REPGROUP (
gname => 'mv_repg',
master => 'DSOURCE.REGRESS.RDBMS.DEV.US.ORACLE.COM',
propagation_mode => 'ASYNCHRONOUS');
END;
/
15)创建刷新组:
BEGIN
DBMS_REFRESH.MAKE (
name => 'mviewadmin.mv_refresh',
list => '',
next_date => SYSDATE,
interval => 'SYSDATE + 1/1440',
implicit_destroy => FALSE,
rollback_seg => '',
push_deferred_rpc => TRUE,
refresh_after_errors => FALSE);
END;
/
16)添加对象到物化视图组:
CREATE MATERIALIZED VIEW mv.t_mv1
REFRESH FAST WITH PRIMARY KEY FOR UPDATE
AS SELECT * FROM [email protected];
BEGIN
DBMS_REPCAT.CREATE_MVIEW_REPOBJECT (
gname => 'mv_repg',
sname => 'mv',
oname => 't_mv1',
type => 'SNAPSHOT',
min_communication => TRUE);
END;
/
17)添加对象到刷新组:
BEGIN
DBMS_REFRESH.ADD (
name => 'mviewadmin.mv_refresh',
list => 'mv.t_mv1',
lax => TRUE);
END;
/
3.测试是否配置成功:
1)主站点上使用测试用户mv,向t表中插入数据:
conn mv/mv
insert into t values(1);
commit;
2)物化视图站点使用测试用户mv登录,查询mv.t_mv1物化视图,发现有数据,配置成功:
SQL> select * from mv.t_mv1;
ID
----------
1