侧边栏壁纸
  • 累计撰写 35 篇文章
  • 累计创建 14 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

MySQL到postgresql的数据迁移和同步

子曰
2023-06-28 / 0 评论 / 0 点赞 / 586 阅读 / 670 字 / 正在检测是否收录...

DBsync

github项目地址:https://github.com/aliyun/rds_dbsync
dbsync 项目目标是围绕 PostgreSQL Greenplum 实现易用的数据的互迁功能。
参考文档:https://blog.csdn.net/weixin_33758863/article/details/91661545

1.1 支持特性和限制

1 支持拉取 MySQL 5.1 5.5 5.6 5.7 版本的 binlog,需要 binlog 相关参数
binlog_format = ROW binlog_row_image = FULL
2 支持同步指定表的各类数据变化到目标DB中,包括对应行的 insert update delete。
3 数据同步的表需要有单列主键。
4 支持对主键进行修改。
5 暂时不支持异构数据库的 DDL 同步。
6 支持指定表镜像方式同步到 PostgreSQL 或 Greenplum(配置文件方式)。
7 支持指定模式的表同步。

1.2 mysql2gp 实现架构

简单的说,mysql2gp 的实现方式是:
1 在客户端主机(也可以部署在其他主机)上启动一个临时 PG 数据库,用于临时存放从 MySQL 拉去到的 binlog 数据。
2 binlog_miner 从源 MySQL 的一个 binlog 文件开始,拉取和解析 binlog 并存放到临时 PG 中。
3 binlog_loader 从临时 PG 中读取增量数据,并做适当的处理,最终批量写入到目标 PostgreSQL 或 Greenplum 中去。

1.3 mysql2gp 模块介绍

mysql2gp 分为5个部分 1 binlog_miner 用于拉取目标库中的 binlog, 并保存到临时 DB 中。
2 binlog_loader 用于读取临时 DB 中的 binlog 数据并加载到目标库中。
3 my.cfg 配置文件,设置需要同步数据的源和目标数据库的链接信息和相关参数。
4 loader_table_list.txt 配置文件,设置需要同步的表名列表,用回车符隔开。
5 临时 DB,用户保存增量数据的临时数据库。建议和 binlog_miner binlog_loader 部署在同一个主机。

pgloader

https://wiki.postgresql.org/wiki/Converting_from_other_Databases_to_PostgreSQL#MySQL
下载地址:https://github.com/dimitri/pgloader/releases
github地址:https://github.com/dimitri/pgloader
部署文档:https://pgloader.readthedocs.io/en/latest/install.html#building-from-sources-on-redhat-centos

脚本生成,一键安装

sh bootstrap-centos.sh
sh bootstrap-centos7.sh

编译生成rpm包

注意需要执行sh bootstrap-centos.sh 下载指定版本的sbcl

Install the [EPEL repo](https://fedoraproject.org/wiki/EPEL#Quickstart).
yum install epel-release

Install rpmbuild dependencies:
sudo yum -y install yum-utils rpmdevtools @"Development Tools"

Install pgloader build dependencies:

sudo yum-builddep pgloader.spec
Download pgloader source:

spectool -g -R pgloader.spec
Build the source and binary RPMs (see rpmbuild –help for other build options):

rpmbuild -ba pgloader.spec

使用方式:

pgloader mysql://zabbix:zabbix@10.0.9.93:61106/zabbix postgresql:///zabbix
0

评论区