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.
Important
Configuring maintenance window is a long running asynchronous operation, similar to changing the service tier of the Azure SQL resource. The resource is available during the operation, except a short reconfiguration that happens at the end of the operation and typically lasts up to 8 seconds even in case of interrupted long-running transactions. To minimize the impact of the reconfiguration you should perform the operation outside of the peak hours.
To configure the maintenance window when you create a database or elastic pool, 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.
The following examples show how to configure the maintenance window using Azure PowerShell. You can install Azure PowerShell.
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 chinaeast2 region using the Get-AzMaintenancePublicConfiguration cmdlet. For databases and elastic pools, set MaintenanceScope
to SQLDB
.
$location = "chinaeast2"
Write-Host "Available maintenance schedules in ${location}:"
$configurations = Get-AzMaintenancePublicConfiguration
$configurations | ?{ $_.Location -eq $location -and $_.MaintenanceScope -eq "SQLDB"}
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_ChinaEast2_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_ChinaEast2_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
The following examples show how to configure the maintenance window using Azure CLI. You can install Azure CLI.
Sign in to Azure
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 trail subscription, create a trial subscription 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 sign 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 chinaeast2 region using the az maintenance public-configuration list command. For databases and elastic pools, set maintenanceScope
to SQLDB
.
location="chinaeast2"
az maintenance public-configuration list --query "[?location=='$location'&&contains(maintenanceScope,'SQLDB')]"
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_ChinaEast2_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_ChinaEast2_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
When applying a maintenance window selection to a database, a brief reconfiguration (several seconds) might be experienced in some cases as Azure applies the required changes.
The following steps set the maintenance window on an existing database or elastic pool 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 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_ChinaEast2_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_ChinaEast2_DB_1"
Write-host "Changing pool maintenance window to ${maintenanceConfig} ..."
$pool = Set-AzSqlElasticPool `
-ResourceGroupName $resourceGroupName `
-ServerName $serverName `
-ElasticPoolName $poolName `
-MaintenanceConfigurationId $maintenanceConfig
$pool
The following examples show how to configure the maintenance window using Azure CLI. You can install Azure CLI.
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_ChinaEast2_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_ChinaEast2_DB_1"
# Update pool
az sql elastic-pool update \
--resource-group $resourceGroupName \
--server $serverName \
--name $poolName \
--maint-config-id $maintenanceConfig
If you create Azure SQL resources as part of this tutorial, be sure to delete unneeded resources after you're finished with them to avoid unnecessary charges.