以最短的停机时间动态缩放数据库资源Dynamically scale database resources with minimal downtime

适用于: Azure SQL 数据库 Azure SQL 托管实例

使用 Azure SQL 数据库和 SQL 托管实例,能够以最小的停机时间向数据库动态添加更多资源;但是,存在一个切换期间,在此期间与数据库的连接会短时间丢失,可以使用重试逻辑来缓解这种情况。Azure SQL Database and SQL Managed Instance enable you to dynamically add more resources to your database with minimal downtime; however, there is a switch over period where connectivity is lost to the database for a short amount of time, which can be mitigated using retry logic.


当对应用的需求从数个设备和客户增加到数百万个时,Azure SQL 数据库和 SQL 托管实例可动态缩放规模,并最大限度减少停机时间。When demand for your app grows from a handful of devices and customers to millions, Azure SQL Database and SQL Managed Instance scale on the fly with minimal downtime. 可伸缩性是平台即服务 (PaaS) 最重要的特性之一,它允许在需要时向服务动态添加更多资源。Scalability is one of the most important characteristics of platform as a service (PaaS) that enables you to dynamically add more resources to your service when needed. Azure SQL 数据库允许轻松更改分配给数据库的资源(CPU 电源、内存、IO 吞吐量和存储)。Azure SQL Database enables you to easily change resources (CPU power, memory, IO throughput, and storage) allocated to your databases.

可缓解由于应用程序的使用情况增加而导致的使用索引或查询重写方法无法修复的性能问题。You can mitigate performance issues due to increased usage of your application that cannot be fixed using indexing or query rewrite methods. 添加更多资源可在数据库达到当前资源限制并需要更多电源处理传入的工作负荷时快速做出反应。Adding more resources enables you to quickly react when your database hits the current resource limits and needs more power to handle the incoming workload. Azure SQL 数据库还可以在不需要资源以降低成本时缩减资源。Azure SQL Database also enables you to scale-down the resources when they are not needed to lower the cost.

不必担心购买硬件和更改底层基础结构。You don't need to worry about purchasing hardware and changing underlying infrastructure. 可以使用滑块通过 Azure 门户轻松缩放数据库。Scaling a database can be easily done via the Azure portal using a slider.


Azure SQL 数据库提供了基于 DTU 的购买模型基于 vCore 的购买模型,而 Azure SQL 托管实例仅提供基于 vCore 的购买模型Azure SQL Database offers the DTU-based purchasing model and the vCore-based purchasing model, while Azure SQL Managed Instance offers just the vCore-based purchasing model.

  • 基于 DTU 的购买模型在以下三个服务层级中提供包括计算、内存和 I/O 资源在内的各种内容,以支持轻型到重型数据库工作负载:基本、标准和高级。The DTU-based purchasing model offers a blend of compute, memory, and I/O resources in three service tiers to support lightweight to heavyweight database workloads: Basic, Standard, and Premium. 每个层中的不同性能级别提供这些资源的不同组合,你可以向其添加更多的存储资源。Performance levels within each tier provide a different mix of these resources, to which you can add additional storage resources.
  • 基于 vCore 的购买模型允许选择 vCore 数、内存容量,以及存储的容量和速度。The vCore-based purchasing model lets you choose the number of vCores, the amount or memory, and the amount and speed of storage. 此购买模型提供三个服务层级:“常规用途”、“业务关键”和“超大规模”。This purchasing model offers three service tiers: General Purpose, Business Critical, and Hyperscale.

可以在小型单一数据库中构建第一个应用,每个月只需在“常规用途”服务层级中花费少量资金。然后可以根据解决方案的需要,随时手动或以编程方式将服务层级更改为“业务关键”服务层级。You can build your first app on a small, single database at a low cost per month in the Basic, Standard, or General Purpose service tier and then change its service tier manually or programmatically at any time to the Premium or Business Critical service tier to meet the needs of your solution. 可在不给应用或客户造成停机的情况下调整性能。You can adjust performance without downtime to your app or to your customers. 动态可伸缩性可让数据库以透明方式响应快速变化的资源要求,使用户只需为用到的资源付费。Dynamic scalability enables your database to transparently respond to rapidly changing resource requirements and enables you to only pay for the resources that you need when you need them.


动态可伸缩性不同于自动缩放。Dynamic scalability is different from autoscale. 自动缩放是指服务根据条件自动缩放,而动态可伸缩性允许在最短停机时间的情况下进行手动缩放。Autoscale is when a service scales automatically based on criteria, whereas dynamic scalability allows for manual scaling with a minimal downtime.

