使用 PowerShell 对 Azure Cosmos DB - API for Table 的表实现的吞吐量 (RU/s) 操作
适用对象: 表
注意
建议使用 Azure Az PowerShell 模块与 Azure 交互。 请参阅安装 Azure PowerShell 以开始使用。 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 Az。
本示例需要 Azure PowerShell Az 5.4.0 或更高版本。 运行 Get-Module -ListAvailable Az
,查看已安装哪些版本。
如果需要安装,请参阅安装 Azure PowerShell 模块。
运行 Connect-AzAccount -Environment AzureChinaCloud 以登录到 Azure。
获取吞吐量
# Reference: Az.CosmosDB | https://learn.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Get RU/s throughput for Azure Cosmos DB Table API table
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$tableName = "myTable"
# --------------------------------------------------
Get-AzCosmosDBTableThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $tableName
更新吞吐量
# Reference: Az.CosmosDB | https://learn.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Update Table throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$tableName = "myTable"
$newRUs = 500
# --------------------------------------------------
$throughput = Get-AzCosmosDBTableThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $tableName
$currentRUs = $throughput.Throughput
$minimumRUs = $throughput.MinimumThroughput
Write-Host "Current throughput is $currentRUs. Minimum allowed throughput is $minimumRUs."
if ([int]$newRUs -lt [int]$minimumRUs) {
Write-Host "Requested new throughput of $newRUs is less than minimum allowed throughput of $minimumRUs."
Write-Host "Using minimum allowed throughput of $minimumRUs instead."
$newRUs = $minimumRUs
}
if ([int]$newRUs -eq [int]$currentRUs) {
Write-Host "New throughput is the same as current throughput. No change needed."
}
else {
Write-Host "Updating throughput to $newRUs."
Update-AzCosmosDBTableThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $tableName `
-Throughput $newRUs
}
迁移吞吐量
# Reference: Az.CosmosDB | https://learn.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Migrate a table to autoscale or standard (manual) throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$tableName = "myTable"
# --------------------------------------------------
Write-Host "Migrate table with standard throughput to autoscale throughput."
Invoke-AzCosmosDBTableThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $tableName -ThroughputType Autoscale
Write-Host "Migrate table with autoscale throughput to standard throughput."
Invoke-AzCosmosDBTableThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $tableName -ThroughputType Manual
清理部署
运行脚本示例后,可以使用以下命令删除资源组以及与其关联的所有资源。
Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"
脚本说明
此脚本使用以下命令。 表中的每条命令均链接到特定于命令的文档。
命令 | 注释 |
---|---|
Azure Cosmos DB | |
Get-AzCosmosDBTableThroughput | 获取指定 API for Table 的吞吐量值。 |
Update-AzCosmosDBMongoDBCollectionThroughput | 更新 API for Table 的吞吐量值。 |
Invoke-AzCosmosDBTableThroughputMigration | 迁移 API for Table Table 的吞吐量。 |
Azure 资源组 | |
Remove-AzResourceGroup | 删除资源组,包括所有嵌套的资源。 |
后续步骤
有关 Azure PowerShell 的详细信息,请参阅 Azure PowerShell 文档。