历史数据迁移
线上库数据增长迅速,需要定期清理历史数据,因为异地灾备,但是带宽很小,不能使用数据泵直接往历史库导数,会导致本地机房到灾备机房的带宽被占满,调研过flink、golden gate、datax,根据需求及配置复杂度,选用了datax
创建DBLINK
在目标库创建DBLINK,目标端数据库需要高版本
create public database link quickpay
connect to kpay identified by Pay_2019
using '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = 10.10.2.210) (PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = paydb)))';
迁移元数据
通过DBLINK迁移元数据到目标库
impdp \' / as sysdba\' directory=dir1 network_link = pay tables=kpay.PAYMENTSIGN11 remap_schema=pay:pay2 remap_tablespace=pay:pay2 CONTENT=METADATA_ONLY
锁定表
将表锁定,确保数据不会变化
alter table kpay.PAYMENTSIGN11 read only;
配置datax
在异地有灾备机房,带宽较小,需要限制同步速度
datax限速
设置传输速度
{"job": {"setting": {"speed": {//设置传输速度 byte/s 尽量逼近这个速度但是不高于它.// channel 表示通道数量,byte表示通道速度,如果单通道速度1MB,配置byte为1048576表示一个channel"byte": 1048576,"channel": 4},},"content": [{"reader": {"name": "oraclereader","parameter": {// 数据库连接用户名"username": "root",// 数据库连接密码"password": "root","column": [//读取指定字段,如果不需要指定字段,用符号*"id","name",],//切分主键,通过该字段分片处理table,配合channel使用"splitPk": "db_id","connection": [{"table": ["user"],"jdbcUrl": ["jdbc:oracle:thin:@[HOST_NAME]:PORT/[DATABASE_NAME]"]}]}},//写入部分脚本"writer": {"name": "oraclewriter","parameter": {//数据库用户名密码"username": "root","password": "root",//写入数据库的对应字段,如果不需要指定字段,用符号*"column": ["*"],"connection": [{"jdbcUrl": "jdbc:oracle:thin:@10.127.0.1:1521/orcl",//指定写入table"table": ["user"]}]}}}]}
}
报错
在有总bps限速条件下,单个channel的bps值不能为空,也不能为非正数
com.alibaba.datax.common.exception.DataXException: Code:[Framework-03], Description:[DataX引擎配置错误,该问题通常是由于DataX安装错误引起,请联系您的运维解决 .]. - 在有总bps限速条件下,单个channel的bps值不能为空,也不能为非正数
at com.alibaba.datax.common.exception.DataXException.asDataXException(DataXException.java:26) ~[datax-common-0.0.1-SNAPSHOT.jar:na]
at
修改文件datax/conf/core.json
core -> transport -> channel -> speed -> “byte”: 2000000,将单个channel的大小改为2MB即可
"core": {"dataXServer": {"address": "http://localhost:7001/api","timeout": 10000,"reportDataxLog": false,"reportPerfLog": false},"transport": {"channel": {"class": "com.alibaba.datax.core.transport.channel.memory.MemoryChannel","speed": {"byte": 2000000,"record": -1},"flowControlInterval": 20,"capacity": 512,"byteCapacity": 67108864},"exchanger": {"class": "com.alibaba.datax.core.plugin.BufferedRecordExchanger","bufferSize": 32}},
}
参考文章
https://blog.csdn.net/weixin_42418589/article/details/126019261