Azure SQL 数据库中的单一数据库支持手动动态可伸缩性,但不支持自动缩放。Single databases in Azure SQL Database support manual dynamic scalability, but not autoscale. 若要获得更多 自动 体验,请考虑使用弹性池,它允许数据库根据各个数据库需求共享池中的资源。For a more automatic experience, consider using elastic pools, which allow databases to share resources in a pool based on individual database needs. 但是,有一些脚本可帮助自动执行 Azure SQL 数据库中的单一数据库的可伸缩性。However, there are scripts that can help automate scalability for a single database in Azure SQL Database. 有关示例,请参阅使用 PowerShell 监视和缩放单个 SQL 数据库For an example, see Use PowerShell to monitor and scale a single SQL Database.

可以随时更改 DTU 服务层级vCore 特征,将应用程序故障时间降至最低(通常在平均 4 秒以下)。You can change DTU service tiers or vCore characteristics at any time with minimal downtime to your application (generally averaging under four seconds). 许多业务和应用只要能够创建数据库并按需调高或调低性能即可,尤其是当使用模式相对容易预测时。For many businesses and apps, being able to create databases and dial performance up or down on demand is enough, especially if usage patterns are relatively predictable. 但如果有无法预测的使用模式,则管理成本和业务模式就会变得相当困难。But if you have unpredictable usage patterns, it can make it hard to manage costs and your business model. 对于这种情况,可以使用一个具有一定数量 eDTU 的弹性池,这些 eDTU 在池中的多个数据库之间共享。For this scenario, you use an elastic pool with a certain number of eDTUs that are shared among multiple databases in the pool.

SQL 数据库简介:按层和级别统计的单一数据库 DTU

Azure SQL 数据库提供动态缩放数据库的功能:Azure SQL Database offers the ability to dynamically scale your databases:

  • 单一数据库中,可以使用 DTUvCore 模型来定义将分配给每个数据库的最大资源量。With a single database, you can use either DTU or vCore models to define maximum amount of resources that will be assigned to each database.
  • 弹性池允许定义池中每组数据库的最大资源限制。Elastic pools enable you to define maximum resource limit per group of databases in the pool.

还可以通过 Azure SQL 托管实例进行缩放:Azure SQL Managed Instance allows you to scale as well:

  • SQL 托管实例使用 vCore 模式,并允许定义分配给实例的最大 CPU 核心数和最大存储空间。SQL Managed Instance uses vCores mode and enables you to define maximum CPU cores and maximum of storage allocated to your instance. 该托管实例中的所有数据库都将共享分配给该实例的资源。All databases within the managed instance will share the resources allocated to the instance.

以任何风格启动纵向扩展或缩减操作将会重启数据库引擎进程,并根据需要将其移到另一虚拟机。Initiating scale up or scale down action in any of the flavors would restart database engine process and move it to a different virtual machine if needed. 将数据库引擎进程移到新虚拟机是一个 在线过程,在该过程进行时,你可以继续使用现有的 Azure SQL 数据库服务。Moving database engine process to a new virtual machine is online process where you can continue using your existing Azure SQL Database service while the process is in progress. 目标数据库引擎完全启动并做好处理查询的准备以后,连接会从源数据库引擎切换到目标数据库引擎Once the target database engine is fully initialized and ready to process the queries, the connections will be switched from source to target database engine.


建议不要在运行长期事务(例如数据导入、数据处理作业、索引重新生成等)或实例上有任何活动连接时缩放托管实例。It is not recommended to scale your managed instance if a long-running transaction, such as data import, data processing jobs, index rebuild, etc., is running, or if you have any active connection on the instance. 为防止完成缩放所耗费的时间比平时更长,应在所有长时间运行的操作完成后缩放实例。To prevent the scaling from taking longer time to complete than usual, you should scale the instance upon the completion of all long-running operations.


当放大/缩小过程完成时,可能会出现短暂的连接中断。You can expect a short connection break when the scale up/scale down process is finished. 如果已实现了标准暂时性错误的重试逻辑,则不会注意到故障转移。If you have implemented Retry logic for standard transient errors, you will not notice the failover.

替代缩放方法Alternative scale methods

在不更改数据库或应用程序代码的情况下,缩放资源是提升数据库性能的最简单和最有效的方法。Scaling resources is the easiest and the most effective way to improve performance of your database without changing either the database or application code. 在某些情况下,即使是最高的服务层级、计算大小和性能优化,也可能无法以成功和经济高效的方式处理工作负载。In some cases, even the highest service tiers, compute sizes, and performance optimizations might not handle your workload in a successful and cost-effective way. 在该情况下,可选择其他选项对数据库进行缩放:In that case you have these additional options to scale your database:

  • 读取扩展是一项在获取数据的一个只读副本时可用的功能,可在该副本中执行要求的只读查询,如报表。Read scale-out is an available feature where you are getting one read-only replica of your data where you can execute demanding read-only queries such as reports. 只读副本将处理只读工作负载,而不会影响主数据库上的资源使用情况。A read-only replica will handle your read-only workload without affecting resource usage on your primary database.
  • 数据库分片是一组技术,可用于将数据拆分为多个数据库,并单独对这些数据库进行缩放。Database sharding is a set of techniques that enables you to split your data into several databases and scale them independently.

后续步骤Next steps