迁移背景
环境说明:
迁移过程
2.1 实施MV分表
alter session force parallel query parallel 10;
alter session force parallel ddl parallel 10;
alter session force parallel dml parallel 10;
create materialized view TABLE_O refresh fast with primary key on demand as
select * FROM USER.BIG_TABLE
where mod(decode(length(col1), 1,ASCII(substr(col1, -1, 1)),
2, ASCII(substr(col1, -1, 1)) + ASCII(substr(col1, -2, 1)),
3, ASCII(substr(col1, -1, 1)) + ASCII(substr(col1, -2, 1)) + ASCII(substr(col1, -3, 1)) ,
......
, 150) = 0 ;复制
分表踩坑:
一开始才用对字段进行hash分表,经测试,oracle hash计算结果和应用程序hash计算结不一致,放弃该方式。 对字段后2位进行ASCII计算去和后和150进行取余,经测试数据分布严重不均匀不能实现良好的分表效果。 多次测试后,最终确定采用字段后40位求和后与150取余。 使用物化视分表,增量刷新缓慢,通过调整参数规避。
2.2 采用ETL同步分表数据到MySQL
由于ogg initial load初始化效率较低,故采用kettle同步mv数据到MySQL:
在10.10.10.13主机部署kettle软件; MySQL提前创建表结构; 配置kettl同步。



2.3 配置ogg同步mv到MySQL
1)Oracle创建ogg账号
CREATE USER GOLDENGATE IDENTIFIED BY goldengate DEFAULT TABLESPACE users TEMPORARY TABLESPACE TEMP;
GRANT CONNECT TO GOLDENGATE;
GRANT ALTER ANY TABLE TO GOLDENGATE;
GRANT ALTER SESSION TO GOLDENGATE;
GRANT CREATE SESSION TO GOLDENGATE;
GRANT FLASHBACK ANY TABLE TO GOLDENGATE;
GRANT SELECT ANY DICTIONARY TO GOLDENGATE;
GRANT SELECT ANY TABLE TO GOLDENGATE;
GRANT RESOURCE TO GOLDENGATE;
GRANT EXECUTE ANY TYPE TO GOLDENGATE;
GRANT SELECT ANY TRANSACTION TO GOLDENGATE;
GRANT CREATE any TABLE,CREATE any SEQUENCE TO goldengate ;
GRANT INSERT ANY TABLE TO GOLDENGATE;
GRANT UPDATE ANY TABLE TO GOLDENGATE;
GRANT DELETE ANY TABLE TO GOLDENGATE;
GRANT CREATE ANY INDEX TO GOLDENGATE;
grant unlimited tablespace to goldengate ;
grant execute on DBMS_FLASHBACK to goldengate;
grant COMMENT ANY TABLE to goldengate;
alter system set enable_goldengate_replication=true sid='*' scope=both;
exec dbms_goldengate_auth.grant_admin_privilege('goldengate')复制
2)归档模式/补充日志/force logging
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
alter database FORCE LOGGING;
set line 350 pages 999
col NAME for a15
col LOG_MODE for a15
col OPEN_MODE for a15
col PLATFORM_NAME for a25
col FORCE_LOGGING for a20
col SUPPLEMENTAL_LOG_DATA_MIN for a25
SELECT
NAME,
LOG_MODE,
OPEN_MODE,
PLATFORM_NAME,
FORCE_LOGGING,
SUPPLEMENTAL_LOG_DATA_MIN
FROM
V$DATABASE;
alter system archive log current;复制
3)部署ogg软件
4)添加ogg凭证
export TNS_ADMIN=/data/ggsdata/tnsadmin
exora=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =10.10.10.11 )(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME =test )
)
)复制
add credentialstore
alter credentialstore add user goldengate@exora alias exora
INFO CREDENTIALSTORE
dblogin useridalias exora复制
5)添加附加日志
add trandata user.table_0
info trandata user.table_0
add trandata user.table_1
info trandata user.table_2
......复制
6)配置ogg mgr
PORT 7809
DYNAMICPORTLIST 7810-7819
ACCESSRULE, PROG SERVER, ALLOW
AUTOSTART EXTRACT *
AUTORESTART EXTRACT * retries 5 waitminutes 3
PURGEOLDEXTRACTS /ogg/ggs_oracle/dirdat/*,usecheckpoints, minkeepdays 2
LAGREPORTMINUTES 10
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 60复制
Start mgr
复制
7)配置extract
参数文件如下:
--base parameter
extract ex_ora
SETENV (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
SETENV (TNS_ADMIN=/data/ggsdata/tnsadmin)
useridalias exora
numfiles 5000
TRANLOGOPTIONS INTEGRATEDPARAMS (max_sga_size 256, parallelism 1)
exttrail /data/ggsdata/dirdat/yx
DISCARDFILE /data/ggsdata/dirrpt/ex_ora_01.dsc,APPEND,MEGABYTES 100
DISCARDROLLOVER AT 3:00
REPORTCOUNT EVERY 30 MINUTES, RATE
REPORTROLLOVER AT 9:00
WARNLONGTRANS 2h, CHECKINTERVAL 30m
TRANLOGOPTIONS INTEGRATEDPARAMS(_CKPT_RETENTION_CHECK_FREQ 300)
TRANLOGOPTIONS EXCLUDEUSER GOLDENGATE
-- Performance optimization
cachemgr cachesize 512M, cachedirectory /data/ggsdata/dirtmp 10G
BR BRINTERVAL 40M, BRDIR BR
--map objects(150个分表)
table UPSYS.t_audition_0;
table UPSYS.t_audition_1;......
复制
添加extract:
dblogin useridalias exora
REGISTER EXTRACT ex_ora , DATABASE
ADD EXTRACT ex_ora, INTEGRATED TRANLOG, BEGIN NOW
ADD EXTTRAIL data/ggsdata/dirdat/yx, EXTRACT ex_ora , MEGABYTES 50
start exora复制
8)配置OGG复制到MySQL
安装ogg for mysql:解压软件即可,不在赘述。 MySQL创建ogg用户。
create user 'goldengate'@'%' identified by 'Goldengate-123';
grant all on *.* to 'goldengate'@'%';复制
配置MySQL ogg mgr进程:
edit params mgr
PORT 7839
DYNAMICPORTLIST 7840-7849
ACCESSRULE, PROG SERVER, ALLOW
AUTOSTART REPLICAT *
AUTORESTART REPLICAT * retries 5 waitminutes 1
--PURGEOLDEXTRACTS /ogg/ggs_mysql/dirdat/*,usecheckpoints, minkeepdays 2
LAGREPORTMINUTES 10
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 60
--STARTUPVALIDATIONDELAY 5
DBLOGIN sourcedb user@10.10.10.12:3306, USERID goldengate, PASSWORD Goldengate-123
Start mgr复制
添加复制进程:
添加添加checkpointtable:
create database pt;
cd $OGG_HOME
ggsci
edit param ./GLOBALS
checkpointtable pt.ggs_checkpoint复制
添加复制进程:
DBLOGIN sourcedb pt@10.10.10.12:3306, USERID goldengate, PASSWORD Goldengate-123
add checkpointtable pt.ggs_checkpoint
add replicat rp_ora,exttrail /data/ggsdata/dirdat/yx,checkpointtable pt.ggs_checkpoint复制
edit params rp_ora
replicat rp_ora
targetdb user@10.10.10.12:3306,userid goldengate,password Goldengate-123
--sourcedefs /data/ggsdata/dirdef/zly.def
discardfile /data/ggsdata/dirrpt/rep_exora.dsc,append,megabytes 50
REPERROR DEFAULT, ABEND
REPORTCOUNT EVERY 60 MINUTES, RATE
REPORTROLLOVER AT 9:00
MAP user.table_0, target user.table_0;
MAP user.table_1, target user.table_1;
......
MAP user.table_149, target user.table_149;复制
Start rp_ora
复制
2.4 配置物化视图增量刷新
set linesize 350 pages 999
col OWNER for a15
col JOB_NAME for a25
col JOB_CREATOR for a25
col ENABLED for a10
col START_DATE for a25
col NEXT_RUN_DATE for a25
col LAST_START_DATE for a25
col REPEAT_INTERVAL for a40
col JOB_ACTION for a60
SELECT OWNER,
JOB_NAME,
ENABLED,
STATE,
JOB_TYPE,
JOB_ACTION,
to_char(START_DATE, 'yyyy/mm/dd hh:mm') START_DATE,
to_char(LAST_START_DATE, 'yyyy/mm/dd hh:mm') LAST_START_DATE,
to_char(NEXT_RUN_DATE, 'yyyy/mm/dd hh:mm') NEXT_RUN_DATE,
REPEAT_INTERVAL,
RUN_COUNT
FROM dba_scheduler_jobs
WHERE
JOB_ACTION LIKE '%TABLE_%"%'
ORDER BY 6 ;复制
exec dbms_scheduler.enable(name=>upper('UPSYS.MV_RF$J_0_S_55082') );
复制
2.5 切换业务到MySQL
业务停止后,手动执行一次快速刷新,ogg无延迟后,将业务切换到MySQL数据库。
经验总结

本文作者:张雷员(上海新炬中北团队)
本文来源:“IT那活儿”公众号

文章转载自IT那活儿,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
【专家有话说第五期】在不同年龄段,DBA应该怎样规划自己的职业发展?
墨天轮编辑部
1328次阅读
2025-03-13 11:40:53
MySQL8.0统计信息总结
闫建(Rock Yan)
501次阅读
2025-03-17 16:04:03
2月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
470次阅读
2025-03-13 14:38:19
SQL优化 - explain查看SQL执行计划(一)
金同学
398次阅读
2025-03-13 16:04:22
MySQL突然崩溃?教你用gdb解剖core文件,快速锁定“元凶”!
szrsu
378次阅读
2025-03-13 00:29:43
MySQL生产实战优化(利用Index skip scan优化性能提升257倍)
chengang
331次阅读
2025-03-17 10:36:40
MySQL数据库当前和历史事务分析
听见风的声音
307次阅读
2025-04-01 08:47:17
MySQL 生产实践-Update 二级索引导致的性能问题排查
chengang
253次阅读
2025-03-28 16:28:31
墨天轮个人数说知识点合集
JiekeXu
244次阅读
2025-04-01 15:56:03
一键装库脚本3分钟极速部署,传统耗时砍掉95%!
IT邦德
243次阅读
2025-03-10 07:58:44