弹性池有助于在 Azure SQL 数据库中管理和缩放多个数据库Elastic pools help you manage and scale multiple databases in Azure SQL Database

适用于: Azure SQL 数据库

Azure SQL 数据库弹性池是一种简单且经济高效的解决方案,用于管理和缩放具有不断变化且不可预测的使用需求的多个数据库。Azure SQL Database elastic pools are a simple, cost-effective solution for managing and scaling multiple databases that have varying and unpredictable usage demands. 同一弹性池中的所有数据库位于单个服务器上,并以固定价格共享固定数量的资源。The databases in an elastic pool are on a single server and share a set number of resources at a set price. Azure SQL 数据库中的弹性池可使 SaaS 开发人员将一组数据库的价格性能优化在规定的预算内,同时为每个数据库提供性能弹性。Elastic pools in Azure SQL Database enable SaaS developers to optimize the price performance for a group of databases within a prescribed budget while delivering performance elasticity for each database.

什么是 SQL 弹性池What are SQL elastic pools

SaaS 开发人员构建在由多个数据库组成的大规模数据层上的应用程序。SaaS developers build applications on top of large scale data-tiers consisting of multiple databases. 常见的应用程序模式是为每位客户设置单一数据库。A common application pattern is to provision a single database for each customer. 但不同的客户通常有不同的和不可预测的使用模式,并且很难预测每个数据库用户的资源需求。But different customers often have varying and unpredictable usage patterns, and it's difficult to predict the resource requirements of each individual database user. 传统上,有两个选择:Traditionally, you had two options:

  • 基于高峰使用情况和付款情况过度预配资源或Over-provision resources based on peak usage and over pay, or
  • 采用低配节省成本,但这样会牺牲高峰期的性能和客户满意度。Under-provision to save cost, at the expense of performance and customer satisfaction during peaks.

弹性池通过确保数据库获取需要时所需的性能资源来解决这个问题。Elastic pools solve this problem by ensuring that databases get the performance resources they need when they need it. 它们提供了一个可预测预算内的简单的资源分配机制。They provide a simple resource allocation mechanism within a predictable budget.

重要

弹性池没有按照数据库收取的费用。There is no per-database charge for elastic pools. 对于池存在的每个小时,需要支付最高的 eDTU 或 vCore 费用,无论使用量是多少,也不管池处于活动状态的时间是否小于一小时。You are billed for each hour a pool exists at the highest eDTU or vCores, regardless of usage or whether the pool was active for less than an hour.

弹性池可让开发人员为由多个数据库共享的池购买资源,以适应单一数据库使用时段不可预测的情况。Elastic pools enable the developer to purchase resources for a pool shared by multiple databases to accommodate unpredictable periods of usage by individual databases. 可以根据基于 DTU 的购买模型基于 vCore 的购买模型为池配置资源。You can configure resources for the pool based either on the DTU-based purchasing model or the vCore-based purchasing model. 池的资源要求取决于其数据库的聚合使用量。The resource requirement for a pool is determined by the aggregate utilization of its databases. 池可用的资源数量由开发者预算控制。The amount of resources available to the pool is controlled by the developer budget. 开发者只需将数据库添加到池,根据需要为数据库设置最小和最大资源(最小和最大 DTU 数,或者最小或最大 vCore 数,具体取决于所选的资源模型),然后基于预算设置池的资源。The developer simply adds databases to the pool, optionally sets the minimum and maximum resources for the databases (either minimum and maximum DTUs or minimum or maximum vCores depending on your choice of resourcing model), and then sets the resources of the pool based on their budget. 开发人员可以使用池顺畅地扩大其服务,以渐增的规模从精简的新创公司发展到成熟的企业。A developer can use pools to seamlessly grow their service from a lean startup to a mature business at ever-increasing scale.

