news 2026/8/24 23:06:13

DataX 迁移oracle表数据到opengauss

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
DataX 迁移oracle表数据到opengauss

DATAX简介:

项目地址:

https://github.com/alibaba/DataX?tab=readme-ov-file

DataX概述:

​DataX 是阿里云 DataWorks数据集成 的开源版本,在阿里巴巴集团内被广泛使用的离线数据同步工具/平台。DataX 实现了包括 MySQL、Oracle、OceanBase、SqlServer、Postgre、HDFS、Hive、ADS、HBase、TableStore(OTS)、MaxCompute(ODPS)、Hologres、DRDS, databend 等各种异构数据源之间高效的数据同步功能。

​DataX本身作为数据同步框架,将不同数据源的同步抽象为从源头数据源读取数据的Reader插件,以及向目标端写入数据的Writer插件,理论上DataX框架可以支持任意数据源类型的数据同步工作。同时DataX插件体系作为一套生态系统, 每接入一套新数据源该新加入的数据源即可实现和现有的数据源互通。

环境:

序号

主机名

IP地址

操作系统

数据库

用户

软件

备注

1

oradb1

192.192.103.123(VIP)

Centos7.9

oradb

hr

Oracle11gRAC

数据源

2

opengaussdb

192.192.103.134

Centos7.9

testdb

hr

Datax、opengauss6.0.3 LTS、Python3

目标库、datax服务器

1.DataX安装部署

软件下载,可在上述github项目地址内下载。

# 上传安装包

[root@opengaussdb ~]# cd /soft

[root@opengaussdb soft]# ls -ltr

-rw-r--r-- 1 root root 1649070902 Mar 11 17:31 datax.tar.gz

# 解压安装包

[root@opengaussdb soft]# tar -xxf datax.tar.gz

[root@opengaussdb soft]# ls -ltr

total 1610424

-rw-r--r-- 1 root root 1649070902 Mar 11 17:31 datax.tar.gz

drwxrwxr-x 11 omm dbgrp 117 Mar 11 17:33 datax

[root@opengaussdb soft]# cd datax/

[root@opengaussdb datax]# ls

bin conf job lib log log_perf plugin script tmp

# DataX自检任务

[root@opengaussdb datax]# python bin/datax.py job/job.json

osInfo: Linux amd64 3.10.0-957.el7.x86_64 jvmInfo: Oracle Corporation 1.8 25.181-b13 cpu num: 8 totalPhysicalMemory: -0.00G freePhysicalMemory: -0.00G maxFileDescriptorCount: -1 currentOpenFileDescriptorCount: -1 GC Names [PS MarkSweep, PS Scavenge] MEMORY_NAME | allocation_size | init_size PS Eden Space | 256.00MB | 256.00MB Code Cache | 240.00MB | 2.44MB Compressed Class Space | 1,024.00MB | 0.00MB PS Survivor Space | 42.50MB | 42.50MB PS Old Gen | 683.00MB | 683.00MB Metaspace | -0.00MB | 0.00MB

…………………

…………………

2026-03-11 17:33:59.546 [job-0] INFO JobContainer -

任 务 启 动 时 刻 : 2026-03-11 17:33:49

任 务 结 束 时 刻 : 2026-03-11 17:33:59

任 务 总 计 耗 时 : 10s

任 务 平 均 流 量 : 253.91KB/s

记 录 写 入 速 度 : 10000rec/s

读 出 记 录 总 数 : 100000

读 写 失 败 总 数 : 0

# 成功执行自检任务

2.DataX使用

同步oracle数据到opengauss

1. 确定oracle、opengauss连接是否正常,检查对象。

--oracle

[oratest1:oracle]:/home/oracle>sqlplus hr/hr@192.192.103.123:1521/oradb

SQL*Plus: Release 11.2.0.4.0 Production on Thu Mar 12 11:12:42 2026

Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Data Mining and Real Application Testing options

SQL> select * from tab;

TNAME TABTYPE CLUSTERID

------------------------------ ------- ----------

COUNTRIES TABLE

DEPARTMENTS TABLE

EMPLOYEES TABLE

EMP_DETAILS_VIEW VIEW

EMP_SALARY_LOG TABLE

JOBS TABLE

JOB_HISTORY TABLE

LOCATIONS TABLE

REGIONS TABLE

T1 TABLE

T_HOT TABLE

TNAME TABTYPE CLUSTERID

