升级镜像实例Upgrading Mirrored Instances

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions)

在将 SQL ServerSQL Server 镜像实例升级到新 SQL Server 2019 (15.x)SQL Server 2019 (15.x) 版本、新 SQL ServerSQL Server服务包或积累更新,或升级到新 Windows 服务包或积累更新时,可以通过执行滚动升级将每个镜像数据库的停机时间降低到仅需一次手动故障转移(如果无法故障转移回原始的主要副本,则需两次手动故障转移)。When upgrading a SQL ServerSQL Server mirrored instance to a new SQL Server 2019 (15.x)SQL Server 2019 (15.x) version, to a new SQL ServerSQL Serverservice pack or cumulative update, or to a new Windows service pack or cumulative update, you can reduce downtime for each mirrored database to only a single manual failover by performing a rolling upgrade (or two manual failovers if failing back to the original primary). 滚动升级是一个多阶段过程,其最简单的形式如下:升级当前在镜像会话中充当镜像服务器的 SQL Server 2019 (15.x)SQL Server 2019 (15.x) 实例,然后对镜像数据库进行手动故障转移,升级以前的主体 SQL Server 2019 (15.x)SQL Server 2019 (15.x) 实例,并恢复镜像。A rolling upgrade is a multi-stage process that in its simplest form involves upgrading the SQL Server 2019 (15.x)SQL Server 2019 (15.x) instance that is currently acting as the mirror server in a mirroring session, then manually failing over the mirrored database, upgrading the former principal SQL Server 2019 (15.x)SQL Server 2019 (15.x) instance, and resuming mirroring. 实际上,确切过程将取决于运行模式以及在所升级的 SQL Server 2019 (15.x)SQL Server 2019 (15.x) 实例上运行的镜像会话的编号和布局。In practice, the exact process will depend on the operating mode and the number and layout of mirroring session running on the SQL Server 2019 (15.x)SQL Server 2019 (15.x) instances that you are upgrading.

备注

有关在迁移过程中使用数据库镜像与日志传送的信息,请下载此 数据库镜像和日志传送白皮书For information on using database mirroring with log shipping during a migration, download this Database Mirroring and Log Shipping whitepaper.

先决条件Prerequisites

开始之前,请仔细阅读以下重要信息:Before you begin, review the following important information:

  • 支持的版本和版本升级:验证是否可以从你的 Windows 操作系统版本和 SQL Server 版本升级到 SQL Server 2016。Supported Version and Edition Upgrades: Verify that you can upgrade to SQL Server 2016 from your version of the Windows operating system and version of SQL Server. 例如,不能直接从 SQL Server 2005 实例升级到 SQL Server 2019 (15.x)SQL Server 2019 (15.x)For example, you cannot upgrade directly from a SQL Server 2005 instance to SQL Server 2019 (15.x)SQL Server 2019 (15.x).

  • 选择数据库引擎升级方法:检查支持的版本和版本升级以及环境中安装的其他组件,并据此选择适当的升级方法和步骤,按正确顺序升级组件。Choose a Database Engine Upgrade Method: Select the appropriate upgrade method and steps based on your review of supported version and edition upgrades and also based on other components installed in your environment to upgrade components in the correct order.

  • 计划并测试数据库引擎升级计划:查看发行说明和已知升级问题、预升级清单,并制定和测试升级计划。Plan and Test the Database Engine Upgrade Plan: Review the release notes and known upgrade issues, the pre-upgrade checklist, and develop and test the upgrade plan.

  • 安装 SQL Server 2016 的硬件和软件要求:查看安装 SQL Server 2019 (15.x)SQL Server 2019 (15.x) 的软件要求。Hardware and Software Requirements for Installing SQL Server 2016: Review the software requirements for installing SQL Server 2019 (15.x)SQL Server 2019 (15.x). 如果需要其他软件,则应在升级过程开始之前在每个节点上安装该软件,从而最大程度减少故障时间。If additional software is required, install it on each node before you begin the upgrade process to minimize any downtime.

在开始滚动升级之前,建议您:Before starting a rolling upgrade, we recommend that you:

  1. 至少对一个镜像会话执行实际手动故障转移:Perform a practice manual failover on at least one of your mirroring sessions:

    备注

    有关手动故障转移如何实现的详细信息,请参阅数据库镜像会话期间的角色切换 (SQL Server)For information about how manual failover works, see Role Switching During a Database Mirroring Session (SQL Server).

  2. 保护数据:Protect your data:

    1. 对每个主体数据库执行完整数据库备份:Perform a full database backup on every principal database:

      创建完整数据库备份 (SQL Server)Create a Full Database Backup (SQL Server).

    2. 在每个主体服务器上运行 DBCC CHECKDB 命令。Run the DBCC CHECKDB command on every principal database.

滚动升级的阶段Stages of a Rolling Upgrade

滚动升级的具体步骤取决于镜像配置的运行模式。The specific steps of a rolling upgrade depend on the operating mode of the mirroring configuration. 不过基本阶段是相同的。However, the basic stages are the same.

备注

有关运行模式的详细信息,请参阅 数据库镜像运行模式For information about the operating modes, see Database Mirroring Operating Modes.

下图是显示各个运行模式的滚动升级基本阶段的流程图。The following illustration is a flowchart that shows the basic stages of a rolling upgrade for each operating mode. 该图后面的内容介绍了对应的步骤。The corresponding procedures are described after the illustration.

显示滚动升级步骤的流程图Flowchart showing steps of a rolling upgrade

重要

在并发镜像会话中,一个服务器实例可能扮演不同的镜像角色(主体服务器、镜像服务器或见证服务器)。A server instance might be performing different mirroring roles (principal server, mirror server, or witness) in concurrent mirroring sessions. 在这种情况下,必须相应地调整基本滚动升级过程。In this case, you will have to adapt the basic rolling upgrade process accordingly. 有关详细信息,请参阅 数据库镜像会话期间的角色切换 (SQL Server)的各版本中均未提供见证服务器实例。For more information, see Role Switching During a Database Mirroring Session (SQL Server).

备注

在许多情况下,滚动升级完成后,将会故障回复到原始主体服务器。In many cases, after the rolling upgrade is completed, you will failback to the original principal server.

将会话从高性能模式更改为高安全模式To change a session from high-performance mode to high-safety mode

  1. 如果镜像会话在高性能模式下运行,则在执行滚动升级之前,将运行模式更改为不带自动故障转移功能的高安全模式。If a mirroring session is running in high-performance mode, before you perform a rolling upgrade, change the operating mode to high safety without automatic failover.

    重要

    如果镜像服务器与主体服务器在地理位置上存有一定距离,则可能不适宜进行滚动升级。If the mirror server is geographically distant from the principal server, a rolling upgrade might be inappropriate.

从会话中删除见证服务器To remove a witness from a session

  1. 如果镜像会话包括见证服务器,则建议您在执行滚动升级之前删除该见证服务器。If a mirroring session involves a witness, we recommend that you remove the witness before you perform a rolling upgrade. 否则,在升级镜像服务器实例时,数据库的可用性将取决于仍然连接至主体服务器实例的见证服务器。Otherwise, when the mirror server instance is being upgraded, database availability depends on the witness that remains connected to the principal server instance. 删除见证服务器之后,可以在滚动升级过程中随时对其进行升级,而不会有数据库停机的风险。After you remove a witness, you can upgrade it at any time during the rolling upgrade process without risking database downtime.

