Skip to main content
emnode
Site Reliability

Protect Azure SQL with auto-failover groups

One reliability capability for Azure SQL Database and Managed Instance: keep a geo-replicated secondary in a second region behind read-write and read-only listener endpoints, so a regional outage becomes a short failover instead of a day of downtime.

14 min·10 sections·AZURE

Last reviewed

Auto-failover groups: the basics

What does an Azure SQL database with no second-region fallback actually look like?

A single Azure SQL Database or Managed Instance lives in one region. Inside that region Microsoft keeps it highly available across fault domains, and zone redundancy can spread it across availability zones, but none of that helps if the whole region has a bad day. When a region is impaired, a database with no geo-replicated secondary has nowhere to fail to: you wait for the region to recover, or you restore from a geo-redundant backup, which is measured in hours and loses recent writes. Azure Advisor surfaces exactly this gap as a reliability recommendation, pointing at databases that have no cross-region replica configured.

An auto-failover group closes that gap. It is a declarative layer on top of active geo-replication: you name a partner server in a second region, add the databases you want protected, and Azure continuously replicates them to a secondary. The group exposes two stable DNS listener endpoints. The read-write listener, '.database.windows.net', always points at whichever server is currently primary. The read-only listener, '.secondary.database.windows.net', points at the secondary. Your application connects to the listener, not to a specific server, so when the primary changes the connection string does not.

The point of the group is that the recovery path is pre-built, not a runbook someone has to improvise during an outage. Microsoft recommends the customer-managed failover policy, where you initiate the failover with one command the moment you confirm a regional outage, and the platform promotes the secondary and repoints the listener. The application reconnects to the same listener name and finds itself talking to the new primary in the second region, typically within a minute. The work is to identify every production database that matters, give it a partner server and a failover group, and point the application at the listener instead of the server, so the failover itself is a single deliberate step rather than an improvised project.

In this lesson you will learn how Azure SQL expresses cross-region resilience, how to find the production databases that have no second-region fallback, and how to put them behind an auto-failover group without changing your application's connection logic. You will see the read-write and read-only listener endpoints, the recommended customer-managed failover policy and the single command that triggers a failover, and a copy-and-paste az CLI and Bicep fix that creates a group as code.

Fun fact

The endpoint that does not move

The cleverest part of a failover group is the part you never see: the read-write listener is just a DNS CNAME, '.database.windows.net', that Azure repoints to whichever server is currently primary. When a failover happens, the database physically moves to another region hundreds of miles away, but your application's connection string does not change a single character. It keeps dialling the same name, the CNAME now resolves to the secondary region, and the app reconnects without knowing it has crossed a region boundary. The hard part of disaster recovery, getting traffic to the right place, is reduced to a name that quietly follows the primary around.

Finding databases with no second-region fallback

Priya is the platform engineer at a payments company doing a reliability review before peak season. Azure Advisor is flagging several production databases under its reliability recommendations, and she wants to know which of them have no cross-region secondary at all before she decides what to protect.

Rather than open each database in the portal, she lists the logical servers and checks which ones already participate in a failover group, so she can separate the databases that are genuinely single-region from the ones that are already covered.

List the failover groups on a server. A production server with none is a single-region database with no automatic cross-region fallback.

$ az sql failover-group list --resource-group rg-payments --server sql-payments-prod -o table
Name ResourceGroup ReplicationRole ReplicationState
------ --------------- ---------------- ----------------
(no failover groups found)
# sql-payments-prod has no failover group: its databases live in one region only.

An empty result on a production server is the signal: these databases have no geo-replicated secondary, so a regional outage means downtime until recovery. Protect these first.

How an auto-failover group actually fails overdeep dive

A failover group sits on top of active geo-replication. The primary streams its transaction log asynchronously to the secondary in the partner region, which is why the recovery point objective is small but not zero: Microsoft documents it at about five seconds, so a forced failover during an outage can lose the last few seconds of committed transactions that had not yet replicated. The secondary is a real, readable copy, which is why it must match the primary's service tier and compute size to carry the workload after a failover rather than buckle under it.

The read-write endpoint failover policy decides who triggers the failover. Microsoft recommends the customer-managed policy (the 'Manual' value in the CLI and Bicep), which keeps you in control: when you confirm a regional outage you run one command and the platform promotes the secondary, typically inside a minute, which is why the documented recovery time with this policy is up to about 60 seconds. The alternative, the Microsoft-managed policy ('Automatic'), delegates the decision to Microsoft, but it fails over every Microsoft-managed group in the affected region at once rather than your single group, it is only triggered in exceptional situations on a best-effort basis, and its grace period cannot be set below one hour because verifying and mitigating a region-wide outage depends on human action; Microsoft's own guidance is not to rely on it for most solutions. Either way, the read-write listener CNAME is repointed to the new primary as part of the promotion, so the application reconnects to the same name and lands on the secondary region.

