Tutorial: Configure active geo-replication and failover (Azure SQL Database)

Applies to: Azure SQL Database

This article shows you how to configure active geo-replication for Azure SQL Database using the Azure portal or Azure CLI and to initiate failover.

For best practices using auto-failover groups, see Auto-failover groups with Azure SQL Database and Auto-failover groups with Azure SQL Managed Instance.

Prerequisites

To configure active geo-replication by using the Azure portal, you need the following resource:

  • A database in Azure SQL Database: The primary database that you want to replicate to a different geographical region.

Note

When using Azure portal, you can only create a secondary database within the same subscription as the primary. If a 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. 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. In the Azure portal, browse to the database that you want to set up for geo-replication.

  2. On the SQL Database page, select your database, scroll to Data management, select Replicas, and then select Create replica.

    Configure geo-replication

  3. Select or create the server for the secondary database, and configure the Compute + storage options if necessary. You can select any region for your secondary server, but we recommend the paired region.

    {alt-text}

    Optionally, you can add a secondary database to an elastic pool. To create the secondary database in a pool, select Yes next to Want to use SQL elastic pool? and select a pool on the target server. A pool must already exist on the target server. This workflow doesn't create a pool.

  4. Click Review + create, review the information, and then click Create.

  5. The secondary database is created and the deployment process begins.

    Screenshot that shows the deployment status of the secondary database.

  6. When the deployment is complete, the secondary database displays its status.

    Screenshot that shows the secondary database status after deployment.

  7. Return to the primary database page, and then select Replicas. Your secondary database is listed under Geo replicas.

    Screenshot that shows the SQL database primary and geo replicas.

Initiate a failover

The secondary database can be switched to become the primary.

  1. In the Azure portal, browse to the primary database in the geo-replication partnership.

  2. Scroll to Data management, and then select Replicas.

  3. In the Geo replicas list, select the database you want to become the new primary, select the ellipsis, and then select Forced failover.

    Screenshot that shows selecting forced failover from the drop-down.

  4. Select Yes to begin the failover.

The command immediately switches the secondary database into the primary role. This process normally should complete within 30 seconds or less.

There's 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, or 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 stops 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 doesn't become read-write until after connectivity is restored.

  1. In the Azure portal, browse to the primary database in the geo-replication partnership.
  2. Select Replicas.
  3. In the Geo replicas list, select the database you want to remove from the geo-replication partnership, select the ellipsis, and then select Stop replication.
  4. 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