Azure SQL 数据库托管实例入门Getting started with Azure SQL Database managed instance

托管实例部署选项创建与最新 SQL Server 本地 (Enterprise Edition) 数据库引擎几乎完全兼容的数据库,提供一个本机虚拟网络 (VNet) 实现来解决常见的安全问题,并提供本地 SQL Server 客户惯用的业务模型The managed instance deployment option creates a database with near 100% compatibility with the latest SQL Server on-premises (Enterprise Edition) database engine, providing a native virtual network (VNet) implementation that addresses common security concerns, and a business model favorable for on-premises SQL Server customers. 本文介绍如何快速配置和创建托管实例以及迁移数据库。In this article, you will learn how to quickly configure and create a managed instance and migrate your databases.

快速入门概述Quickstart overview

参考以下快速入门可以快速创建托管实例、为客户端应用程序配置虚拟机或点到站点 VPN 连接,并使用 .bak 文件将数据库还原到新的托管实例。The following quickstarts enable you to quickly create a managed instance, configure a virtual machine or point to site VPN connection for client application, and restore a database to your new managed instance using a .bak file.

配置环境Configure environment

作为第一步,你需要使用将放置托管实例的网络环境创建第一个托管实例,并启用从要执行查询的计算机或虚拟机到托管实例的连接。As a first step, you would need to create your first Managed Instance with the network environment where it will be placed, and enable connection from the computer or virtual machine where you are executing queries to Managed Instance. 可以使用下列指南:You can use the following guides:

作为手动创建托管实例的替代方法,可使用 PowerShell带资源管理器模板的 PowerShellAzure CLI 来编写脚本并自动执行此过程。As an alternative to manual creation of Managed Instance, you can use PowerShell, PowerShell with Resource Manager template, or Azure CLI to script and automate this process.

迁移数据库Migrate your databases

创建托管实例和配置访问权限后,可以开始迁移本地 SQL Server 或 Azure VM 上的数据库。After you create a managed instance and configure access, you can start migrating your databases from SQL Server on-premises or Azure VMs. 如果要迁移的源数据库中存在一些不受支持的功能,则迁移将会失败。Migration fails if you have some unsupported features in the source database that you want to migrate. 若要避免失败并检查兼容性,可以安装数据迁移助手 (DMA),用于分析 SQL Server 上的数据库,并找出可能会阻止迁移到托管实例的任何问题,例如,是否存在 FileStream 或多个日志文件。To avoid failures and check compatibility, you can install Data Migration Assistant (DMA) that analyzes your databases on SQL Server and finds any issue that could block migration to a managed instance, such as existence of FileStream or multiple log files. 解决这些问题后,即可将数据库迁移到托管实例。If you resolve these issues, your databases are ready to migrate to managed instance. 数据库实验助手是另一个有用的工具,它可以记录 SQL Server 上的工作负荷,并在托管实例上重放该工作负荷,以便可以确定在迁移到托管实例时是否会出现任何性能问题。Database Experimentation Assistant is another useful tool that can record your workload on SQL Server and replay it on a managed instance so you can determine are there going to be any performance issues if you migrate to a managed instance.

确保可将数据库迁移到托管实例后,可以使用本机 SQL Server 还原功能通过 .bak 文件将数据库还原到托管实例。Once you are sure that you can migrate your database to a managed instance, you can use the native SQL Server restore capabilities to restore a database into a managed instance from a .bak file. 可以使用此方法从本地安装的 SQL Server 数据库引擎或 Azure VM 迁移数据库。You can use this method to migrate databases from SQL Server database engine installed on-premises or Azure VM. 请参阅快速入门从备份还原到托管实例For a quickstart, see Restore from backup to a managed instance. 此快速入门介绍了如何使用 RESTORE Transact-SQL 命令从 Azure Blob 存储中存储的 .bak 文件还原。In this quickstart, you restore from a .bak file stored in Azure Blob storage using the RESTORE Transact-SQL command.

Tip

若要使用 BACKUP Transact-SQL 命令创建 Azure Blob 存储中数据库的备份,请参阅 SQL Server 备份到 URLTo use the BACKUP Transact-SQL command to create a backup of your database in Azure Blob storage, see SQL Server backup to URL.

参考这些快速入门可以快速创建、配置数据库备份并将其还原到托管实例。These quickstarts enable you to quickly create, configure, and restore database backup to a managed instance. 在某些情况下,需要自定义或自动化托管实例和所需网络环境的部署。In some scenarios, you would need to customize or automate deployment of managed instances and the required networking environment. 下面将会介绍这些方案。These scenarios will be described below.