------------------------------ ------- ----------

T_SEQ TABLE

12 rows selected.

--openGauss

[omm@opengaussdb openGauss]$ gsql -h 192.192.103.134 -p 15400 -Uhr -d testdb -r

Password for user hr:

gsql ((openGauss 6.0.3 build 4e5c48e7) compiled at 2025-12-23 21:03:10 commit 0 last mr 8753 )

SSL connection (cipher: ECDHE-RSA-AES128-GCM-SHA256, bits: 128)

Type "help" for help.

testdb=>\d List of relations Schema | Name | Type | Owner | Storage

--------+-----------+-------+-------+----------------------------------

hr | employees | table | hr | {orientation=row,compression=no}

public | t1 | table | | {orientation=row,compression=no}

public | t2 | table | | {orientation=row,compression=no}

public | t3 | table | | {orientation=row,compression=no}

(4 rows)

testdb=> select count(*) from employees;

count

-------

0

(1 row)

2. 确定reader和writer

源库reader为oraclereader,目标库writer为postgresqlwriter。

查看reader和writer模板的方式(-r 读模板; -w 写模板):

[root@opengaussdb datax]# python bin/datax.py -r oraclereader -w postgresqlwriter

{

"job": {

"content": [

{

"reader": {

"name": "oraclereader",

"parameter": {

"column": [],

"connection": [

{

"jdbcUrl": [],

"table": [] } ],

"password": "",

"username": "" } },

"writer": {

"name": "postgresqlwriter",

"parameter": {

"column": [],

"connection": [

{

"jdbcUrl": "",

"table": []

}

], "password": "",

"postSql": [],

"preSql": [],

"username": "" } } } ],

"setting": { "speed": {

"channel": ""

}

}

}

}

3. 编写同步JSON脚本

[root@opengaussdb job]# vi ora2gsdb.json

{

"job": {

"content": [

{

"reader": {

"name": "oraclereader",

"parameter": {

"username": "hr",

"password": "hr",

"column": ["*"],

"connection": [

{

"table": ["EMPLOYEES"],

"jdbcUrl": [

"jdbc:oracle:thin:@//192.192.103.123:1521/oradb"

]

}

]

}

},

"writer": {

"name": "postgresqlwriter",

"parameter": {

"username": "hr",

"password": "Huawei_1234",

"column": ["*"],

"connection": [

{

"jdbcUrl": "jdbc:postgresql://192.192.103.134:15400/testdb",

"table": ["employees"]

}

]

}

}

}

],

"setting": {

"speed": {

"channel": 2

}

}

}

}

4. 通过datax.py指定json任务运行同步数据

注意,datax不支持client SCRAM mechanisms验证机制,所以需要修改opengauss认证方式。

--修改验证方式

#查看opengauss默认验证机制

openGauss=# show password_encryption_type;

password_encryption_type

--------------------------

2 (1 row)

0 表示MD5,1表示MD5和sha256,2表示sha256.

#同时修改数据库参数和pg_hba.conf文件

1)修改password_encryption_type

[omm@opengaussdb ~]$ gs_guc reload -N all -I all -c "password_encryption_type=0"

2)编辑pg_hba.conf文件,修改sha为MD5

host all all 0.0.0.0/0 md5

[omm@opengaussdb dn]$ gs_ctl reload

3)查看修改结果

openGauss=# show password_encryption_type;

password_encryption_type

--------------------------

0

(1 row)

4)修改数据库用户密码

openGauss=# alter user hr password 'Huawei_1234';

openGauss=# select usename,usesysid,usecreatedb,usesuper,passwd from pg_shadow where usename='hr';

usename | usesysid | usecreatedb | usesuper | passwd

---------+----------+-------------+----------+-------------------------------------

hr | 38057 | f | f | md5eeee246dbfc9b65cf35a6ab1fd4e51cf

(1 row)

执行同步任务:

[root@opengaussdb datax]# python bin/datax.py job/ora2gsdb.json

osInfo: Linux amd64 3.10.0-957.el7.x86_64

jvmInfo: Oracle Corporation 1.8 25.181-b13

cpu num: 8

totalPhysicalMemory: -0.00G

freePhysicalMemory: -0.00G maxFileDescriptorCount:-1 currentOpenFileDescriptorCount:-1

GC Names [PS MarkSweep,PSScavenge] MEMORY_NAME | allocation_size | init_size

