The ability to change to a different maintenance window is not available for every service level or in every region. For details on feature availability, see Maintenance window availability.
To configure the maintenance window when you create a database, elastic pool, or managed instance, set the desired Maintenance window on the Additional settings page.
Set the maintenance window while creating a single database or elastic pool
For step-by-step information on creating a new database or pool, see Create an Azure SQL Database single database.
Set the maintenance window while creating a managed instance
For step-by-step information on creating a new managed instance, see Create an Azure SQL Managed Instance.
The following examples show how to configure the maintenance window using Azure PowerShell. You can install Azure PowerShell, or use the Azure Cloud Shell.
Launch Azure Cloud Shell
The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured to use with your account.
To open the Cloud Shell, select Try it from the upper right corner of a code block. You can also launch Cloud Shell in a separate browser tab by going to https://shell.azure.com.
When Cloud Shell opens, verify that PowerShell is selected for your environment. Subsequent sessions will use Azure CLI in a PowerShell environment. Select Copy to copy the blocks of code, paste it into the Cloud Shell, and press Enter to run it.
Discover available maintenance windows
When setting the maintenance window, each region has its own maintenance window options that correspond to the timezone for the region the database or pool is located.
Discover SQL Database and elastic pool maintenance windows
The following example returns the available maintenance windows for the eastus2 region using the Get-AzMaintenancePublicConfiguration cmdlet. For databases and elastic pools, set MaintenanceScope
to SQLDB
.
$location = "eastus2"
Write-Host "Available maintenance schedules in ${location}:"
$configurations = Get-AzMaintenancePublicConfiguration
$configurations | ?{ $_.Location -eq $location -and $_.MaintenanceScope -eq "SQLDB"}
Discover SQL Managed Instance maintenance windows
The following example returns the available maintenance windows for the eastus2 region using the Get-AzMaintenancePublicConfiguration cmdlet. For managed instances, set MaintenanceScope
to SQLManagedInstance
.
$location = "eastus2"
Write-Host "Available maintenance schedules in ${location}:"
$configurations = Get-AzMaintenancePublicConfiguration
$configurations | ?{ $_.Location -eq $location -and $_.MaintenanceScope -eq "SQLManagedInstance"}
Set the maintenance window while creating a single database
The following example creates a new database and sets the maintenance window using the New-AzSqlDatabase cmdlet. The -MaintenanceConfigurationId
must be set to a valid value for your database's region. To get valid values for your region, see Discover available maintenance windows.
# Set variables for your database
$resourceGroupName = "your_resource_group_name"
$serverName = "your_server_name"
$databaseName = "your_db_name"
# Set selected maintenance window
$maintenanceConfig = "SQL_EastUS2_DB_1"
Write-host "Creating a standard-series (Gen5) 2 vCore database with maintenance window ${maintenanceConfig} ..."
$database = New-AzSqlDatabase `
-ResourceGroupName $resourceGroupName `
-ServerName $serverName `
-DatabaseName $databaseName `
-Edition GeneralPurpose `
-ComputeGeneration Gen5 `
-VCore 2 `
-MaintenanceConfigurationId $maintenanceConfig
$database
Set the maintenance window while creating an elastic pool
The following example creates a new elastic pool and sets the maintenance window using the New-AzSqlElasticPool cmdlet. The maintenance window is set on the elastic pool, so all databases in the pool have the pool's maintenance window schedule. The -MaintenanceConfigurationId
must be set to a valid value for your pool's region. To get valid values for your region, see Discover available maintenance windows.
# Set variables for your pool
$resourceGroupName = "your_resource_group_name"
$serverName = "your_server_name"
$poolName = "your_pool_name"
# Set selected maintenance window
$maintenanceConfig = "SQL_EastUS2_DB_2"
Write-host "Creating a Standard 50 pool with maintenance window ${maintenanceConfig} ..."
$pool = New-AzSqlElasticPool `
-ResourceGroupName $resourceGroupName `
-ServerName $serverName `
-ElasticPoolName $poolName `
-Edition "Standard" `
-Dtu 50 `
-DatabaseDtuMin 10 `
-DatabaseDtuMax 20 `
-MaintenanceConfigurationId $maintenanceConfig
$pool
Set the maintenance window while creating a managed instance
The following example creates a new managed instance and sets the maintenance window using the New-AzSqlInstance cmdlet. The maintenance window is set on the instance, so all databases in the instance have the instance's maintenance window schedule. For -MaintenanceConfigurationId
, the MaintenanceConfigName must be a valid value for your instance's region. To get valid values for your region, see Discover available maintenance windows.
New-AzSqlInstance -Name "your_mi_name" `
-ResourceGroupName "your_resource_group_name" `
-Location "your_mi_location" `
-SubnetId /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/Microsoft.Network/virtualNetworks/{VNETName}/subnets/{SubnetName} `
-MaintenanceConfigurationId "/subscriptions/{SubID}/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_{Region}_{MaintenanceConfigName}" `
-AsJob
The following examples show how to configure the maintenance window using Azure CLI. You can install Azure CLI, or use the Azure Cloud Shell.
Configuring the maintenance window with Azure CLI is only available for SQL Managed Instance.
Launch Azure Cloud Shell
The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured to use with your account.
To open the Cloud Shell, select Try it from the upper right corner of a code block. You can also launch Cloud Shell in a separate browser tab by going to https://shell.azure.com.
When Cloud Shell opens, verify that Bash is selected for your environment. Subsequent sessions will use Azure CLI in a Bash environment. Select Copy to copy the blocks of code, paste it into the Cloud Shell, and press Enter to run it.
Sign in to Azure
Cloud Shell is automatically authenticated under the initial account signed-in with. Use the following script to sign in using a different subscription, replacing <Subscription ID>
with your Azure Subscription ID. If you don't have an Azure subscription, create an Azure free account before you begin.
subscription="<subscriptionId>" # add subscription here
az account set -s $subscription # ...or use 'az login'
For more information, see set active subscription or log in interactively
Discover available maintenance windows
When setting the maintenance window, each region has its own maintenance window options that correspond to the timezone for the region the database or pool is located.
Discover SQL Database and elastic pool maintenance windows
The following example returns the available maintenance windows for the eastus2 region using the az maintenance public-configuration list
command. For databases and elastic pools, set maintenanceScope
to SQLDB
.
location="eastus2"
az maintenance public-configuration list --query "[?location=='$location'&&contains(maintenanceScope,'SQLDB')]"
Discover SQL Managed Instance maintenance windows
The following example returns the available maintenance windows for the eastus2 region using the az maintenance public-configuration list
command. For managed instances, set maintenanceScope
to SQLManagedInstance
.
az maintenance public-configuration list --query "[?location=='eastus2'&&contains(maintenanceScope,'SQLManagedInstance')]"
Set the maintenance window while creating a single database
The following example creates a new database and sets the maintenance window using the az sql db create command. The --maint-config-id
(or -m
) must be set to a valid value for your database's region. To get valid values for your region, see Discover available maintenance windows.
# Set variables for your database
resourceGroupName="your_resource_group_name"
serverName="your_server_name"
databaseName="your_db_name"
# Set selected maintenance window
maintenanceConfig="SQL_EastUS2_DB_1"
# Create database
az sql db create \
--resource-group $resourceGroupName \
--server $serverName \
--name $databaseName \
--edition GeneralPurpose \
--family Gen5 \
--capacity 2 \
--maint-config-id $maintenanceConfig
Set the maintenance window while creating an elastic pool
The following example creates a new elastic pool and sets the maintenance window using the az sql elastic-pool create cmdlet. The maintenance window is set on the elastic pool, so all databases in the pool have the pool's maintenance window schedule. The --maint-config-id
(or -m
) must be set to a valid value for your pool's region. To get valid values for your region, see Discover available maintenance windows.
# Set variables for your pool
resourceGroupName="your_resource_group_name"
serverName="your_server_name"
poolName="your_pool_name"
# Set selected maintenance window
maintenanceConfig="SQL_EastUS2_DB_2"
# Create elastic pool
az sql elastic-pool create \
--resource-group $resourceGroupName \
--server $serverName \
--name $poolName \
--edition GeneralPurpose \
--family Gen5 \
--capacity 2 \
--maint-config-id $maintenanceConfig
Set the maintenance window while creating a managed instance
The following example creates a new managed instance and sets the maintenance window using az sql mi create. The maintenance window is set on the instance, so all databases in the instance have the instance's maintenance window schedule. MaintenanceConfigName must be a valid value for your instance's region. To get valid values for your region, see Discover available maintenance windows.
az sql mi create -g mygroup -n myinstance -l mylocation -i -u myusername -p mypassword --subnet /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/Microsoft.Network/virtualNetworks/{VNETName}/subnets/{SubnetName} -m /subscriptions/{SubID}/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_{Region}_{MaintenanceConfigName}
When applying a maintenance window selection to a database, a brief reconfiguration (several seconds) may be experienced in some cases as Azure applies the required changes.
The following steps set the maintenance window on an existing database, elastic pool, or managed instance using the Azure portal:
Set the maintenance window for an existing database or elastic pool
Navigate to the SQL database or elastic pool you want to set the maintenance window for.
In the Settings menu select Maintenance, then select the desired maintenance window.
Set the maintenance window for an existing managed instance
Navigate to the managed instance you want to set the maintenance window for.
In the Settings menu select Maintenance, then select the desired maintenance window.
Set the maintenance window for an existing database
The following example sets the maintenance window on an existing database using the Set-AzSqlDatabase cmdlet.
The -MaintenanceConfigurationId
must be set to a valid value for your database's region. To get valid values for your region, see Discover available maintenance windows.
# Select different maintenance window
$maintenanceConfig = "SQL_EastUS2_DB_2"
Write-host "Changing database maintenance window to ${maintenanceConfig} ..."
$database = Set-AzSqlDatabase `
-ResourceGroupName $resourceGroupName `
-ServerName $serverName `
-DatabaseName $databaseName `
-MaintenanceConfigurationId $maintenanceConfig
$database
Set the maintenance window on an existing elastic pool
The following example sets the maintenance window on an existing elastic pool using the Set-AzSqlElasticPool cmdlet.
It's important to make sure that the $maintenanceConfig
value is a valid value for your pool's region. To get valid values for a region, see Discover available maintenance windows.
# Select different maintenance window
$maintenanceConfig = "SQL_EastUS2_DB_1"
Write-host "Changing pool maintenance window to ${maintenanceConfig} ..."
$pool = Set-AzSqlElasticPool `
-ResourceGroupName $resourceGroupName `
-ServerName $serverName `
-ElasticPoolName $poolName `
-MaintenanceConfigurationId $maintenanceConfig
$pool
Set the maintenance window on an existing managed instance
The following example sets the maintenance window on an existing managed instance using the Set-AzSqlInstance cmdlet.
It's important to make sure that the $maintenanceConfig
value must be a valid value for your instance's region. To get valid values for a region, see Discover available maintenance windows.
Set-AzSqlInstance -Name "your_mi_name" `
-ResourceGroupName "your_resource_group_name" `
-MaintenanceConfigurationId "/subscriptions/{SubID}/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_{Region}_{MaintenanceConfigName}" `
-AsJob
The following examples show how to configure the maintenance window using Azure CLI. You can install Azure CLI, or use the Azure Cloud Shell.
Set the maintenance window for an existing database
The following example sets the maintenance window on an existing database using the az sql db update command. The --maint-config-id
(or -m
) must be set to a valid value for your database's region. To get valid values for your region, see Discover available maintenance windows.
# Select different maintenance window
maintenanceConfig="SQL_EastUS2_DB_2"
# Update database
az sql db update \
--resource-group $resourceGroupName \
--server $serverName \
--name $databaseName \
--maint-config-id $maintenanceConfig
Set the maintenance window on an existing elastic pool
The following example sets the maintenance window on an existing elastic pool using the az sql elastic-pool update command.
It's important to make sure that the maintenanceConfig
value is a valid value for your pool's region. To get valid values for a region, see Discover available maintenance windows.
# Select different maintenance window
maintenanceConfig="SQL_EastUS2_DB_1"
# Update pool
az sql elastic-pool update \
--resource-group $resourceGroupName \
--server $serverName \
--name $poolName \
--maint-config-id $maintenanceConfig
Set the maintenance window on an existing managed instance
The following example sets the maintenance window using az sql mi update. The maintenance window is set on the instance, so all databases in the instance have the instance's maintenance window schedule. For -MaintenanceConfigurationId
, the MaintenanceConfigName must be a valid value for your instance's region. To get valid values for your region, see Discover available maintenance windows.
az sql mi update -g mygroup -n myinstance -m /subscriptions/{SubID}/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_{Region}_{MainteanceConfigName}
Be sure to delete unneeded resources after you're finished with them to avoid unnecessary charges.