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

SQL 数据库弹性池是一种简单且经济高效的解决方案,用于管理和缩放具有不断变化且不可预测的使用需求的多个数据库。SQL Database elastic pools are a simple, cost-effective solution for managing and scaling multiple databases that have varying and unpredictable usage demands. 同一弹性池中的所有数据库位于单个 Azure SQL 数据库服务器上,并以固定价格共享固定数量的资源。The databases in an elastic pool are on a single Azure SQL Database 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 is 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.

Important

弹性池没有按照数据库收取的费用。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, 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. 可将更多资源添加现有池而不会造成数据库关闭,除非需要移动数据库以便提供更多计算资源来预留新 eDTU。Additional resources can be added to an existing pool with no database downtime, except that the databases may need to be moved to provide the additional compute resources for the new eDTU reservation. 同样,随时可以从现有池中删除不再需要的额外资源。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 subtract databases to the pool. 如果可以预测到数据库的资源利用率不足,则将其移出。If a database is predictably under-utilizing resources, move it out.

Note

将数据库移入或移出弹性池时,除了在操作结束时删除数据库连接时有短暂的停机时间(大约为几秒)外,几乎没有停机时间。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.

可以加入池的数据库越多,就可以节省更多的成本。The more databases you can add to a pool the greater your savings become. 具体取决于应用程序使用模式,可能会看到与使用两个 S3 数据库相同的成本节约。Depending on your application utilization pattern, it is 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:

适用于池的单一数据库

在所示的五分钟时间段内,DB1 高峰最高达到 90 个 DTU,但其整体平均使用量低于五个 DTU。For the five-minute period illustrated, 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.

池的价格取决于池的 eDTU。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.

以下与数据库计数和数据库使用率相关的经验法则可帮助确保池提供相比于使用单一数据库计算大小降低的成本。The following rules of thumb related to database count and database utilization help to ensure that a pool delivers reduced cost compared to using compute sizes for single databases.

数据库的最小数目Minimum number of databases

如果单一数据库的资源聚合量比池所需的资源多 1.5 倍,那么弹性池更具成本效益。If the aggregate amount of resources for single databases is more than 1.5x the resources needed for the pool, then an elastic pool is more cost effective.

基于 DTU 的购买模型示例DTU-based purchasing model example
至少需要 2 个 S3 数据库或 15 个 S0 数据库,才能使 100 个 eDTU 池比使用单一数据库计算大小更具成本效益。At least two S3 databases or at least 15 S0 databases are needed for a 100 eDTU pool to be more cost-effective than using compute sizes for single databases.

并发高峰数据库的最大数目Maximum number of concurrently peaking databases

通过共享资源,并非池中的所有数据库都能同时达到使用单一数据库可用资源的最大限制。By sharing resources, not all databases in a pool can simultaneously use resources up to the limit available for single databases. 并发高峰的数据库越少,可以设置的池资源就越低,也就能实现池更大的成本效益。The fewer databases that concurrently peak, the lower the pool resources can be set and the more cost-effective the pool becomes. 一般而言,池中不能有 2/3(或 67%)以上的数据库的高峰同时达到其资源限制。In general, not more than 2/3 (or 67%) of the databases in the pool should simultaneously peak to their resources limit.

基于 DTU 的购买模型示例DTU-based purchasing model example

To reduce costs for three S3 databases in a 200 eDTU pool, at most two of these databases can simultaneously peak in their utilization. 否则,如果四个 S3 数据库中超过两个同时高峰,则必须将池缩放为超过 200 个 eDTU。Otherwise, if more than two of these four S3 databases simultaneously peak, the pool would have to be sized to more than 200 eDTUs. 如果将池重设大小为超过 200 个 eDTU,则需要加入更多的 S3 数据库到池,才能使成本低于单一数据库的计算大小。If the pool is resized to more than 200 eDTUs, more S3 databases would need to be added to the pool to keep costs lower than compute sizes for single databases.

请注意,此示例未考虑池中其他数据库的使用率。Note this example does not consider utilization of other databases in the pool. 如果在任何给定时间点,所有数据库都有一些使用量,则可以同时处于高峰的数据库应少于 2/3(或 67%)。If all databases have some utilization at any given point in time, then less than 2/3 (or 67%) of the databases can peak simultaneously.

每个数据库的资源使用率Resource utilization per database

数据库的高峰和平均使用率之间的差异为,长时间的低使用率和短时间的高使用率。A large difference between the peak and average utilization of a database indicates prolonged periods of low utilization and short periods of high utilization. 这个使用模式非常适合在数据库之间共享资源。This utilization pattern is ideal for sharing resources across databases. 当数据库的高峰使用率比平均使用率大 1.5 倍左右时,应考虑将数据库用作池。A database should be considered for a pool when its peak utilization is about 1.5 times greater than its average utilization.

基于 DTU 的购买模型示例:高峰为 100 个 DTU 且平均使用 67 个或更少 DTU 的 S3 数据库是在池中共享 eDTU 的良好候选项。DTU-based purchasing model example: An S3 database that peaks to 100 DTUs and on average uses 67 DTUs or less is a good candidate for sharing eDTUs in a pool. 或者,高峰为 20 个 DTU 且平均使用 13 个或更少 DTU 的 S1 数据库是池的良好候选项。Alternatively, an S1 database that peaks to 20 DTUs and on average uses 13 DTUs or less is a good candidate for a pool.

