1

mogdb-利来国际app

张鹏远 2021-11-08
327

mtk–异构数据迁移工具

异构数据库迁移工具,支持在不同的数据库之间进行数据迁移和程序迁移,目前支持离线全量迁移。

1.多数据库类型支持
支持 oracle,db2, opengauss,sqlserver, mysql 等数据库之间的互相迁移 (互为源和目标)。

2.迁移性能调整

支持调整数据迁移过程中的批量查询、批量插入大小等细粒度参数,来调整数据迁移的性能。

支持数据迁移时的多并发,并行和数据分片。

3.结构和数据分离

支持同步迁移对象结构和数据;也支持仅迁移结构或者仅迁移数据(在结构已经迁移完之后)。

支持表级和 schema 级的迁移范围限定,允许指定schema下全部对象或者某些对象进行迁移 。

支持迁移过程中的 schema 重映射,也就是支持将对象从源schema迁移到目标端的不同名schema下 。

4.程序迁移(支持oracle/mysql为源,opengauss/mogdb为目标)

支持oracle/mysql->opengauss/mogdb的存储过程,函数,触发器,包迁移。

自动根据opengauss/mogdb的语法规则,对oracle/mysql的程序进行改写,之后再在目标端opengauss/mogdb数据库中创建。

mtk模块

mtk迁移

1.mtk表结构定义转换
读取线程从源数据库视图获取基本信息,内部转为为自定义数据结构,写入线程根据目标数据库类型转为支持的语法进行创建。
2.mtk数据迁移
mtk内部定义数据结构,读取线程从数据库读取原始数据转为内部格式,然后放入队列,写入线程从队列里进行读取并分批次,批量提交到目标数据库

mtk迁移测试(oracle–>mogdb)

1.基准测试

获取mtk license

./mtk license gen

2.在mogdb数据库服务器中安装oracle客户端

安装完成后,配置tns,设置环境变量,确保可以正常访问oracle数据库

export ld_library_path=/app/oracle/client/instantclient_19_5

3.在mogdb中创建数据库、用户,并赋予权限。

create database test;创建目标数据库
create user mogdb with password "mogdb_123";
grant all on schema public to mogdb ;
alter user mogdb sysadmin;
grant create on database test to mogdb;(mtk支持同时迁移多个schema,在mogdb中会自动创建需要的schema,因此需要赋予迁移用户创建schema的权限)

4.在oracle中创建表空间、用户及生成测试数据

create tablespace mogdb datafile ' data' size 10g;
create user mogdb identified by "mogdb_123" default tablespace mogdb;
grant connect,resource to mogdb;

测试数据采用benchmarksql 生成100仓数据。
props.ora 配置

db=oracle
driver=oracle.jdbc.driver.oracledriver
conn=jdbc:oracle:thin:@192.168.6.52:1521/new19cdb
user=mogdb
[email protected]
warehouses=100
loadworkers=20
terminals=1
//to run specified transactions per terminal- runmins must equal zero
runtxnsperterminal=10
//to run for specified minutes- runtxnsperterminal must equal zero
runmins=0
//number of total transactions per minute
limittxnspermin=300
//set to true to run in 4.x compatible mode. set to false to use the
//entire configured database evenly.
terminalwarehousefixed=true
//the following five values must add up to 100
neworderweight=45
paymentweight=43
orderstatusweight=4
deliveryweight=4
stocklevelweight=4
// directory name to create for collecting detailed result data.
// comment this out to suppress.
resultdirectory=my_result_%ty-%tm-%td_%th%tm%ts
oscollectorscript=./misc/os_collector_linux.py
oscollectorinterval=1
//[email protected]
oscollectordevices=net_eth0 blk_sda

5.编辑mtk_config.json文件
关于mtk配置说明可以参考:https://docs.mogdb.io/zh/mtk/v2.0/mtk-config

{
  "source": {
    "type": "oracle",
    "connect": {
      "version": "",
      "host": "192.168.6.52",
      "user": "mogdb",
      "port": 1521,
      "password": "mogdb",
      "dbname": "new19cdb",
      "dsn": ""
    }
  },
  "target": {
    "type": "mogdb",
    "connect": {
      "version": "2.0.1",
      "host": "192.168.6.7",
      "user": "mogdb",
      "port": 26000,
      "password": "[email protected]",
      "dbname": "test",
      "dsn": ""
    },
    "parameter": {
      "dropexistingobject": false,
      "trunctable": false,
      "parallelinsert": 4,
      "path": "./data",
      "filetype": "sql"
    }
  },
  "limit": {
    "parallel": 4,
    "fetchsize": 0,
    "batchsize": 0,
    "buffersize": 0
  },
  "object": {
    "schemas": [
      "mogdb"
    ]
  },
  "dataonly": false,
  "schemaonly": false,
  "reportfile": "./report_oracle2mogdb_schemaonly.html"
}

5.迁移开始

