Skip to content

Latest commit

 

History

History
63 lines (47 loc) · 3.5 KB

File metadata and controls

63 lines (47 loc) · 3.5 KB
title Use PowerShell to Monitor and Scale a Single Database
description Use an Azure PowerShell example script to monitor and scale a single database in Azure SQL Database.
author WilliamDAssafMSFT
ms.author wiassaf
ms.reviewer wiassaf, mathoma
ms.date 06/10/2025
ms.service azure-sql-database
ms.subservice performance
ms.topic sample
ms.custom
sqldbrb=1
devx-track-azurepowershell
ms.devlang powershell

Use PowerShell to monitor and scale a single database in Azure SQL Database

[!INCLUDEappliesto-sqldb]

This PowerShell script example monitors the performance metrics of a single database, scales it to a higher compute size, and creates an alert rule on one of the performance metrics.

[!INCLUDE quickstarts-free-trial-note] [!INCLUDE updated-for-az] [!INCLUDE cloud-shell-try-it.md]

If you choose to install and use PowerShell locally, this tutorial requires Az PowerShell 1.4.0 or later. If you need to upgrade, see Install Azure PowerShell module. If you are running PowerShell locally, you also need to run Connect-AzAccount to create a connection with Azure.

Sample script

[!code-powershell-interactivemain]

Note

For a full list of metrics, see metrics supported. [!TIP] Use Get-AzSqlDatabaseActivity to get the status of database operations and use Stop-AzSqlDatabaseActivity to cancel a database update operation.

Clean up deployment

Use the following command to remove the resource group and all resources associated with it.

Remove-AzResourceGroup -ResourceGroupName $resourcegroupname

Script explanation

This script uses the following commands. Each command in the table links to command-specific documentation.

Command Notes
New-AzResourceGroup Creates a resource group in which all resources are stored.
New-AzSqlServer Creates a server that hosts a single database or elastic pool.
Get-AzMetric Shows the size usage information for the database.
Set-AzSqlDatabase Updates database properties or moves the database into, out of, or between elastic pools.
Add-AzMetricAlertRule (Deprecated) Adds or updates an alert rule to automatically monitor metrics in the future. Applies only to classic metric-based alert rules.
Add-AzMetricAlertRuleV2 Adds or updates an alert rule to automatically monitor metrics in the future. Applies only to non-classic metric-based alert rules.
Remove-AzResourceGroup Deletes a resource group including all nested resources.

Related content