Overview: As we know, it's crucial that you run Database maintenance regularly in order to keep your database performance up with the latest statistics and healthy indexes, here we provide another way to schedule this job using Azure Data Factory; this can be done on a scheduled time interval weekly/bi-weekly/monthly.
Solution: This article will show steps to schedule Database maintenance using the Azure Data Factory(ADF). ADF can use as an SQL agent to schedule and automate Azure SQL database tasks. In addition, database maintenance plans not supported in Azure can also be replaced with Azure pipelines.
Note: Using ADF will incur an additional cost. |
Use case:
This can be done via AzureSQLMaintenance store procedure (SP) to perform complete Database maintenance, Store procedure and blog written by Yochanan Rachamim are listed below.
Blogs:
How to maintain Azure SQL Indexes and Statistics - Microsoft Tech Community
Code:
Main steps:
Step by Step walkthrough:
-- Execute on Master
CREATE LOGIN DBAdmin WITH password='<your-password>';
-- Execute on Master and user database
CREATE USER DBAdmin FROM LOGIN DBAdmin;
-- permission
EXEC sp_addrolemember 'db_owner', 'DBAdmin';
3. Download and deploy AzureSQLMaintenance to a user database. Code: AzureSQLMaintenance
4. Open Azure data factory to create a pipeline and name it.
You can Import pipeline template using below zip file.
https://github.com/HitenBhavsarMSFT/DataFactoryTemplate/blob/main/AzureSQLMaintenance.zip
Add store procedure activity.
Press "+ New" and set up linked Serviced by adding a name, type, subscription, Server, database, authentication type, User, and password. Test connection for the connectivity check.
After selecting Linked Service, Select AzureSQLMaintenance store procedure
Import parameter, for operation parameter, provides the value "ALL".
Parameter value represents the database task it will perform. Blog
ALL = Run through all indexes and statistics and take a smart decision about steps taken for each object
STATISTICS = run smart maintenance only for statistics
INDEX = run smart maintenance only for indexes
All other parameters can be removed from the setting tab.
"Publish all " to publish and save the pipeline.
Note: Use trigger now to test the pipeline.
Use monitor pipeline run to check the Manual trigger.
5. Schedule pipeline using trigger using "New/Edit" button.
Enter trigger detail like name, Desc type. Then, publish the trigger to make it effective.
I hope you find this article helpful. If you have any feedback, please do not hesitate to provide it in the comment section below.
Hiten Bhavsar (Author)
Ahmed Mahmoud (Co-Author)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.