rds_dbsync数据源同步工具
生活随笔
收集整理的這篇文章主要介紹了
rds_dbsync数据源同步工具
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、介紹
dbsync 項目目標是圍繞 PostgreSQL Greenplum ,實現易用的數據的互遷功能
github地址:https://github.com/aliyun/rds_dbsync
?
支持的功能如下:
?
?
?
二、功能1(基于 MySQL binlog 解析的增量數據同步)
1、原理介紹
官方文檔說明:https://github.com/aliyun/rds_dbsync/blob/master/doc/mysql2gp.md
1.在客戶端主機(也可以部署在其他主機)上啟動一個臨時 PG 數據庫,用于臨時存放從 MySQL 拉去到的 binlog 數據2.binlog_miner 從源 MySQL 的一個 binlog 文件開始,拉取和解析 binlog 并存放到臨時 PG 中3.binlog_loader 從臨時 PG 中讀取增量數據,并做適當的處理,最終批量寫入到目標 PostgreSQL 或 Greenplum 中去2、配置相關數據源和目標數據源
1、mysql數據源
1、數據庫,create database syncdb1; 2、用戶權限,需要擁有select權限和binlog拉取權限,此處使用root權限 3、同步的表(切換到syncdb1數據庫),create table tb1(a int primary key, b char(10));2、pgsql臨時數據庫
1、用戶,create user test with password 'test'; 2、數據庫,create database test with owner 'test';3、pgsql目的數據庫
1、用戶,create user syncdb with password 'syncdb'; 2、數據庫,create database syncdb with owner 'syncdb'; 3、同步的表(使用syncdb用戶切換到syncdb數據庫),create table tb1(a int primary key, b char(10));3、搭建步驟
1、下載和解壓縮
下載地址:https://github.com/aliyun/rds_dbsync/releases 解壓縮:unzip mysql2pgsql.bin.el7.20171213.zip && mv mysql2pgsql.bin.el7.20171213 mysql2pgsql2、修改配置文件,vim bin/my.cfg
1、mysql數據源 [src.mysql] host = "118.190.209.102" port = "5700 user = "root" password = "123456" db = "syncdb1" encodingdir = "share" encoding = "utf8" binlogfile = "mysql-bin.000001" binlogfile_offset = "154" serverid = 1292、pgsql臨時數據庫 [local.pgsql] connect_string = "host=127.0.0.1 dbname=test port=5432 user=test password=test"3、pgsql目的數據庫 [desc.pgsql] connect_string = "host=118.190.209.102 dbname=syncdb port=5432 user=syncdb password=syncdb" target_schema = "public" ignore_copy_error_count_each_table = "0"4、需要同步的表設置 [binlogloader] loader_table_list = "loader_table_list.txt" load_batch = 2 load_batch_gap = 10 # load任務的間隔3、修改配置文件,vim bin/loader_table_list.txt
tb14、啟動同步進程
1、 啟動 binlog 拉取進程
cd bin ./binlog_miner2、 啟動 binlog 寫入進程
cd bin ./binlog_loader5、過程中pgsql臨時表的介紹
1、mysql數據源插入數據
insert into tb1 select 1,'a';2、pgsql臨時表數據
1、binlog_data表 test=# select * from binlog_data;id | event | tbname | new_row | old_key | flag ----+-------+--------+---------+---------+------1 | 1 | tb1 | 1|'a' | 1 | 12、binlog_load_table_status表 test=# select * from binlog_load_table_status;id | tbname | last_load_time | apply_id | task_id ----+--------+----------------------------+----------+---------1 | tb1 | 2018-08-01 15:02:52.307866 | 1 | 13、binlog_miner_status test=# select * from binlog_miner_status;id | binlogfile | position | binlog_data_id | last_update ----+------------------+----------+----------------+---------------------------1 | mysql-bin.000001 | 419 | 1 | 2018-08-01 15:02:51.520234、binlog_washer_status test=# select * from binlog_washer_status;id | b | e | count | finish_time ----+---+---+-------+----------------------------1 | 0 | 1 | 1 | 2018-08-01 15:02:51.7535913、pgsql目的數據庫
syncdb=> select * from tb1;a | b ---+------------1 | a6、存在問題和解決思路
1、數據源同步的表,發生ddl變更操作后,啟動dml操作
報錯
解決
1、調整目的數據庫的表結構,和源端保持一致 2、重新啟動binlog_loader進程2、多個庫中表的同步
這個工具默認是同步下面對應的庫表,所以每個進程只能同步一個庫
可以并發啟動多個進程,每個進程分別同步一個庫,最終的目標庫可以保持一致,實現mysql多個庫中的表同步到pgsql的一個庫的一個表
3、同步表比較多和數據量比較大時,會造成性能的瓶頸
轉載于:https://blog.51cto.com/11257187/2153182
總結
以上是生活随笔為你收集整理的rds_dbsync数据源同步工具的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 圭古文化获数百万天使轮融资 ,持续探索原
- 下一篇: datatables 获取 pageLe