自定义网络环境Customize network environment

尽管在使用 Azure 门户创建实例时可以自动配置 VNet/子网,但最好是在开始创建托管实例之前创建 VNet/子网,因为这样可以配置 VNet 和子网的参数。Although the VNet/subnet can be automatically configured when the instance is created using the Azure portal, it might be good to create it before you start creating Managed Instances because you can configure the parameters of VNet and subnet. 创建和配置网络环境的最简单方法是使用 Azure 资源部署模板,这样可以创建并配置实例所要放入到的网络和子网。The easiest way to create and configure the network environment is to use Azure Resource deployment template that will create and configure you network and subnet where the instance will be placed. 只需按下 Azure 资源管理器部署按钮,然后在表单中填充参数即可。You just need to press the Azure Resource Manager deploy button and populate the form with parameters.

或者,也可以使用此 PowerShell 脚本自动创建网络。As an alternative, you can also use this PowerShell script to automate creation of the network.

如果已有一个可用于部署托管实例的 VNet 和子网,需要确保该 VNet 和子网符合网络要求If you already have a VNet and subnet where you would like to deploy your managed instance, you need to make sure that your VNet and subnet satisfy the networking requirements. 使用此 PowerShell 脚本来验证子网的配置是否正确Use this PowerShell script to verify that your subnet is properly configured. 此脚本可以验证网络并报告问题,告知应该更改哪些设置,然后让你在 VNet/子网中进行必要的更改。This script validates your network and report any issues, and it tells you what should be changed and then offers to make the necessary changes in your VNet/subnet. 如果你不想要手动配置 VNet/子网,请运行此脚本。Run this script if you don't want to configure your VNet/subnet manually. 对网络基础结构做出任何重大配置更改后,也可以运行此脚本。You can also run it after any major reconfiguration of your network infrastructure. 若要创建并配置自己的网络,请参阅连接体系结构,以及这篇有关创建和配置托管实例环境的最终指南If you want to create and configure your own network, read connectivity architecture and this ultimate guide for creating and configuring a managed instance environment.

迁移到托管实例Migrate to a managed instance

参考这些快速入门中的文章可以快速设置托管实例,以及使用本机 RESTORE 功能移动数据库。Articles in these quickstarts enable you to quickly set up a managed instance and move your databases using the native RESTORE capability. 如果想要快速完成概念验证,并验证解决方案在 Azure SQL 数据库托管实例上是否有效,这是一个很好的起点。This is a good starting point if you want to complete quick proof-of concepts and verify that your solution can work on Managed Instance.

但是,若要迁移生产数据库,甚至迁移用于某些性能测试的开发/测试数据库,则需要考虑使用其他技术,例如:However, in order to migrate your production database or even dev/test databases that you want to use for some performance test, you would need to consider using some additional techniques, such as:

  • 性能测试 - 测量源 SQL Server 实例的基线性能,并将其与迁移数据库的目标托管实例上的性能进行比较。Performance testing - You should measure baseline performance on your source SQL Server instance and compare them with the performance on the destination Managed Instance where you have migrated the database. 详细了解性能比较的最佳做法Learn more about the best practices for performance comparison.
  • 联机迁移 - 使用本文所述的本机 RESTORE 时,必须等待数据库还原完毕(如果该数据库尚未存储在 Azure Blob 存储中,还要等待复制到其中)。Online migration - With the native RESTORE described in this article, you have to wait for the databases to be restored (and copied to Azure Blob storage if not already stored there). 这会导致应用程序出现一段停机时间,尤其是数据库较大时。This causes some downtime of your application especially for larger databases. 若要移动生产数据库,请使用数据迁移服务 (DMS),它可以在尽量缩短停机时间的情况下迁移数据库。To move your production database, use the Data Migration service (DMS) to migrate your database with the minimal downtime. 为实现这种迁移,DMS 会以增量方式将源数据库中发生的更改推送到所要还原的托管实例数据库。DMS accomplishes this by incrementally pushing the changes made in your source database to the managed instance database being restored. 这样,便可以在尽量缩短停机时间的前提下,快速将应用程序从源数据库切换到目标数据库。This way, you can quickly switch your application from source to target database with the minimal downtime.

详细了解建议的迁移过程Learn more about the recommended migration process.

后续步骤Next steps