PS Eden Space | 256.00MB | 256.00MB

Code Cache | 240.00MB | 2.44MB

Compressed Class Space | 1,024.00MB | 0.00MB PS Survivor Space | 42.50MB | 42.50MB

PS Old Gen | 683.00MB | 683.00MB Metaspace | -0.00MB | 0.00MB

………………….

…………………

………………….

[total cpu info] =>

averageCpu | maxDeltaCpu | minDeltaCpu

-1.00% | -1.00% | -1.00%

[total gc info] =>

NAME | totalGCCount | maxDeltaGCCount | minDeltaGCCount | totalGCTime | maxDeltaGCTime | minDeltaGCTime

PS MarkSweep | 1 | 1 | 1 | 0.045s | 0.045s | 0.045s

PS Scavenge | 1 | 1 | 1 | 0.025s | 0.025s | 0.025s

2026-03-12 10:58:15.777 [job-0] INFO JobContainer - PerfTrace not enable!

2026-03-12 10:58:15.777 [job-0] INFO StandAloneJobContainerCommunicator - Total 107 records, 6484 bytes | Speed 648B/s, 10 records/s | Error 0 records, 0 bytes | All Task WaitWriterTime 0.001s | All Task WaitReaderTime 0.000s | Percentage 100.00%

2026-03-12 10:58:15.778 [job-0] INFO JobContainer -

任 务 启 动 时 刻 : 2026-03-12 10:58:04

任 务 结 束 时 刻 : 2026-03-12 10:58:15

任 务 总 计 耗 时 : 11s

任 务 平 均 流 量 : 648B/s

记 录 写 入 速 度 : 10rec/s

读 出 记 录 总 数 : 107

读 写 失 败 总 数 : 0

5. 验证

登录opengauss数据库查看

testdb=> \d

List of relations

Schema | Name | Type | Owner | Storage

--------+-----------+-------+-------+----------------------------------

hr | employees | table | hr | {orientation=row,compression=no}

public | t1 | table | | {orientation=row,compression=no}

public | t2 | table | | {orientation=row,compression=no}

public | t3 | table | | {orientation=row,compression=no}

(4 rows)

testdb=> select count(*) from employees;

count

-------

107

(1row)

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/14 16:50:44

怎么降AIGC率?学姐盘点3个好用的降AI工具及5个手改技巧指南

最近我发现很多同学都在苦恼降ai这件事,后台发来的截图里,那报告,简直红得触目惊心。 现在的系统早已是next level,不是看你用了什么词,而是在分析你的文本生成逻辑。今天这篇文章,我不讲虚的,…

作者头像 李华
网站建设 2026/7/14 16:50:43

李哥深度学习班学习笔记——图像识别

一、导入依赖库​ import random #用于设置随机种子,保证实验可复现 import torch #Pytorh核心库,构建和训练神经网络 import torch.nn as nn #Pytorch神经网络层模块 import numpy as np #数值计算库,处理矩阵 import os #…

作者头像 李华
网站建设 2026/7/14 16:50:48

全自动颗粒清洁度分析系统,西恩士工业让颗粒计数精准高效

颗粒计数是清洁度检测的核心环节,传统的人工颗粒计数,不仅效率低,还容易出现误判、漏判,尤其是大规模生产时,人工计数根本跟不上节奏。西恩士的全自动颗粒清洁度分析系统,让颗粒计数摆脱人工,做…

作者头像 李华
网站建设 2026/7/14 16:51:01

不要499,不用复杂命令 小白1秒上手的0成本养虾指南来了!

不用499上门安装 不用复杂命令 不用担心安全风险 只需1分钟 人人都能轻松养一只属于自己的 ‘龙虾’(OpenClaw)! 来蚂蚁百宝箱Tbox 体验真正免下载 0成本的 OpenClaw 服务 我们彻底砍掉了繁琐的电脑安装环节:打开官网 http:…

作者头像 李华
网站建设 2026/7/14 16:50:47

告别安装报错:OpenClaw部署中常见的Node.js环境问题与解决方案

告别安装报错:OpenClaw部署中常见的Node.js环境问题与解决方案 1. 引言 OpenClaw是一款基于Node.js开发的自动化工具,因此在部署过程中,Node.js环境的配置至关重要。本文将介绍OpenClaw部署中常见的Node.js环境问题,并提供详细的…

作者头像 李华