All Products
Search
Document Center

ApsaraDB RDS:Switch workloads over between the primary and secondary nodes of an ApsaraDB RDS for MySQL instance

Last Updated:Nov 21, 2024

If the primary node of your RDS instance fails or the RDS instance has a potential risk and an emergency repair is performed on the secondary node of the RDS instance, the system automatically switches your workloads over between the primary node and the secondary node to ensure service availability. After the switchover is complete, the secondary node serves as the primary node. The endpoint that is used to connect to your database system remains unchanged. Your application can automatically connect to the new primary node by using the endpoint. You can also manually switch your workloads over between the primary node and the secondary node.

Prerequisites

  • If the RDS instance is not a read-only instance, make sure that the RDS instance runs one of the following RDS editions:

    • RDS High-availability Edition

    • RDS Enterprise Edition

    • RDS Cluster Edition

    Note

    An RDS instance that runs RDS Basic Edition does not support the primary/secondary switchover feature because it does not include secondary nodes.

  • If the RDS instance is a read-only instance, make sure that the RDS instance runs RDS High-availability Edition and uses cloud disks.

Background information

  • Automatic primary/secondary switchover: By default, the automatic primary/secondary switchover feature is enabled. If the primary node of your RDS instance fails, the system automatically switches your workloads over to the secondary node. For more information about the causes of primary/secondary switchovers, see Reasons for primary/secondary switchovers.

  • Manual primary/secondary switchover: You can also manually switch your workloads over between the primary node and the secondary node of your RDS instance when the automatic primary/secondary switchover feature is enabled. You can perform manual primary/secondary switchovers for disaster recovery drills. You can also perform manual primary/secondary switchovers if you use the multi-zone deployment method and want to connect your application to the RDS instance in the zone that is closest to your application.

Note
  • In an RDS for MySQL instance that runs RDS High-availability Edition, data is synchronized between the primary node and the secondary node in real time. You can access only the primary node of the instance. The secondary node runs only as a standby and cannot be directly accessed.

  • Read-only RDS instances that run RDS High-availability Edition also support the primary/secondary switchover feature and allow you to view primary/secondary switchover logs.

For more information about how to switch workloads over between the primary and second nodes of RDS instances that run different database engines, see the following topics:

Impacts

  • A service interruption that lasts about 30 seconds occurs during a primary/secondary switchover. Make sure that your application is configured to automatically reconnect to your database system.

    If your application uses an earlier version of the Druid component for connection management, your application may fail to automatically reconnect to your database system after disconnection. We recommend that you upgrade the Druid component to 1.1.16 or later to resolve this issue.

  • After a primary/secondary switchover is performed for an RDS instance, the read-only RDS instances that are attached to the RDS instance must re-establish the connections that are used to replicate data to and synchronize incremental data from the RDS instance. As a result, the data on the read-only RDS instances shows latencies of a few minutes.

  • A primary/secondary switchover does not cause changes to the endpoints that are used to connect to your RDS instance. However, the IP addresses that are associated with the endpoints may change. If your application uses endpoints to connect to your RDS instance, your application can still run as expected after a primary/secondary switchover.

  • A switchover may take longer when an instance fails.

Perform a manual primary/secondary switchover

  1. Go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the ID of the instance.

  2. In the left-side navigation pane, click Service Availability.

  3. In the Availability Information section of the page that appears, click Switch Primary/Secondary Instance.

  4. Specify the time at which you want to perform a primary/secondary switchover. Then, click OK.

    Important

    You cannot perform specific operations during a primary/secondary switchover. For example, you cannot manage databases or accounts or change the network type. We recommend that you select Within Specified Time Range.

    If you use RDS Cluster Edition, you can perform a primary/secondary switchover in the Instance Topology Management section of the Basic Information page.

Disable the automatic primary/secondary switchover feature for a short period of time

By default, the automatic primary/secondary switchover feature is enabled. If the primary node of an RDS instance fails, the system automatically switches your workloads over from the primary node to the secondary node. You can temporarily disable the automatic primary/secondary switchover feature in the following scenarios:

  • A large-scale sales promotion during which you do not want a primary/secondary switchover to affect system availability

  • An important application upgrade during which you do not want a primary/secondary switchover to cause unexpected issues

  • A major event during which you do not want a primary/secondary switchover to affect system stability

  1. Go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the ID of the instance.

  2. In the left-side navigation pane, click Service Availability.

  3. In the Availability Information section, click Automatic Primary/Secondary Switchover.

    Note

    If you cannot find Automatic Primary/Secondary Switchover, check whether the RDS instance meets all prerequisites.

  4. Select Temporarily Disable, configure the Deadline parameter, and then click OK.

    Note
    • When the date and time specified by the Deadline parameter arrives, the automatic primary/secondary switchover feature is automatically enabled.

    • If you do not configure the Deadline parameter, the automatic primary/secondary switchover feature is disabled for one day by default. You can set the Deadline parameter to 23:59:59 seven days later at most.

After the configuration is complete, you can check the deadline after which the automatic primary/secondary failover feature is automatically enabled on the Service Availability page.

View primary/secondary failover logs

  1. Go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the ID of the instance.

  2. In the left-side navigation pane, click Service Availability.

  3. In the Primary/Secondary Switching Logs section of the page that appears, select a time range and view the primary/secondary switchover logs that are generated over the selected time range.

    image.png

FAQ

  • Can I access the secondary node of an RDS instance?

    If you use RDS Cluster Edition, you can access the secondary nodes in your RDS cluster. If you use a different RDS edition, you cannot access the secondary nodes of RDS instances.

  • Do I need to manually switch my workloads back from the secondary node to the primary node after a primary/secondary switchover?

    No, you do not need to manually switch your workloads back from the secondary node to the primary node after a primary/secondary switchover. The data in the primary node is the same as the data in the secondary node. After a primary/secondary switchover, the secondary node automatically becomes the new primary node. Therefore, you do not need to manually switch the workloads back.

  • Each time a primary/secondary switchover is performed, my RDS instance does not run as expected 10 minutes after the primary/secondary switchover is complete. What are the possible causes? How do I handle the issue?

    If an exception on your RDS instance triggers a primary/secondary switchover to ensure high availability, your application may fail to identify and respond to the changes to the connections. If no timeout periods are specified for socket connections, your application waits for the database to return the results. In most cases, your application is disconnected after hundreds of seconds. During this period, some connections to the RDS instance cannot work as expected, and a large number of SQL statements fail to be executed. To avoid invalid connections, we recommend that you configure the connectTimeout and socketTimeout parameters to prevent your application from waiting for a long period of time due to network errors. This reduces the time required to recover from failures.

    You must configure these parameters based on your workloads and usage modes. For online transactions, we recommend that you set the connectTimeout parameter to 1 to 2 seconds and the socketTimeout parameter to 60 to 90 seconds. This configuration is for reference only.

Related operations

Operation

Description

SwitchDBInstanceHA

Switches workloads over between primary and secondary nodes.

ModifyHASwitchConfig

Enables or disables the automatic primary/secondary switchover feature for an instance.

DescribeHASwitchConfig

Queries the settings of the automatic primary/secondary switchover feature for an instance.