Delen via


Doorvoerbewerkingen (RU/s) met Azure CLI voor een database of container voor Azure Cosmos DB voor NoSQL

VAN TOEPASSING OP: NoSQL

Met het script in dit artikel maakt u een API voor NoSQL-database met gedeelde doorvoer en een API voor NoSQL-container met toegewezen doorvoer, waarna de doorvoer voor zowel de database als de container wordt bijgewerkt. Met het script wordt de migratie van standaarddoorvoer naar doorvoer met automatische schaalaanpassing uitgevoerd en de waarde van doorvoer met automatische schaalaanpassing gelezen nadat de migratie is voltooid.

Als u geen Azure-abonnement hebt, kunt u een gratis Azure-account maken voordat u begint.

Vereisten

  • Voor dit artikel is versie 2.12.1 of hoger van Azure CLI vereist. Als u Azure Cloud Shell gebruikt, is de nieuwste versie al geïnstalleerd.

Voorbeeldscript

Azure Cloud Shell starten

Azure Cloud Shell is een gratis interactieve shell waarmee u de stappen in dit artikel kunt uitvoeren. In deze shell zijn algemene Azure-hulpprogramma's vooraf geïnstalleerd en geconfigureerd voor gebruik met uw account.

Als u Cloud Shell wilt openen, selecteert u Proberen in de rechterbovenhoek van een codeblok. U kunt Cloud Shell ook openen in een afzonderlijk browsertabblad door naar https://shell.azure.com te gaan.

Wanneer Cloud Shell wordt geopend, controleert u of Bash is geselecteerd voor uw omgeving. Volgende sessies gebruiken Azure CLI in een Bash-omgeving, selecteer Kopiëren om de codeblokken te kopiëren, plak deze in Cloud Shell en druk op Enter om deze uit te voeren.

Aanmelden bij Azure

Cloud Shell wordt automatisch geverifieerd onder het eerste account waarmee is aangemeld. Gebruik het volgende script om u aan te melden met een ander abonnement, waarbij u <Subscription ID> uw Azure-abonnements-id vervangt. Als u geen Azure-abonnement hebt, kunt u een gratis Azure-account maken voordat u begint.

subscription="<subscriptionId>" # add subscription here

az account set -s $subscription # ...or use 'az login'

Zie Voor meer informatie het instellen van een actief abonnement of het interactief aanmelden

Het script uitvoeren

# Throughput operations for a SQL API database and container

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="throughput-sql-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
database="msdocs-db-sql-cosmos"
container="container1"
partitionKey="/partitionKey"
originalThroughput=400
updateThroughput=500

# Create a resource group
echo "Creating $resourceGroup in $location..."
az group create --name $resourceGroup --location "$location" --tags $tag

# Create a Cosmos account for SQL API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup

# Create a SQL API database
echo "Creating $database with $originalThroughput"
az cosmosdb sql database create --account-name $account --resource-group $resourceGroup --name $database --throughput $originalThroughput

# Create a SQL API container
echo "Creating $container with $maxThroughput"
az cosmosdb sql container create --account-name $account --resource-group $resourceGroup --database-name $database --name $container --partition-key-path $partitionKey --throughput $originalThroughput

# Throughput operations for SQL API database
#   Read the current throughput
#   Read the minimum throughput
#   Make sure the updated throughput is not less than the minimum
#   Update the throughput
#   Migrate between standard (manual) and autoscale throughput
#   Read the autoscale max throughput

# Retrieve the current provisioned database throughput
az cosmosdb sql database throughput show --resource-group $resourceGroup --account-name $account --name $database --query resource.throughput -o tsv

# Retrieve the minimum allowable database throughput
minimumThroughput=$(az cosmosdb sql database throughput show --resource-group $resourceGroup --account-name $account --name $database --query resource.minimumThroughput -o tsv)

echo $minimumThroughput

