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.
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.
Find the 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.
For Settings, you must provide a DB Instance Identifier (i.e. the name for this instance). Something like “rdspg-fcj-labs-read” works.
For the Instance Configurations and AWS Region sections, leave the default values. Uncheck the Enable storage autoscaling option.
Notice that you can optionally size the Read Replica use a different instance tier than your primary instance. In your case, the Destination Region will likely be different than what you see in the screenshot and that is OK.
For Connectivity, leave the defaults.
Leave the Network Security settings at their default.
For Availability, select Multi-AZ DB instance.
For simplicity, we’ll leave the rest at their defaults. Scroll to the bottom and click Create read replica.
It will take about 10 minutes for your read replica to be created. Your primary database continues to be available as this happens.
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.
On the detail page for the read replica, first notice the endpoint. The read replica has a different endpoint than your primary instance
Next, scroll down to view the replication details. You can see that our primary instance is replicating to our read replica instance.
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;
RDS PostgreSQL also allows you to promote a read replica to be a standalone instance. We will do that in the next Lab.
Congratulations: In this lab, you added a read replica instance to your configuration to provide additional read scalability to your application.
Alternatively you can create the read replica instance using the AWS CLI as shown below: