在 Azure 入口網站中為 Azure SQL Database 設定主動式異地複寫,並起始容錯移轉Configure active geo-replication for Azure SQL Database in the Azure portal and initiate failover

本文說明您如何使用 Azure 入口網站在 Azure SQL Database 中為獨立和集區資料庫設定主動式異地複寫,並起始容錯移轉。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 (preview), 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.

注意

使用 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 為基礎的購買模型以虛擬核心為基礎的購買模型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.

注意

如果夥伴資料庫已經存在 (例如,因終止先前的「異地複寫」關聯性所導致),命令將會失敗。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 Database 頁面上,選取 [異地複寫],然後選取要建立次要資料庫的區域。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 Database] 刀鋒視窗上,選取 [所有設定] > [異地複寫]。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.

    容錯移轉

  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.

注意

此命令的設計目的是要快速復原發生中斷的資料庫。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 Database 頁面上,選取 [異地複寫]。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