Dragonfly Cloud announces new enterprise security features - learn more

Question: How do you scale a PostgreSQL database on AWS RDS?

Answer

Scaling a PostgreSQL database on AWS RDS can be approached in two primary ways: vertically and horizontally. Both strategies have their use cases, depending on whether you need to handle increased load by adding more computing resources to an existing instance (vertical scaling) or by adding more instances to distribute the load (horizontal scaling).

Vertical Scaling

Vertical scaling involves increasing the size of your RDS instance. This can typically be done without downtime using the AWS Management Console, CLI, or SDKs.

  1. Console Method:

    • Go to the RDS dashboard.
    • Select 'Databases' from the sidebar.
    • Click on the database identifier you want to modify.
    • Choose 'Modify'.
    • In the 'DB Instance Class' section, select a new instance class with more CPU, RAM, etc.
    • Scroll down and click 'Continue', then choose when to apply changes.
  2. AWS CLI:

aws rds modify-db-instance \\ --db-instance-identifier mydbinstance \\ --db-instance-class db.m4.large \\ --apply-immediately

This command changes the instance type of mydbinstance to db.m4.large and applies the change immediately.

Horizontal Scaling (Read Replicas)

For read-heavy applications, you can offload read requests to one or more Read Replicas. This allows your primary DB instance to handle writes while replicas handle reads.

  1. Creating a Read Replica via Console:

    • Navigate to the RDS dashboard.
    • Choose 'Databases' and select your primary database.
    • Under 'Actions', choose 'Create read replica'.
    • Specify the DB Instance Identifier for the replica and other configurations.
    • Click 'Create read replica'.
  2. AWS CLI:

aws rds create-db-instance-read-replica \\ --db-instance-identifier myreadreplica \\ --source-db-instance-identifier mydbinstance

This command creates a new read replica myreadreplica for the source database mydbinstance.

Considerations

  • Backup and Recovery: Ensure that your backup strategy accommodates the scaled infrastructure.
  • Monitoring and Performance Tuning: Utilize CloudWatch and RDS performance insights to monitor and tune your instances.
  • Cost: More resources mean higher costs. Be mindful of your configuration choices and regularly review your usage and costs.

Vertical scaling is simpler but has its limits based on the maximum capabilities of RDS instances. Horizontal scaling, particularly through read replicas, offers more flexibility for scaling out but requires additional management to ensure optimal performance and utilization.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost