快速入门:通过 Azure PowerShell 暂停和恢复 Synapse SQL 池中的计算Quickstart: Pause and resume compute in Synapse SQL pool with Azure PowerShell

可以使用 Azure PowerShell 暂停和恢复 Synapse SQL 池(数据仓库)计算资源。You can use Azure PowerShell to pause and resume the Synapse SQL pool (data warehouse) compute resources. 如果没有 Azure 订阅,可在开始前创建一个 1 元人民币试用帐户。If you don't have an Azure subscription, create a 1rmb trial account before you begin.

准备阶段Before you begin

Note

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

本快速入门假设已有一个可以暂停和恢复的 SQL 池。This quickstart assumes you already have a SQL pool that you can pause and resume. 如果需要创建一个 SQL 池,可以参考创建和连接 - 门户创建名为 mySampleDataWarehouse 的 SQL 池。If you need to create one, you can use Create and Connect - portal to create a SQL pool called mySampleDataWarehouse.

登录 AzureLog in to Azure

使用 Connect-AzAccount -EnvironmentName AzureChinaCloud 命令登录到 Azure 订阅,并按屏幕说明操作。Log in to your Azure subscription using the Connect-AzAccount -EnvironmentName AzureChinaCloud command and follow the on-screen directions.

Connect-AzAccount -EnvironmentName AzureChinaCloud

若要查看正在使用的订阅,请运行 Get-AzSubscriptionTo see which subscription you are using, run Get-AzSubscription.

Get-AzSubscription

如果需要使用与默认订阅不同的订阅,请运行 Set-AzContextIf you need to use a different subscription than the default, run Set-AzContext.

Set-AzContext -SubscriptionName "MySubscription"

查找 SQL 池信息Look up SQL pool information

查找计划暂停和恢复的 SQL 池的数据库名称、服务器名称和资源组。Locate the database name, server name, and resource group for the SQL pool you plan to pause and resume.

按照以下步骤查找 SQL 池的位置信息:Follow these steps to find location information for your SQL pool:

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 在 Azure 门户的左侧页中单击“Azure Synapse Analytics (前称为 SQL 数据仓库)”。 Click Azure Synapse Analytics (formerly SQL DW) in the left page of the Azure portal.

  3. 从“Azure Synapse Analytics (以前称为 SQL DW)” 页中选择 mySampleDataWarehouseSelect mySampleDataWarehouse from the Azure Synapse Analytics (formerly SQL DW) page. 此时将打开 SQL 池。The SQL pool opens.

    服务器名称和资源组

  4. 记下 SQL 池名称,即数据库名称。Write down the SQL pool name, which is the database name. 同时记下服务器名称和资源组。Also write down the server name, and the resource group.

  5. 在 PowerShell cmdlet 中请仅使用服务器名称的第一个组成部分。Use only the first part of the server name in the PowerShell cmdlets. 在上图中,完整的服务器名称为“sqlpoolservername.database.chinacloudapi.cn”。In the preceding image, the full server name is sqlpoolservername.database.chinacloudapi.cn. 我们在 PowerShell cmdlet 中使用 sqlpoolservername 作为服务器名称。We use sqlpoolservername as the server name in the PowerShell cmdlet.

暂停计算Pause compute

为了节省成本,可以按需暂停和恢复计算资源。To save costs, you can pause and resume compute resources on-demand. 例如,如果晚上和周末不使用数据库,那么可以在这些时间暂停数据库的使用,然后在白天时恢复使用。For example, if you are not using the database during the night and on weekends, you can pause it during those times, and resume it during the day.

Note

数据库暂停时,不对计算资源进行收费。There is no charge for compute resources while the database is paused. 但是,仍将收取存储费用。However, you continue to be charged for storage.

若要暂停数据库,请使用 Suspend-AzSqlDatabase cmdlet。To pause a database, use the Suspend-AzSqlDatabase cmdlet. 以下示例暂停 sqlpoolservername 服务器上托管的 SQL 池 mySampleDataWarehouseThe following example pauses a SQL pool named mySampleDataWarehouse hosted on a server named sqlpoolservername. 该服务器位于名为 myResourceGroup 的 Azure 资源组中 。The server is in an Azure resource group named myResourceGroup.

Suspend-AzSqlDatabase -ResourceGroupName "myResourceGroup" `
-ServerName "nsqlpoolservername" -DatabaseName "mySampleDataWarehouse"

以下示例将数据库检索到 $database 对象中。The following example retrieves the database into the $database object. 然后,它通过管道将该对象传递给 Suspend-AzSqlDatabaseIt then pipes the object to Suspend-AzSqlDatabase. 结果存储在对象 resultDatabase 中。The results are stored in the object resultDatabase. 最后一个命令显示结果。The final command shows the results.

$database = Get-AzSqlDatabase -ResourceGroupName "myResourceGroup" `
-ServerName "sqlpoolservername" -DatabaseName "mySampleDataWarehouse"
$resultDatabase = $database | Suspend-AzSqlDatabase
$resultDatabase

恢复计算Resume compute

若要启动数据库,请使用 Resume-AzSqlDatabase cmdlet。To start a database, use the Resume-AzSqlDatabase cmdlet. 以下示例启动 sqlpoolservername 服务器上托管的 mySampleDataWarehouse 数据库。The following example starts a database named mySampleDataWarehouse hosted on a server named sqlpoolservername. 该服务器位于名为 myResourceGroup 的 Azure 资源组中 。The server is in an Azure resource group named myResourceGroup.

Resume-AzSqlDatabase -ResourceGroupName "myResourceGroup" `
-ServerName "sqlpoolservername" -DatabaseName "mySampleDataWarehouse"

下一示例将数据库检索到 $database 对象中。The next example retrieves the database into the $database object. 然后,它通过管道将对象传递给 Resume-AzSqlDatabase,并将结果存储在 $resultDatabase 中。It then pipes the object to Resume-AzSqlDatabase and stores the results in $resultDatabase. 最后一个命令显示结果。The final command shows the results.

$database = Get-AzSqlDatabase -ResourceGroupName "myResourceGroup" `
-ServerName "sqlpoolservername" -DatabaseName "mySampleDataWarehouse"
$resultDatabase = $database | Resume-AzSqlDatabase
$resultDatabase

检查 SQL 池操作的状态Check status of your SQL pool operation

若要检查 SQL 池的状态,请使用 Get-AzSqlDatabaseActivity cmdlet。To check the status of your SQL pool, use the Get-AzSqlDatabaseActivity cmdlet.

Get-AzSqlDatabaseActivity -ResourceGroupName "myResourceGroup" -ServerName "sqlpoolservername" -DatabaseName "mySampleDataWarehouse"

清理资源Clean up resources

针对 SQL 池的数据仓库单元数和存储的数据收费。You are being charged for data warehouse units and data stored your SQL pool. 这些计算和存储资源是分开计费的。These compute and storage resources are billed separately.

  • 要将数据保存在存储中,请暂停计算。If you want to keep the data in storage, pause compute.
  • 若要避免将来产生费用,可以删除该 SQL 池。If you want to remove future charges, you can delete the SQL pool.

请按照下列步骤按需清理资源。Follow these steps to clean up resources as you desire.

  1. 登录到 Azure 门户并单击该 SQL 池。Sign in to the Azure portal, and click on your SQL pool.

    清理资源

  2. 要暂停计算,请单击“暂停” 按钮。To pause compute, click the Pause button. 暂停 SQL 池后,会看到“启动”按钮。 When the SQL pool is paused, you see a Start button. 要恢复计算,请单击“启动” 。To resume compute, click Start.

  3. 若要删除 SQL 池以免产生计算或存储费用,请单击“删除”。 To remove the SQL pool so you are not charged for compute or storage, click Delete.

  4. 若要删除创建的 SQL 服务器,请依次单击“sqlpoolservername.database.chinacloudapi.cn”、“删除”。 To remove the SQL server you created, click sqlpoolservername.database.chinacloudapi.cn, and then click Delete. 请谨慎执行此删除操作,因为删除服务器的同时也会删除分配给该服务器的所有数据库。Be careful with this deletion, since deleting the server also deletes all databases assigned to the server.

  5. 要删除资源组,请单击“myResourceGroup” ,然后单击“删除资源组” 。To remove the resource group, click myResourceGroup, and then click Delete resource group.

后续步骤Next steps

若要详细了解 SQL 池,请继续阅读将数据加载到 SQL 池一文。To learn more about SQL pool, continue to the Load data into SQL pool article. 有关管理计算功能的其他信息,请参阅管理计算概述一文。For additional information about managing compute capabilities, see the Manage compute overview article.