Azure 虚拟机(资源管理器)上 SQL Server 的自动修补Automated Patching for SQL Server on Azure virtual machines (Resource Manager)

适用于: Azure VM 上的 SQL Server

自动修补将为运行 SQL Server 的 Azure 虚拟机建立一个维护时段。Automated Patching establishes a maintenance window for an Azure virtual machine running SQL Server. 只能在此维护时段内安装自动更新。Automated Updates can only be installed during this maintenance window. 对于 SQL Server,此限制可以确保在数据库的最佳可能时间发生系统更新和任何关联的重新启动。For SQL Server, this restriction ensures that system updates and any associated restarts occur at the best possible time for the database.


仅安装标记为“重要”或“关键”的 Windows 和 SQL Server 更新 。Only Windows and SQL Server updates marked as Important or Critical are installed. 其他 SQL Server 更新(如未标记为“重要”或“关键”的服务包和累积更新)则必须手动安装 。Other SQL Server updates, such as service packs and cumulative updates that are not marked as Important or Critical, must be installed manually.

自动修补依赖于 SQL Server 基础架构即服务 (IaaS) 代理扩展Automated Patching depends on the SQL Server infrastructure as a service (IaaS) Agent Extension.


若要使用自动修补,请考虑以下先决条件:To use Automated Patching, consider the following prerequisites:

操作系统Operating system:

  • Windows Server 2008 R2Windows Server 2008 R2
  • Windows Server 2012Windows Server 2012
  • Windows Server 2012 R2Windows Server 2012 R2
  • Windows Server 2016Windows Server 2016
  • Windows Server 2019Windows Server 2019

SQL Server 版本SQL Server version:

  • SQL Server 2008 R2SQL Server 2008 R2
  • SQL Server 2012SQL Server 2012
  • SQL Server 2014SQL Server 2014
  • SQL Server 2016SQL Server 2016
  • SQL Server 2017SQL Server 2017
  • SQL Server 2019SQL Server 2019

Azure PowerShellAzure PowerShell:


本文已经过更新,以便使用 Azure Az PowerShell 模块。This article has been updated to use the Azure Az PowerShell module. 若要与 Azure 交互,建议使用的 PowerShell 模块是 Az PowerShell 模块。The Az PowerShell module is the recommended PowerShell module for interacting with Azure. 若要开始使用 Az PowerShell 模块,请参阅安装 Azure PowerShellTo get started with the Az PowerShell module, see Install Azure PowerShell. 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 AzTo learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.


自动修补依赖 SQL Server IaaS 代理扩展。Automated Patching relies on the SQL Server IaaS Agent Extension. 当前的 SQL 虚拟机库映像默认添加此扩展。Current SQL virtual machine gallery images add this extension by default. 有关详细信息,请参阅 SQL Server IaaS 代理扩展For more information, see SQL Server IaaS Agent Extension.


下表描述了可为自动修补配置的选项。The following table describes the options that can be configured for Automated Patching. 实际配置步骤根据使用的是 Azure 门户还是 Azure Windows PowerShell 命令而有所不同。The actual configuration steps vary depending on whether you use the Azure portal or Azure Windows PowerShell commands.

设置Setting 可能的值Possible values 说明Description
自动修补Automated Patching 启用/禁用(已禁用)Enable/Disable (Disabled) 为 Azure 虚拟机启用或禁用自动修补。Enables or disables Automated Patching for an Azure virtual machine.
维护计划Maintenance schedule 每天、星期一、星期二、星期三、星期四、星期五、星期六、星期日Everyday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday 为虚拟机下载和安装 Windows、SQL Server 和 Azure 更新的计划。The schedule for downloading and installing Windows, SQL Server, and Azure updates for your virtual machine.
维护开始时间Maintenance start hour 0-240-24 更新虚拟机的本地开始时间。The local start time to update the virtual machine.
维护时段持续时间Maintenance window duration 30-18030-180 允许完成更新下载和安装的分钟数。The number of minutes permitted to complete the download and installation of updates.
修补程序类别Patch Category 重要Important 要下载并安装的 Windows 更新类别。The category of Windows updates to download and install.

在 Azure 门户中配置Configure in the Azure portal

可以在预配期间或针对现有的 VM,使用 Azure 门户配置自动修补。You can use the Azure portal to configure Automated Patching during provisioning or for existing VMs.

新的 VMNew VMs

在资源管理器部署模型中创建新的 SQL Server 虚拟机时,可以使用 Azure 门户配置自动修补。Use the Azure portal to configure Automated Patching when you create a new SQL Server virtual machine in the Resource Manager deployment model.

