你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用命令行工具处理超大规模弹性池

适用于:Azure SQL 数据库

本文介绍如何使用命令行工具(如 Azure CLI 和 PowerShell)创建、缩放数据库,并将其移动到超大规模弹性池。 除了这些方法之外,你始终可以使用 Azure 门户进行大多数操作。

注意

超大规模弹性池目前处于预览状态。

先决条件

若要使用超大规模弹性池,应具有:

创建新超大规模弹性池

可以使用 Azure CLI 或 Azure PowerShell 创建超大规模弹性池。

使用 az sql elastic-pool create 命令创建超大规模弹性池。

以下示例创建一个具有四个 vCore 和两个辅助池副本的超大规模弹性池:

az sql elastic-pool create --resource-group "my-example-rg" --server "my-example-sql-svr" --name "my_hs_pool" --edition "Hyperscale" --capacity 4 --family Gen5 --ha-replicas 2

以下示例创建一个具有四个 vCore 和一个辅助池副本的区域冗余超大规模弹性池:

az sql elastic-pool create --resource-group "myresourcegroup" --server "mylogicalserver" --name "zr-hs-ep" --family Gen5 --edition Hyperscale --capacity 4 --ha-replicas 1 --zone-redundant

纵向扩展超大规模弹性池

可以使用 Azure CLI 或 Azure PowerShell 纵向扩展现有超大规模弹性池。

使用 az sql elastic-pool update 命令纵向扩展现有超大规模弹性池。

以下示例将现有超大规模弹性池纵向扩展到 8 个 vCore,并将每个 DB 的最小值和最大值分别设置为 0 和 2:

az sql elastic-pool update --resource-group "my-example-rg" --server "my-example-sql-svr" --name "my_hs_pool" --capacity 8 --db-min-capacity 0 --db-max-capacity 2

横向扩展(或缩减)超大规模弹性池

使用 Azure CLI 或 Azure PowerShell 添加或删除现有超大规模弹性池的辅助池副本(也称为横向扩展或横向缩减)。

使用 az sql elastic-pool update 命令,通过添加辅助池副本横向扩展现有超大规模弹性池,或删除辅助池副本在弹性池中进行横向缩减。

以下示例横向扩展现有超大规模弹性池,以使用四个辅助池副本:

# use the --ha-replicas (--read-replicas can also be used) parameter to specify the new number of high-availability replicas:
az sql elastic-pool update --resource-group "my-example-rg" --server "my-example-sql-svr" --name "my_hs_pool" --ha-replicas 4

以下示例横向缩减现有超大规模弹性池,以使用一个辅助池副本:

# use the --ha-replicas (--read-replicas can also be used) parameter to specify the new number of high-availability replicas:
az sql elastic-pool update --resource-group "my-example-rg" --server "my-example-sql-svr" --name "my_hs_pool" --ha-replicas 1

将现有数据库移动到超大规模弹性池

可以使用 Azure CLI 或 Azure PowerShell 将 Azure SQL 数据库中的现有数据库移动到现有超大规模弹性池中。

使用 az sql db update 命令将现有数据库移动到现有超大规模弹性池中。

以下示例将数据库 my_existing_db 移动到现有超大规模弹性池 my_hs_pool 中:

az sql db update --resource-group "my-example-rg" --server "my-example-sql-svr" --name "my_existing_db" --elastic-pool "my_hs_pool"

将现有弹性池从 Gen5 升级到高级系列硬件

可以使用 Azure CLI 或 Azure PowerShell 将现有弹性池从 Gen5 升级到高级系列硬件。

目前无法通过 Azure CLI 使用。 请改为使用 Azure PowerShell 或 Azure 门户。

将现有常规用途数据库迁移到区域冗余超大规模弹性池

可以使用 Azure CLI 或 Azure PowerShell 将现有的常规用途数据库迁移到区域冗余超大规模弹性池。

az sql db update --resource-group "myresourcegroup" --server "mylogicalserver" --name "gp_zrs_standalone_db" --elastic-pool "zr-hs-ep" --backup-storage-redundancy Zone

REST API

使用 2021-11-01 REST API(或更高版本)来处理超大规模弹性池的次要副本。

以下示例横向扩展现有超大规模弹性池,以使用四个辅助副本:

PATCH https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}?api-version=2021-11-01-preview

{
  "properties": {
    "highAvailabilityReplicaCount": 4
  }
}