在池中,单独的数据库都被赋予了在固定参数内自动缩放的灵活性。Within the pool, individual databases are given the flexibility to auto-scale within set parameters. 高负荷下的数据库可能会消耗更多的资源以满足需求。Under heavy load, a database can consume more resources to meet demand. 低负荷下的数据库消耗较少的资源,没有任何负荷的数据库不会消耗任何资源。Databases under light loads consume less, and databases under no load consume no resources. 设置整个池(而非单个数据库)的资源简化了管理任务。Provisioning resources for the entire pool rather than for single databases simplifies your management tasks. 此外,必须具有该池的可预测预算。Plus, you have a predictable budget for the pool. 可在故障时间最短的情况下向现有池添加其他资源。Additional resources can be added to an existing pool with minimum downtime. 同样,随时可以从现有池中删除不再需要的额外资源。Similarly, if extra resources are no longer needed they can be removed from an existing pool at any point in time. 并且可以从池中添加或删除数据库。And you can add or remove databases from the pool. 如果可以预测到数据库的资源利用率不足,则将其移出。If a database is predictably under-utilizing resources, move it out.

备注

将数据库移入或移出弹性池时,除了在操作结束时删除数据库连接时有短暂的停机时间(大约为几秒)外,几乎没有停机时间。When moving databases into or out of an elastic pool, there is no downtime except for a brief period of time (on the order of seconds) at the end of the operation when database connections are dropped.

何时应当考虑使用 SQL 数据库弹性池When should you consider a SQL Database elastic pool

池很适合具有特定使用模式的大量数据库。Pools are well suited for a large number of databases with specific utilization patterns. 对于给定的数据库,此模式的特征是低平均使用量与相对不频繁的使用高峰。For a given database, this pattern is characterized by low average utilization with relatively infrequent utilization spikes. 相反,具有持久性中-高利用率的多个数据库不应放在同一弹性池中。Conversely, multiple databases with persistent medium-high utilization should not be placed in the same elastic pool.

可以加入池的数据库越多,就可以节省更多的成本。The more databases you can add to a pool the greater your savings become. 可能只需两个 S3 数据库就可以节省开支,具体取决于应用程序使用模式。Depending on your application utilization pattern, it's possible to see savings with as few as two S3 databases.

以下各部分有助于了解如何评估特定的数据库集合是否会因使用池而受益。The following sections help you understand how to assess if your specific collection of databases can benefit from being in a pool. 这些示例使用标准池,但同样的原理也适用于基本和高级池。The examples use Standard pools but the same principles also apply to Basic and Premium pools.

评估数据库使用模式Assessing database utilization patterns

下图显示了一个数据库示例,该数据库有大量的闲置时间,但也会定期出现活动高峰。The following figure shows an example of a database that spends much time idle, but also periodically spikes with activity. 这是适合池的使用模式:This is a utilization pattern that is suited for a pool:

适用于池的单一数据库

该图显示了从 12:00 到 1:00 的 1 小时内的 DTU 使用情况,其中每个数据点的粒度为 1 分钟。The chart illustrates DTU usage over a 1 hour time period from 12:00 to 1:00 where each data point has 1 minute granularity. 在 12:10,DB1 使用的 DTU 个数达到峰值(90 个 DTU),但其整体平均使用量低于五个 DTU。At 12:10 DB1 peaks up to 90 DTUs, but its overall average usage is less than five DTUs. 在单一数据库中运行此工作负荷需要 S3 计算大小,但在低活动期间,这可使大多数资源处于未使用状态。An S3 compute size is required to run this workload in a single database, but this leaves most of the resources unused during periods of low activity.

池可让这些未使用的 DTU 跨多个数据库共享,因此减少了所需的 DTU 数和总体成本。A pool allows these unused DTUs to be shared across multiple databases, and so reduces the DTUs needed and overall cost.

以上一个示例为基础,假设有其他数据库具有与 DB1 类似的使用模式。Building on the previous example, suppose there are additional databases with similar utilization patterns as DB1. 在接下来的两个图中,4 个数据库和 20 个数据库的使用量分层放在同一图形中,以演示在使用基于 DTU 的购买模型时数据库使用量在整个时间段上非重叠的性质:In the next two figures below, the utilization of four databases and 20 databases are layered onto the same graph to illustrate the non-overlapping nature of their utilization over time using the DTU-based purchasing model:

使用模式适用于池的 4 个数据库

使用模式适用于池的 20 个数据库

