postgresql实时同步数据表mysql

应客户要求,需要同步数据到他们自己的数据库用于简单的数据分析,但这部分数据在postgresql,客户又不想再建pg,想直接同步到他们现有的mysql库,实时性倒是不要求。

考虑到

1、异构数据库同步

2、只同步指定客户的行数据

有之前同步到es的经验,同样使用了腾讯oceanus,其它工具没搞定

客户库中创建表
SQL 复制代码
CREATE TABLE tb_1 (
    id bigint primary key,
    did bigint,
    gid bigint,
    fee DECIMAL(10,2),
    created_at timestamp,
    type smallint,
    remark string ,
    key i_did(did)
);
创建SQL作业
sql 复制代码
CREATE TABLE tb_1 (
    id bigint,
    did bigint,
    gid bigint,
    fee DECIMAL(10,2),
    create_time timestamp,
    type smallint,
    remark string,
    PRIMARY KEY (`id`) NOT ENFORCED
) WITH (
  'connector' = 'postgres-cdc',
  'hostname' = 'ip', 
  'port' = '5432',             
  'username' = 'user', 
  'password' = 'pwd', 
  'database-name' = 'db',
  'schema-name' = 'your-schema', 
  'table-name' = 'tbname',
  'slot.name' = 'slotname_tb_1',
  'scan.incremental.snapshot.enabled' = 'true'
);



CREATE TABLE kh_tb_1 (
    id bigint,
    did bigint,
    gid bigint,
    fee DECIMAL(10,2),
    create_time timestamp,
    type smallint,
    remark string,
    PRIMARY KEY (`id`) NOT ENFORCED
) WITH (
  'connector' = 'jdbc',
  'url' = 'jdbc:mysql://xxxxxx:3306/db?rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai',
  'table-name' = 'tb_1',
  'username' = 'user',
  'password' = 'pwd',
  'sink.buffer-flush.max-rows' = '5000',
  'sink.buffer-flush.interval' = '2s',
  'sink.max-retries' = '10'
);

insert into kh_tb_1 select * from tb_1 where did=xxxxxxx;

需要注意的:

1.字段类型要合理和对应,跟着cdc的类型走,不跟数据库一样

2.只有这个客户数据,insert不要忘了加where

3.pg涉及同步slot, slot.name要一张表一个,表多的话,要修改pg参数,max_replication_slots(默认是10,修改此参数要重启)

4.报错[55000]: ERROR: cannot delete from table "tb_1" because it does not have a replica identity ,调整下表 alter table tb_1 REPLICA IDENTITY FULL;

启动作业任务即可。

相关推荐
_星辰大海乀12 分钟前
表的设计、聚合函数
java·数据结构·数据库·sql·mysql·数据库开发
未来之窗软件服务1 小时前
solidwors插件 开发————仙盟创梦IDE
前端·javascript·数据库·ide·仙盟创梦ide
yc_12241 小时前
SqlHelper 实现类,支持多数据库,提供异步操作、自动重试、事务、存储过程、分页、缓存等功能。
数据库·c#
Leo.yuan2 小时前
基于地图的数据可视化:解锁地理数据的真正价值
大数据·数据库·信息可视化·数据挖掘·数据分析
好吃的肘子2 小时前
MongoDB入门
数据库·mongodb
noravinsc2 小时前
人大金仓数据库 与django结合
数据库·python·django
代码配咖啡3 小时前
《Navicat之外的新选择:实测支持国产数据库的SQLynx核心功能解析》
数据库
懒大王爱吃狼3 小时前
怎么使用python进行PostgreSQL 数据库连接?
数据库·python·postgresql
时序数据说3 小时前
IoTDB集群的一键启停功能详解
大数据·数据库·开源·时序数据库·iotdb
小叶子来了啊4 小时前
信息系统运行管理员:临阵磨枪版
运维·服务器·数据库