Oracle Replication配置及测试
游波
【 关键词 】
Oracle,Replication,主站点,物化视图,优化
【 文章摘要 】
本文根据巴基斯坦异地容灾系统的需要,对Oracle容灾方案中的高级复制作配置和评估,供方案决策。本文给出了基于物化视图复制方式的详细的配置步骤,给出了功能测试结果和详细的性能测试指标,并对测试结果进行的初步的分析。分析结果可供开发人员和系统设计人员在作系统容灾备份方案时参考。
环境配置
按配置主站点,视图站点,主组,视图组的次序进行配置。(注:第五步在创建时不需要)
主站点
地址:10.130.61.209:1521 zxin
操作系统:aix
版本:9206
dba账号:system/oracle
sysdba账号sys/oracle
备战点
地址:10.130.32.132:1521 ngncc_db
操作系统:windows
版本:9201
dba账号:system/ngcc
sysdba账号sys/ngcc
系统账号:administrator/ngcc
一、配置主站点
1.连接主站点209,创建复制管理员并授予相应的权限
conn system/oracle@209
create user repadmin identified by repadmin;
begin
dbms_repcat_admin.grant_admin_any_schema(
username=>'repadmin');
end;
/
grant comment any table to REPADMIN;
grant lock any table to REPADMIN;
grant select any dictionary to REPADMIN;
2.注册
begin
DBMS_DEFER_SYS.REGISTER_PROPAGATOR (username=>'repadmin');
end;
/
disconnect;
conn repadmin/repadmin@209
3生成调度作业,实际上会增加一个job
BEGIN
DBMS_DEFER_SYS.SCHEDULE_PURGE (
next_date => SYSDATE,
interval => 'SYSDATE + 1/1440',
delay_seconds => 0);
END;
/
4创建与物化站点对应的用户,作物化视图管理员兼远程刷新(复制代理是备份机连接主站点的用户)
disconnect;
conn system/oracle@209
--Create proxy materialized view administrator.
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;
GRANT SELECT ANY DICTIONARY TO proxy_mviewadmin;
GRANT SELECT ANY TABLE TO proxy_mviewadmin;
二、创建物化视图站点
conn system/ngcc@132
创建用户
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;
创建public DBLINK
drop public database link ORACL209 ;
create public database link ORACL209
using '(description=
(address=(protocol=tcp)(host=10.130.61.209)(port=1521))
(connect_data=(service_name=zxin)))' ;
建立复制管理员mvadmin的数据库连接:
connect mviewadmin/mviewadmin@132
drop database link ORACL209
create database link ORACL209 connect to proxy_mviewadmin
identified by proxy_mviewadmin
using '(description=
(address=(protocol=tcp)(host=10.130.61.209)(port=1521))
(connect_data=(service_name=zxin)))'
三、创建主体组
disconnect;
connect repadmin/repadmin@209;
BEGIN
DBMS_REPCAT.CREATE_MASTER_REPGROUP (
gname => 'zxinkf_repg');
END;
/
//一般只将表和索引添加到主体组中,因此存储过程,job,等其他数据库对象的
//更新不会同步,数据库表空间的操作也必须手工进行
//注意:需要同步的表必须有PK,没有PK也必须有候选键
//------cc_operator
BEGIN
DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
gname => 'zxinkf_repg',
type => 'TABLE',
oname => 'cc_operator',
sname => 'zxdb_kf',
use_existing_object => TRUE,
copy_rows => TRUE);
END;
/
BEGIN
DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
gname => 'zxinkf_repg',
type => 'INDEX',
oname => 'PK_CC_OPERATOR',
sname => 'zxdb_kf',
use_existing_object => TRUE,
copy_rows => FALSE);
END;
/
//------cc_opergroup
BEGIN
DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
gname => 'zxinkf_repg',
type => 'TABLE',
oname => 'cc_opergroup',
sname => 'zxdb_kf',
use_existing_object => TRUE,
copy_rows => TRUE);
END;
/
BEGIN
DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
gname => 'zxinkf_repg',
type => 'INDEX',
oname => 'PK_CC_OPERGROUP',
sname => 'zxdb_kf',
use_existing_object => TRUE,
copy_rows => FALSE);
END;
/
为表生成复制支持
BEGIN
DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT (
sname => 'zxdb_kf',
oname => 'cc_operator',
type => 'TABLE',
min_communication => TRUE);
END;
/
BEGIN
DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT (
sname => 'zxdb_kf',
oname => 'cc_opergroup',
type => 'TABLE',
min_communication => TRUE);
END;
/
创建实体化视图日志
create materialized view log on zxdb_kf.cc_operator;
create materialized view log on zxdb_kf.cc_opergroup;
停止复制:
BEGIN
DBMS_REPCAT.SUSPEND_MASTER_ACTIVITY (
gname => 'zxinkf_repg');
END;
/
启动复制:
BEGIN
DBMS_REPCAT.RESUME_MASTER_ACTIVITY (
gname => 'zxinkf_repg');
END;
/
启动复制失败:
1.如果该住组内存在object没有正确生成复制,就会失败。可以将这些object 从主组内drop掉
四、创建物化视图组
连接到备份机
conn zxdb_kf/zxdb_kf@132;
drop database link ORACL209;
CREATE DATABASE LINK ORACL209
CONNECT TO proxy_mviewadmin IDENTIFIED BY proxy_mviewadmin
using '(description=
(address=(protocol=tcp)(host=10.130.61.209)(port=1521))
(connect_data=(service_name=zxin)))'
2.创建物化视图组Create the materialized view group.
CONNECT mviewadmin/mviewadmin@132
3Create the refresh group.
BEGIN
DBMS_REFRESH.MAKE (
name => 'mviewadmin.209_refresh',
list => '',
next_date => SYSDATE,
interval => 'SYSDATE + 1/1440',
implicit_destroy => FALSE,
rollback_seg => '',
push_deferred_rpc => TRUE,
refresh_after_errors => FALSE);
END;
创建物化视图
conn zxdb_kf/zxdb_kf@132
drop MATERIALIZED VIEW zxdb_kf.cc_operator_mv
CREATE MATERIALIZED VIEW zxdb_kf.cc_operator_mv
REFRESH FAST WITH PRIMARY KEY
AS SELECT * FROM zxdb_kf.cc_operator@ORACL209
CREATE MATERIALIZED VIEW zxdb_kf.cc_opergroup_mv
REFRESH FAST WITH PRIMARY KEY
AS SELECT * FROM zxdb_kf.cc_opergroup@ORACL209
向刷新组中添加复制对象
CONNECT mviewadmin/mviewadmin@132
BEGIN
DBMS_REFRESH.SUBTRACT (
name => 'mviewadmin.209_refresh',
list => 'zxdb_kf.cc_operator_mv',
lax => TRUE);
END;
/
BEGIN
DBMS_REFRESH.ADD (
name => 'mviewadmin.209_refresh',
list => 'zxdb_kf.cc_operator_mv',
lax => TRUE);
END;
/
BEGIN
DBMS_REFRESH.ADD (
name => 'mviewadmin.209_refresh',
list => 'zxdb_kf.cc_opergroup_mv',
lax => TRUE);
END;
/
五、移除replication
conn zxdb_kf/zxdb_kf@132;
drop MATERIALIZED VIEW zxdb_kf.yb_test1_mv;
CONNECT mviewadmin/mviewadmin@132;
BEGIN
DBMS_REFRESH.DESTROY (
name =>'mviewadmin.209_refresh');
end;
/
conn zxdb_kf/zxdb_kf@132;
drop DATABASE LINK ORACL209;
功能测试
1. 主站点表结构的变化,比如增加了列,备站点的表结构不会自动发生变化
后续其他字段的更新,和记录的增加删除仍然成功。
需要drop掉view后,重建。然后将表从刷新组去掉,重新加入
2.有关MATERIALIZED VIEW的信息在下面的视图中
SNAP$
SNAP_COLMAP$主键
SNAP_LOADERTIME$
SNAP_LOGDEP$
SNAP_OBJCOL$
SNAP_REFOP$
SNAP_REFTIME$
SNAP_SITE$
3.备站点down机情况下
修改的数据会在主站点物化视图日志表中保存,直到备站点启动
4.如果数据不刷新,需要检查主站和备站点的job是否正常。
5.如果备站点可更新,即使做了insert,delete,update
也会被自动刷新为主站点同样数据。但是备站点表物化视图不能做truncat,做了会引起备站的job失败,导致整个备站点的replication都失败。此时可以重建视图,再编译job。
6.主站点的表作了truncat,结果不会同步到备站点。备站点的数据不受影响,后续的主站点的更新仍然能正确同步到备站点。
性能测试
一、基本状态
1.测试条件
在主站点创建表
create table zxdb_kf.yb_test1(a int,b varchar(50),
constraint idx_yb_test1 primary key( a )
)
表中有10000条数据
1个线程作insert 间隔5ms,总耗时197s
2.测试步骤
先在表中插入20000条数据
然后使用10个线程(连接)测试,作
2个线程作insert 间隔5ms
4个线程作update 间隔5ms
4个线程作select 1000条 间隔tms
3.测试结果
| 1000次总耗时 | 5000次总耗时 |
insert | 25 | 120 |
update | 24 | 118 |
select | 7 | 32 |
二、归档状态
测试条件同上,但是打开归档
| 1000次总耗时 | 5000次总耗时 |
insert | 27 | 124 |
update | 28 | 123 |
select | 7 | 32 |
三、Replication状态
1.测试步骤
disconnect;
connect repadmin/repadmin@209;
BEGIN
DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
gname => 'zxinkf_repg',
type => 'TABLE',
oname => 'yb_test1',
sname => 'zxdb_kf',
use_existing_object => TRUE,
copy_rows => TRUE);
END;
/
BEGIN
DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
gname => 'zxinkf_repg',
type => 'INDEX',
oname => 'IDX_YB_TEST1',
sname => 'zxdb_kf',
use_existing_object => TRUE,
copy_rows => FALSE);
END;
/
BEGIN
DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT (
sname => 'zxdb_kf',
oname => 'yb_test1',
type => 'TABLE',
min_communication => TRUE);
END;
/
create materialized view log on zxdb_kf.yb_test1;
创建物化视图
conn zxdb_kf/zxdb_kf@132
drop MATERIALIZED VIEW zxdb_kf.yb_test1_mv
CREATE MATERIALIZED VIEW zxdb_kf.yb_test1_mv
REFRESH FAST WITH PRIMARY KEY for update
AS SELECT * FROM zxdb_kf.yb_test1@ORACL209
CONNECT mviewadmin/mviewadmin@132;
BEGIN
DBMS_REFRESH.SUBTRACT (
name => 'mviewadmin.209_refresh',
list => 'zxdb_kf.yb_test1_mv',
lax => TRUE);
END;
/
BEGIN
DBMS_REFRESH.ADD (
name => 'mviewadmin.209_refresh',
list => 'zxdb_kf.yb_test1_mv',
lax => TRUE);
END;
/
2.测试结果
| 1000次总耗时 | 5000次总耗时 |
insert | 37 | 184 |
update | 36 | 186 |
select | 7 | 35 |
四、进行性能优化后Replication状态
本项测试目的是验证进行oracle性能优化后对Replication性能的影响。
1.优化参数
*.aq_tm_processes=0
*.db_file_multiblock_read_count=32
*.job_queue_processes=30
*._job_queue_interval=30
*.large_pool_size=83886080
*.parallel_automatic_tuning=TRUE
*.db_writer_processes=4
*.cursor_sharing=SIMILAR
*.open_cursors=300
*.pga_aggregate_target=125829120
*.processes=350
*.open_links=10
*.open_links_per_instance=10
*.query_rewrite_enabled='TRUE'
*.shared_pool_size=104857600
*.star_transformation_enabled='FALSE'
2.测试结果
测试条件同上
| 1000次总耗时 | 5000次总耗时 |
insert | 33 | 169 |
update | 33 | 169 |
select | 7 | 35 |
总结
从测试来看replication的方式可靠性比较高,但对于性能影响较大。对于查询没有影响,对于更新影响较大.在压力测试下,可能使更新速度降低达50%。从原理上分析,性能下降的原因主要在于触发器和本地物化视图日志表的写入。而归档方式产生的性能下降<5%.
通过oracle性能优化单条更新语句相对于优化前速度提升了(185-169)/169*100%=9.5%。
另外一点就是,本地物化视图日志表在大压力下表段空间增长,可能会带来两个问题。一是网路的带宽是否够用。二是使本地物化视图日志表高水线HWM增长带来性能问题,可以通过定期回收解决。