Azure SQL Database Geo-Replication

This article explains how to configure and manage active geo-replication for Azure SQL Database. Geo-replication provides disaster recovery capabilities by allowing you to create readable, geographically replicated secondary databases that can be failed over to.

What is Geo-Replication?

Geo-replication allows you to asynchronously replicate your primary Azure SQL Database to another Azure region. This feature is designed for disaster recovery scenarios where a region outage might impact your primary database. By having a readable secondary replica in a different region, you can minimize data loss and application downtime.

Key Concepts

Supported Scenarios

How to Configure Geo-Replication

Prerequisites

Steps to Create a Geo-Replicated Secondary

You can configure geo-replication using the Azure portal, Azure CLI, or PowerShell.

Using the Azure Portal:

  1. Navigate to your primary Azure SQL Database in the Azure portal.
  2. In the database overview pane, select Replicas from the left-hand menu.
  3. Click Create replica.
  4. Configure the settings for the secondary replica:
    • Region: Select the desired Azure region for your secondary database.
    • Server: Choose an existing Azure SQL server or create a new one in the target region.
    • Compute + storage: Select the desired service tier and compute size. It's recommended to match the primary's performance level.
  5. Click Review + create, then Create.
Important: The secondary database is initially created as a blank database that is populated with data from the primary. The creation time depends on the size of the primary database.

Using Azure CLI:


az sql db replica create --dest-resource-group <dest-resource-group-name> --server <dest-server-name> --name <secondary-db-name> --partner-db <primary-db-resource-id> --edition <edition> --service-objective <service-objective> --region <target-region>
            

Using PowerShell:


New-AzSqlDatabaseSecondary -PartnerDatabaseId <primary-db-resource-id> -ResourceGroupName <dest-resource-group-name> -ServerName <dest-server-name> -SecondaryDatabaseName <secondary-db-name> -Edition <edition> -ServiceObjectiveName <service-objective> -Location <target-region>
            

Managing Geo-Replication

Monitoring Replication Status

You can monitor the replication status of your geo-replicated databases in the Azure portal under the Replicas section of your primary database. Key metrics include:

Performing a Failover

A failover is a critical operation that switches the primary and secondary roles. There are two types of failovers:

To perform a failover:

  1. Navigate to your primary Azure SQL Database in the Azure portal.
  2. Go to Replicas.
  3. Select the secondary database you wish to fail over to.
  4. Click Failover.
  5. Choose the failover type (Planned or Unplanned) and confirm.
Tip: For critical applications, consider setting up automatic failover policies or using Azure Traffic Manager to redirect traffic to the secondary database during an outage.

Performing a Failback

After a failover, you may want to move the primary role back to the original primary database. This is known as failback.

  1. Navigate to the new primary database (which was the secondary).
  2. Go to Replicas.
  3. Select the database that is now the secondary.
  4. Click Failover and choose Planned failover.

Considerations

Best Practices

Note: Geo-replication is a powerful tool for disaster recovery. Always combine it with other Azure resilience features for comprehensive protection.