tencent cloud

Feedback

Primary/Replica Switch

Last updated: 2023-12-27 10:17:46
    MySQL supports the switch of primary and secondary databases. In the event of an instance failure, the system automatically promotes the secondary database to primary to ensure system availability and data integrity. In addition to automatic switch during anomalous conditions such as failures, you can also manually switch the databases via the console.

    Background

    In enterprise-level applications, the database often forms a critical component of the business system. Any database failure or downtime can have serious implications on business operations. To safeguard system availability and data integrity, high-availability solutions such as primary-replica replication are implemented. Primary-replica switch is a crucial technical method within the replication scheme, which enables a quick switch to the backup database when the primary database is faulty, averting business interruptions and data losses.
    

    Prerequisites

    The instance architecture is set to either two-node or three-node.
    The instance is in running status, with no ongoing tasks.

    Precautions

    During the primary-secondary database switch, a momentary disconnection occurs. We recommend that you perform the switch during off-peak hours and make sure that your application has a reconnection mechanism.
    After the switch, the instance connection address remains the same. The original primary instance converts into a secondary instance, and the application automatically connects to the new primary instance (formerly the secondary instance).

    The steps are as follows:

    Note:
    Automatic fallback is not supported after the primary/secondary switch, but manual fallback can be done if needed (i.e., perform another primary/secondary switch after the first one is completed).
    1. Log in to the TencentDB for MySQL console. In the instance list, click an instance ID or Manage in the operation column to access the instance details page.
    2. On the Instance Details page, click Switch Primary/Secondary under Availability Info.
    
    3. In the pop-up window, select the switch time, check "With the Primary/Secondary instance switch, there will be a brief disconnection; ensure that your application has a reconnection mechanism", and click OK.
    During Maintenance Period: When data synchronization between primary and secondary AZs has been completed, the system will switch the primary and secondary instances in the next maintenance period. During this period, the instance status shows as Pending Primary/Secondary Switch and operations such as configuration adjustments or instance termination cannot be performed. For operations related to setting the instance maintenance time, please see Setting Instance Maintenance Time.
    Switch Immediately: The switch will occur immediately upon the completion of data synchronization between the primary and secondary AZs.
    

    FAQs

    Will the instance address change after the primary and secondary database switch?

    The instance address remains the same after the switch. The original primary instance works as a secondary, with applications automatically connecting to the new primary instance (formerly the secondary).

    After a manual switch, if an instance is upgraded or expanded, will this affect or reset the information of the primary and secondary AZs?

    The switch will not affect or reset the information of the primary and secondary AZs.
    
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support