Code Monkey home page Code Monkey logo

replicate-postgresql-to-mysql's Introduction

Continuous replication PostgreSQL to MySQL using Debezium and JDBC over Kafka Connect

Motivation

We set a goal to migrate our production database from MySQL to PostgreSQL, but we faced a challenge โ€” we use a BI tool called Metabase connected directly to the MySQL, and migrating queries would take significant time.

In order to make this process smoother, this continuous replication was set up to allow us using old MySQL database with the latest data, while in production we would already use brand new PostgreSQL.

Requirements

  1. Docker
  2. Credentials for the databases

Setting up

Connectors

  1. Configure your PostgreSQL and MySQL connectors stored in connect/ directory.

    cp connect/mysql-connector.json.example connect/mysql-connector.json
    cp connect/postgres-connector.json.example connect/postgres-connector.json
  2. Add replication publication to PostgreSQL database. Connect to your database and run:

    CREATE PUBLICATION dbz_publication FOR ALL TABLES;

If you have a managed database and don't have root access, instead of ALL TABLES, list the specific tables

Containers

  1. Adjust ports in .env (if needed)

  2. Start the containers:

    docker compose up -d
  3. Verify plugins have been loaded:

    docker compose exec kafka-connect curl -s  http://localhost:8083/connector-plugins | jq
  4. Add MySQL and PostgreSQL connectors:

    docker compose exec kafka-connect curl -i -X POST -H "Content-Type:application/json" -d @connect/postgres-connector.json http://localhost:8083/connectors
    docker compose exec kafka-connect curl -i -X POST -H "Accept:application/json" -H  "Content-Type:application/json" -d @connect/mysql-connector.json http://localhost:8083/connectors
  5. Verify synchronization process has started by listing topics. You should see topics representing tables in there:

    docker compose exec kafka kafka-topics --list --bootstrap-server localhost:9092
  6. (Optional) Make a safe update in the PostgreSQL database and check in the MySQL the change has been applied.

Monitoring

  • Stream kafka-connect logs

    docker-compose logs -f kafka-connect --tail 100
  • Check connector status

    docker-compose exec kafka-connect curl localhost:8083/connectors/jdbc-sink-mysql/status | jq

Resources used

replicate-postgresql-to-mysql's People

Contributors

breart avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.