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;

启动作业任务即可。

相关推荐
清风徐来QCQ5 分钟前
redis 面试可能会问的问题
数据库·redis·面试
这辈子谁会真的心疼你6 分钟前
如何修改照片定位信息?详细介绍两个方法
数据库
Oueii9 分钟前
构建一个基于命令行的待办事项应用
jvm·数据库·python
小瓦码J码20 分钟前
PostgreSQL pg_stat_statements 性能分析利器(二)全表扫描导致物理IO爆炸
数据库·postgresql
2501_9454235425 分钟前
如何为开源Python项目做贡献?
jvm·数据库·python
2401_8845632427 分钟前
使用Flask快速搭建轻量级Web应用
jvm·数据库·python
清风徐来QCQ28 分钟前
Redis以及如何在springboot中使用
数据库·redis·缓存
xcLeigh28 分钟前
告别 Excel 繁琐操作!Metabase让数据可视化触手可及
mysql·docker·信息可视化·excel·数据可视化·metabase·cpolar
编程饭碗37 分钟前
【Mysql日期字段】
数据库·mysql
Thomas.Sir37 分钟前
精通 MySQL 面试题
数据结构·数据库·mysql