Automated Patching for SQL Server on Azure virtual machines (Resource Manager)
Automated Patching establishes a maintenance window for an Azure virtual machine running SQL Server. Automated Updates can only be installed during this maintenance window. For SQL Server, this restriction ensures that system updates and any associated restarts occur at the best possible time for the database.
Only Windows and SQL Server updates marked as Important or Critical are installed. Other SQL Server updates, such as service packs and cumulative updates that are not marked as Important or Critical, must be installed manually.
Automated Patching depends on the SQL Server infrastructure as a service (IaaS) Agent Extension.
To use Automated Patching, consider the following prerequisites:
- Windows Server 2008 R2
- Windows Server 2012
- Windows Server 2012 R2
- Windows Server 2016
SQL Server version:
- SQL Server 2008 R2
- SQL Server 2012
- SQL Server 2014
- SQL Server 2016
- SQL Server 2017
- Install the latest Azure PowerShell commands if you plan to configure Automated Patching with PowerShell.
This article has been updated to use the new Azure PowerShell Az module. You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. For Az module installation instructions, see Install Azure PowerShell.
Automated Patching relies on the SQL Server IaaS Agent Extension. Current SQL virtual machine gallery images add this extension by default. For more information, see SQL Server IaaS Agent Extension.
The following table describes the options that can be configured for Automated Patching. The actual configuration steps vary depending on whether you use the Azure portal or Azure Windows PowerShell commands.
|Automated Patching||Enable/Disable (Disabled)||Enables or disables Automated Patching for an Azure virtual machine.|
|Maintenance schedule||Everyday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday||The schedule for downloading and installing Windows, SQL Server, and Microsoft updates for your virtual machine.|
|Maintenance start hour||0-24||The local start time to update the virtual machine.|
|Maintenance window duration||30-180||The number of minutes permitted to complete the download and installation of updates.|
|Patch Category||Important||The category of Windows updates to download and install.|
Configure in the Azure portal
You can use the Azure portal to configure Automated Patching during provisioning or for existing VMs.
Use the Azure portal to configure Automated Patching when you create a new SQL Server virtual machine in the Resource Manager deployment model.
In the SQL Server settings tab, select Change configuration under Automated patching. The following Azure portal screenshot shows the SQL Automated Patching blade.
For more information, see Provision a SQL Server virtual machine on Azure.
The following screenshots are from the SQL virtual machines resource within the Azure portal. For end-of-support (EOS) SQL server VMs, and SQL Server VMs that have not been registered with the SQL VM resource provider, use the SQL Server configuration tab to manage your SQL Server VM instead.
For existing SQL Server virtual machines, open your SQL virtual machines resource and select Patching under Settings.
When you're finished, click the OK button on the bottom of the SQL Server configuration blade to save your changes.
If you are enabling Automated Patching for the first time, Azure configures the SQL Server IaaS Agent in the background. 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. After that the Azure portal reflects the new settings.
Configure with PowerShell
After provisioning your SQL VM, use PowerShell to configure Automated Patching.
In the following example, PowerShell is used to configure Automated Patching on an existing SQL Server VM. The New-AzVMSqlServerAutoPatchingConfig command configures a new maintenance window for automatic updates.
$vmname = "vmname" $resourcegroupname = "resourcegroupname" $aps = New-AzVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Thursday" -MaintenanceWindowStartingHour 11 -MaintenanceWindowDuration 120 -PatchCategory "Important"
s Set-AzVMSqlServerExtension -AutoPatchingSettings $aps -VMName $vmname -ResourceGroupName $resourcegroupname
If the extension is not already installed, installing it restarts SQL Server.
Based on this example, the following table describes the practical effect on the target Azure VM:
|DayOfWeek||Patches installed every Thursday.|
|MaintenanceWindowStartingHour||Begin updates at 11:00am.|
|MaintenanceWindowsDuration||Patches must be installed within 120 minutes. Based on the start time, they must complete by 1:00pm.|
|PatchCategory||The only possible setting for this parameter is Important. This installs Windows update marked Important; it does not install any SQL Server updates that are not included in this category.|
It could take several minutes to install and configure the SQL Server IaaS Agent.
To disable Automated Patching, run the same script without the -Enable parameter to the New-AzVMSqlServerAutoPatchingConfig. The absence of the -Enable parameter signals the command to disable the feature.
For information about other available automation tasks, see SQL Server IaaS Agent Extension.
For more information about running SQL Server on Azure VMs, see SQL Server on Azure virtual machines overview.