All Products
Search
Document Center

ApsaraDB RDS:Use the primary/secondary switchover feature

Last Updated:Mar 28, 2026

ApsaraDB RDS for PostgreSQL automatically switches workloads from the primary instance to the secondary instance when the primary instance fails. After the switchover, the secondary instance becomes the new primary instance, and your connection endpoints remain unchanged so your application reconnects automatically. You can also trigger a manual switchover for disaster recovery drills or to reduce latency with multi-zone deployments.

Prerequisites

Before you begin, make sure that you have:

  • An RDS instance running RDS High-availability Edition or RDS Cluster Edition

RDS Basic Edition does not provision a secondary instance and does not support primary/secondary switchovers.
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.

Potential impacts

Before triggering a switchover, understand the following effects:

  • Service interruption: A switchover causes approximately 30 seconds of downtime. A switchover may take longer when an instance fails. Configure your application to reconnect automatically after a disconnection. If your application uses the Druid connection pool, upgrade Druid to version 1.1.16 or later to make sure automatic reconnection works correctly.

  • Read-only instance lag: After a switchover, read-only instances re-establish their replication connections to the new primary instance. Expect a few minutes of data lag on read-only instances.

  • Endpoint stability: Connection endpoints remain unchanged after a switchover. The IP addresses associated with those endpoints may change, so connect using the endpoint hostname rather than the IP address.

Trigger a manual switchover

Trigger a manual switchover for disaster recovery drills, or when using a multi-zone deployment and you want the application to connect to the instance in the zone closest to it.

  1. Go to the Instances page. In the top navigation bar, select the region where your RDS instance resides. Then find the instance and click its ID.

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

  3. In the Availability Information section, click Switch Primary/Secondary Instance.

  4. Set the Switching Time parameter and click OK.

    We recommend that you select Switch Within Maintenance Window.
    OptionDescription
    Switch NowTriggers the switchover immediately.
    Switch Within Maintenance WindowDelays the switchover to the next maintenance window to minimize impact on running workloads.
During a switchover, operations such as database and account management and network type changes are unavailable.

Disable automatic switchovers temporarily

By default, automatic primary/secondary switchovers are enabled. When the primary instance fails, the system switches workloads to the secondary instance automatically. For more information about the causes of primary/secondary switchovers, see Reasons for primary/secondary switchovers. You can temporarily disable this behavior in the following scenarios:

  • A large-scale sales promotion

  • A critical application upgrade

  • A major event requiring stable database connectivity

Only RDS High-availability Edition with cloud disks and RDS Cluster Edition with cloud disks support temporarily disabling automatic switchovers.

To disable automatic switchovers:

  1. Go to the Instances page. In the top navigation bar, select the region where your RDS instance resides. Then find the instance and click its ID.

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

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

    If Configure Primary/Secondary Switchover is not displayed, verify that your instance runs RDS High-availability Edition.
  4. Select Disable Temporarily, set the Deadline parameter, and click OK.

    Automatic switchovers are re-enabled when the deadline arrives. If you do not set a deadline, automatic switchovers are disabled for one day by default. The maximum deadline is 23:59:59 seven days from now.

After saving, the deadline is displayed on the Service Availability page so you can confirm when automatic switchovers will resume.

View switchover logs

  1. Go to the Instances page. In the top navigation bar, select the region where your RDS instance resides. Then find the instance and click its ID.

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

  3. In the Primary/Secondary Switching Logs section, select a time range to view the switchover logs generated during that period.

image.png
Read-only instances running RDS High-availability Edition also support viewing primary/secondary switchover logs.

FAQ

Do I need to switch workloads back to the original primary instance after a switchover?

No. After a switchover, the secondary instance becomes the new primary instance with the same data. No additional action is required.

After a switchover, my application behaves abnormally for several minutes. What causes this and how do I fix it?

This typically happens when socket connections have no timeout configured. Without a timeout, your application waits indefinitely for database responses after the old connections are invalidated, causing SQL statements to queue up and fail.

Set connectTimeout and socketTimeout on your database connections to limit how long the application waits during network errors. For online transaction workloads, set connectTimeout to 1–2 seconds and socketTimeout to 60–90 seconds. Adjust these values based on your actual workload and latency requirements.

API reference

OperationDescription
SwitchDBInstanceHASwitches workloads between primary and secondary instances
ModifyHASwitchConfigEnables or disables automatic primary/secondary switchovers
DescribeHASwitchConfigQueries the automatic switchover settings for an instance