I’ve recently had to look over a client server where a maintenance plan had been failing for some time. The inhouse DBA was unaware of the failures because he had no alerting on the jobs and the big red crosses weren’t big or red enough to have caught his attention. When I looked at the cause of the failures it was due to a native maintenance plan not being able to reoganise an index with page level locking disabled. Whenever a reorganise plan hits a database with page level locking disabled it generates the following error:
Executing the query “ALTER INDEX Indexname] ON [dbo]….” failed with the following error: “The index “Indexname” (partition 1) on table “tablename” cannot be reorganized because page level locking is disabled.”. Possible failure reasons: Problems with the query, “ResultSet” property not set correctly, parameters not set correctly, or connection not established correctly.
There are two ways of getting around this. The first way is to generate TSQL scripts to enable Page level locking prior to the re-organise and then re-enable it after the maintenance is completed. JP Chen has the scripts to do that here. Note: Haven’t tested those, but they look right. I suspect you may need to exclude the system tables as well.
The second, and easier way, is to set up a rebuild step and move the affected databases into that step of your maintenance plan. Rebuilds do not require a page lock because the index is completely rebuilt rather than shuffled around. The TSQL to figure out which database you need to move from the re-organise to the rebuild step is:
exec sp_MSforeachdb ‘use ? select db_name(), (case when count(*)>0 then ”Page Locks Disabled:” ELSE ”Page Locks” END) from sys.indexes where allow_page_locks=0 and name not in(”queue_clustered_index”,”queue_secondary_index”)’
and if you want to get the specific indexes you can use this:
exec sp_MSforeachdb ‘use ? select db_name(), object_id,name from sys.indexes where allow_page_locks=0 and name not in(”queue_clustered_index”,”queue_secondary_index”)’
Standard disclaimer about sp_MSforeachdb being an undocumented stored procedure and maintenance plans being somewhat limited form of doing your index mainteance apply:)