Home / Databases / SQL Server

DatabasesRunbookAdvanced

SQL Server Availability Group rolling major-version upgrade: order, failover point, rollback window and the traps

Upgrade an Always On AG to a new SQL Server major version with one short failover. Covers replica order, the point of no return, reads and backups during the window, and verification.

Deepak Bhardwaj7 min read

Applies toSQL Server 2016 to 2022 and 2025 on Windows Server Failover Clustering, Enterprise and Standard (basic AG) editions

Goal

Move every replica of an Always On availability group (AG) to a newer SQL Server major version. The application should see one planned failover of under a minute, and you need a clear rollback option until the moment that failover happens.

The plan rests on one rule. Log can flow from a lower version to a higher one, never back. Upgrade the secondaries first, fail over once to an upgraded secondary, then upgrade the old primary. Once the database comes online on the newer version, its internal version is upgraded and the old binaries can no longer read its log.

Caution

Your rollback window closes at the failover in step 5. After that, getting back to the old version means restoring a pre-upgrade backup and losing every change since then. Take a full backup and a log backup just before step 5, and get a go/no-go sign-off.

What changes during the window

Item Behaviour while versions are mixed
Readable secondaries A replica on a higher version than the primary can't serve reads, even if it is configured as readable. Expect read-only routing targets to fail
Backups on secondaries Microsoft's guidance is that replicas aren't available for backups during a version upgrade. Run log backups on the primary for the whole window
Log flow from a higher-version primary to a lower-version secondary Not possible. Lower-version replicas show NOT SYNCHRONIZING until you upgrade them
Automatic failover Can fail over to a replica you haven't upgraded yet, or away from an upgraded one. Turn it off
Database compatibility level Doesn't change. Raise it later, as a separate change

Checks before you start

Record versions, roles and sync health for every replica:

SELECT ar.replica_server_name, ars.role_desc, ar.availability_mode_desc,
       ar.failover_mode_desc, ar.secondary_role_allow_connections_desc,
       drs.database_id, DB_NAME(drs.database_id) AS db,
       drs.synchronization_state_desc, drs.log_send_queue_size, drs.redo_queue_size
FROM sys.availability_replicas ar
JOIN sys.dm_hadr_availability_replica_states ars ON ars.replica_id = ar.replica_id
LEFT JOIN sys.dm_hadr_database_replica_states drs ON drs.replica_id = ar.replica_id
ORDER BY ar.replica_server_name, db;

SELECT SERVERPROPERTY('ProductVersion') AS version,
       SERVERPROPERTY('ProductUpdateLevel') AS cu,
       SERVERPROPERTY('Edition') AS edition;

Then confirm the following:

  • The supported upgrade path from your source version to the target. Check the "Supported version and edition upgrades" page for the target release, along with its OS requirements.
  • The Windows Server version on each node is supported by the target release. If it isn't, you need a new cluster plus a distributed AG or log shipping. An in-place rolling upgrade won't work.
  • You've run Data Migration Assistant (or its replacement in your tooling) against the databases and reviewed any deprecated features.
  • Logins, Agent jobs, linked servers and credentials are in sync on all replicas. Agent jobs in particular must be ready to run on the new primary.
  • SSISDB is in the AG. If it is, read the SSIS catalog upgrade steps for AGs first, because SSISDB needs its own upgrade wizard after the engine upgrade.

Runbook

1. Freeze automatic failover and switch to synchronous commit

Run on the primary. Every replica that will become a failover target must be synchronous before step 5.

ALTER AVAILABILITY GROUP [AG1] MODIFY REPLICA ON N'SQL02'
  WITH (FAILOVER_MODE = MANUAL);
ALTER AVAILABILITY GROUP [AG1] MODIFY REPLICA ON N'SQL01'
  WITH (FAILOVER_MODE = MANUAL);
ALTER AVAILABILITY GROUP [AG1] MODIFY REPLICA ON N'SQL02'
  WITH (AVAILABILITY_MODE = SYNCHRONOUS_COMMIT);

