Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autoscaling Azure SQL Database

We have an application that uses Azure SQL for the database backend. Under normal load/conditions this database can successfully run on a Premium 1 plan. However, during the early morning hours we have jobs that run that increase database load. During these few hours we need to move to a Premium 3 plan. The cost of a Premium 3 is about 8 times more, so obviously we do not want to pay the costs of running on this plan 24/7.

Is it possible to autoscale the database up and down? Cloud services offer an easy way to scale the number of instances in the Azure Portal, however, nothing like this exists for Azure SQL databases. Can this be done programmatically with the Azure SDK? I have been unable to locate any documentation on this subject.

like image 761
kspearrin Avatar asked Nov 06 '14 14:11

kspearrin


People also ask

How long does it take to scale Azure SQL managed instance?

90% of operations finish in 4 hours (creation) or 2.5 hours (resizing) . 90% of operations finish in 4 hours (creation) or 2.5 hours (resizing) + time to seed all databases (220 GB/hour).

How do I increase allocated size in SQL Azure?

Allow data growth in an elastic pool when the file space allocated for its databases reaches the pool max size. Allow decreasing the max size of a single database or elastic pool. Allow changing a single database or elastic pool to a different service tier or performance tier with a lower max size.

What is the maximum size of Azure SQL Database?

Data storage limits in Azure SQL Database have increased from 1.5 TB to 2 TB for single databases and elastic pools configured with 8 and 10 vcores.

How do I increase database storage in Azure?

Extra storage for a single database can be provisioned by increasing its max size using the Azure portal, Transact-SQL, PowerShell, the Azure CLI, or the REST API. The price of extra storage for a single database is the extra storage amount multiplied by the extra storage unit price of the service tier.


2 Answers

After digging through the articles in @ErikEJ's answer (Thanks!) I was able to find the following, which appears to be newly published with the release of the Elastic Scale preview:

Changing Database Service Tiers and Performance Levels

The following REST APIs are now newly available as well, which let you do pretty much whatever you want to your databases:

REST API Operations for Azure SQL Databases

And for my original question of scaling service tiers (ex. P1 -> P3 -> P1):

Update Database REST API

With these new developments I am going to assume it's only a matter of time before autoscaling is also available as a simple configuration in the Azure Portal, much like cloud services.

like image 167
kspearrin Avatar answered Sep 17 '22 13:09

kspearrin


Another way to do it is using Azure automation and using run book below:

param (     # Desired Azure SQL Database edition {Basic, Standard, Premium}     [parameter(Mandatory=$true)]      [string] $Edition,      # Desired performance level {Basic, S0, S1, S2, P1, P2, P3}     [parameter(Mandatory=$true)]      [string] $PerfLevel  )  inlinescript {     # I only care about 1 DB so, I put it into variable asset and access from here     $SqlServerName = Get-AutomationVariable -Name 'SqlServerName'     $DatabaseName = Get-AutomationVariable -Name 'DatabaseName'       Write-Output "Begin vertical scaling script..."      # Establish credentials for Azure SQL Database server      $Servercredential = new-object System.Management.Automation.PSCredential("yourDBadmin", ("YourPassword" | ConvertTo-SecureString -asPlainText -Force))       # Create connection context for Azure SQL Database server     $CTX = New-AzureSqlDatabaseServerContext -ManageUrl “https://$SqlServerName.database.windows.net” -Credential $ServerCredential      # Get Azure SQL Database context     $Db = Get-AzureSqlDatabase $CTX –DatabaseName $DatabaseName      # Specify the specific performance level for the target $DatabaseName     $ServiceObjective = Get-AzureSqlDatabaseServiceObjective $CTX -ServiceObjectiveName "$Using:PerfLevel"      # Set the new edition/performance level     Set-AzureSqlDatabase $CTX –Database $Db –ServiceObjective $ServiceObjective –Edition $Using:Edition -Force      # Output final status message     Write-Output "Scaled the performance level of $DatabaseName to $Using:Edition - $Using:PerfLevel"     Write-Output "Completed vertical scale" } 


Ref:
Azure Vertically Scale Runbook
Setting schedule when u want to scale up/down.
For me, I used 2 schedules with input parameters, 1 for scaling up and another one for scaling down.
Hope that help.

like image 20
Chris Phan Avatar answered Sep 20 '22 13:09

Chris Phan