All Products
Search
Document Center

ApsaraDB for MongoDB:Configure a primary/secondary switchover for a replica set instance

Last Updated:Nov 01, 2024

By default, an ApsaraDB for MongoDB replica set instance consists of a primary node, a secondary node, and a hidden node. The primary and secondary nodes provide external endpoints, and the hidden node serves as a daily standby node to ensure high availability. If a node fails, the high availability system of ApsaraDB for MongoDB automatically triggers a primary/secondary switchover to ensue the availability of the instance. You can also trigger a primary/secondary switchover for an ApsaraDB for MongoDB instance in scenarios such as routine disaster recovery drills.

Background information

  • You can trigger a primary/secondary switchover only for replica set and sharded cluster instances, but not for standalone instances due to their single-node architecture.

  • After you trigger a primary/secondary switchover for an instance, the instance is disconnected for up to 30 seconds. Make sure that your applications can automatically reconnect to the instance.

  • You can trigger a primary/secondary switchover only for instances in the running state.

Procedure

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

  2. In the left-side navigation pane of the instance details page, click Service Availability.

  3. Click Switch Role.

  4. In the Switch Role panel, select two roles and configure Effective At.

    • Effective Immediately: The system immediately performs a primary/secondary switchover.

    • Effective Within Maintenance Window:The system performs a primary/secondary switchover within the specified maintenance window. You can select the current maintenance window or specify a custom maintenance window in the Change Maintenance Window drop-down list.

  5. Click OK.

    The instance status changes to Switching Role. After the instance status changes back to Running, the primary/secondary switchover is successful.

    Note
    • The switchover takes about one minute. Then, the instance returns to normal.

    • If you have connected to an instance by using the endpoint of the primary node in the instance, you need to connect to the instance by using the endpoint of the new primary node after a primary/secondary switchover. Otherwise, data may fail to be read from or written to the instance. For more information, see Connect to a replica set instance.

FAQ

Why does the high availability system of ApsaraDB for MongoDB trigger a primary/standby switchover?

Related API operations

Operation

Description

SwitchDBInstanceHA

Switches the primary and secondary nodes for an ApsaraDB for MongoDB instance.