在上图中,黑线表示跨所有 20 个数据库的聚合 DTU 使用量。The aggregate DTU utilization across all 20 databases is illustrated by the black line in the preceding figure. 其中表明聚合 DTU 使用量永远不会超过 100 个 DTU,并指出 20 个数据库可以在此时间段内共享 100 个 eDTU。This shows that the aggregate DTU utilization never exceeds 100 DTUs, and indicates that the 20 databases can share 100 eDTUs over this time period. 相比于将每个数据库放入单一数据库的 S3 计算大小,这会导致 DTU 减少 20 倍和价格降低 13 倍。This results in a 20x reduction in DTUs and a 13x price reduction compared to placing each of the databases in S3 compute sizes for single databases.

由于以下原因,此示例很理想:This example is ideal for the following reasons:

  • 每一数据库之间的高峰使用量和平均使用量有相当大的差异。There are large differences between peak utilization and average utilization per database.
  • 每个数据库的高峰使用量在不同时间点发生。The peak utilization for each database occurs at different points in time.
  • eDTU 会在多个数据库之间共享。eDTUs are shared between many databases.

在 DTU 购买模型中,池的价格取决于池的 eDTU。In the DTU purchasing model, the price of a pool is a function of the pool eDTUs. 尽管池的 eDTU 单位价格比单一数据库的 DTU 单位价格多 1.5 倍,但 池 eDTU 可由多个数据库共享,因而所需的 eDTU 总数更少While the eDTU unit price for a pool is 1.5x greater than the DTU unit price for a single database, pool eDTUs can be shared by many databases and fewer total eDTUs are needed. 定价方面和 eDTU 共享的这些差异是池可以提供成本节省可能性的基础。These distinctions in pricing and eDTU sharing are the basis of the price savings potential that pools can provide.

在 vCore 购买模型中,弹性池的 vCore 单价与单一数据库的 vCore 单价相同。In the vCore purchasing model, the vCore unit price for elastic pools is the same as the vCore unit price for single databases.

如何选择正确的池大小How do I choose the correct pool size

池的最佳大小取决于聚合池中所有数据库所需的资源。The best size for a pool depends on the aggregate resources needed for all databases in the pool. 这涉及到决定以下项:This involves determining the following:

  • 池中所有数据库使用的最大计算资源。Maximum compute resources utilized by all databases in the pool. 计算资源由 eDTU 或 vCore 编制索引,具体取决于所选的购买模型。Compute resources are indexed by either eDTUs or vCores depending on your choice of purchasing model.
  • 池中所有数据库使用的最大存储字节。Maximum storage bytes utilized by all databases in the pool.

有关每种购买模型中的服务层级和资源限制,请参阅基于 DTU 的购买模型基于 vCore 的购买模型For service tiers and resource limits in each purchasing model, see the DTU-based purchasing model or the vCore-based purchasing model.

以下步骤可帮助你评估池是否比单一数据库更具成本效益:The following steps can help you estimate whether a pool is more cost-effective than single databases:

  1. 通过如下方式来估算池所需的 eDTU 或 vCore:Estimate the eDTUs or vCores needed for the pool as follows:
    • 对于基于 DTU 的购买模型:For the DTU-based purchasing model:
      • MAX(<DB 的总数目 × 每 DB 的平均 DTU 使用率>、<同时达到峰值的 DB 数目 × 每 DB 的峰值 DTU 使用率>) MAX(<Total number of DBs × Average DTU utilization per DB>, <Number of concurrently peaking DBs × Peak DTU utilization per DB>)
    • 对于基于 vCore 的购买模型:For the vCore-based purchasing model:
      • MAX(<DB 的总数目 × 每 DB 的平均 vCore 使用率>、<同时达到峰值的 DB 数目 × 每 DB 的峰值 vCore 使用率>) MAX(<Total number of DBs × Average vCore utilization per DB>, <Number of concurrently peaking DBs × Peak vCore utilization per DB>)
  2. 通过添加池中所有数据库所需的数据大小,估计池所需的总存储空间。Estimate the total storage space needed for the pool by adding the data size needed for all the databases in the pool. 对于 DTU 购买模型,确定提供此存储量的 eDTU 池大小。For the DTU purchasing model, then determine the eDTU pool size that provides this amount of storage.
  3. 对于基于 DTU 的购买模型,请取步骤 1 和步骤 2 中 eDTU 估算值中较大的那个。For the DTU-based purchasing model, take the larger of the eDTU estimates from Step 1 and Step 2. 对于基于 vCore 的购买模型,请取步骤 1 中的 vCore 估算值。For the vCore-based purchasing model, take the vCore estimate from Step 1.
  4. 请参阅 SQL 数据库定价页,找到大于步骤 3 中估算值的最小池大小。See the SQL Database pricing page and find the smallest pool size that is greater than the estimate from Step 3.
  5. 将步骤 4 的池价格与使用单一数据库适当计算大小的价格相比较。Compare the pool price from Step 4 to the price of using the appropriate compute sizes for single databases.

