Schematics

rds-migration.drawio (1).png

The arrows represents the flow of data , the direction of the networks connections have to reversed (the subscriber connects to the publisher)

# Procedure

## 1) Prepare the origin server

### a) Connect to the database (origin server)

Mysql


Postgresql

## From your laptop
# Using teleport to connect to the origin k8s cluster
tsh kube login <env>

# Get Stolon proxy External IP
kubectl get svc <env>db-stolon-proxy
# You need to make sure your bastion IP is whitelisted in the spec.loadBalancerSourceRanges of the service
# You can get the bastion IP by running this from it: aws ec2 describe-addresses | jq '.Addresses | map(select((.Tags[] | .Value | contains ("sandbox") and contains ("nat-eip")) and (.Tags[] | .Key=="Name"))) | .[].PublicIp'

### From the AWS bastion of the environment you are migrating to
# Connect to Azure DB instance. Password can be found on the helm/charts/stolon/values.yaml in the deploy repo
psql "host=<stolon-external-proxy-ip> user=stolon dbname=production"

### b) Ensure origin configuration

Mysql

SHOW VARIABLES LIKE 'binlog_format';
SHOW VARIABLES LIKE 'max_binlog_cache_size';
SHOW VARIABLES LIKE 'max_binlog_size';
SHOW VARIABLES LIKE 'sync_binlog';

Postgresql

The following parameters must be set

- `wal_level` must be set to logical **(This requires the origin database server to be restarted if not already configured like this)**
- `max_replication_slots` at least 5 (should already be higher)
- `max_wal_senders` at least 10 (should already be higher)

c) Create the user in the with the good permissions to allow dump and subscription (origin server not read replicas)

Mysql

# On origin

CREATE USER 'db_migration'@'%' IDENTIFIED BY 'super_password';
GRANT REPLICATION SLAVE ON *.* TO 'db_migration'@'%';
GRANT REPLICATION CLIENT ON *.* TO 'db_migration'@'%';
FLUSH PRIVILEGES;

Postgresql

# On origin

CREATE USER db_migration WITH PASSWORD '<my password>' REPLICATION;
GRANT production to rds_replication;