Search code examples
azure-sql-databaseazure-sql-server

Automatically trigger Azure SQL database to be "online"


I am using an Azure Serverless SQL database that goes to a "paused" state after 2 hours - this is all working as "auto-pause" is enabled (this I don't want to change).

Azure Auto Pause

Is it possible to somehow automatically trigger the SQL database to be "online" say once a day for when the application end-user start work in the morning so they not having to wait for the database to become 'on-line'?


Solution

  • As per the Official documentation,

    Auto-resuming can be triggered if any of the below conditions are true:

    • Authentication and authorization
    • Threat detection
    • Data discovery and classification
    • Auditing
    • Data masking
    • Transparent data encryption
    • Vulnerability assessment
    • Query (performance) data store
    • Performance recommendations
    • Auto-tuning
    • Database copying
    • SQL data sync
    • Modifying certain database metadata
    • SQL Server Management Studio (SSMS)

    You can automatically trigger the azure serverless SQL database to be “online” if you trigger the any of the above conditions daily.
    Viewing auditing records, updating or viewing auditing policy can trigger the auto-resume of the database.
    The Get-AzSqlDatabaseAudit can be used for that. Please check the Powershell script below which is referred from here.

    Get-AzSqlDatabaseAudit
    [-ResourceGroupName] <String>
    [-ServerName] <String>
    [-DatabaseName] <String>
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]
    

    If you automate the above script to run daily, you can achieve your requirement.
    Please go through this Article by Salaudeen Rajack on sharepointdiary to check the process of automating the Powershell script.

    Also, you can auto-resume the database by creating the backup of your database.
    Please go through this Official blog to Automate the exporting of azure SQL database as .bacpac to blob storage.

    Please refer this SO thread to check various approaches other than these.