在 Azure 门户中为 Azure SQL 数据库配置活动异地复制,并启动故障转移Configure active geo-replication for Azure SQL Database in the Azure portal and initiate failover

本文说明如何使用 Azure 门户为 Azure SQL 数据库中的单一和共用数据库配置活动异地复制,以及如何启动故障转移。This article shows you how to configure active geo-replication for single and pooled databases in Azure SQL Database using the Azure portal and to initiate failover.

有关自动故障转移组与单一数据库和共用数据库的信息,请参阅将故障转移组与单一数据库和共用数据库配合使用的最佳做法For information about auto-failover groups with single and pooled databases, see Best practices of using failover groups with single and pooled databases. 有关自动故障转移组与托管实例的信息,请参阅将故障转移组与托管实例配合使用的最佳做法For information about auto-failover groups with Managed Instances, see Best practices of using failover groups with managed-instances.

必备条件Prerequisites

若要使用 Azure 门户配置活动异地复制,需要以下资源:To configure active geo-replication by using the Azure portal, you need the following resource:

  • Azure SQL 数据库:要复制到其他地理区域的主数据库。An Azure SQL database: The primary database that you want to replicate to a different geographical region.

Note

如果使用 Azure 门户,仅可在与主要数据库相同的订阅内创建辅助数据库。When using Azure portal, you can only create a secondary database within the same subscription as the primary. 如果辅助数据库需要位于其他订阅中,请使用 Create Database REST APIALTER DATABASE Transact-SQL APIIf secondary database is required to be in a different subscription, use Create Database REST API or ALTER DATABASE Transact-SQL API.

添加辅助数据库Add a secondary database

以下步骤在异地复制合作关系中创建新的辅助数据库。The following steps create a new secondary database in a geo-replication partnership.

只有订阅所有者或共有者才能添加辅助数据库。To add a secondary database, you must be the subscription owner or co-owner.

辅助数据库具有与主数据库相同的名称,并默认使用相同的服务层级和计算大小。The secondary database has the same name as the primary database and has, by default, the same service tier and compute size. 辅助数据库可以是单一数据库,也可以是共用数据库。The secondary database can be a single database or a pooled database. 有关详细信息,请参阅基于 DTU 的购买模型基于 vCore 的购买模型For more information, see DTU-based purchasing model and vCore-based purchasing model. 创建辅助数据库并设定种子后,会开始将数据从主数据库复制到新的辅助数据库。After the secondary is created and seeded, data begins replicating from the primary database to the new secondary database.

Note

如果合作伙伴数据库已存在(例如,在终止之前的异地复制关系的情况下),命令会失败。If the partner database already exists (for example, as a result of terminating a previous geo-replication relationship) the command fails.

  1. Azure 门户中,浏览到需要设置以便进行异地复制的数据库。In the Azure portal, browse to the database that you want to set up for geo-replication.

  2. 在 SQL 数据库页上,选择“异地复制”,并选择要创建辅助数据库的区域。 On the SQL database page, select geo-replication, and then select the region to create the secondary database. 可以选择除托管主数据库的区域以外的任何区域,但我们建议选择配对区域。You can select any region other than the region hosting the primary database, but we recommend the paired region.

    配置异地复制

  3. 选择或配置辅助数据库的服务器和定价层。Select or configure the server and pricing tier for the secondary database.

    配置辅助数据库

  4. 可以选择将辅助数据库添加到弹性池中。Optionally, you can add a secondary database to an elastic pool. 要在池中创建辅助数据库,单击“弹性池” ,并在目标服务器上选择一个池。To create the secondary database in a pool, click elastic pool and select a pool on the target server. 目标服务器上必须已存在一个池。A pool must already exist on the target server. 此工作流不会创建池。This workflow does not create a pool.

  5. 单击“创建” 添加辅助数据库。Click Create to add the secondary.

  6. 此时会创建辅助数据库,种子设定过程开始。The secondary database is created and the seeding process begins.

    配置辅助数据库

  7. 完成种子设定过程时,辅助数据库会显示其状态。When the seeding process is complete, the secondary database displays its status.

    种子设定完成

启动故障转移Initiate a failover

辅助数据库可以通过切换变为主数据库。The secondary database can be switched to become the primary.

  1. Azure 门户中,浏览到异地复制合作关系中的主数据库。In the Azure portal, browse to the primary database in the geo-replication partnership.

  2. 在 SQL 数据库边栏选项卡中,选择“所有设置” > “异地复制” 。On the SQL Database blade, select All settings > geo-replication.

  3. 在“辅助数据库” 列表中,选择想要其成为新的主数据库的数据库并单击“故障转移” 。In the SECONDARIES list, select the database you want to become the new primary and click Failover.

    failover

  4. 单击“是” 开始故障转移。Click Yes to begin the failover.

该命令会立即将辅助数据库切换为主数据库角色。The command immediately switches the secondary database into the primary role. 此过程通常会在 30 秒或更短的时间内完成。This process normally should complete within 30 sec or less.

切换角色时,有一小段时间无法使用这两个数据库(大约为 0 到 25 秒)。There is a short period during which both databases are unavailable (on the order of 0 to 25 seconds) while the roles are switched. 如果主数据库具有多个辅助数据库,则该命令会自动重新配置其他辅助数据库以连接到新的主数据库。If the primary database has multiple secondary databases, the command automatically reconfigures the other secondaries to connect to the new primary. 在正常情况下,完成整个操作所需的时间应该少于一分钟。The entire operation should take less than a minute to complete under normal circumstances.

Note

此命令旨在快速恢复已中断的数据库。This command is designed for quick recovery of the database in case of an outage. 它将触发故障转移但不进行数据同步(强制故障转移)。It triggers failover without data synchronization (forced failover). 如果发出命令时主数据库处于在线状态且正在提交事务,则可能会丢失某些数据。If the primary is online and committing transactions when the command is issued some data loss may occur.

删除辅助数据库Remove secondary database

此操作会永久终止到辅助数据库的复制,并会将辅助数据库的角色更改为常规的读写数据库。This operation permanently terminates the replication to the secondary database, and changes the role of the secondary to a regular read-write database. 如果与辅助数据库的连接断开,命令会成功,但辅助数据库必须等到连接恢复后才会变为可读写。If the connectivity to the secondary database is broken, the command succeeds but the secondary does not become read-write until after connectivity is restored.

  1. Azure 门户中,浏览到异地复制合作关系中的主数据库。In the Azure portal, browse to the primary database in the geo-replication partnership.

  2. 在 SQL 数据库页上,选择“异地复制”。 On the SQL database page, select geo-replication.

  3. 在“辅助数据库” 列表中,选择需要从异地复制合作关系中删除的数据库。In the SECONDARIES list, select the database you want to remove from the geo-replication partnership.

  4. 单击“停止复制” 。Click Stop Replication.

    删除辅助数据库

  5. 确认窗口随即打开。A confirmation window opens. 单击“是”从异地复制合作关系中删除数据库。 Click Yes to remove the database from the geo-replication partnership. (将其设置为不属于任何复制的读写数据库。)(Set it to a read-write database not part of any replication.)

后续步骤Next steps