Wednesday, February 9, 2011

Enabling page level locking

Sometimes index rebuild task will be failed due to the following issue:

Description: Executing the query "ALTER INDEX [IDX_XXX_OF_DATE] ON [dbo].[DI..." failed with the following error: "The index "IDX_XXX_OF_DATE" (partition 1) on table "XXXX_OF_CF" cannot be reorganized because page level locking is disabled.".

Solution

Enable page level locking…

To find the disabled page level locking indexes, please execute the given query:

SELECT * FROM sys.indexes WHERE allow_page_locks = 0

Copy the index names from the above output and enable locking by executing the below query:

Alter Index <index name> On <table name> Set (ALLOW_PAGE_LOCKS = ON)

If we want to do the same for multiple indexes in single database at a time, please execute the following:

Use <dbname>

GO

select 'alter index ['+s.[name]+'] on ['+t.[name]+'] Set (ALLOW_PAGE_LOCKS = ON);' from sys.indexes as s inner join sysobjects as t on s.[object_id] = t.[id] where s.[allow_page_locks] = 0 and is_unique = 0

Copy the given OUTPUT and paste it into new NEW QUERY WINDOW and execute it.

Check for disabled indexes and re-run the job.

10 comments:

  1. Sometimes index rebuild task will be failed..

    Index rebuilds WONT fail. If page level locking is disabled REORGANISE tasks will fail. You can still rebuild the index however.

    ReplyDelete
  2. It check only for non clustered indexes,how about clustered indexes

    ReplyDelete
  3. It checks only for non clustered indexes,how about clustered indexes?

    ReplyDelete
  4. It checks only for non clustered indexes,how about clustered indexes?

    ReplyDelete
  5. It check only for non clustered indexes,how about clustered indexes

    ReplyDelete
  6. Thank you very good , In my case I had to add select 'alter index ['+Object_schema_name( t.id ) because of different schema

    ReplyDelete