https://learn.microsoft.com/en-us/sql/database-engine/availability-groups/windows/upgrading-always-on-availability-group-replica-instances?view=sql-server-ver16

When upgrading a SQL Server instance that hosts an Always On availability group (AG) to a new SQL Server version, to a new SQL Server service pack or cumulative update, or when installing to a new Windows service pack or cumulative update, you can reduce downtime for the primary replica to only a single manual failover by performing a rolling upgrade (or two manual failovers if failing back to the original primary).

During the upgrade process, a secondary replica won’t be available for failover or for read-only operations, and after the upgrade, it may take some time for the secondary replica to catch up with the primary replica node depending upon the volume of activity on the primary replica node (so expect high network traffic).

Also be aware that after the initial failover to a secondary replica running a newer version of SQL Server, the databases in that AG will run through an upgrade process to bring them to the latest version. During this time, there will be no readable replicas for any of these databases. Downtime after the initial failover will depend on the number of databases in the AG. If you plan on failing back to the original primary, this step won’t be repeated when you fail back.

Rolling upgrade basics for availability groups

Observe the following guidelines when performing server upgrades or updates in order to minimize downtime and data loss for your AGs:

  • Before you start the rolling upgrade:
    • Perform a practice manual failover on at least one of your synchronous-commit replica instances
    • Protect your data by performing a full database backup on every availability database
    • Run DBCC CHECKDB on every availability database
  • Always upgrade the remote secondary replica instances first, then local secondary replica instances next, and the primary replica instance last.
  • Backups can’t occur on a database that is in the process of being upgraded. Prior to upgrading the secondary replicas, configure the automated backup preference to run backups only on the primary replica. During a version upgrade, no replicas are readable or available for backups. During a non-version upgrade, you can configure automated backups to run on secondary replicas prior to upgrading the primary replica.
  • During a version upgrade, readable secondaries can’t be read after an upgrade of the readable secondary and before either the primary replica is failed over to an upgraded secondary, or the primary replica is upgraded.
  • To prevent the AG from unintended failovers during the upgrade process, remove availability failover from all synchronous-commit replicas before you begin.
  • Don’t upgrade the primary replica instance before failing over the AG to an upgraded instance with a secondary replica first. Otherwise, client applications may suffer extended downtime during the upgrade on the primary replica instance.
  • Always fail over the AG to a synchronous-commit secondary replica instance. If you fail over to an asynchronous-commit secondary replica instance, the databases are vulnerable to data loss, and data movement is automatically suspended until you manually resume data movement.
  • Don’t upgrade the primary replica instance before upgrading or updating any other secondary replica instance. An upgraded primary replica can no longer ship logs to any secondary replica whose SQL Server instance that hasn’t yet been upgraded to the same version. When data movement to a secondary replica is suspended, no automatic failover can occur for that replica, and your availability databases are vulnerable to data loss. This also applies during a rolling upgrade where you manually failover from an old primary to a new primary. As such, after you upgrade the old primary, you may need to resume synchronization.
  • Before failing over an AG, verify that the synchronization state of the failover target is SYNCHRONIZED. WarningInstalling a new instance or new version of SQL Server to a server that has an older version of SQL Server installed may inadvertently cause an outage for any availability group that is hosted by the older version of SQL Server. This is because during the installation of the instance or version of SQL Server, the SQL Server high availability module (RHS.EXE) gets upgraded. This results in a temporary interruption of your existing availability groups in the primary role on the server. Therefore, it is highly recommended that you do one of the following when installing a newer version of SQL Server to a system already hosting an older version of SQL Server with an availability group:
    • Install the new version of SQL Server during a maintenance window.
    • Fail over the availability group to the secondary replica so it is not primary during the installation of the new SQL Server instance.

Rolling upgrade process

In practice, the exact process depends on factors such as the deployment topology of your AGs and the commit mode of each replica. But in the simplest scenario, a rolling upgrade is a multi-stage process that in its simplest form involves the following steps:

Diagram of AG Upgrade in HADR Scenario.
  1. Remove automatic failover on all synchronous-commit replicas
  2. Upgrade all asynchronous-commit secondary replica instances.
  3. Upgrade all remote synchronous-commit secondary replica instances.
  4. Upgrade all local synchronous-commit secondary replica instances.
  5. Manually fail over the AG to a (newly upgraded) local synchronous-commit secondary replica.
  6. Upgrade or update the local replica instance that formerly hosted the primary replica.
  7. Configure automatic failover partners as desired.

If necessary, you can perform an extra manual failover to return the AG to its original configuration.

 Note

Upgrading a synchronous-commit replica and taking it offline will not delay transactions on the primary. Once the secondary replica is disconnected, transactions are committed on the primary without waiting for logs to harden on the secondary replica.

If REQUIRED_SYNCHRONIZED_SECONDARIES_TO_COMMIT is set to either 1 or 2, the Primary replica may be unavailable for read/writes when a corresponding number of sync secondary replicas are not available during the update process.

 Note

When you perform an in-place upgrade of a secondary replica to a newer version of SQL Server, the database inside the availability group remains in the Synchronizing / In recovery or Synchronized / In Recovery state until the availability group is manually failed over, which finishes the recovery and upgrades the database. An upgraded primary replica can no longer ship logs to any lower version secondary replica and data movement stops and no automatic failover can occur for that replica, and your availability databases are vulnerable to data loss. After you upgrade the old primary, you may need to resume synchronization. It is recommended to upgrade all secondary replicas before failing over to a replica with the new version. That way you have the option of doing a failover after the database(es) are upgraded to the new format.

AG with one remote secondary replica

If you have deployed an AG only for disaster recovery, you may need to fail over the AG to an asynchronous-commit secondary replica. Such configuration is illustrated by the following figure:

Diagram of AG Upgrade in DR Scenario.

In this situation, you must fail over the AG to the asynchronous-commit secondary replica during the rolling upgrade. To prevent data loss, change the commit mode to synchronous commit, and wait for the secondary replica to be synchronized before you fail over the AG. Therefore, the rolling upgrade process may look as follows:

  1. Upgrade the secondary replica instance on the remote site
  2. Change the commit mode to synchronous commit
  3. Wait until synchronization state is SYNCHRONIZED
  4. Fail over the AG to the secondary replica on the remote site
  5. Upgrade or update the local (primary site) replica instance
  6. Fail over the AG back to the primary site
  7. Change the commit mode to asynchronous commit

Since the synchronous-commit mode isn’t a recommended setting for data synchronization to a remote site, client applications may notice an immediate increase in database latency after the setting change. Moreover, performing a failover causes all unacknowledged log messages to be discarded. The number discarded log messages can be significant due to the high network latency between the two sites, causing clients to experience a high volume of transactional failure. You can minimize the effect on client applications by doing the following actions:

  • Carefully select a maintenance window during low client traffic
  • While upgrading or updating SQL Server on the primary site, change the availability mode back to asynchronous commit, then revert to synchronous commit when you are ready to fail over to the primary site again
Last modified: April 16, 2024

Author

Comments

Write a Reply or Comment