Updated on 2022-02-10 GMT+08:00

Adding a Read Replica

Application Scenario

In read-intensive scenarios, a single DB instance may be unable to handle the read pressure and service performance may be affected. To offload read pressure on the database, you can create read replicas in a region. These read replicas can process a large number of read requests and increase application throughput. Data synchronization between the primary DB instance and read replicas is not affected by network latency. Read replicas and the primary DB instance must be in the same region but can be in different AZs. This section describes how to use Terraform scripts to create an RDS read replica.

Procedure

  1. For details about how to create a MySQL database, see Creating an RDS MySQL DB Instance.
  2. Create an RDS read replica. The following uses MySQL as an example.

    data "huaweicloud_availability_zones" "myaz" {}
    
    resource "huaweicloud_rds_read_replica_instance" "myreplica" {
      name                = "myreplica"
      flavor              = "rds.mysql.c2.large.rr"
      primary_instance_id = huaweicloud_rds_instance.myinstance.id
      availability_zone   = data.huaweicloud_availability_zones.myaz.names[1]
    
      volume {
        type = "ULTRAHIGH"
      }
      tags = {
        type = "readonly"
      }
    }
    1. Run terraform plan to view resources.
    2. After you confirm that the resource information is correct, run terraform apply to start resource creation.
    3. Run terraform show to view information about the created RDS read replica.

Table 1 Parameter description

Resource Name

Parameter

Description

huaweicloud_rds_read_replica_instance

name

(Mandatory) Read replica name.

  • The value must be 4 to 64 characters in length and start with a letter. It is case-sensitive and can contain only letters, digits, hyphens (-), and underscores (_).

flavor

(Mandatory) Read replica flavor. In this example, rds.mysql.c2.large.rr is used. You can query the instance flavor via huaweicloud_rds_flavors.

primary_instance_id

(Mandatory) Primary DB instance ID.

availability_zone

(Mandatory) AZ where the read replica is located. For details, see Regions and Endpoints.

tags

(Optional) Instance tags.

volume

type

(Mandatory) Disk type of the read replica.

  • Options:

    ULTRAHIGH: SSD type

    ULTRAHIGHPRO: ultra-high I/O (advanced), which supports ultra-high performance (advanced) DB instances.