Index & Statistics Maintenance

Status: Reviewed (deep-dive v1)
Stack: PowerShell (optional host pressure) → SQL jobs/procs → Blazor Server UI
Depends on: SQL-01 Inventory; safer after SQL-02 Backup coverage is trusted
Goal: Keep indexes and stats healthy without wrecking log/IO during business hours.


Why this third

Fragmented indexes and stale stats cause real pain — but blind rebuilds cause more. Measure, threshold, window, then act. Never maintain what you haven’t inventoried and can’t restore.


What “good” looks like


Starting thresholds (confirm with Rick)

Metric Reorganize Rebuild Skip / watch
Fragmentation (avg_fragmentation_in_percent) ~10–30% ≥ ~30% < ~10%
Page count Only if ≥ ~1000 pages (ignore tiny indexes) Same Small indexes
Stats UPDATE if modification counter high or sample stale After large data loads Tiny tables

These are common starting points, not dogma. Partitioned tables, LOBs, columnstore, and AG secondaries need special cases (see below).

Prefer:


Checklist — collect / evaluate (SQL first; PS assists)

Run against inventoried instances in a maintenance/eval job (read-heavy).

Avoid scanning every DB with DETAILED mode on a large estate during peak.


Checklist — store (SQL + stored procedures)

Table Purpose
dbo.IndexMaintPolicy Per-instance or per-db thresholds + window
dbo.IndexHealthSnapshot Latest frag/page stats sample
dbo.StatsHealthSnapshot Latest stats modification sample
dbo.IndexMaintQueue Planned actions (Reorg/Rebuild/UpdateStats) + status
dbo.IndexMaintRun Job run audit (start/end, counts, errors)

Procs / jobs:

Execution engine can be T-SQL job steps or PS calling T-SQL; keep commands logged.


Checklist — present (Blazor Server)


Operator runbook (short)

  1. Check Backup coverage Green for the DB before heavy rebuilds
  2. Open Index health → sort by fragmentation × page_count
  3. Confirm window / AG role (prefer primary for rebuilds unless policy says otherwise)
  4. If job failed mid-run: read IndexMaintRun error; check log disk, blocking, timeout
  5. After big load/ETL: prefer targeted stats update before blaming indexes
  6. If users report slowness post-maint: check for oversized maintenance still running; kill only with change control

Special cases (don’t skip)

Situation Guidance
Always On secondary Readable secondary: reorg sometimes OK; rebuilds usually on primary; respect backup preference / sync lag
Enterprise vs Standard ONLINE rebuild not on all editions; plan downtime or reorg-only
Columnstore Different DMVs / rebuild semantics — track separately later
LOB / XML / spatial Rebuild cost high; test in nonprod
Fill factor Don’t change casually; document if used for hotspot tables
Ola Hallengren / Minion / custom If already present, document which; don’t run two competing jobs

Job design tips (lean)


Permissions notes


Done definition for this topic


Next after this

SQL Agent jobs & schedules — monitor the jobs that run this maintenance (and backups).


SQL Dude — SQL-03 Index & Statistics Maintenance v1