• ananda.murugesan (10/4/2012)


    I have configured index rebuild on weekly basis at 3 AM..in production server,

    I have checked at 9 AM there is no table locking and blocking that particular table which was made it rebuild the index.

    Think about it, you quite possibly won't find any issue when you're looking 6 hours later!!! 😉

    ananda.murugesan (10/4/2012)


    As per your script rebuild index is online mode even though table is accessing through application even if locking that table.

    You're missing the point, the table is already locked when the rebuild command starts, online won't guarantee completion here, Books Online states

    SQL Server Books Online


    ONLINE = { ON | OFF }

    Specifies whether underlying tables and associated indexes are available for queries and data modification during the index operation. The default is OFF.

    For an XML index or spatial index, only ONLINE = OFF is supported, and if ONLINE is set to ON an error is raised.

    Note:

    Online index operations are available only in SQL Server Enterprise, Developer, and Evaluation editions.

    ON

    Long-term table locks are not held for the duration of the index operation. During the main phase of the index operation, only an Intent Share (IS) lock is held on the source table. This allows queries or updates to the underlying table and indexes to continue. At the start of the operation, a Shared (S) lock is very briefly held on the source object. At the end of the operation, an S lock is very briefly held on the source if a nonclustered index is being created, or an SCH-M (Schema Modification) lock is acquired when a clustered index is created or dropped online, or when a clustered or nonclustered index is being rebuilt. ONLINE cannot be set to ON when an index is being created on a local temporary table.

    OFF

    Table locks are applied for the duration of the index operation. An offline index operation that creates, rebuilds, or drops a clustered, spatial, or XML index, or rebuilds or drops a nonclustered index, acquires a Schema modification (Sch-M) lock on the table. This prevents all user access to the underlying table for the duration of the operation. An offline index operation that creates a nonclustered index acquires a Shared (S) lock on the table. This prevents updates to the underlying table but allows read operations, such as SELECT statements.

    This means that for the rebuild to start it will need some short term access which can be blocked if another operation is already running (an update for instance).

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