如何选择正确的池大小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:

  • 池中所有数据库使用的最大资源(最大 DTU 数或最大 vCore 数,具体取决于所选的资源模型)。Maximum resources utilized by all databases in the pool (either maximum DTUs or maximum vCores depending on your choice of resourcing model).
  • 池中所有数据库使用的最大存储字节。Maximum storage bytes utilized by all databases in the pool.

有关每个资源模型提供的服务层级,请参阅基于 DTU 的购买模型基于 vCore 的购买模型For available service tiers for each resource model, see the DTU-based purchasing model or the vCore-based purchasing model.

在无法使用工具的情况下,以下分步步骤有助于评估池是否比单一数据库更具成本效益:In cases where you can't use tooling, the following step-by-step 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 的购买模型:MAX(<数据库的总数目 X 每一数据库的平均 DTU 使用率 >,For DTU-based purchasing model: MAX(<Total number of DBs X average DTU utilization per DB>,

    <并发高峰数据库的数目 X 每一数据库的高峰 DTU 使用率 )<Number of concurrently peaking DBs X Peak DTU utilization per DB)

    对于基于 vCore 的购买模型:MAX(<数据库的总数目 X 每一数据库的平均 vCore 使用率>、For vCore-based purchasing model: MAX(<Total number of DBs X average vCore utilization per DB>,

    <并发高峰数据库的数目 X 每一数据库的高峰 vCore 使用率)<Number of concurrently peaking DBs X Peak vCore utilization per DB)

  2. 通过将池内所有的数据库所需的字节数相加来估算池所需要的存储空间。Estimate the storage space needed for the pool by adding the number of bytes needed for all the databases in the pool. 然后,确定提供此存储量的 eDTU 池的大小。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. 将步骤 5 的池价格与使用单一数据库适当计算大小的价格相比较。Compare the pool price from Step 5 to the price of using the appropriate compute sizes for single databases.

将其他 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. 或者可以创建一个弹性池:导航到现有 SQL 服务器,然后单击“创建池”,直接在该服务器中创建一个池。 Or you can create an elastic pool by navigating to an existing SQL server and clicking Create pool to create a pool directly into that server. 此处的唯一差别是要跳过在池预配工作流期间指定服务器的步骤。The only difference here is you skip the step where you specify the server during the pool provisioning workflow.

Note

可以在服务器上创建多个池,但不能将数据库从不同的服务器添加到同一个池中。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.

若要开始监视弹性池,请在门户中找到并打开该弹性池。To start monitoring your elastic pool, find and open an elastic pool in the portal. 首先会出现一个屏幕,其中概述了该弹性池的状态。You will first see a screen that gives you an overview of the status of your elastic pool. 这包括:This includes:

  • 显示弹性池资源使用情况的监视图表Monitoring charts showing resources usage of the elastic pool
  • 针对弹性池的最近警报和建议(如果有)Recent alerts and recommendations, if available, for the elastic pool

下图显示一个示例弹性池:The following graphic shows an example elastic pool:

池视图

如需有关池的详细信息,可在此概述中单击任何可用信息。If you want more information about the pool you can click on any of the available information in this overview. 单击“资源利用率”图表会转到“Azure 监视”视图,在其中可以自定义图表中显示的指标和时间段。 Clicking on the Resource utilization chart will take you to the Azure Monitoring view where you can customize the metrics and time window shown in the chart. 单击任何显示的通知会转到一个边栏选项卡,其中显示了该警报或建议的完整详细信息。Clicking on any available notifications will take you to a blade that shows the full details of that alert or recommendation.

若要监视池中的数据库,可在左侧资源菜单“监视”部分中单击“数据库资源利用率”。 If you would like to monitor the databases inside your pool, you can click on Database resource utilization in the Monitoring section of the resource menu on the left.

数据库资源利用率页

自定义图表显示To customize the chart display

可以编辑图表和指标页以显示其他指标,如 CPU 百分比、数据 IO 百分比和已用日志 IO 百分比。You can edit the chart and the metric page to display other metrics such as CPU percentage, data IO percentage, and log IO percentage used.

在“编辑图表”窗体中,可选择固定时间范围,或单击“自定义”选择过去两周内的任何 24 小时时间段,然后选择要监视的资源 。On the Edit Chart form, you can select a fixed time range or click custom to select any 24-hour window in the last two weeks, and then select the resources to monitor.

选择要监视的数据库To select databases to monitor

默认情况下,“数据库资源利用率”边栏选项卡中的图表按 DTU 或 CPU(取决于服务层级)显示排名靠前的 5 个数据库。 By default, the chart in the Database Resource Utilization blade will show the top 5 databases by DTU or CPU (depending on your service tier). 可以在图表下面的列表中,通过选中和取消选中左侧的复选框,在此图表中显示或隐藏相应的数据库。You can switch up the databases in this chart by selecting and unselecting databases from the list below the chart via the checkboxes on the left.

还可以选择在此数据库表中并列查看更多的指标,以获取更完整的数据库性能视图。You can also select more metrics to view side by side in this database table to get a more complete view of your databases performance.

有关详细信息,请参阅在 Azure 门户中创建 SQL 数据库警报For more information, see create SQL Database alerts in Azure portal.

后续步骤Next steps