Operazioni di velocità effettiva (UR/s) con PowerShell per un database o un contenitore per Azure Cosmos DB per NoSQL
SI APPLICA A: NoSQL
Nota
È consigliabile usare il modulo Azure Az PowerShell per interagire con Azure. Per iniziare, vedere Installare Azure PowerShell. Per informazioni su come eseguire la migrazione al modulo AZ PowerShell, vedere Eseguire la migrazione di Azure PowerShell da AzureRM ad Az.
Questo esempio richiede Azure PowerShell Az 5.4.0 o versione successiva. Eseguire Get-Module -ListAvailable Az
per determinare le versioni installate.
Se è necessario installarlo, vedere Installare il modulo Azure PowerShell.
Eseguire Connect-AzAccount per accedere ad Azure.
Misurare la velocità effettiva
# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Get database or container throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$databaseName = "myDatabase"
$containerName = "myContainer"
# --------------------------------------------------
Write-Host "Get database shared throughput - if none provisioned, will return error."
Get-AzCosmosDBSqlDatabaseThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $databaseName
Write-Host "Get container dedicated throughput - if none provisioned, will return error."
Get-AzCosmosDBSqlContainerThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName `
-Name $containerName
Aggiornare la velocità effettiva
# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Update container throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$databaseName = "myDatabase"
$containerName = "myContainer"
$newRUs = 500
# --------------------------------------------------
$throughput = Get-AzCosmosDBSqlContainerThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName -Name $containerName
$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-AzCosmosDBSqlContainerThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName `
-Name $containerName -Throughput $newRUs
}
Eseguire la migrazione della velocità effettiva
# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Migrate a database or container to autoscale or standard (manual) throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$databaseName = "myDatabase"
$containerName = "myContainer"
# --------------------------------------------------
Write-Host "Migrate database with standard throughput to autoscale throughput."
Invoke-AzCosmosDBSqlDatabaseThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $databaseName -ThroughputType Autoscale
Write-Host "Migrate database with autoscale throughput to standard throughput."
Invoke-AzCosmosDBSqlDatabaseThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $databaseName -ThroughputType Manual
Write-Host "Migrate container with standard throughput to autoscale throughput."
Invoke-AzCosmosDBSqlContainerThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName -Name $containerName -ThroughputType Autoscale
Write-Host "Migrate container with autoscale throughput to standard throughput."
Invoke-AzCosmosDBSqlContainerThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName -Name $containerName -ThroughputType Manual
Pulire la distribuzione
Dopo l'esecuzione dello script di esempio, è possibile usare il comando seguente per rimuovere il gruppo di risorse e tutte le risorse ad esso associate.
Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"
Spiegazione dello script
Questo script usa i comandi seguenti. Ogni comando della tabella include collegamenti alla documentazione specifica del comando.
Comando | Note |
---|---|
Azure Cosmos DB | |
Get-AzCosmosDBSqlDatabaseThroughput | Ottenere il provisioning della velocità effettiva in un database Di Azure Cosmos DB per NoSQL. |
Get-AzCosmosDBSqlContainerThroughput | Ottenere il provisioning della velocità effettiva in un contenitore Azure Cosmos DB per NoSQL. |
Update-AzCosmosDBSqlDatabaseThroughput | Aggiornamenti il valore della velocità effettiva di un database Azure Cosmos DB per NoSQL. |
Update-AzCosmosDBSqlContainerThroughput | Aggiornamenti il valore della velocità effettiva di un contenitore Azure Cosmos DB per NoSQL. |
Invoke-AzCosmosDBSqlDatabaseThroughputMigration | Eseguire la migrazione della velocità effettiva di un database Azure Cosmos DB per NoSQL. |
Invoke-AzCosmosDBSqlContainerThroughputMigration | Eseguire la migrazione della velocità effettiva di un contenitore Azure Cosmos DB per NoSQL. |
Gruppi di risorse di Azure | |
Remove-AzResourceGroup | Consente di eliminare un gruppo di risorse incluse tutte le risorse annidate. |
Passaggi successivi
Per altre informazioni su Azure PowerShell, vedere la documentazione di Azure PowerShell.