---
title: "Automating index and statistics maintenance"
slug: "automating-index-and-statistics-maintenance"
abstract: ""
---
# Automating index and statistics maintenance

For optimal performance, perform maintenance daily during off peak times. At a minimum, perform weekly.

## Ola Hallengren scripts (on-prem and IaaS)

1. Download from: [https://ola.hallengren.com](https://ola.hallengren.com/)
2. Run MaintenanceSolution.sql to install jobs:

    :::lettered
    1. IndexOptimize
    2. UpdateStatistics
    3. DatabaseIntegrityCheck
    :::

3. Schedule using SQL Agent

## Azure runbooks (PaaS)

1. Create Azure Automation Account
2. Add PowerShell Runbook that:

    :::lettered
    1. Connects to Azure SQL
    2. Executes Ola’s procedures
    :::

3. Schedule it (daily/weekly)
4. Grant permission via managed identity or connection string

## Monitoring execution and failures

- Use Azure Automation dashboard
- Enable alerts on job failures
- Log job output for troubleshooting