Skip to main content

Overview

Database migrations are a critical part of maintaining and upgrading your database infrastructure. This guide explains how to safely perform database migrations while ensuring your data replication continues to work correctly with Artie.

Blue/green source database migration

An AWS blue/green deployment copies your database to a new green environment and then switches your application to it.

Amazon RDS and Aurora PostgreSQL

Use these steps when you upgrade an Amazon RDS or Aurora PostgreSQL database with an AWS blue/green deployment. The steps follow the limits that AWS documents: Do these steps in this order:
  1. Stop application writes.
  2. Let Artie read all changes.
  3. Pause the pipeline.
  4. Drop the Artie replication slot.
  5. Create the blue/green deployment.
  6. Switch over to green.
  7. Point the network path to the green writer.
  8. Resume the pipeline.
  9. Make sure that a test row gets to the destination.
  10. Start application writes again.
Artie does not capture changes that you write between the slot drop and the resume. This period includes the time that AWS needs to create the deployment. If you cannot stop writes, backfill the tables that changed in this period. Start the backfill after the test row check passes.
1

Stop application writes

Stop all application writes to blue. Let open transactions finish. Keep writes stopped until the last step.
2

Let Artie read all changes

Keep the pipeline running. Do the read check in step 2 of the PostgreSQL in-place upgrade.
3

Pause the pipeline

Pause the pipeline. Do the pause check in step 3 of the PostgreSQL in-place upgrade. The slot must show active as false.
4

Drop the Artie replication slot

Do not drop the Artie slot before all of these conditions are true:
  • Application writes are stopped.
  • Artie has read all changes.
  • The pipeline is paused.
If you drop the slot too early, Artie cannot get the changes that it did not read.
Drop the slot. Then make sure that no other non-physical slots remain on blue.
The second query must return no rows. If slots remain, other consumers use them. Decide what to do with them before you create the deployment.
5

Create the blue/green deployment

Create the deployment with the target engine version. Make sure that rds.logical_replication is 1 in the green parameter group.Do not run DDL, GRANT or REVOKE on blue during the deployment. AWS blocks the switchover after these changes.
6

Switch over to green

Do the switchover. Green takes the original endpoints. Connect to the writer endpoint and record the writer IP for the next step.
7

Point the network path to the green writer

Make sure that the network path from Artie gets to the green writer before you resume Artie. If Artie resumes before this, it connects to the old blue database.For PrivateLink with an NLB IP target, a Lambda function keeps the target IP current. Run the Lambda, or wait for its next run. Then check the target group.
The only target must be the writer IP from the last step, with the state healthy.
8

Resume the pipeline

Resume the pipeline. Artie finds no slot, so it resets its saved position and creates a new slot on green. Do the resume check in step 6 of the PostgreSQL in-place upgrade.
9

Make sure that a test row gets to the destination

Insert a test row on green and find it in the destination. Use the test row check in step 7 of the PostgreSQL in-place upgrade.
10

Start application writes again

Start application writes again when the test row is in the destination. Monitor the pipeline lag in the analytics portal.

In-place major version upgrade

Major version upgrades (e.g., PostgreSQL 14 to 15) require stopping database replication to perform the necessary upgrade and restart your database. This is because major version upgrades often include breaking changes that can affect replication.

PostgreSQL in-place upgrade

To upgrade with an AWS blue/green deployment, use the Amazon RDS and Aurora PostgreSQL steps. Do these steps in this order:
  1. Stop application writes.
  2. Let Artie read all changes.
  3. Pause the pipeline.
  4. Drop the Artie replication slot.
  5. Upgrade the database.
  6. Resume the pipeline.
  7. Make sure that a test row gets to the destination.
  8. Start application writes again.
AWS keeps logical replication slots during a major version upgrade only when the source is PostgreSQL 17 or later. These steps drop the slot on all versions. When you resume, Artie finds that its slot is missing or that the major version changed. Artie then resets its saved position and starts on a new slot.
Artie does not capture changes that you write between the slot drop and the resume. Keep writes stopped for this period. If you cannot stop writes, backfill the tables that changed.
1

