Operasi throughput (RU/s) dengan PowerShell untuk database atau kontainer untuk Azure Cosmos DB for NoSQL
BERLAKU UNTUK: NoSQL
Catatan
Kami menyarankan agar Anda menggunakan modul Azure Az PowerShell untuk berinteraksi dengan Azure. Lihat Menginstal Azure PowerShell untuk memulai. Untuk mempelajari cara bermigrasi ke modul Az PowerShell, lihat Memigrasikan Azure PowerShell dari AzureRM ke Az.
Sampel ini memerlukan Azure PowerShell Az 5.4.0 atau yang lebih baru. Jalankan Get-Module -ListAvailable Az
untuk melihat versi mana yang dipasang.
Jika Anda perlu memasang, lihat Pasang modul Azure PowerShell.
Jalankan Connect-AzAccount untuk masuk ke Azure.
Dapatkan throughput
# 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
Perbarui throughput
# 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
}
Migrasikan throughput
# 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
Membersihkan penyebaran
Setelah sampel skrip dijalankan, perintah berikut dapat digunakan untuk menghapus grup sumber daya dan semua sumber daya yang terkait.
Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"
Penjelasan skrip
Skrip ini menggunakan perintah berikut. Setiap perintah dalam tabel ditautkan ke dokumentasi spesifik perintah.
Perintah | Catatan |
---|---|
Azure Cosmos DB | |
Get-AzCosmosDBSqlDatabaseThroughput | Dapatkan throughput yang disediakan pada Azure Cosmos DB untuk NoSQL Database. |
Get-AzCosmosDBSqlContainerThroughput | Dapatkan throughput yang disediakan pada Azure Cosmos DB untuk Kontainer NoSQL. |
Update-AzCosmosDBSqlDatabaseThroughput | Updates nilai throughput Azure Cosmos DB untuk Database NoSQL. |
Update-AzCosmosDBSqlContainerThroughput | Updates nilai throughput Azure Cosmos DB untuk Kontainer NoSQL. |
Invoke-AzCosmosDBSqlDatabaseThroughputMigration | Memigrasikan throughput Azure Cosmos DB untuk NoSQL Database. |
Invoke-AzCosmosDBSqlContainerThroughputMigration | Memigrasikan throughput Azure Cosmos DB untuk Kontainer NoSQL. |
Grup Sumber Daya Azure | |
Remove-AzResourceGroup | Menghapus grup sumber daya termasuk semua sumber daya berlapis. |
Langkah berikutnya
Untuk informasi selengkapnya tentang Azure PowerShell, lihat dokumentasi Azure PowerShell.