简体   繁体   English

恢复无服务器 Azure 数据库

[英]resume serverless azure database

I am trying to automate a serverless azure database to be online during set hours and then paused "off hours".我正在尝试使无服务器的 azure 数据库在设定时间内自动上线,然后在“下班时间”暂停。

Is there a way to do this using PowerShell commands or another automated way to put it online starting at a specific time during the work week?有没有办法使用 PowerShell 命令或另一种自动方式来做到这一点,使其在工作周的特定时间开始在线?

Right now using the autopause option, but the main issue is that it requires an initial database hit to put the database online, which causes too long of a down time between the first database hit to the database being online and usable by the application.现在使用自动暂停选项,但主要问题是它需要初始数据库命中才能使数据库联机,这会导致从第一个数据库命中到数据库联机并可供应用程序使用之间的停机时间太长。 Thanks谢谢

You have got REST API call to pause Azure SQL database.你有 REST API 调用来暂停 Azure SQL 数据库。

https://docs.microsoft.com/en-us/rest/api/sql/Databases/Pause https://docs.microsoft.com/en-us/rest/api/sql/Databases/Pause

POST https://management.azure.com/subscriptions/00000000-1111-2222-3333- 
444444444444/resourceGroups/Default-SQL- 
SouthEastAsia/providers/Microsoft.Sql/servers/
testsvr/databases/testdwdb/pause?api-version=2019-06-01-preview

Similarly, you can resume the Azure SQL Database, using REST API call同样,您可以使用 REST API 调用恢复 Azure SQL 数据库

https://docs.microsoft.com/en-us/rest/api/sql/databases/resume https://docs.microsoft.com/en-us/rest/api/sql/databases/resume

POST https://management.azure.com/subscriptions/{subscriptionId} 
/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ 
databases/{databaseName}/resume?api-version=2019-06-01-preview

You can set up automated calls as specific times to pause and resume.您可以将自动呼叫设置为暂停和恢复的特定时间。 You can leverage Invoke-RestMethod Reference in Powershell to call the rest method.您可以利用 Powershell 中的Invoke-RestMethod 引用来调用 rest 方法。

The PowerShell command Set-AzSqlDatabase which has an option to set the AutoPauseDelayInMinutes for a serverless azure database might to be an option to automate this process. PowerShell 命令 Set-AzSqlDatabase 具有为无服务器 azure 数据库设置 AutoPauseDelayInMinutes 的选项,可能是自动执行此过程的选项。

Set the AutoPauseDelayInMinutes to -1 to opt out during normal business hours and then to the desired value prior to off hours.将 AutoPauseDelayInMinutes 设置为 -1 以在正常工作时间选择退出,然后在下班时间之前设置为所需的值。

As pause and resume commands have not implemented yet on Serverless edition of Azure SQL Database, for resume you can just open a connection to it using a simple powershell由于 Azure SQL 数据库的无服务器版本尚未实现暂停和恢复命令,因此您只需使用简单的 powershell 打开到它的连接即可恢复

$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $connectionString
$sqlConnection.Open()

By setting ConnectTimeout and also doing retry you can ensure the Database is online before making your actual connection from the application/service.通过设置 ConnectTimeout 并进行重试,您可以在从应用程序/服务建立实际连接之前确保数据库在线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM