Migrate to Innovate Summit:
Learn how migrating and modernizing to Azure can boost your business's performance, resilience, and security, enabling you to fully embrace AI.Register now
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This article describes how to stop and start an instance to save on billing costs when you're using Azure SQL Managed Instance in the General Purpose service tier. You can stop and start your instance by using the Azure portal, Azure PowerShell, Azure CLI, or REST API.
Note
The stop and start feature controls billing and should not be used to restart the instance as a troubleshooting step.
Overview
To save on billing costs, you can stop your General Purpose managed instance when you're not using it. Stopping an instance is similar to deallocating a virtual machine. When an instance is in a stopped state, you're no longer billed for compute and licensing costs but still billed for data and backup storage.
Stopping a managed instance clears all cached data.
This feature introduces three new managed instance states, as the following diagram indicates:
- Stopping
- Stopped
- Starting
After the stop operation is initiated, it typically takes about 5 minutes to stop the instance. However, starting an instance takes about 20 minutes from the moment the start operation is initiated. Only managed instances in a ready state can be stopped. After the instance is stopped, it stays in a stopped state until a start operation is initiated, either manually or triggered with a defined schedule. Only instances that are in a stopped state can be started.
When you create a managed instance, start a stopped managed instance, or resize a managed instance (such as changing the service tier, storage, hardware generation, or number of vCores), Azure allocates compute resources to the underlying virtual cluster. While there's continual investment in additional infrastructure to support customer demand, there might be occasional resource allocation failures from unprecedented growth of demand for Azure services in specific regions. This might result in a prolonged operation duration (approximately 4 hours if there's a new virtual cluster buildout, in accordance with management operation durations), or a failure to start the instance, in which case you should try again later.
Important
As a platform as a service (PaaS) service, SQL Managed Instance is responsible for compliance for every part of the system components. If there's an urgent need for system maintenance that requires the instance to be online, Azure can initiate the start operation and keep the instance online until the maintenance operation is completed, at which time Azure stops the instance. Compute and license charges are applied for the entire time the instance is in an online state.
Action types
There are two ways to stop and start an instance: either manually on demand or by creating a schedule.
Manual commands
You can use manual commands to immediately trigger a stop and start action. Manual commands are good for instances that have longer periods of inactivity without regular patterns, or for testing purposes. Alternatively, you can use Azure Automation schedules or any custom solution that creates customized and more flexible schedules that you can't set up by using the built-in stop and start scheduler in SQL Managed Instance.
Scheduled commands
You can also create a schedule with one or more multiple points of time when a stop or start action is triggered. Scheduled commands are good for instances that have regular patterns, such as starting an instance every weekday at 8 AM, stopping it at 5 PM, and then starting it during the weekend at 7 AM and stopping it at 11 AM. Scheduling your commands eliminates the need for you to create custom solutions or to use Azure Automation to create stop and start schedules.
Scheduled items represent points in time when stop and start events are initiated, not when the instance is up and running. When you're creating a schedule, take the operation duration into account. For example, if you want to have your instance up and running at 8 AM, you can define a schedule that initiates the start operation at 7:40 AM.
Consider the following rules for a stop and start schedule:
Scheduled items are defined as a stop-and-start pair, and they must have both stop and start values populated. It's not possible to have a populated stop value with a missing start value, and vice versa.
There can't be an overlap of scheduled pairs. If there's an overlap of scheduled times, the API returns an error.
The time span between any two successive actions (that is, a start after a stop or a stop after a start) must be at least one hour. For example, if a start is scheduled for 10 AM, the stop action can't be scheduled before 11 AM.
If there are conflicting operations when a stop is triggered (such as scaling vCore in progress), the mechanism retries after 10 minutes. If after 10 minutes the conflicting operation is still active, the stop operation gets skipped.
Billing
Stopped instances don't get billed for vCores and the SQL license, they're charged only for data and backup storage. However, vCores and license billing is charged for every started hour. For example, at 12:01, you're charged for the entire hour, even if the instance is stopped within the hour.
Azure Hybrid Benefit
The Azure Hybrid Benefit (AHB) is applied per resource. If your instance is using the Azure Hybrid Benefit to save on licensing costs, to apply that benefit to another resource when the instance is in a stopped state, you must first disable AHB on the instance, and then stop the instance. Similarly, after you restart the instance, you have to reenable AHB on it to apply the licensing benefit.
Reservation pricing
Azure Reservation is applied for the vCores and hours emitted. When an instance that's eligible for reserved pricing is stopped, reserved pricing is automatically redirected to another instance, if one exists. You can use the stop and start feature to overprovision reserved instance pricing.
For example, let's say that you've purchased a managed instance with a reservation for 16 vCores. You can run two instances with 8 vCores each from 1 PM to 2 PM, stop both instances, and then run two different instances with 8 vCores each from 2 PM to 3 PM. This approach would consume your 16 vCore limit for each hour, spread among four instances in total.
Reservation discounts are offered on a "use it or lose it" basis. That is, if you don't have matching resources for a specified hour, the reservation quantity for that hour is lost. Unused reserved hours can't be carried forward.
Limitations of the stop and start feature
Consider the following limitations:
Stop and start of an instance is currently only possible for instances in the General Purpose service tier.
You can't stop instances that:
Have an ongoing management operation (such as an ongoing restore, vCore scaling, and so on)
While a managed instance is in a stopped state, it's not possible to change its configuration properties. To change any properties, you must start the instance.
While the instance is in a stopped state, it's not possible to take backups. For example, let's say that you have long-term backups configured, with yearly backups in place. If you stop the instance during the defined yearly backup period, the backup is skipped. We recommend that you keep the instance up and running during the yearly backup period.
It's not possible to cancel the stop or start operation after it's been initiated.
If there is a vulnerability assessment scan scheduled for SQL Managed Instance and instance is stopped, the scan operation will still be initiated and the scan execution will fail.
Maintenance notifications will not be fired for instances that are in stopped state. This results with:
Incomplete sequence of notifications (for example, advanced notification is not sent, in progress notification is sent).
SQL Managed Instance is missing from the list of impacted resources in the notification content.
Error logs that are available in SQL Managed Instance aren't persisted and are automatically erased on instance stop.
Prerequisites
To use the instance stop and start feature, your instance must be in the General Purpose service tier.
Instances that don't meet the prerequisite have the stop and start controls disabled on the Overview page for the SQL managed instance resource in the Azure portal. Hovering over the control explains why the feature can't be used by the instance.
Prepare command line environment
Skip this step if you're using the Azure portal.
If you want to stop or start an instance by using PowerShell or the Azure CLI you need to prepare your environment by configuring command line tools, and defining your parameters.
Alternatively to configuring your command line tools, you can also use the Azure Cloud Shell, which is a free interactive shell you can use to run the steps in this article. It has common preinstalled Azure tools and configured to use with your account. If you don't have an Azure subscription, create an Azure free account before you begin.
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.
To stop and start your instance with PowerShell, you can install Azure PowerShell, or use the Azure Cloud Shell.
When Cloud Shell opens, verify that PowerShell is selected for your environment. Subsequent sessions 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.
Once PowerShell or Cloud Shell is launched, define the parameters:
To stop and start your instance with the Azure CLI, you can install Azure CLI, or use the Azure Cloud Shell.
When Cloud Shell opens, verify that Bash is selected for your environment. Subsequent sessions 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.
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.
Azure CLI
subscription="<Subscription-ID>"instanceName="<SQL-MI-name>"
resourceGroupName="<SQL-MI-resource-group>"az account set -s$subscription# ...or use 'az login'
POST
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
providers/Microsoft.Sql/managedInstances/{managedInstanceName}/stop?api-version=2021-08-01-preview
After your managed instance is stopped, to start it by using the Azure portal, go to the Overview page of your instance, and then select the Start button.
If your instance is already started, the Start button is unavailable.
To start your managed instance with PowerShell, use Start-AzSqlInstance, such as the following sample script:
To create a schedule to stop and start a managed instance with the Azure CLI, use az sql mi start-stop-schedule create, such as the following sample script:
Azure CLI
scheduleItems="[{'startDay':'Monday','startTime':'10:00','stopDay':'Monday','stopTime':'18:00'},{'startDay':'Tuesday','startTime':'10:00','stopDay':'Tuesday','stopTime':'18:00'},{'startDay':'Wednesday','startTime':'12:00','stopDay':'Wednesday','stopTime':'22:00'},{'startDay':'Thursday','startTime':'14:00','stopDay':'Thursday','stopTime':'20:00'},{'startDay':'Friday','startTime':'14:00','stopDay':'Friday','stopTime':'20:00'}]"timezone="Central Europe Standard Time"az sql mi start-stop-schedule create --mi"$instanceName"-g"$resourceGroupName"--timezone-id"$timezone"--schedule-list"$scheduleItems"
az sql mi start-stop-schedule show --mi"$instanceName"-g"$resourceGroupName"
Update schedule
To update an existing schedule to stop and start a managed instance, use az sql mi start-stop-schedule update, such as the following sample script:
Azure CLI
# append an item
newScheduleItem="{'startDay':'Friday','startTime':'09:00 PM','stopDay':'Friday','stopTime':'11:00 PM'}"az sql mi start-stop-schedule update --mi$instanceName-g$resourceGroupName--add schedule_list "$newScheduleItem"# remove an item#items in list are indexed (0 based)az sql mi start-stop-schedule update --mi$instanceName-g$resourceGroupName--remove schedule_list 2
GET
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
providers/Microsoft.Sql/managedInstances/{managedInstanceName}/startStopSchedules/default?api-version=2022-08-01-preview
Currently, the Activity Log only captures operations initiated via Azure Resource Manager (ARM). The scheduled start and stop operations are not tracked on the Activity Log. Hence, at this time, it is not possible to view the history of the scheduled start and stop operations via the Activity Log in Azure portal or via any monitoring that is based on such logs.
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.
Learn how to use the Next-gen General Purpose service tier (preview) in Azure SQL Managed Instance, which is an architectural upgrade to the existing General Purpose service tier that can be used for new and existing instances.
The vCore purchasing model lets you independently scale compute and storage resources, match on-premises performance, and optimize price for Azure SQL Managed Instance.
Learn how to restart an instance by manually failing over primary and secondary replicas of Azure SQL Managed Instance by using PowerShell, the Azure CLI or REST API.
Learn how to create instance pools for Azure SQL Managed Instance, a feature that lets you share resources for multiple instances, and provides a convenient and cost-efficient way to migrate smaller SQL Server databases to the cloud at scale. Create your instance pool by using the Azure portal, PowerShell, or the Azure CLI.