Stop application writes

Stop all application writes to the source database. Let open transactions finish. Keep writes stopped until the last step.
2

Let Artie read all changes

Keep the pipeline running. Wait until the analytics portal shows that Artie has caught up. Then do the read check on the source.
Run the query again after one minute. behind_bytes must be small, and it must not increase.
3

Pause the pipeline

In the analytics portal, click Pause pipeline and choose the Pause pipeline option. This option also stops Artie from reading the source. Then do the pause check.
The slot must show active as false.
4

Drop the Artie replication slot

Do not drop the Artie slot before all of these conditions are true:
  • Application writes are stopped.
  • Artie has read all changes.
  • The pipeline is paused.
If you drop the slot too early, Artie cannot get the changes that it did not read.
The default slot name is artie. If you set an override, use that name.
5

Upgrade the database

Upgrade the database to the new major version and restart it. Check the PostgreSQL considerations before you resume.
6

Resume the pipeline

Resume the pipeline in the analytics portal. Artie creates a new slot. Then do the resume check.
postgres_version must show the new version. active must be true. behind_bytes must be zero or more. A negative value means that Artie uses an old position. If you see a negative value, keep writes stopped and contact Artie.
7

Make sure that a test row gets to the destination

The slot checks can pass when no data gets to the destination. Do the test row check to see that data moves from the source to the destination. Insert a row with a unique ID into a small table that the pipeline replicates.
Then find the row in the destination.
The query must return the row with the same values.
8

Start application writes again

Start application writes again when the test row is in the destination. Monitor the pipeline lag in the analytics portal.

Other databases

  1. Schedule an application downtime and pause your application.
  2. In the analytics portal, check that Artie has caught up. Then click Pause pipeline and choose the Pause pipeline option, which also stops Artie from reading the source.
  3. Perform the database upgrade and restart your database server.
  4. Resume your Artie pipeline.
  5. Resume your application.

Database-specific considerations

  • Ensure wal_level is set to logical in your new version
  • Verify that all required extensions are available in the new version
  • Check that your replication slots are properly configured
  • Verify binlog_format is set to ROW
  • Ensure binlog_retention_hours is set appropriately (recommended 24+ hours)
  • Check that GTID is enabled if you’re using it
  • Ensure your replica set is properly configured in the new version
  • Verify that change streams are enabled
  • Check that your service account has the correct permissions

Minor version upgrade

Minor version upgrades (e.g., PostgreSQL 14.1 to 14.2) do not require stopping database replication. These upgrades are typically handled automatically by your database provider and applied during your maintenance window.
While minor version upgrades are generally safe, it’s still recommended to:
  • Monitor your replication lag during the upgrade
  • Have a rollback plan ready
  • Test the upgrade in a staging environment first

Best practices

  1. Always test migrations in a staging environment first
  2. Back up your data before any major version upgrade
  3. Monitor replication lag during and after the upgrade
  4. Keep your Artie pipeline paused until the upgrade is complete
  5. Verify data consistency after the upgrade

Troubleshooting

For Postgres, Artie finds or creates a replication slot. The default slot name is artie, unless you set an override. If the slot is missing or the Postgres major version changed, Artie resets its saved position. Artie then starts on the new slot and captures changes from that point.For other sources, Artie resumes from the last position it saved. If the database no longer has that position, contact us so we can backfill.
If you lose data, contact us and we’ll start a backfill. We recommend:
  1. Document the extent of data loss
  2. Note the approximate time window affected
  3. Contact our support team immediately
  4. Keep your pipeline paused until we can assist
For Postgres, you can run this query to see all the replication slots on the server:
Make sure that active is false. Then drop the replication slot.
Dropping a replication slot deletes the WAL that Artie has not read. Do not drop the Artie slot before writes are stopped, Artie has read all changes, and the pipeline is paused.
  1. Replication slot overflow: If you see this error, you may need to increase your WAL retention period
  2. Connection issues: Verify your database credentials and network connectivity
  3. Permission errors: Ensure your service account has the correct permissions after the upgrade
  4. Schema changes: Check if any schema changes were made during the upgrade that might affect replication