SQL Server Resumable Index Rebuilds: Reducing Downtime and Avoiding Restarts on Busy Tables

SQL Server Resumable Index Rebuilds: Reducing Downtime and Avoiding Restarts on Busy Tables

When index maintenance starts on a large SQL Server table, the main risk is not whether the command will execute. The real risk is that maintenance will overlap with production traffic, consume more transaction log than expected, or force the team to start over after an interruption. For order, payment, and event tables that receive writes throughout the day, a multi-hour outage is usually unacceptable.

Combining online index rebuilds with resumable index operations makes this work much easier to control. The online option allows queries and data modifications to continue during most of the operation. The resumable option allows the rebuild to pause after a defined period and continue later instead of restarting from the beginning.

A realistic problem: a 420 GB order history table

Consider a representative system with a Sales.OrderHistory table containing approximately 180 million rows and 420 GB of data. The application frequently executes the following query:

SELECT OrderId, CustomerId, OrderDate, Status, TotalAmount
FROM Sales.OrderHistory
WHERE CustomerId = @CustomerId
  AND OrderDate >= @StartDate
  AND OrderDate < @EndDate;

The supporting index has reached 48 percent logical fragmentation. That number alone is not enough to justify a rebuild. You should also check whether the index is used by important plans, how full its pages are, how much write traffic it receives, and whether the server has enough disk and log capacity for the operation.

In this example, test measurements showed that the query’s logical reads had increased from about 18,000 pages to 31,000 pages under the same parameters. Reporting queries were also approximately 35 percent slower. Maintenance was therefore justified, but the available maintenance window was limited to 01:00–04:00.

What online and resumable actually change

An offline rebuild can hold long-duration locks that prevent access to the table while the index is recreated. An online rebuild keeps the table available for most of the operation. It is not completely lock-free, however. Short schema or table locks may still be required at the beginning or end. Therefore, “online” should never be interpreted as “blocking is impossible.”

A resumable rebuild turns a long, uninterrupted DDL operation into a controllable operation. It can pause when the maintenance window ends, resume on the next window, or recover from an interruption without discarding all progress. Resumable index operations are supported in SQL Server 2017 and later, Azure SQL Database, and Azure SQL Managed Instance.

Identify the right index and estimate resource needs

Start by reviewing the target index and its physical characteristics:

SELECT
    i.name AS IndexName,
    i.type_desc,
    ps.page_count,
    ps.avg_fragmentation_in_percent,
    ps.avg_page_space_used_in_percent
FROM sys.dm_db_index_physical_stats
(
    DB_ID(),
    OBJECT_ID(N'Sales.OrderHistory'),
    NULL,
    NULL,
    'LIMITED'
) AS ps
JOIN sys.indexes AS i
  ON i.object_id = ps.object_id
 AND i.index_id = ps.index_id
WHERE i.name = N'IX_OrderHistory_Customer_OrderDate';

If page_count is small, a rebuild may provide little measurable benefit. For a large index, plan for the new index structure, mapping structures, temporary workspace, and concurrent modifications. During an online operation, the existing and new structures may use disk space at the same time. Checking only the total database size is not enough; validate free space in the relevant filegroup and transaction log.

First implementation: a time-limited resumable rebuild

The following command starts an online, resumable rebuild. MAX_DURATION = 120 allows the operation to run for approximately 120 minutes before it pauses:

ALTER INDEX IX_OrderHistory_Customer_OrderDate
ON Sales.OrderHistory
REBUILD WITH
(
    RESUMABLE = ON,
    MAX_DURATION = 120,
    MAXDOP = 4,
    SORT_IN_TEMPDB = OFF
);

MAXDOP = 4 is used here to limit CPU pressure. The appropriate value depends on the server’s processor capacity and concurrent workload, so it should be tested rather than copied blindly. Resumable operations do not support SORT_IN_TEMPDB = ON, which is why the example leaves it disabled.

If the operation pauses, executing the same rebuild command again resumes the existing resumable operation. However, RESUMABLE = ON is not a permanent index metadata setting. It must be specified explicitly for each new DDL operation.

