This repository contains a powershell script (runbook) to shrink Databases in Azure elastic pools.
Following is the flow of Scrip
- This script take all Sql Servers (based on parameters passed)
- Then, loops over each sql server
- Then, retrives all elastic pools in each server.
- Then, loops over each get ealstic pool.
- Then, gets elasticpool metrics by exectuting sql command on master
- Then, looks of avg_allocated_storage_percent.
- If avg_allocated_storage_percent is very high (for ex: greater than 90 percent)
- Then, gets all Dbs into that elasticpool.
- Then, loops over foreach Databae.
- Then retrives Database Storage Metrics
- Then, looks for DatabaseDataSpaceAllocatedUnusedInMB (you can use percentage of Unused vs total space)
- If DatabaseDataSpaceAllocatedUnusedInMB is quite hign (for ex greater than 1GB)
- Then, shirnks the Database
This script uses AZ modules of Microsoft Azure PowerShell
https://github.com/Azure/azure-powershell/blob/master/documentation/announcing-az-module.md https://docs.microsoft.com/en-us/powershell/azure/new-azureps-module-az