# Make sure the updated throughput is not less than the minimum allowed throughput
if [ $updateThroughput -lt $minimumThroughput ]; then
    updateThroughput=$minimumThroughput
fi

# Update database throughput
echo "Updating $database throughput to $updateThroughput"
az cosmosdb sql database throughput update --account-name $account --resource-group $resourceGroup --name $database --throughput $updateThroughput

# Migrate the database from standard (manual) throughput to autoscale throughput
az cosmosdb sql database throughput migrate --account-name $account --resource-group $resourceGroup --name $database --throughput-type "autoscale"

# Retrieve current autoscale provisioned max database throughput
az cosmosdb sql database throughput show --account-name $account --resource-group $resourceGroup --name $database --query resource.autoscaleSettings.maxThroughput -o tsv

# Throughput operations for SQL API container
#   Read the current throughput
#   Read the minimum throughput
#   Make sure the updated throughput is not less than the minimum
#   Update the throughput
#   Migrate between standard (manual) and autoscale throughput
#   Read the autoscale max throughput

# Retrieve the current provisioned container throughput
az cosmosdb sql container throughput show --account-name $account --resource-group $resourceGroup --database-name $database --name $container --query resource.throughput -o tsv

# Retrieve the minimum allowable container throughput
minimumThroughput=$(az cosmosdb sql container throughput show --account-name $account --resource-group $resourceGroup --database-name $database --name $container --query resource.minimumThroughput -o tsv)
echo $minimumThroughput

# Make sure the updated throughput is not less than the minimum allowed throughput
if [ $updateThroughput -lt $minimumThroughput ]; then
    updateThroughput=$minimumThroughput
fi

# Update container throughput
echo "Updating $container throughput to $updateThroughput"
az cosmosdb sql container throughput update --account-name $account --resource-group $resourceGroup --database-name $database --name $container --throughput $updateThroughput

# Migrate the container from standard (manual) throughput to autoscale throughput
az cosmosdb sql container throughput migrate --account-name $account --resource-group $resourceGroup --database-name $database --name $container --throughput "autoscale"

# Retrieve the current autoscale provisioned max container throughput
az cosmosdb sql container throughput show --account-name $account --resource-group $resourceGroup --database-name $database --name $container --query resource.autoscaleSettings.maxThroughput -o tsv

Resources opschonen

Gebruik de volgende opdracht om de resourcegroep en alle bijbehorende resources te verwijderen met behulp van de opdracht az group delete - tenzij u deze resources voortdurend nodig hebt. Het kan even duren voordat sommige van deze resources zijn gemaakt en dat deze kunnen worden verwijderd.

az group delete --name $resourceGroup

Voorbeeldverwijzing

In dit script worden de volgende opdrachten gebruikt. Elke opdracht in de tabel is een koppeling naar specifieke documentatie over de opdracht.

Opdracht Opmerkingen
az group create Hiermee wordt een resourcegroep gemaakt waarin alle resources worden opgeslagen.
az cosmosdb create Hiermee wordt een Azure Cosmos DB-account gemaakt.
az cosmosdb sql database create Hiermee maakt u een Azure Cosmos DB for NoSQL-database.
az cosmosdb sql container create Hiermee maakt u een Azure Cosmos DB for NoSQL-container.
az cosmosdb sql database throughput update Doorvoer bijwerken voor een Azure Cosmos DB for NoSQL-database.
az cosmosdb sql container throughput update Doorvoer bijwerken voor een Azure Cosmos DB for NoSQL-container.
az cosmosdb sql database throughput migrate Doorvoer migreren voor een Azure Cosmos DB for NoSQL-database.
az cosmosdb sql container throughput migrate Doorvoer migreren voor een Azure Cosmos DB for NoSQL-container.
az group delete Hiermee verwijdert u een resourcegroep met inbegrip van alle ingesloten resources.

Volgende stappen

Raadpleeg de documentatie van Azure Cosmos DB CLI voor meer informatie over de Azure Cosmos DB CLI.