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;

启动作业任务即可。

相关推荐
ShiXZ21338 分钟前
Redis 常用指令全集:redis-cli 实战速查手册
数据库·redis·缓存
晓子文集1 小时前
Tushare接口文档:期货日线行情(fut_daily)
大数据·数据库·金融数据·量化投资·tushare
WA内核拾荒者2 小时前
WhatsApp 账号异常检测的自动化告警系统设计
数据库·python·自动化
龙仔7255 小时前
人大金仓OS_Core数据库自动备份实施笔记(银河麒麟Linux)
linux·数据库·笔记·备份·人大金仓
老杨聊技术6 小时前
CentOS 7 安装 MySQL 8 保姆级教程
linux·mysql·centos
sunxr.2276 小时前
Mysql-----最后一次作业
数据库·mysql
普通网友6 小时前
Python FastAPI 异步数据库管理
数据库·fastapi
晓子文集6 小时前
Tushare接口文档:期货合约信息表(fut_basic)
大数据·数据库·金融·金融数据·量化投资
三言老师7 小时前
CentOS7.9:Redis‑Cluster集群部署结构化实战教程
linux·运维·服务器·数据库
旺仔学长 哈哈7 小时前
Spring Boot 智能停车场管理系统---附源码+数据库文档
数据库·spring boot·后端·智能停车场