export ld_library_path=/app/oracle/client/instantclient_19_5
./mtk -c oracle2opengauss.json --reportfile mtk_report.html --logfile mtk_report.log

以下是迁移后的日志输出:
可以看到包含用户、序列、表结构、表数据、索引、约束、对比表数据、修改不适用序列以及统计信息。

以下是表数据、及表数据对比。

mtk参数配置reportffile后会生成相应的html报告,更加方便阅读。

mtk常用命令

1.检查配置文件
[[email protected] mtk_0.0.38_linux_amd64]$ ./mtk check-config -c oracle2opengauss.json 
use config :oracle2opengauss.json
2.预运行检查
[[email protected] mtk_0.0.38_linux_amd64]$ ./mtk check-config -c oracle2opengauss.json --prerun 
use config :oracle2opengauss.json
there is no error in the configuration file
3.显示源端数据库模式大小
[[email protected] mtk_0.0.38_linux_amd64]$ ./mtk show-schema -c oracle2opengauss.json 
schemaname                     size
mogdb                          2.72gib
sys                            2.287gib
test                           940mib
mdsys                          235.2mib
xdb                            69.81mib
audsys                         52.25mib
system                         18.12mib
wmsys                          6.562mib
dvsys                          4.562mib
ctxsys                         2.812mib
gsmadmin_internal              1.5mib
orddata                        1.312mib
dbsnmp                         896kib
outln                          576kib
ordsys                         384kib
ojvmsys                        384kib
lbacsys                        320kib
4.显示源端数据库信息
[[email protected] mtk_0.0.38_linux_amd64]$ ./mtk show-db-info -c oracle2opengauss.json
source database          : oracle 
    version              : 19.6.1.0.0 
    chartset             : al32utf8 
target database              : mogdb 
    version              : 2.0.1 
    chartset             : sql_ascii 
    datcompatibility        : a 
5.显示支持数据库类型
[[email protected] mtk_0.0.38_linux_amd64]$ ./mtk show-type -c oracle2opengauss.json 
type                 database                                 comments
schema               all                                      oracle users, 
                                                              mysql database, 
                                                              db2 schema, 
                                                              sqlserver database schema
objecttype           oracle,postgres,opengauss                oracle, 
                                                              postgres, 
                                                              opengauss
domain               postgres,opengauss                       not support
sequence             postgres,oracle,db2,opengauss,dm,mysql   
queue                oracle                                   not support
table                all                                      
rule                 postgres,opengauss                       not support
tabledata            all                                      
tabledataestimate    oracle,mysql,db2                         
index                all                                      
constraint           all                                      
view                 all                                      
materializedview     oracle,db2,postgres,opengauss            
function             all                                      support oracle to opengauss
procedure            all                                      support oracle to opengauss
package              oracle,dm                                support oracle to opengauss
trigger              all                                      support oracle to opengauss
dblink               oracle,dm                                not support
synonym              oracle,db2,opengauss,dm                  
tabledatacom         all                                      
altersequence        all                                      mysql table auto incr to to opengauss seq
                                                              db2 column generated always id to mysql auto incr
collstatistics       all                                      collect table statistics
6.显示源端要迁移的前n个表大小
[[email protected] mtk_0.0.38_linux_amd64]$ ./mtk show-table -c oracle2opengauss.json 
(-n 前n个表(默认为20))
tabname                                                       partitioned  totalsize   datasize    lobsize       rows avgrowslen   colcount
mogdb.bmsql_stock                                                   false       1gib       1gib         0b    3000000       306b          0
mogdb.bmsql_order_line                                              false     640mib     640mib         0b    9003690        60b          0
mogdb.bmsql_customer                                                false     568mib     568mib         0b     900000       552b          0
mogdb.bmsql_history                                                 false      60mib      60mib         0b     900000        54b          0
mogdb.bmsql_oorder                                                  false      39mib      39mib         0b     900000        33b          0
mogdb.bmsql_item                                                    false       9mib       9mib         0b     100000        72b          0
mogdb.bmsql_new_order                                               false       5mib       5mib         0b     270000        10b          0
mogdb.bmsql_config                                                  false      64kib      64kib         0b          4        16b          0
mogdb.bmsql_warehouse                                               false      64kib      64kib         0b         30        78b          0
mogdb.bmsql_district                                                false      64kib      64kib         0b        300        87b          0
mogdb.test1                                                      true        44b        44b         0b          0       8mib          0
7.自动生成单表并行条件
oracle - rowid
db2 - mod (仅支持数字列和主键)
mysql - mod (仅支持数字列和主键)
  -f, --format string   生成显示格式为json或yaml(默认为“json”)
  -p, --parallel int    拆分并行任务
  -s, --size string     大表的大小(默认为“1gb”)
