数据库使用postgresql安装了postgis插件存储了geometry空间数据,想使用datax做数据同步,但datax本身不支持geometry类型数据,如何改造呢?
1.首先下载已改造支持geometry类型的datax引擎,下载地址
https://download.csdn.net/download/letterss/88799803
2.将下载的datax引擎解压,将plugin里面reader模块的postgresqlreader和wrtier模块的postgresqlwriter分别替换自己的引擎模块即可,如果只使用postgresql数据库,则不用替换直接使用下载的引擎。
3.测试
新建了两张表my_table,my_table_copy1
CREATE TABLE my_table (id SERIAL PRIMARY KEY, geom GEOMETRY);
CREATE TABLE my_table_copy1(id SERIAL PRIMARY KEY, geom GEOMETRY);
向my_table添加数据
INSERT INTO my_table (geom) VALUES ('POINT(0 0)');
查询数据显示如下
使用datax同步,dataxjson如下
{"job": {"setting": {"speed": {"channel": "6","byte": "12242880"},"errorLimit": {"record": "5","percentage": "0.02"}},"content": [{"reader": {"name": "postgresqlreader","parameter": {"username": "XVko54UY9nOe/3JQGQUikw==","password": "fMaKElymbiVDjjwluBXyhA==","column": ["\"id\"", "\"geom\""],"splitPk": "","connection": [{"table": ["public.my_table"],"jdbcUrl": ["jdbc:postgresql://localhost:5432/postgres"]}]}},"writer": {"name": "postgresqlwriter","parameter": {"username": "XVko54UY9nOe/3JQGQUikw==","password": "fMaKElymbiVDjjwluBXyhA==","column": ["\"id\"", "\"geom\""],"preSql": ["truncate table public.my_table_copy1"],"connection": [{"table": ["public.my_table_copy1"],"jdbcUrl": "jdbc:postgresql://localhost:5432/postgres"}]}},"transformer": []}]}
}
同步成功,可以看到my_table_copy1 geom字段也有数据了,且数据一致