重要

如果池中的数据库数量接近所支持的最大值,请确保考虑密集弹性池中的资源管理If the number of databases in a pool approaches the maximum supported, make sure to consider Resource management in dense elastic pools.

将其他 SQL 数据库功能与弹性池一起使用Using other SQL Database features with elastic pools

弹性作业和弹性池Elastic jobs and elastic pools

借助池,可以通过在 elastic jobsWith a pool, management tasks are simplified by running scripts in elastic jobs. 弹性作业可消除与大量数据库有关的大部分问题。An elastic job eliminates most of tedium associated with large numbers of databases.

有关用于操作多个数据库的其他数据库工具的详细信息,请参阅 使用 Azure SQL 数据库进行扩展For more information about other database tools for working with multiple databases, see Scaling out with Azure SQL Database.

弹性池中的数据库的业务连续性选项Business continuity options for databases in an elastic pool

共用数据库通常支持和可用于单一数据库相同的业务连续性功能Pooled databases generally support the same business continuity features that are available to single databases.

使用 Azure 门户创建新的 SQL 数据库弹性池Creating a new SQL Database elastic pool using the Azure portal

在 Azure 门户中可以通过两种方法创建弹性池。There are two ways you can create an elastic pool in the Azure portal.

  1. 可以通过在 市场 中搜索“SQL 弹性池”或者通过在 SQL 弹性池浏览边栏选项卡中单击“+添加”来创建弹性池。You can create an elastic pool by searching SQL elastic pool in the Marketplace or clicking +Add on the SQL elastic pools browse blade. 可以通过此池预配工作流指定新的或现有的服务器。You are able to specify a new or existing server through this pool provisioning workflow.

  2. 或者可以创建一个弹性池:导航到现有服务器,然后单击“+ 新建池”,直接在该服务器中创建一个池。Or you can create an elastic pool by navigating to an existing server and clicking + New pool to create a pool directly into that server.

备注

可以在服务器上创建多个池,但不能将数据库从不同的服务器添加到同一个池中。You can create multiple pools on a server, but you can't add databases from different servers into the same pool.

该池的服务层级决定了池中弹性数据库的可用功能,以及每个数据库可用的最大资源量。The pool's service tier determines the features available to the elastics in the pool, and the maximum amount of resources available to each database. 有关详细信息,请参阅 DTU 模型中弹性池的资源限制。For details, see Resource limits for elastic pools in the DTU model. 有关弹性池的基于 vCore 的资源限制,请参阅基于 vCore 的资源限制 - 弹性池For vCore-based resource limits for elastic pools, see vCore-based resource limits - elastic pools.

若要配置池的资源和定价,请单击“配置池”。To configure the resources and pricing of the pool, click Configure pool. 然后选择服务层级,将数据库添加到池,并配置池及其数据库的资源限制。Then select a service tier, add databases to the pool, and configure the resource limits for the pool and its databases.

完成配置池后,可以单击“应用”,将池命名,然后单击“确定”以创建池。When you have completed configuring the pool, you can click 'Apply', name the pool, and click 'OK' to create the pool.

监视弹性池及其数据库Monitor an elastic pool and its databases

在 Azure 门户中,可以监视弹性池和该池中的数据库的利用率。In the Azure portal, you can monitor the utilization of an elastic pool and the databases within that pool. 还可以对弹性池进行一组更改,并同时提交所有更改。You can also make a set of changes to your elastic pool and submit all changes at the same time. 这些更改包括添加或删除数据库、更改弹性池设置或更改数据库设置。These changes include adding or removing databases, changing your elastic pool settings, or changing your database settings.

可以将内置的性能监视警报工具与性能等级组合使用。You can use the built-in performance monitoring and alerting tools, combined with performance ratings. 此外,SQL 数据库可发出指标和资源日志,以方便进行监视。Additionally, SQL Database can emit metrics and resource logs for easier monitoring.

后续步骤Next steps