在“SQL Server 设置”选项卡中,选择“自动修补” 。In the SQL Server settings tab, select Automated patching. 下面的 Azure 门户屏幕截图显示了“SQL 自动修补”边栏选项卡。The following Azure portal screenshot shows the SQL Automated Patching blade.

Azure 门户中的 SQL 自动修补

有关详细信息,请参阅在 Azure 上预配 SQL Server 虚拟机For more information, see Provision a SQL Server virtual machine on Azure.

现有 VMExisting VMs

对于现有的 SQL Server 虚拟机,请选择 SQL Server 虚拟机。For existing SQL Server virtual machines, select your SQL Server virtual machine. 然后选择“设置”边栏选项卡的“SQL Server 配置”部分。 Then select the SQL Server configuration section of the Settings blade.

现有 VM 的 SQL 自动修补

在“SQL Server 配置”边栏选项卡的“自动修补”部分中,单击“编辑”按钮。In the SQL Server configuration blade, click the Edit button in the Automated patching section.

配置现有 VM 的 SQL 自动修补

完成后,单击“SQL Server 配置”边栏选项卡底部的“确定”按钮保存更改 。When you're finished, click the OK button on the bottom of the SQL Server configuration blade to save your changes.

当你首次启用自动修补时,Azure 会在后台配置 SQL Server IaaS 代理。If you are enabling Automated Patching for the first time, Azure configures the SQL Server IaaS Agent in the background. 在此期间,Azure 门户可能不会显示已配置自动修补。During this time, the Azure portal might not show that Automated Patching is configured. 请等待几分钟,以便安装和配置代理。Wait several minutes for the agent to be installed and configured. 随后,Azure 门户将反映新设置。After that the Azure portal reflects the new settings.

使用 PowerShell 配置Configure with PowerShell

预配 SQL VM 后,使用 PowerShell 配置自动修补。After provisioning your SQL VM, use PowerShell to configure Automated Patching.

以下示例使用 PowerShell 在现有的 SQL Server VM 上配置自动修补。In the following example, PowerShell is used to configure Automated Patching on an existing SQL Server VM. New-AzVMSqlServerAutoPatchingConfig 命令可为自动更新配置新的维护时段。The New-AzVMSqlServerAutoPatchingConfig command configures a new maintenance window for automatic updates.

# Sign in the Azure China Cloud
Connect-AzAccount -Environment AzureChinaCloud

$vmname = "vmname"
$resourcegroupname = "resourcegroupname"
$aps = New-AzVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Thursday" -MaintenanceWindowStartingHour 11 -MaintenanceWindowDuration 120  -PatchCategory "Important"

Set-AzVMSqlServerExtension -AutoPatchingSettings $aps -VMName $vmname -ResourceGroupName $resourcegroupname


如果尚未安装该扩展,安装该扩展将会重新启动 SQL Server。If the extension is not already installed, installing it restarts SQL Server.

下表根据此示例描述了对目标 Azure VM 产生的实际效果:Based on this example, the following table describes the practical effect on the target Azure VM:

参数Parameter 效果Effect
DayOfWeekDayOfWeek 每个星期四安装修补程序。Patches installed every Thursday.
MaintenanceWindowStartingHourMaintenanceWindowStartingHour 在上午 11:00 开始更新。Begin updates at 11:00am.
MaintenanceWindowsDurationMaintenanceWindowsDuration 必须在 120 分钟内完成修补程序安装。Patches must be installed within 120 minutes. 根据开始时间,修补必须在下午 1:00 之前完成。Based on the start time, they must complete by 1:00pm.
PatchCategoryPatchCategory 此参数的唯一可能设置为 ImportantThe only possible setting for this parameter is Important. 这会安装标记为“重要”的 Windows 更新;不安装未包含在此类别中的任何 SQL Server 更新。This installs Windows update marked Important; it does not install any SQL Server updates that are not included in this category.

可能需要花费几分钟来安装和配置 SQL Server IaaS 代理。It could take several minutes to install and configure the SQL Server IaaS Agent.

若要禁用自动修补,请在不使用 -Enable 参数的情况下对 New-AzVMSqlServerAutoPatchingConfig 运行同一脚本。To disable Automated Patching, run the same script without the -Enable parameter to the New-AzVMSqlServerAutoPatchingConfig. 缺少 -Enable 参数会向该命令发出指示以禁用此功能。The absence of the -Enable parameter signals the command to disable the feature.

后续步骤Next steps

有关其他可用自动化任务的信息,请参阅 SQL Server IaaS 代理扩展For information about other available automation tasks, see SQL Server IaaS Agent Extension.

有关在 Azure VM 上运行 SQL Server 的详细信息,请参阅 Azure 虚拟机上的 SQL Server 概述For more information about running SQL Server on Azure VMs, see SQL Server on Azure virtual machines overview.