This repository contains a PowerShell-based Azure Function App designed to perform essential maintenance tasks on Azure SQL databases. Since Azure SQL lacks a built-in SQL Agent, this application acts as a substitute to automate tasks like index maintenance and statistics updates, ensuring optimal database performance.
- Automated execution of index and statistics maintenance tasks.
- Serverless architecture leveraging Azure Functions.
- Configurable triggers (e.g., Timer, HTTP) for flexible scheduling.
- Secure integration with Azure SQL using managed identities or connection strings.
- Comprehensive logging and monitoring via Azure Application Insights.
- An active Azure subscription.
- Azure SQL Database instance.
- Azure Functions Core Tools (for local development).
- Azure CLI installed.
git clone https://github.com/your-repo/AzSQLMaintFunc.git
cd AzSQLMaintFunc
Ensure you have the required tools installed:
- PowerShell Core (for local testing and development).
Set the following environment variables before deploying the function app:
SQL_CONNECTION_STRING
: Connection string for your Azure SQL Database.MAINTENANCE_TASKS
: Specify tasks to execute (e.g.,IndexRebuild
,UpdateStatistics
).
Additionally, populate the following variables for deployment:
$SQL_Name = "<YourAzureSQLName>"
$SQL_RG = "<YourResourceGroupName>"
$TENANT_ID = "<YourAzureTenantID>"
$SUB_ID = "<YourAzureSubscriptionID>"
Deploy the function app using the Azure CLI:
az functionapp create --resource-group <ResourceGroupName> --consumption-plan-location <Region> --runtime powershell --name <FunctionAppName> --storage-account <StorageAccountName>
- Use the Azure Portal or Application Insights to monitor function execution.
- Trigger the function manually or via the configured schedule.
Contributions are welcome! Feel free to submit a pull request or open an issue for any bugs or feature suggestions.
This project is licensed under the MIT License.