Indexes play an important role in SQL Server performance. They help the database engine locate records efficiently, reduce unnecessary table scans, and improve query execution times. However, creating or rebuilding indexes on large production tables can consume significant resources and affect application availability.
A traditional index rebuild may require locks that interfere with queries and data modifications. On a busy database, even a short blocking period can increase response times, cause application timeouts, and affect dependent services.
SQL Server provides several features to manage index maintenance with less disruption. Online index operations allow users to access and modify table data while supported index operations are running. Resumable index operations allow long-running index builds and rebuilds to pause and continue later. Low-priority lock waiting provides additional control over blocking during online operations.
In this article, we will explore how to create and rebuild SQL Server indexes with reduced blocking, use resumable operations, monitor index maintenance, and plan safer production deployments.
Why Index Maintenance Can Affect Production Applications
An index stores data in a structure that helps SQL Server locate rows without scanning an entire table. Over time, indexes may require maintenance because of page splits, fragmentation, changing data distributions, or changes in application query patterns.
For example, consider an order management application with millions of records in an Orders table. A query frequently searches orders by customer and creation date.
SELECT
OrderId,
CustomerId,
OrderDate,
Status
FROM dbo.Orders
WHERE CustomerId = 10025
ORDER BY OrderDate DESC;
An appropriate index can help SQL Server locate the customer's orders more efficiently.
CREATE INDEX IX_Orders_CustomerId_OrderDate
ON dbo.Orders (CustomerId, OrderDate DESC)
INCLUDE (Status);
However, creating this index on a large production table requires SQL Server to read existing data, build the index structure, and allocate storage.
Depending on the operation, SQL Server may acquire schema locks that temporarily prevent other operations from accessing or modifying the table.
The impact depends on several factors:
- Table size and row count.
- Index type and structure.
- Database edition and supported features.
- Available CPU, memory, and storage throughput.
- Concurrent transactions.
- Locking behavior.
- Whether the operation runs online or offline.
For production systems, index maintenance should be planned around application workload rather than treated as an isolated database task.
Understanding Online Index Operations
SQL Server supports online index operations for supported index types and configurations.
When an index is created or rebuilt with ONLINE = ON, the underlying table remains available for most queries and data modifications during the operation.
For example:
CREATE INDEX IX_Orders_CustomerId_OrderDate
ON dbo.Orders (CustomerId, OrderDate DESC)
INCLUDE (Status)
WITH (ONLINE = ON);
For an existing index, use:
ALTER INDEX IX_Orders_CustomerId_OrderDate
ON dbo.Orders
REBUILD WITH (ONLINE = ON);
Online operations reduce the period during which application activity is blocked. They are particularly useful for large tables that must remain available during maintenance.
However, online does not mean lock-free. SQL Server still requires certain locks at the beginning and completion of an operation. Short schema locks may affect concurrent activity, especially when long-running transactions are present.
Online index operations can also require additional disk space because the existing index and the new index structure may coexist during the operation.
Before using ONLINE = ON, verify that the specific index operation, index type, and SQL Server edition support it.
Using WAIT_AT_LOW_PRIORITY to Reduce Blocking
One challenge with online index operations is acquiring the locks required to start or complete the operation.
A long-running transaction may hold a lock that prevents an index operation from obtaining the required lock. If the index operation waits with normal priority, it can contribute to blocking other application requests.
SQL Server provides WAIT_AT_LOW_PRIORITY to control this behavior for supported online index operations.
Consider the following example:
ALTER INDEX IX_Orders_CustomerId_OrderDate
ON dbo.Orders
REBUILD
WITH
(
ONLINE = ON
(
WAIT_AT_LOW_PRIORITY
(
MAX_DURATION = 5 MINUTES,
ABORT_AFTER_WAIT = SELF
)
)
);
This configuration tells SQL Server to wait for the required lock using low priority for up to five minutes.
If the operation cannot obtain the lock within that period, ABORT_AFTER_WAIT = SELF causes the index operation to exit rather than allowing it to continue waiting with normal priority.
This approach protects application transactions from being disrupted by an index maintenance operation that cannot acquire the required lock.
Understanding ABORT_AFTER_WAIT Options
SQL Server supports three options for controlling what happens after the low-priority waiting period expires.
Option | Behavior |
|---|
NONE | Continue waiting for the required lock using normal priority |
SELF | Stop the current index operation |
BLOCKERS | Terminate blocking user transactions so the index operation can continue |
SELF is generally a safer choice for production maintenance because it avoids terminating application transactions.
BLOCKERS should be used only when the operational impact is fully understood. It requires the appropriate permission, including ALTER ANY CONNECTION, and can terminate user transactions that are blocking the index operation.
WAIT_AT_LOW_PRIORITY is available for supported online operations. Its availability and syntax depend on the SQL Server version and deployment platform.
Understanding Resumable Index Operations
Large index operations may take considerable time to complete. A maintenance window may end before the operation finishes, or an unexpected interruption may occur.
Resumable index operations address this problem by allowing supported index builds and rebuilds to pause and continue later.
SQL Server introduced resumable online index rebuilds in SQL Server 2017. Resumable online index creation is supported in SQL Server 2019 and later.
A resumable index operation requires ONLINE = ON.
For example:
ALTER INDEX IX_Orders_CustomerId_OrderDate
ON dbo.Orders
REBUILD
WITH
(
ONLINE = ON,
RESUMABLE = ON,
MAX_DURATION = 60 MINUTES
);
The MAX_DURATION value specifies how long the resumable operation runs before SQL Server pauses it.
In this example, SQL Server can pause the operation after 60 minutes if it has not completed.
The operation does not automatically restart at a later time. A database administrator or maintenance process must resume it.
This is useful when maintenance must fit into controlled execution windows.
Pausing and Resuming an Index Rebuild
A running resumable index operation can be paused manually.
ALTER INDEX IX_Orders_CustomerId_OrderDate
ON dbo.Orders
PAUSE;
After the maintenance window becomes available, resume the operation:
ALTER INDEX IX_Orders_CustomerId_OrderDate
ON dbo.Orders
RESUME;
You can also provide options when resuming:
ALTER INDEX IX_Orders_CustomerId_OrderDate
ON dbo.Orders
RESUME
WITH
(
MAXDOP = 2,
MAX_DURATION = 45 MINUTES
);
MAXDOP controls the maximum degree of parallelism for the operation. Reducing parallelism may help limit CPU pressure, although it can also increase the time required to finish the rebuild.
If a resumable operation is no longer required, it can be terminated using:
ALTER INDEX IX_Orders_CustomerId_OrderDate
ON dbo.Orders
ABORT;
Aborting is different from pausing. A paused operation retains its resumable state, while an aborted operation is terminated.
Combining ONLINE, RESUMABLE, and WAIT_AT_LOW_PRIORITY
These options address different maintenance challenges and can be used together when supported.
ONLINE = ON allows concurrent access to the underlying table for supported operations.RESUMABLE = ON allows a long-running operation to pause and resume.WAIT_AT_LOW_PRIORITY controls how the operation waits for certain locks.
The following example combines these options:
ALTER INDEX IX_Orders_CustomerId_OrderDate
ON dbo.Orders
REBUILD
WITH
(
ONLINE = ON
(
WAIT_AT_LOW_PRIORITY
(
MAX_DURATION = 5 MINUTES,
ABORT_AFTER_WAIT = SELF
)
),
RESUMABLE = ON,
MAX_DURATION = 60 MINUTES,
MAXDOP = 2
);
There are two separate duration settings in this statement.
The five-minute value controls how long the operation waits for a required lock at low priority before applying the selected abort behavior.
The 60-minute value controls how long the resumable index rebuild runs before it is paused.
This distinction is important when configuring maintenance schedules.
A resumable index operation cannot run inside an explicit user transaction. Do not wrap this statement in BEGIN TRANSACTION and COMMIT.
Creating Indexes Online and Resumably
Resumable operations can also be used when creating supported indexes.
For example:
CREATE INDEX IX_Orders_Status_OrderDate
ON dbo.Orders (Status, OrderDate)
INCLUDE (CustomerId)
WITH
(
ONLINE = ON,
RESUMABLE = ON,
MAX_DURATION = 60 MINUTES,
MAXDOP = 2
);
This allows the index creation process to run online and pause after the configured duration if it has not completed.
One important difference is version support. Resumable online index rebuilds are available starting with SQL Server 2017, while resumable online index creation is available starting with SQL Server 2019.
Not every index can use resumable operations. For example, resumable operations do not support filtered indexes, columnstore indexes, disabled indexes, or the ALTER INDEX REBUILD ALL command. Other restrictions apply to computed, timestamp, and included columns.
Always check the feature limitations for the target SQL Server version before scheduling the operation.
Monitoring Resumable Index Operations
Database administrators need to know whether an index operation is running, paused, or completed.
SQL Server provides the sys.index_resumable_operations catalog view for monitoring resumable index operations.
SELECT
OBJECT_SCHEMA_NAME(object_id) AS SchemaName,
OBJECT_NAME(object_id) AS TableName,
name AS IndexName,
state_desc AS OperationState,
percent_complete,
start_time,
last_pause_time,
page_count
FROM sys.index_resumable_operations;
This query helps identify active or paused operations and their progress.
The state_desc column provides the operation state, while percent_complete indicates the reported completion percentage.
Monitoring is important because a paused operation may continue to consume disk space and affect data modification performance. SQL Server must maintain both the original index and the in-progress index structure while a resumable operation remains paused.
A paused operation should therefore not be left unattended indefinitely.
Choosing Between REBUILD and REORGANIZE
SQL Server provides two common index maintenance operations: REBUILD and REORGANIZE.
They serve different purposes.
Feature | REBUILD | REORGANIZE |
|---|
Operation | Recreates the index | Reorganizes existing index pages |
Execution | Can run online when supported | Always performed online |
Resource usage | Can require significant CPU, memory, and disk resources | Generally less resource-intensive |
Resumable support | Supported for eligible online operations | Not applicable in the same way |
Statistics | Rebuild updates associated index statistics | Does not perform the same full statistics update |
Typical use | Recreating an index when maintenance is justified | Reorganizing leaf-level fragmentation |
A rebuild is not automatically necessary whenever fragmentation exists. Fragmentation should be considered alongside page density, query performance, index usage, and workload characteristics.
For some workloads, improving page density or correcting a poor index design may provide more value than repeatedly rebuilding indexes.
Common Mistakes During Index Maintenance
Assuming Online Means No Blocking
Online operations still require locks at certain stages. Long-running transactions can delay index maintenance and affect application performance.
Use low-priority lock waiting where supported, and monitor blocking during maintenance.
Using RESUMABLE Without ONLINE
Resumable index operations require ONLINE = ON. A statement that enables resumability without the online option is not valid.
Wrapping Resumable Operations in Explicit Transactions
Resumable index DDL cannot run inside an explicit transaction. Execute it as a standalone statement.
Ignoring Paused Index Operations
Paused operations can continue consuming disk space and add overhead to data modifications. Monitor them and resume or abort them according to the maintenance plan.
Rebuilding Every Index Automatically
Rebuilding all indexes on a schedule without checking their condition can waste resources and increase maintenance duration.
Review fragmentation, page density, usage statistics, and query performance before selecting indexes for maintenance.
Using BLOCKERS Without Understanding the Impact
The BLOCKERS option can terminate application transactions. Use it only when the operational consequences are understood and approved.
Best Practices for Production SQL Server Databases
- Prefer online index operations when the required operation and SQL Server edition support them.
- Use resumable operations for eligible index builds and rebuilds that may exceed maintenance windows.
- Configure
WAIT_AT_LOW_PRIORITY to prevent maintenance operations from unnecessarily disrupting application workloads. - Prefer
ABORT_AFTER_WAIT = SELF when protecting application transactions is more important than completing maintenance immediately. - Use
MAXDOP to control parallel resource consumption. - Monitor resumable operations and investigate long-paused builds.
- Ensure sufficient storage is available before starting large index operations.
- Review the actual execution plan and index usage before adding new indexes.
- Test maintenance scripts against a representative workload.
- Avoid overlapping index operations on the same table when SQL Server does not support the combination.
- Check SQL Server version, edition, and index-type limitations before deployment.
- Schedule maintenance based on workload patterns and measurable performance needs.
Advantages and Disadvantages
Advantages
- Online operations reduce application disruption during supported index maintenance.
- Resumable operations make long-running index builds easier to manage.
- Low-priority lock waiting provides better control over blocking.
- Maintenance can be divided across multiple execution windows.
MAXDOP helps control parallel resource usage.- Monitoring views make resumable operations easier to manage.
Disadvantages
- Online operations may require additional storage and system resources.
- Some index types and configurations do not support online or resumable operations.
- Short blocking periods can still occur.
- Resumable operations require monitoring and operational management.
- Paused operations can affect DML performance and consume additional disk space.
- Advanced options require careful version and edition compatibility checks.
Conclusion
Creating and rebuilding indexes is an important part of SQL Server database maintenance, but poorly planned operations can affect production applications.
SQL Server provides online index operations, resumable builds, and low-priority lock waiting to make maintenance more manageable. Online operations reduce the time during which application access is restricted, resumable operations allow long-running work to continue across maintenance windows, and WAIT_AT_LOW_PRIORITY helps control lock-related blocking.
These features do not eliminate every performance or locking concern. Database administrators should still evaluate index usage, storage requirements, workload patterns, and feature compatibility before running maintenance.
A well-planned index maintenance strategy improves database performance while reducing unnecessary disruption to production applications.
Join the conversation! Your thoughts help the community grow.