mysql到pg库_pg_chameleon是一个从MySQL复制到PostgreSQL的工具

pg_chameleon是一个用Python编写的MySQL到PostgreSQL的数据复制系统,支持从多个MySQL模式读取并恢复到目标PostgreSQL数据库。它包括了对枚举和二进制数据类型的支持,以及基本的DDL操作。该工具需要源数据库为MySQL 5.5+,目标数据库为PostgreSQL 9.5+,并且要求被复制的表具有主键或唯一键。
摘要由CSDN通过智能技术生成

68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f746865347468646f63746f722f70675f6368616d656c656f6e2e737667

68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f746865347468646f63746f722f70675f6368616d656c656f6e2e737667

68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f746865347468646f63746f722f70675f6368616d656c656f6e2e737667

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4253442d626c75652e737667

68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f746865347468646f63746f722f70675f6368616d656c656f6e

68747470733a2f2f696d672e736869656c64732e696f2f707970692f646d2f70675f6368616d656c656f6e2e737667

pg_chameleon is a MySQL to PostgreSQL replica system written in Python 3. The system use the library mysql-replication to pull the row images from MySQL which are stored into PostgreSQL as JSONB. A pl/pgsql function decodes the jsonb values and replays the changes against the PostgreSQL database.

Requirements

Replica host

Operating system: Linux, FreeBSD, OpenBSD Python: CPython 3.5+

Optionals for building documentation

Origin database

MySQL: 5.5+

Destination database

PostgreSQL: 9.5+

Example scenarios

Analytics

Migrations

Data aggregation from multiple MySQL databases

Features

Read from multiple MySQL schemas and restore them it into a target PostgreSQL database. The source and target schema names can be different.

Setup PostgreSQL to act as a MySQL slave.

Support for enumerated and binary data types.

Basic DDL Support (CREATE/DROP/ALTER TABLE, DROP PRIMARY KEY/TRUNCATE, RENAME).

Discard of rubbish data coming from the replica.

Conservative approach to the replica. Tables which generate errors are automatically excluded from the replica.

Possibilty to refresh single tables or single schemas.

Basic replica monitoring.

Detach replica from MySQL for migration support.

Data type override (e.g. tinyint(1) to boolean)

Daemonised init_replica process.

Daemonised replica process with two separated subprocess, one for the read and one for the replay.

Rollbar integration

Caveats

The replica requires the tables to have a primary or unique key. Tables without primary/unique key are initialised during the init_replica process but not replicated.

The copy_max_memory is just an estimate. The average rows size is extracted from mysql's informations schema and can be outdated. If the copy process fails for memory error check the failing table's row length and the number of rows for each slice.

Python 3 is supported only from version 3.5 as required by mysql-replication .

The lag is determined using the last received event timestamp and the postgresql timestamp. If the mysql is read only the lag will increase because no replica event is coming in.

The detach replica process resets the sequences in postgres to let the database work standalone. The foreign keys from the source MySQL schema are extracted and created initially as NOT VALID. The foreign keys are created without the ON DELETE or ON UPDATE clauses. A second run tries to validate the foreign keys. If an error occurs it gets logged out according to the source configuration.

Setup

Create a virtual environment (e.g. python3 -m venv venv)

Activate the virtual environment (e.g. source venv/bin/activate)

Upgrade pip with pip install pip --upgrade

Install pg_chameleon with pip install pg_chameleon.

Create a user on mysql for the replica (e.g. usr_replica)

Grant access to usr on the replicated database (e.g. GRANT ALL ON sakila.* TO 'usr_replica';)

Grant RELOAD privilege to the user (e.g. GRANT RELOAD ON *.* to 'usr_replica';)

Grant REPLICATION CLIENT privilege to the user (e.g. GRANT REPLICATION CLIENT ON *.* to 'usr_replica';)

Grant REPLICATION SLAVE privilege to the user (e.g. GRANT REPLICATION SLAVE ON *.* to 'usr_replica';)

Configuration directory

The system wide install is now supported correctly.

The configuration is set with the command chameleon set_configuration_files in $HOME/.pg_chameleon . Inside the directory there are three subdirectories.

configuration is where the configuration files are stored.

pid is where the replica pid file is created. it can be changed in the configuration file

logs is where the replica logs are saved if log_dest is file. It can be changed in the configuration file

You should use config-example.yaml as template for the other configuration files. Check the configuration file reference for an overview.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值