2. Upgrade remote and asynchronous secondaries first

Start with DR replicas and any replica you won't fail over to. While its SQL Server is offline, the primary keeps that replica's log. Watch log use on the primary:

SELECT name, log_reuse_wait_desc FROM sys.databases WHERE name = N'AppDb';
DBCC SQLPERF(LOGSPACE);

If the log is filling and the upgrade is overrunning, you can remove the database from that replica and re-seed it afterwards. That's cheaper than a full log on the primary.

3. Upgrade the synchronous secondary you will fail over to

Run setup on the node, apply the target cumulative update in the same window, and reboot if setup asks you to. After the restart, data movement from the lower-version primary should resume automatically. If it doesn't, resume it on the secondary:

ALTER DATABASE [AppDb] SET HADR RESUME;

Wait for SYNCHRONIZED with a redo queue near zero. Redo on the upgraded secondary may be slower than usual while it catches up.

4. Pre-failover checkpoint

  • Take the full and log backups from the caution box above. Copy them off the primary's storage.
  • Script the logins with their SIDs (sp_help_revlogin or dbatools Export-DbaLogin).
  • Get the go/no-go decision. This is the last point at which rollback is just "uninstall the new version on the secondaries and re-seed".

5. Fail over to the upgraded secondary

Run on the target secondary (SQL02), not the primary:

ALTER AVAILABILITY GROUP [AG1] FAILOVER;

In PowerShell with dbatools:

Invoke-DbaAgFailover -SqlInstance SQL02 -AvailabilityGroup AG1 -Confirm:$false

When each database comes online on the new primary, its internal database version is upgraded, and the error log records the version steps. This can take longer than a normal failover, so allow for it in your timeout expectations. The old primary (SQL01) can no longer receive log, and its databases show as not synchronizing.

6. Upgrade the old primary

Run setup on SQL01, apply the same CU and reboot. Then resume data movement and confirm it's synchronized:

ALTER DATABASE [AppDb] SET HADR RESUME;  -- run on SQL01 if still suspended

7. Restore the original configuration

ALTER AVAILABILITY GROUP [AG1] MODIFY REPLICA ON N'SQL01'
  WITH (FAILOVER_MODE = AUTOMATIC);
ALTER AVAILABILITY GROUP [AG1] MODIFY REPLICA ON N'SQL02'
  WITH (FAILOVER_MODE = AUTOMATIC);

If you want the original node back as primary, fail back now. Both nodes are on the same version, so this is an ordinary planned failover.

Verify

  • Every replica reports the same ProductVersion and ProductUpdateLevel.
  • All databases are SYNCHRONIZED on the synchronous replicas and SYNCHRONIZING on the asynchronous ones, with no suspend reason in sys.dm_hadr_database_replica_states.suspend_reason_desc.
  • Read-only routing works again. Test it with ApplicationIntent=ReadOnly through the listener.
  • Backup jobs on your preferred backup replica succeed, and the next log backup chains on from the pre-failover one.
  • Agent jobs and SSIS packages ran on the new primary, and SSISDB has been upgraded if it applies.

Common traps

Symptom Cause Fix
Upgraded secondary stays NOT SYNCHRONIZING Data movement suspended after the restart ALTER DATABASE ... SET HADR RESUME on the secondary
Read-only app errors during the window Higher-version secondaries refuse reads Point reports at the primary temporarily, or accept the outage
Primary log grows during a long upgrade Offline replica still holding log truncation Remove the database from that replica and re-seed it later
Plans regress after the move New engine and optimizer fixes Keep the old compatibility level. Use Query Store to compare, then raise the level as a separate change
Failover went to a lower-version node Automatic failover was left on Set every replica to MANUAL before you start

Prevent it next time

  • Keep the AG version-uniform outside upgrade windows, and keep a scripted version of this runbook in source control.
  • Hold the compatibility level change for a week, with Query Store in READ_WRITE, so engine and optimizer changes stay separate.
  • Rehearse the runbook on a copy of the AG built from the same automation, and time step 5 there so stakeholders get a real number.