执行滚动升级To perform the rolling upgrade

  1. 为了最大限度地减少停机时间,我们建议:通过更新任何当前在其所有镜像会话中均为镜像服务器的镜像伙伴开始滚动升级。To minimize downtime, we recommend the following: Start the rolling upgrade by updating any mirroring partner that is currently the mirror server in all its mirroring sessions. 此时,可能需要更新多个服务器实例。You might have to update multiple server instances at this point.

    备注

    在滚动升级过程中可以随时升级见证服务器。A witness can be upgraded at any point in the rolling upgrade process. 例如,如果某个服务器实例在会话 1 中为镜像服务器,在会话 2 中为见证服务器,则可以立即升级此服务器实例。For example, if a server instance is a mirror server in Session 1 and is a witness in Session 2, you can upgrade the server instance now.

    要首先升级的服务器实例是由镜像会话的当前配置决定的,如下所示:The server instance to upgrade first depends on the current configuration of your mirroring sessions, as follows:

    • 如果任何服务器实例在其所有镜像会话中均已为镜像服务器,则将此服务器实例升级为新版本。If any server instance is already the mirror server in all its mirroring sessions, upgrade the server instance to the new version.

    • 如果在任何镜像会话中所有服务器实例当前都是主体服务器,则选择一个要首先升级的服务器实例。If all your server instances are currently the principal server in any mirroring sessions, select one server instance to upgrade first. 然后,对其每个主体数据库进行手动故障转移并升级该服务器实例。Then, manually fail over each of its principal databases and upgrade that server instance.

    升级完成后,服务器实例将自动重新加入其每个镜像会话。After being upgraded, a server instance automatically rejoins each of its mirroring sessions.

  2. 对于其镜像服务器实例刚完成升级的每个镜像会话,请等待会话进行同步。For each mirroring session whose mirror server instance has just been upgraded, wait for the session to synchronize. 然后,连接到主体服务器实例并对会话进行手动故障转移。Then, connect to the principal server instance, and manually fail over the session. 故障转移后,已升级的服务器实例成为该会话的主体服务器,而以前的主体服务成为镜像服务器。On failover, the upgraded server instance becomes the principal server for that session, and the former principal server becomes the mirror server.

    此步骤的目的是让其他服务器实例在其作为伙伴的每个镜像会话中成为镜像服务器。The goal of this step is for another server instance to become the mirror server in every mirroring session in which it is a partner.

    在出现故障时转移到已升级的服务器实例后的限制。Restrictions after you failover to an upgraded server instance.

    在从早期服务器实例故障转移到 SQL Server 2019 (15.x)SQL Server 2019 (15.x) 服务器实例后,数据库会话将挂起。After failing over from an earlier server instance to a SQL Server 2019 (15.x)SQL Server 2019 (15.x) server instance, the database session is suspended. 直到升级完其他伙伴后,此会话才能继续。It cannot be resumed until the other partner has been upgraded. 但主体服务器仍然接受连接,并允许对主体数据库进行数据访问和修改。However, the principal server is still accepting connections and allowing data access and modifications on the principal database.

    备注

    如果建立新镜像会话,则要求所有服务器实例运行相同版本的 SQL ServerSQL ServerEstablishing a new mirroring session requires that the server instances all be running the same version of SQL ServerSQL Server.

  3. 完成故障转移后,我们建议您在主体数据库上运行 DBCC CHECKDB 命令。After you fail over, we recommend that you run the DBCC CHECKDB command on the principal database.

  4. 升级在其作为伙伴的所有镜像会话中目前为镜像服务器的每个服务器实例。Upgrade each server instance that is now the mirror server in all mirroring sessions in which it is a partner. 此时,可能需要更新多个服务器。You might have to update multiple servers at this point.

    重要

    在复杂的镜像配置中,某个服务器实例在一个或多个镜像会话中可能仍作为原始主体服务器。In a complex mirroring configuration, some server instance might still be the original principal server in one or more mirroring sessions. 对这些服务器实例重复步骤 2-4,直至涉及的所有实例均已升级。Repeat steps 2-4 for those server instances until all instances involved are upgraded.

  5. 继续镜像会话。Resume the mirroring session.

    备注

    升级完见证服务器并将其重新添加到镜像会话中之后,自动故障转移功能才会起作用。Automatic failover will not work until the witness has been upgraded and added back into the mirroring session.

  6. 升级在其所有镜像会话中为见证服务器的任何剩余服务器实例。Upgrade any remaining server instance that is the witness in all its mirroring sessions. 在已升级的见证服务器重新加入镜像会话之后,自动故障转移功能将重新变为可用。After an upgraded witness rejoins a mirroring session, automatic failover becomes possible again. 此时,可能需要更新多个服务器。You might have to update multiple servers at this point.

将会话恢复为高性能模式To return a session to high-performance mode

  1. 可以选择使用下列方法之一返回高性能模式:Optionally, return to high-performance mode by using one of the following methods:

    • SQL Server Management StudioSQL Server Management Studio 中:使用“数据库属性”对话框中的镜像页将“操作模式”选项更改为“高性能(同步)” 。In SQL Server Management StudioSQL Server Management Studio: Change the Operating mode option to High performance (asynchronous) by using the Mirroring Page of the Database Properties dialog box.

    • Transact-SQLTransact-SQL 中:使用 ALTER DATABASE 将事务安全设置为 OFF。In Transact-SQLTransact-SQL: Use ALTER DATABASEto set transaction safety to OFF.

将见证服务器重新添加到镜像会话中To add a witness back into a mirroring session

  1. 在高安全模式下,可以选择让见证服务器重新回到每个镜像会话中。Optionally, in high-safety mode, reestablish the witness to each mirroring session.

    返回见证服务器To return a witness

另请参阅See Also

使用安装向导(安装程序)升级到 SQL Server 2016 Upgrade to SQL Server 2016 Using the Installation Wizard (Setup)
从命令提示符安装 SQL Server 2016 Install SQL Server 2016 from the Command Prompt
ALTER DATABASE 数据库镜像 (Transact-SQL) ALTER DATABASE Database Mirroring (Transact-SQL)
BACKUP (Transact-SQL) BACKUP (Transact-SQL)
查看镜像数据库的状态 (SQL Server Management Studio) View the State of a Mirrored Database (SQL Server Management Studio)
数据库镜像 (SQL Server) Database Mirroring (SQL Server)
数据库镜像会话期间的角色切换 (SQL Server) Role Switching During a Database Mirroring Session (SQL Server)
在数据库镜像会话中强制服务 (Transact-SQL) Force Service in a Database Mirroring Session (Transact-SQL)
启动数据库镜像监视器 (SQL Server Management Studio) Start Database Mirroring Monitor (SQL Server Management Studio)
数据库镜像运行模式Database Mirroring Operating Modes