postgresql实时同步到mysql
https://www.518cn.com 发布时间:2025-03-18 22:38 作者:网络
摘要:应客户要求,需要同步数据到他们自己的数据库用于简单的数据分析,但这部分数据在postgresql,客户又不想再建pg,想直接同步到他们现有的mysql库,实时性倒是不要求。 考虑到 1、异构
应客户要求,需要同步数据到他们自己的数据库用于简单的数据分析,但这部分数据在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;
启动作业任务即可。
欢迎关注我的公众号:老王76。一起进步吧!
相关文章
- 优化GreatSQL日志文件空间占用 GreatSQL对于日志文件磁盘空间占用,做了一些优化,对于binlog、...03-18
- "数据约束条件" date: 2022-11-24T21:24:31 08:00 draft: false MySQL字段约束条件 无符号, 零填充...03-18
【GreatSQL优化器-16】INDEX_SKIP_SCAN
【GreatSQL优化器-16】INDEX_SKIP_SCAN 一、INDEX_SKIP_SCAN介绍 GreatSQL 优化器的索引跳跃扫描(Index Ski...03-18- MySQL 是一个非常流行的开源关系数据库管理系统,在各种应用场景中都得到了广泛的应用。随...03-18
- 🤖 DB-GPT 是一个开源的 AI 原生数据应用程序开发框架,具有 AWEL(代理工作流表达式语...03-18
GreatSQL 8.0.32-27 GA (2025-3-10)
GreatSQL 8.0.32-27 GA (2025-3-10) 版本信息 发布时间:2025年3月10日 版本号:8.0.32-27, Revision aa66a38591...03-18- 6. MySQL 索引的数据结构(详细说明) @目录6. MySQL 索引的数据结构(详细说明)1. 为什么使用索引2...03-18
- @Override @Transactional(rollbackFor = Exception.class) public void batchInsertDeviceData(IotMsgNotifyData iotMsgNotifyDa...03-18
- 个人Qt项目总结——数据库查询断言问题 问题: 当我使用MySQL数据库的查询操作时, 如果查询...03-18
- MySQL 是一种广泛使用的关系数据库管理系统,MySQL 8 是其最新的主要版本,结合了出色的性能和...03-18
最新评论