Migrating to a Multi-AZ DB cluster using a read replica

Amazon RDS Read Replicas provide enhanced performance and durability for RDS instances. They make it easy to elastically scale out beyond the capacity constraints of a single DB instance for read-heavy database workloads. You can create from one to 5 replicas of a given source DB Instance and serve high-volume application read traffic from multiple copies of your data, thereby increasing aggregate read throughput. Read replicas can also be promoted when needed to become standalone DB instances. Find more features of RDS Read-replicas here .

To migrate a Single-AZ deployment or Multi-AZ DB instance deployment to a Multi-AZ DB cluster deployment with reduced downtime, you can create a Multi-AZ DB cluster read replica. Please visit Working with Multi-AZ DB cluster read replicas for additional details.

Amazon RDS creates a second DB instance using a snapshot of the source DB instance. It will uses the engines’ native asynchronous replication to update the read replica whenever there is a change to the source DB instance. The read replica operates as a DB instance that allows only read-only connections; applications can connect to a read replica just as they would to any DB instance.

To migrate a Single-AZ deployment or Multi-AZ DB instance deployment to a Multi-AZ DB cluster deployment with reduced downtime, you can create a Multi-AZ DB cluster read replica.

  1. Find RDS PostgreSQL instance rdspg-fcj-labs under the Databases menu and click on the radio button in front of the DB Instance. Click on the Actions drop down on the right side and choose Create Read Replica. migrating

  2. For Settings, you must provide a DB Instance Identifier (i.e. the name for this instance). migrating

  3. For the Availability section, select Multi-AZ DB Cluster - new deployment option. migrating

  4. For simplicity, we’ll leave the rest at their defaults. Scroll to the bottom and click Create read replica

After you click Create read replica, you’ll be taken back to the Databases page. Click the refresh icon to refresh the page and you should see the read replica being created. migrating

It will take about 10 minutes for your read replica to be created. Your primary database continues to be available as this happens.

  1. Once the Read Replica status is Available on the Databases page ( you may need to use the refresh icon to see the latest Status ), click on the new read replica instance.

migrating

  1. On the detail page for the Multi-AZ DB replica cluster, first notice the endpoint(s). The replica has a different endpoint(s) than your primary instance.

migrating

  1. Next, scroll down to view the replication details. You can see that our primary instance is replicating to our read replica instance. migrating

You can then connect to the read replica using its endpoint and the same username and password as the source instance. For example, connect and execute the following query to check the replication lag between the source and the replica:

SELECT extract(epoch from now() - pg_last_xact_replay_timestamp()) AS replica_lag;

migrating

You can also promote this Multi-AZ read replica cluster to a stand-alone cluster. We will do that in the next step.

  1. Click on Actions, and select Promote to detach and promote the rdspg-fcj-labs-read-test Multi-AZ DB Cluster by selecting Promote read replica migrating

It will take about 1-2 minutes for your read replica to be detached and promoted as an independent RDS DB Cluster with Multi-AZ DB Cluster deployment option.

At this point, you have successfully migrated your RDS PostgreSQL instance with Multi-AZ DB Instance deployment mode to the RDS PostgreSQL Multi-AZ DB Cluster deployment option.

Congratulations: In this lab, you added a Multi-AZ DB Cluster read replica instance to your configuration to migrate your application/database from Multi-AZ DB Instance deployment option to the Multi-AZ DB Cluster deployment option.

(OPTIONAL) AWS CLI

Alternatively you can promote the read replica using the AWS CLI as shown below:

Code