MOR-PROC-039 Version 1 Last Review Date: June, 2025
Database Auto-scaling
1. Overview
In Azure, database resources are costly to run, especially at high SKU's, often costing thousands per month. High capacity SKU's are often only needed during business hours, meaning much cost is associated with times of minimal database activity. For this reason, we have established database auto-scaling, to scale down key database resources outside of business hours.
The scaling strategy can differ depending on the environment. See the individual sections for each environment for more details.
2. Database Auto-scaling on Production
2.1. Strategy
For Production, we need to ensure the platform operates smoothly for most users. As CBC's business involves maintenance service providers that operate early in the morning and with office workers potentially working late, we need a wide designation of business hours, which should generally exclude weekends. The current timeframe selected will be from 6am to 7pm weekdays, with a review planned to see what capacity is used to determine if we can reduce the 'business hours' further.
2.2. Implementation
A script was found (by Vladan) that will allow for time based, and day of week based scheduling that extends the base scheduling available to Azure runbook scheduling, allowing us to specify time and day of week where the resource should be scaled up, with the remaing time reverting to the default scaling. This script exists in an Azure Runbook, within an Azure Automation Account. The schedule runs hourly, and only makes an actual resource change if the boundary between business hours and 'default' has been crossed, i.e., twice daily.
An alert has also been created that will detect a runbook failure and alert the CMMS Support email address.
Script
The script itself is stored in the MoreCore Design Respository / Azure Scripts / Auto DB Scaling.txt file.
Script Variables
| Field | Value |
|---|---|
| Environment Name | AzureCloud |
| ResourceGroupName | CBC-AUSE |
| server name | cbc |
| database name | cmms-prod |
| Schedule | [{WeekDays:[1,2,3,4,5], StartTime:"05:59:59", StopTime:"18:59:59", Edition: "Standard", Tier: "S9"}] |
| Timezone | AUS Eastern Standard Time |
| Edition | Standard |
| Tier | S6 |
Azure Resources
3. Database Auto-scaling on POST
3.1. Strategy
THe strategy for POST differs to PROD in that we don't have an active userbase to support, nor a daily need to use the POST environment. For that reason, we don't need to scale up the database every weekday, but only when we need it. The approach is therefore to scale down the database daily at 5pm, and only upscale manually as need arises.
3.2. Implementation
A script was developed by Shane Rose to set the DTU point on the given database. No additional scheduling logic is built into the script, meaning it will action the change only when called by the Azure schedule, which is set to run at 5pm daily.
Script
The script itself is stored in the MoreCore Design Respository / Azure Scripts / SetDatabaseDTUusage.txt file.
Script Variables
| Field | Value |
|---|---|
| ResourceGroupName | cbc-performance-test-post |
| DatabaseName | cmms-prod-20230622 |
| ServerName | cbc-performance-test-post |
| newServiceObjective | S0 |