Database Failover / Swap Procedure
When to Use
- Planned maintenance on the primary SQL Server
- Restoring from a backup or snapshot
- Switching to a read replica for reporting isolation
- Incident response: primary database is unhealthy
Prerequisites
- Azure CLI authenticated (
az login) - Access to the resource group containing the Private DNS zone
- Approval from team lead (production swaps)
Steps
1. Verify Current State
.\database\dns-alias\show-current.ps1 -ResourceGroup <rg>2. Verify Target Database is Healthy
az sql db show --resource-group <rg> --server <target-server> --name <target-db> --query "status"3. Swap the DNS Alias
# Dry run first.\database\dns-alias\swap-primary.ps1 -ResourceGroup <rg> -NewTarget <server.database.windows.net> -WhatIf
# Execute swap.\database\dns-alias\swap-primary.ps1 -ResourceGroup <rg> -NewTarget <server.database.windows.net>4. Verify Applications
- Wait ~30 seconds for connections to drain
- Check HISD portal login
- Check eshars-mobile-api health endpoint
- Check eshars_mgmt portal
5. Document
Add an entry to the swap log below.
Swap Log
| Date | Alias | Old Target | New Target | Reason | Performed By |
|---|---|---|---|---|---|
| template | primary | old-server.database.windows.net | new-server.database.windows.net | reason | name |