当前位置: 首页 > article >正文

postgresql实时同步数据表mysql

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

1、异构数据库同步

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

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

客户库中创建表
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作业
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;

启动作业任务即可。


http://www.kler.cn/a/555468.html

相关文章:

  • HttpSession类的对象session:保存的数据谁有权限读取?
  • 面试基础-如何设计一个短链接系统
  • 使用 Docker-compose 部署 MySQL
  • Openai Dashboard可视化微调大语言模型
  • C++游戏开发流程图
  • idea从远程gitee拉取项目
  • SVN服务器搭建【Linux】
  • Node os模块
  • Android开发-深入解析Android中的AIDL及其应用场景
  • SpringCloud系列教程:微服务的未来(二十四)Direct交换机、Topic交换机、声明队列交换机
  • 蓝桥杯备赛 Day15 动态规划
  • STM32 HAL库UART串口数据接收实验
  • Golang访问Google Sheet
  • Java 中的内存泄漏问题及解决方案
  • PDF 分割与合并 工具资源分享
  • 合规数助力律师专业工作,开启法律科技新篇
  • PassGPT:基于大型语言模型的密码建模和(引导式)生成
  • 火绒终端安全管理系统V2.0病毒防御功能介绍
  • 解决本地模拟IP的DHCP冲突问题
  • C++ 模板 简单易懂