Migration guide: SQL Server to Azure SQL Managed Instance
Applies to:
Azure SQL Managed Instance
In this guide, you learn how to migrate your user databases from SQL Server to Azure SQL Managed Instance.
Review the Prerequisites, and complete the Pre-migration steps, before continuing.
Migrate
After you complete the steps for the pre-migration stage, you're ready to perform the schema and data migration.
Migrate your data using your chosen migration method.
This section provides general migration steps for the following recommended migration options:
- Managed instance link
- Log Replay Service (LRS)
- Azure SQL migration extension for Azure Data Studio - migration with near-zero downtime.
- Native
RESTORE DATABASE FROM URL
- uses native backups from SQL Server and requires some downtime.
SQL Managed Instance targets user scenarios requiring mass database migration from on-premises or Azure VM database implementations. These are the optimal choice when you need to lift and shift the back end of the applications that regularly use instance level and/or cross-database functionalities. If this is your scenario, you can move an entire instance to a corresponding environment in Azure without the need to rearchitect your applications.
To move SQL instances, you need to plan carefully:
- The migration of all databases that need to be collocated (ones running on the same instance).
- The migration of instance-level objects that your application depends on, including logins, credentials, SQL Agent jobs and operators, and server-level triggers.
SQL Managed Instance is a managed service that allows you to delegate some of the regular DBA activities to the platform as they're built in. Therefore, some instance-level data doesn't need to be migrated, such as maintenance jobs for regular backups or Always On configuration, as high availability is built in.
Azure Data Studio
This section provides high-level steps to migrate from SQL Server to Azure SQL Managed Instance with minimal downtime by using the Azure SQL migration extension in Azure Data Studio. For detailed instructions, see Tutorial: Migrate SQL Server to Azure SQL Managed Instance online in Azure Data Studio.
To migrate with Azure Data Studio, follow these steps:
- Download and install Azure Data Studio and the Azure SQL migration extension for Azure Data Studio.
- Launch the Migrate to Azure SQL Migration wizard in the extension in Azure Data Studio.
- Select databases for assessment and view migration readiness or issues (if any). Additionally, collect performance data and get right-sized Azure recommendation.
- Select your Azure account and your target Azure SQL Managed Instance from your subscription.
- Select the location of your database backups. Your database backups can either be located on an on-premises network share or in Azure Blob Storage container.
- Create a new Azure Database Migration Service using the wizard in Azure Data Studio. If you previously created an Azure Database Migration Service using Azure Data Studio, you can reuse the same if desired.
- Optional: If your backups are on an on-premises network share, download and install self-hosted integration runtime on a machine that can connect to the source SQL Server, and the location containing the backup files.
- Start the database migration and monitor the progress in Azure Data Studio. You can also monitor the progress under the Azure Database Migration Service resource in Azure portal.
- Complete the cutover.
- Stop all incoming transactions to the source database.
- Make application configuration changes to point to the target database in Azure SQL Managed Instance.
- Take any tail log backups for the source database in the backup location specified.
- Ensure all database backups have the status Restored in the monitoring details page.
- Select Complete cutover in the monitoring details page.
Managed Instance link
This section provides high-level steps to migrate from SQL Server to Azure SQL Managed Instance with minimal downtime by using the Managed Instance link. For detailed instructions, review Migrate with the link.
To migrate with the link, follow these steps:
- Create your target SQL Managed Instance: Azure portal, PowerShell, Azure CLI.
- Prepare your environment for the link.
- Configure the link with SSMS or scripts.
- Stop the workload.
- Validate data on the target instance.
- Fail over the link.
Log Replay Service (LRS)
This section provides high-level steps to migrate from SQL Server to Azure SQL Managed Instance with minimal downtime by using the Log Replay Service (LRS). For detailed instructions, review Migrate databases from SQL Server by using Log Replay Service.
To migrate with LRS, follow these steps:
- Create an Azure storage account with a blob container.
- Authenticate to your Blob Storage storage account using an SAS token or a managed identity and validate access.
- Be sure to configure your folder structure correctly if you plan to migrate multiple databases.
- Upload your backups to your storage account by either copying your backups, or taking backups directly by using the BACKUP TO URL.
- Determine if you want to run LRS in autocomplete or continuous mode.
- Start LRS.
- Monitor migration progress.
- Complete the migration (if in continuous mode).
Back up and restore
One key capability of Azure SQL Managed Instance that enables quick and easy database migration is the native restore to SQL managed instance of database backup (.bak
) files stored in Azure Storage. Backing up and restoring are asynchronous operations based on the size of your database.
The following diagram provides a high-level overview of the process:
Note
The time to take the backup, upload it to Azure storage, and perform a native restore operation to Azure SQL Managed Instance is based on the size of the database. Factor a sufficient downtime to accommodate the operation for large databases.
The following table provides more information regarding the methods you can use depending on source SQL Server version you're running:
Step | SQL Engine and version | Backup/restore method |
---|---|---|
Put backup to Azure Storage | Before 2012 SP1 CU2 | Upload .bak file directly to Azure Storage |
2012 SP1 CU2 - 2016 | Direct backup using deprecated WITH CREDENTIAL syntax | |
2016 and later versions | Direct backup using WITH SAS CREDENTIAL | |
Restore from Azure Storage to a managed instance | RESTORE FROM URL with SAS CREDENTIAL |
Important
When you're migrating a database protected with transparent data encryption to a managed instance using native restore option, the corresponding certificate from the on-premises or Azure VM SQL Server needs to be migrated before database restore. For detailed steps, see Migrate a certificate of a TDE-protected database to Azure SQL Managed Instance.
Restore of system databases isn't supported. To migrate instance-level objects (stored in master
or msdb
databases), we recommend to script them out and run T-SQL scripts on the destination instance.
To migrate using backup and restore, follow these steps:
Back up your database to Azure Blob Storage. For example, use backup to url in SQL Server Management Studio. Use the Microsoft Azure Tool to support databases earlier than SQL Server 2012 SP1 CU2.
Connect to your Azure SQL Managed Instance using SQL Server Management Studio.
Create a credential using a Shared Access Signature to access your Azure Blob storage account with your database backups. For example:
CREATE CREDENTIAL [https://mitutorials.blob.core.windows.net/databases] WITH IDENTITY = 'SHARED ACCESS SIGNATURE', SECRET = '<secret>'
Restore the backup from the Azure storage blob container. For example:
RESTORE DATABASE [TargetDatabaseName] FROM URL = 'https://mitutorials.blob.core.windows.net/databases/WideWorldImporters-Standard.bak'
Once restore completes, view the database in Object Explorer within SQL Server Management Studio.
To learn more about this migration option, see Quickstart: Restore a database to Azure SQL Managed Instance with SSMS.
Note
A database restore operation is asynchronous and can be retried. You might get an error in SQL Server Management Studio if the connection breaks or a time-out expires. Azure SQL Database will keep trying to restore database in the background, and you can track the progress of the restore using the sys.dm_exec_requests and sys.dm_operation_status views.
Data sync and cutover
When using migration options that continuously replicate / sync data changes from source to the target, the source data and schema can change and drift from the target. During data sync, ensure that all changes on the source are captured and applied to the target during the migration process.
After you verify that data is the same on both source and target, you can cut over from the source to the target environment. It's important to plan the cutover process with business / application teams to ensure minimal interruption during cutover doesn't affect business continuity.
Important
For details on the specific steps associated with performing a cutover as part of migrations using DMS, see Performing migration cutover.
Post-migration
After you successfully complete the migration stage, go through a series of post-migration tasks to ensure that everything is functioning smoothly and efficiently.
The post-migration phase is crucial for reconciling any data accuracy issues and verifying completeness, and addressing performance issues with the workload.
Monitor and remediate applications
Once you complete the migration to a managed instance, you should track the application behavior and performance of your workload. This process includes the following activities:
- Compare performance of the workload running on the managed instance with the performance baseline that you created on the source SQL Server instance.
- Continuously monitor performance of your workload to identify potential issues and improvement.
Perform tests
The test approach for database migration consists of the following activities:
- Develop validation tests: To test database migration, you need to use SQL queries. You must create the validation queries to run against both the source and the target databases. Your validation queries should cover the scope you defined.
- Set up test environment: The test environment should contain a copy of the source database and the target database. Be sure to isolate the test environment.
- Run validation tests: Run the validation tests against the source and the target, and then analyze the results.
- Run performance tests: Run performance test against the source and the target, and then analyze and compare the results.
Use advanced features
You can take advantage of the advanced cloud-based features offered by SQL Managed Instance, such as built-in high availability, threat detection, and monitoring and tuning your workload.
Azure SQL Analytics allows you to monitor a large set of managed instances in a centralized manner.
Some SQL Server features are only available once the database compatibility level is changed to the latest compatibility level (150).
Related content
- Services and tools available for data migration scenarios
- Service Tiers in Azure SQL Managed Instance
- T-SQL differences between SQL Server & Azure SQL Managed Instance
- Azure total Cost of Ownership Calculator
- Migrate databases with Azure SQL Migration extension for Azure Data Studio
- Tutorial: Migrate SQL Server to Azure SQL Managed Instance with DMS
- Cloud Adoption Framework for Azure
- Best practices for costing and sizing workloads migrate to Azure
- Data Access Migration Toolkit (Preview)
- Overview of Database Experimentation Assistant