DBAtlas · Database operations atlas

Forced failover (FORCE_FAILOVER_ALLOW_DATA_LOSS) and post-failover recovery

SQL ServerAlways On & HA

Command

-- 1) On each candidate secondary: pick the most current one (highest end_of_log_lsn)
SELECT ag.name AS ag_name, DB_NAME(drs.database_id) AS db,
       drs.synchronization_state_desc, drs.end_of_log_lsn, drs.last_commit_time
FROM   sys.dm_hadr_database_replica_states drs
  JOIN sys.availability_groups ag ON ag.group_id = drs.group_id
WHERE  drs.is_local = 1;

-- 2) On the chosen replica (while the primary is unreachable):
ALTER AVAILABILITY GROUP [AG_Musteri] FORCE_FAILOVER_ALLOW_DATA_LOSS;

-- 3) On the other secondaries, resume the suspended data movement:
ALTER DATABASE [Musteri] SET HADR RESUME;

-- 4) When the old primary returns (now a SUSPENDED secondary):
--    take a snapshot first to inspect the lost transactions, then resume
CREATE DATABASE [Musteri_lost_snap]
  ON (NAME = N'Musteri', FILENAME = N'D:\Data\Musteri_lost_snap.ss')
  AS SNAPSHOT OF [Musteri];
ALTER DATABASE [Musteri] SET HADR RESUME;

What it does

Makes a DR replica the primary, accepting data loss, when the primary is completely lost; then resumes the suspended data movement on the other replicas and, when the old primary returns, takes a snapshot to inspect transactions that never reached the new primary.

When to use it

When the primary data center is down, only an asynchronous replica is left, or a synchronous replica is not SYNCHRONIZED and a failover is still required.

Caution

DATA LOSS: transactions after the last hardened LSN are lost. Get RPO sign-off from the business first. After a forced failover all secondary databases are SUSPENDED; the log is not truncated and keeps growing until HADR RESUME. If WSFC quorum is lost, start the cluster with forced quorum first (PowerShell: Start-ClusterNode -FixQuorum), otherwise the command fails. HADR RESUME on the old primary permanently discards the lost transactions; do not resume without taking the snapshot.

Open in DBAtlas →

Related