DB24 LogoDB24 Docs

    Index Maintenance

    Last updated: November 12, 2026

    Index Maintenance

    Index maintenance keeps your SQL Server indexes healthy by detecting and resolving fragmentation before it impacts query performance. DB24 automates this process — evaluating every eligible index on every eligible database, choosing the right action based on fragmentation level and index type, and respecting your configured thresholds and maintenance windows.


    Eligibility

    Not every database or index is processed on every run. DB24 applies a two-level eligibility check before any maintenance is performed.

    Database eligibility

    A database must meet all of the following to be included:

    ConditionRule
    AG roleMust be the primary replica — AG secondaries are never touched
    Read-onlyDatabase must not be read-only
    AccessThe service account must have access
    ExclusionsNot listed in the exclusions table (CategoryId = 100 or 101)
    Has eligible indexesAt least one index must be present in the maintenance index list

    Index eligibility

    Each index within an eligible database is then evaluated individually:

    ConditionRule
    Index typeRowstore (type 1–4) or Columnstore (type 5–7) only
    StateNot disabled, not hypothetical
    OwnershipNot a system-owned (MS-shipped) index
    Allocation unitIN_ROW_DATA only for Rowstore
    FragmentationAt or above the configured minimum threshold
    Minimum sizeMust meet both the minimum page count and minimum row count
    ExclusionsNot listed in the exclusions table for this specific database

    Thresholds and Configuration

    All thresholds are configurable per scope — instance-wide, primary, or secondary — via cfg.Maintenance.

    Rowstore indexes

    ParameterDefaultDescription
    MediumFragmentation_RS5%Minimum fragmentation to qualify for any maintenance
    HighFragmentation_RS30%Fragmentation level that triggers Rebuild instead of Reorganize
    MaxPDensityForReorg_RS80%Page density ceiling for Reorganize — indexes above this are Rebuilt to avoid page splits
    MinIXPages_RS2,000 pagesMinimum page count for inclusion
    MinIXRows_RS2,000 rowsMinimum row count for inclusion

    Columnstore indexes

    ParameterDefaultDescription
    MediumFragmentation_CS20%Minimum fragmentation to qualify
    MinIXPages_CS0 pagesNo page floor
    MinIXRows_CS5,000 rowsMinimum row count for inclusion

    General settings

    ParameterDefaultDescription
    RunMaintenanceIndex1 (instance/primary), 0 (secondary)Master on/off switch per scope
    MaxDOP2 (instance), 0 (primary/secondary)Parallelism for Rebuild operations
    SortInTempDB1 (instance), 0 (others)Whether Rebuild sort operations use TempDB
    OnlineOption0Rebuilds run offline by default
    AllowRowLocks1Row-level locking enabled
    AllowPageLocks1Page-level locking enabled

    Maintenance Actions

    Rowstore

    The action taken depends on both fragmentation level and page density:

    FragmentationPage DensityAction
    ≥ Medium and < High≤ MaxPDensityForReorg (80%)Reorganize with LOB_COMPACTION = ON
    ≥ Medium and < High> MaxPDensityForReorg (80%)No action — see note below
    ≥ High (30%)AnyRebuild with configured MAXDOP, ONLINE, SORT_IN_TEMPDB, and lock options

    The dead zone: An index that is moderately fragmented but highly dense (page density above 80%) receives no maintenance. Reorganizing such an index risks excessive page splits and log growth. The index will naturally accumulate more fragmentation over time until it crosses the High threshold and qualifies for a Rebuild.

    Columnstore

    Columnstore indexes are always Reorganized using LOB_COMPACTION = ON, COMPRESS_ALL_ROW_GROUPS = ON, regardless of fragmentation level. Rebuild is never used.

    This is intentional: COMPRESS_ALL_ROW_GROUPS flushes all open and closed delta rowgroups into the columnstore, making Rebuild effectively redundant. This behavior requires SQL Server 2016 or later.


    Partitioned Indexes

    Partitioned indexes are evaluated and maintained at the partition level. Each partition is assessed independently, and PARTITION = N is appended to the ALTER INDEX command where applicable.


    Runtime Behavior

    A few important behaviors govern how maintenance runs in practice:

    Maintenance window is checked per index.
    The window is evaluated at the start of every index iteration. If the window closes mid-run, the remaining indexes in that database — and all subsequent databases — are skipped immediately.

    Disk space is checked before every index.
    Free space is verified across all volumes hosting the database's files before each index is processed. If any volume breaches the configured threshold, the current database is aborted and processing continues with the next. Each volume breach is logged once per run.