SQL Server is not cheap! If you have a small to medium sized database, spending £40k on SQL licencing on top of hardware costs is prohibitively expensive. Add to that: Backups, hardware redundency, site failure recovery, physical and electronic security while still maintaining access for users. It's an expensive game if you do it on the cheap and a really really expensive game if you do it right. What's the answer?
Azure?
Azure can become expensive too. Beyond the 'Basic' SQL single SQL Database at around £5/m ($6), you have the option of several 'Standard' tiers before you're into the 'Premium' tier and the vCore based purchasing model. For this post, I'm going to look at the Basic and Standard offerings for small to medium sized databases. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
What Azure SQL Tiers are there? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Azure SQL Single Database SKUs
Note: Prices will vary over time and depending on your agreement with Microsoft. The key takeaway here is that costs go up as performance goes up. Note: For simplicity on the per hour value, a month is calculated as 30days or 720hrs. Note: For simplicity vCore based purchasing and Elastic-Pool configurations have been omitted |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
How Much Could You Save Scaling Down Overnight? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Lets just assume you need good performance for your sales team during the day, they need an S4 instance with 200 DTUs. From 6pm to 6am, the phone lines are closed and only management are likely to be tinkering.
Running an S4 instance 24/7 would cost around $368.08/m or $4417/y If you scaled down to an S0 overnight, you would save $174.84/m or $2098/y
Just under 50% saving! |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
How Much Time Could You Save Running a Heavy Job? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Lets just assume you have a data-refresh job that takes 24hrs on an S0 instance with 10DTUs, the rest of the time your website pulls data every now and again. If you ran the same job on an S6 instance with 400DTUs, in theory it should take around 40 minutes. (it's not an exact science) An S6 instance would cost you $1.02 for the hour's uplift. That kind of shift makes the impossible possible!
Running an S6 instance 24/7 would cost $8834/y Running an S0 instance 23/7 and an S6 for 1hr per day would cost $578/y |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Is Switching Service Tiers Easy? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
What About Automating the Change? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Scaling can be done from TSQL inside your database (Query, Stored Procedure etc.) or in PowerShell |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TSQL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The key piece of TSQL code looks as simple as this:
You will need to wrap this code in some error checking if running it automatically. You may also need to wait until the scaling process has completed. The SQL command will return instantly.
The following code wraps some basic error checking around the scaling code. The code scales the SQL Database to an S6 instance, does a resource intensive task (SELECT @@VERSION) and then reverts the database to it's original SKU. In production you would want to add additional error checking, logging, exception handling etc. You wouldn't want to be stuck on a P15 SQU until the bill drops on your doormat.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PowerShell | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The Simple PowerShell to Scale a Database is:
A list of useful SQL PowerShell Commands can be found here: set-azsqldatabase |