自动调整Azure SQL数据库

ksp*_*rin 36 azure azure-elastic-scale azure-sql-database

我们有一个使用Azure SQL作为数据库后端的应用程序.在正常负载/条件下,此数据库可以在Premium 1计划上成功运行.但是,在凌晨时分,我们有一些工作会增加数据库负载.在这几个小时内,我们需要转向Premium 3计划.Premium 3的成本大约是8倍,所以显然我们不想支付全天候运行此计划的成本.

是否可以上下自动调整数据库?云服务提供了一种简单的方法来扩展Azure门户中的实例数量,但是,Azure SQL数据库不存在这样的情况.可以使用Azure SDK以编程方式完成吗?我无法找到有关此主题的任何文档.

ksp*_*rin 18

在深入了解@ ErikEJ的答案(谢谢!)之后,我能够找到以下内容,这些内容似乎是随​​着Elastic Sc​​ale预览的发布而新发布的:

更改数据库服务层和性能级别

现在还提供了以下REST API,它们可以让您在数据库中执行任何操作:

Azure SQL数据库的REST API操作

对于我缩放服务层的原始问题(例如P1 - > P3 - > P1):

更新数据库REST API

通过这些新的开发,我将假设自动缩放也可以作为Azure门户中的简单配置提供,这与云服务非常相似.

  • @DavidPeden,做一个`select*from slo_service_objectives` - 它给你客观id和名字之间的映射,如"P1"或"S2". (4认同)

Eri*_*kEJ 12

是的,该功能可用:Azure SQL数据库弹性比例

https://docs.microsoft.com/en-gb/azure/sql-database/sql-database-elastic-scale-introduction

  • 弹性比例似乎不进行自动缩放,它用于跨多个数据库分区/分片数据.对于大场景,这是有帮助的,而不是在白天进行缩放 (7认同)

Chr*_*han 12

另一种方法是使用Azure自动化并使用下面的运行手册:

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"
}
Run Code Online (Sandbox Code Playgroud)


参考:
Azure垂直
扩展Runbook当您想要向上/向下扩展时设置时间表.
对我来说,我使用2个带有输入参数的时间表,1个用于放大,另一个用于缩小.
希望有所帮助.

  • 真棒!这个解决方案涉及更多的阅读(学习如何创建一个自动化帐户,一个新的资产(凭证),一个新的Runbook(这个)和一个新的计划.但它的工作就像一个魅力.谢谢! (2认同)
  • 这是一个很好的答案,可以通过*Classic Azure Portal*完成.(1)创建自动化帐户(2)资产>添加>凭据> PS凭证> {您的数据库管理员信息}(3)导入上述Runbook(按照链接并先下载)(4)测试:作者>草稿>开始,从上面和其他参数提供凭证名称.(5)如果一切顺利,发布Runbook并创建时间表(非常自我解释). (2认同)

Lan*_*kin 9

在某些情况下,最简单的选择可能是运行SQL查询,如msdn中所述.

例如:

ALTER DATABASE [database_name] MODIFY (EDITION = 'standard', SERVICE_OBJECTIVE = 'S3', MAXSIZE = 250 GB)
Run Code Online (Sandbox Code Playgroud)