Monitor and resume the operation safely

Use the following catalog view to inspect running and paused operations:

SELECT
    object_schema_name(object_id) AS SchemaName,
    object_name(object_id) AS TableName,
    name AS IndexName,
    state_desc,
    percent_complete,
    total_execution_time,
    page_count,
    last_pause_time
FROM sys.index_resumable_operations
ORDER BY start_time;

The state_desc value can be RUNNING or PAUSED. If the operation paused when the maintenance window ended, resume it during the next window:

ALTER INDEX IX_OrderHistory_Customer_OrderDate
ON Sales.OrderHistory RESUME WITH (MAXDOP = 4);

If the workload becomes sensitive during business hours, pause the operation explicitly:

ALTER INDEX IX_OrderHistory_Customer_OrderDate
ON Sales.OrderHistory PAUSE;

If the rebuild is no longer needed, abort it instead of leaving it paused:

ALTER INDEX IX_OrderHistory_Customer_OrderDate
ON Sales.OrderHistory ABORT;

A paused operation can keep both the original and new index structures in place. Data modifications may therefore continue to pay additional maintenance cost. Leaving an operation in the PAUSED state for an extended period is not a good operational practice if it will never be completed.

Reduce blocking with low-priority waiting

The final phase of an online rebuild may require a short lock transition. A long-running query can delay that transition, while the rebuild itself may otherwise create undesirable waiting. Low-priority waiting can be used to limit this interaction:

ALTER INDEX IX_OrderHistory_Customer_OrderDate
ON Sales.OrderHistory
REBUILD WITH
(
    (
        WAIT_AT_LOW_PRIORITY
        (
            MAX_DURATION = 5,
            ABORT_AFTER_WAIT = SELF
        )
    ),
    RESUMABLE = ON,
    MAX_DURATION = 120,
    MAXDOP = 4
);

In this example, the operation waits at low priority for five minutes. If it cannot acquire the required lock, the rebuild terminates itself. In production, SELF is often the safer choice because it does not automatically terminate user queries or the sessions blocking the maintenance operation.

Plan for transaction log and disk usage

Index rebuilds can generate substantial I/O and transaction log activity. Resumable execution provides better control than one uninterrupted operation, but it does not eliminate the need for data-file, log-file, or free-disk capacity. While an operation is paused, the original and newly built structures may both consume space.

  • Check free space in the relevant filegroup before starting.
  • Do not rely on small, repeated autogrowth events for the transaction log.
  • Include log backup health and disk-capacity alerts in the maintenance plan.
  • Measure the additional write workload generated during the rebuild.
  • Document the recovery procedure if the operation pauses or fails.

During an online rebuild, changes to indexed columns may need to update an additional copy of the index. As a result, an operation can be technically online while still causing a temporary reduction in write throughput.

When this approach is not appropriate

Not every index should be rebuilt. On a small index, the cost may exceed the benefit. Rebuilding every index on a fixed schedule based only on fragmentation percentage can create unnecessary I/O. If query performance is stable and page density is acceptable, maintenance may be postponed.

Online index operations are not supported identically across all SQL Server versions and editions. Before using this approach in production, verify that the target version and edition support ONLINE, RESUMABLE, and the specific index type. XML indexes, filtered indexes, and some specialized scenarios have additional restrictions.

A practical maintenance runbook

  1. Select indexes using actual query cost and page-density evidence, not fragmentation percentage alone.
  2. Measure duration, CPU, I/O, blocking, and log impact in a test environment.
  3. Start in production with a conservative MAXDOP and bounded MAX_DURATION.
  4. Create monitoring for sys.index_resumable_operations.
  5. Pause the operation when the maintenance window ends; abort it if it will not be completed.
  6. Compare query duration, logical reads, log usage, and blocking after completion.

Resumable online index rebuilds replace the “start it overnight and hope it finishes” model with a controlled operational process. With correct index selection, resource planning, and monitoring, large-table maintenance can continue without a full application outage and without restarting from zero after an interruption.

Sources

//

0 Comments

Write Comment

E-Mail address will not be published