MoreCore Platform
Automation
Database Auto-scaling
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

FieldValue
Environment NameAzureCloud
ResourceGroupNameCBC-AUSE
server namecbc
database namecmms-prod
Schedule[{WeekDays:[1,2,3,4,5], StartTime:"05:59:59", StopTime:"18:59:59", Edition: "Standard", Tier: "S9"}]
TimezoneAUS Eastern Standard Time
EditionStandard
TierS6

Azure Resources

Resource TypeNameLink
Automation AccountAutomationhttps://portal.azure.com/#@cbcgroup.com.au/resource/subscriptions/e89e4cf9-5904-400a-9af4-531dd7b774bd/resourceGroups/cmms-prod/providers/Microsoft.Automation/automationAccounts/Automation/overview (opens in a new tab)
RunbookAzureSQLDatabaseScheduledAutoScalinghttps://portal.azure.com/#@cbcgroup.com.au/resource/subscriptions/e89e4cf9-5904-400a-9af4-531dd7b774bd/resourceGroups/cmms-prod/providers/Microsoft.Automation/automationAccounts/Automation/runbooks/AzureSQLDatabaseScheduledAutoScaling/overview (opens in a new tab)

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

FieldValue
ResourceGroupNamecbc-performance-test-post
DatabaseNamecmms-prod-20230622
ServerNamecbc-performance-test-post
newServiceObjectiveS0

Azure Resources

Resource TypeNameLink
Automation Accountcbc-post-automationhttps://portal.azure.com/#@cbcgroup.com.au/resource/subscriptions/e89e4cf9-5904-400a-9af4-531dd7b774bd/resourceGroups/cbc-performance-test-post/providers/Microsoft.Automation/automationAccounts/cbc-post-automation/overview (opens in a new tab)
RunbookSetDatabaseDTUUsagehttps://portal.azure.com/#@cbcgroup.com.au/resource/subscriptions/e89e4cf9-5904-400a-9af4-531dd7b774bd/resourceGroups/cbc-performance-test-post/providers/Microsoft.Automation/automationAccounts/cbc-post-automation/runbooks/SetDatabaseDTUusage/overview (opens in a new tab)