Two details decide whether failover is actually transparent. First, the application must connect through the listener endpoint, never a hardcoded server name, or it will keep dialling the dead region after failover. Second, anything the database depends on, firewall rules, logins, and for Managed Instance the networking, must already exist on the secondary, because failover does not create them on the fly. Get those right and the recovery is a single command with a documented recovery time of up to about 60 seconds, rather than an hours-long restore.

What is the impact of leaving a critical database single-region?

The direct impact is duration of downtime during a regional event. A database with no geo-replicated secondary has two options when its region is impaired: wait for Azure to recover the region, which is outside your control and can take hours, or restore from a geo-redundant backup into another region, which is also measured in hours and loses every write since the last backup point. Either way the service the database backs is down for the length of the regional event, and the business absorbs that whole window.

The second-order impact is the recovery scramble. Without a pre-built failover path, an outage becomes an improvised project: find a healthy region, restore backups, reconcile lost data, repoint connection strings, and verify the application under pressure while customers are waiting. An auto-failover group converts all of that into a single deliberate command with documented objectives, roughly a five-second recovery point and, with the recommended customer-managed policy, a recovery time of up to about 60 seconds, so the people who would otherwise be scrambling are instead running one step and watching it complete.

On the business-continuity side, many regulated and contractual regimes expect demonstrable cross-region recovery for systems of record. A configured failover group, with the application proven to reconnect through the listener, is concrete evidence that the database can survive the loss of a region, which is far stronger than a backup you have never restored under fire.

How do you put a database behind a failover group safely?

Work it per database, and build the secondary side before you create the group. The order matters: a failover group that promotes to a secondary missing firewall rules or logins fails over into a database the application cannot use.

1. Choose the databases worth protecting

Not every database needs a second-region replica. Identify the production databases whose downtime has a real hourly cost, the ones backing revenue or customer-facing services, and protect those. Reporting, test and staging databases can usually accept backup-based recovery and do not justify a standing secondary.

2. Stand up a matching secondary server

Create a logical server (or Managed Instance) in a second region and make sure the secondary can actually serve the workload: the same service tier and compute size as the primary, and the same firewall rules, logins and, for Managed Instance, networking. Failover does not create these for you, so anything missing on the secondary is missing after failover.

3. Create the group with the recommended customer-managed policy

Create the failover group naming the partner server, add the databases, and set the read-write failover policy to Manual, which is the customer-managed policy Microsoft recommends. The group creates the read-write and read-only listener endpoints automatically. With this policy you trigger the failover yourself with one command when you confirm an outage, which fails over just this group and gives a recovery time of up to about 60 seconds. The Microsoft-managed policy (Automatic) instead delegates failover to Microsoft, fails over every Microsoft-managed group in the region on a best-effort basis, and forces a grace period of at least one hour, so Microsoft advises against relying on it for most solutions.

4. Point the application at the listener

Change the application's connection string from the server name to the read-write listener, '.database.windows.net', and send read-only workloads to '.secondary.database.windows.net' if you want them served from the replica. This is the step that makes failover transparent: without it, the app keeps dialling the old region after a failover.

# 1. Create the failover group on the primary server, naming the second-region
#    partner server. Use the recommended customer-managed policy: in the CLI the
#    value 'Manual' is the customer-managed policy, where you trigger failover.
az sql failover-group create \
  --name fog-payments \
  --resource-group rg-payments \
  --server sql-payments-prod \
  --partner-server sql-payments-dr \
  --partner-resource-group rg-payments-dr \
  --failover-policy Manual \
  --add-db ledgerdb

# 2. Confirm the listener endpoints and replication state.
az sql failover-group show \
  --name fog-payments \
  --resource-group rg-payments \
  --server sql-payments-prod \
  --query "{readWrite:readWriteEndpoint.failoverPolicy, role:replicationRole, state:replicationState}" \
  -o table

# 3. App connects to the read-write listener, never the server name:
#    Server=tcp:fog-payments.database.windows.net,1433; ...
#    Read-only workloads can target fog-payments.secondary.database.windows.net

# 4. During a regional outage, trigger the failover yourself from the secondary
#    server. --allow-data-loss lets the forced failover proceed when the primary
#    is unreachable (accepting the ~5s RPO of asynchronous replication).
az sql failover-group set-primary \
  --name fog-payments \
  --resource-group rg-payments-dr \
  --server sql-payments-dr \
  --allow-data-loss

Quick quiz

Question 1 of 5

A production Azure SQL database has zone redundancy enabled but no failover group. Azure Advisor flags it under reliability. What does the failover group add that zone redundancy does not?

You can now treat Azure SQL resilience as a per-database decision rather than a runbook: find the production databases with no second-region fallback, stand up a matching secondary, put the ones whose downtime actually costs money behind a failover group with the recommended customer-managed policy, and point the application at the read-write listener so failover is transparent. A region having a bad day becomes a short, one-command failover instead of an afternoon of downtime.

Back to the library