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)                                                                                                                                                                                                                                                                     

                                                                                                                                                                                                                                                                            

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