[[email protected] mtk_0.0.38_linux_amd64]$ ./mtk show-table-split -c oracle2opengauss.json -p 8 -s 500m(这里设置迁移并行度为8,大小超过500m的表分片)
{
 "mogdb": {
  "bmsql_customer": [
   " rowid between 'aaavooaacaaaaggaaa' and 'aaavooaacaaart/ei/'",
   " rowid between 'aaavooaacaaaruaaaa' and 'aaavooaacaaaxn/ei/'",
   " rowid between 'aaavooaacaaaxoaaaa' and 'aaavooaacaaanf/ei/'",
   " rowid between 'aaavooaacaaangaaaa' and 'aaavooaacaaar9/ei/'",
   " rowid between 'aaavooaacaaar aaaa' and 'aaavooaacaaaxf/ei/'",
   " rowid between 'aaavooaacaaaxgaaaa' and 'aaavooaacaabbf/ei/'",
   " rowid between 'aaavooaacaabbgaaaa' and 'aaavooaacaabgn/ei/'",
   " rowid between 'aaavooaacaabgoaaaa' and 'aaavooaacaabi3/ei/'"
  ],
  "bmsql_order_line": [
   " rowid between 'aaavotaacaaalewaaa' and 'aaavotaacaaaqf/ei/'",
   " rowid between 'aaavotaacaaaqgaaaa' and 'aaavotaacaaavv/ei/'",
   " rowid between 'aaavotaacaaavwaaaa' and 'aaavotaacaaalx/ei/'",
   " rowid between 'aaavotaacaaal4aaaa' and 'aaavotaacaaaqf/ei/'",
   " rowid between 'aaavotaacaaariaaaa' and 'aaavotaacaaavn/ei/'",
   " rowid between 'aaavotaacaaavwaaaa' and 'aaavotaacaaa/x/ei/'",
   " rowid between 'aaavotaacaaa/oaaaa' and 'aaavotaacaabef/ei/'",
   " rowid between 'aaavotaacaabewaaaa' and 'aaavotaacaabjx/ei/'"
  ],
  "bmsql_stock": [
   " rowid between 'aaavovaacaaaac4aaa' and 'aaavovaacaaaex/ei/'",
   " rowid between 'aaavovaacaaaeyaaaa' and 'aaavovaacaaaix/ei/'",
   " rowid between 'aaavovaacaaaiyaaaa' and 'aaavovaacaaaap/ei/'",
   " rowid between 'aaavovaacaaaaqaaaa' and 'aaavovaacaaaep/ei/'",
   " rowid between 'aaavovaacaaaeqaaaa' and 'aaavovaacaaaip/ei/'",
   " rowid between 'aaavovaacaaaiqaaaa' and 'aaavovaacaaa0h/ei/'",
   " rowid between 'aaavovaacaaa0iaaaa' and 'aaavovaacaaa4h/ei/'",
   " rowid between 'aaavovaacaaa4iaaaa' and 'aaavovaacaaa8h/ei/'"
  ]
 }
}
8.预估表数据迁移时间
  -n, --netband int    指定网络带宽,以mb为单位(默认为100)
  -p, --parallel int   指定并行度,默认值为配置信息中的limit.parallel
[[email protected] mtk_0.0.38_linux_amd64]$ ./mtk show-table-data-estimate -c oracle2opengauss.json -n 500 -p 8 (这里设置带宽为500mb,并行为8)
    tabledataestimate 
           begintime :2021-11-01t12:28:26 08:00
             endtime :2021-11-01t12:29:51 08:00
             usetime :1 m 24 ss
9.同步模式预览
mtk sync-schema -c oracle2opengauss.json
同步对象类型
mtk sync-object-type -c oracle2opengauss.json
同步域
mtk sync-domain -c oracle2opengauss.json
同步自定义类型
mtk sync-custom-type -c oracle2opengauss.json
同步序列
mtk sync-sequence -c oracle2opengauss.json
同步队列
mtk sync-queue -c oracle2opengauss.json
同步表
mtk sync-table -c oracle2opengauss.json
同步数据
mtk sync-table-data -c oracle2opengauss.json
预估表数据迁移时间
mtk sync-table-data-estimate -c oracle2opengauss.json
同步索引
mtk sync-index -c oracle2opengauss.json
同步约束
mtk sync-constraint -c oracle2opengauss.json
同步视图
mtk sync-view -c oracle2opengauss.json
同步触发器
mtk sync-trigger -c oracle2opengauss.json
同步存储过程
mtk sync-procedure -c oracle2opengauss.json
同步函数
mtk sync-function -c oracle2opengauss.json
同步包
mtk sync-package -c oracle2opengauss.json
同步同义词
mtk sync-synonym -c oracle2opengauss.json
同步dblink
mtk sync-db-link -c oracle2opengauss.json
同步规则
mtk sync-rule -c oracle2opengauss.json
表行计数比较
mtk sync-table-data-com -c oracle2opengauss.json
修改序列起始值
mtk sync-alter-sequence -c oracle2opengauss.json
收集表统计信息
mtk sync-coll-statistics -c oracle2opengauss.json
「喜欢文章,快来给作者赞赏墨值吧」
【利来手机国际的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:[email protected]进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论