Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Sql Server Programming

Finding all the indexes on a server with AllowPageLocks set to FALSE?


Hi,

While trying to figure out why a Reorganise Indexes task on SQL Server 2005
kept failing, I've discovered that any indexes created via SMSS have
AllowPageLocks set to false (due to SMSS leaving "Use page locks when
accessing the index" unticked by default when creating an index). This
causes the Reorganise task to fail with the error

Executing the query "ALTER INDEX [<index name>] ON [<table name>] REORGANIZE
WITH ( LOB_COMPACTION = ON )
" failed with the following error: "The index "<index name>" (partition 1)
on table "<table name>" 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.

So now I need to find every index on my server that has been created without
AllowPageLocks enabled, and enable it. Is there an easy way to pull up the
AllowPageLocks option value for all indexes across a server in one go? I
could then use this to generate a list of sp_indexoption statements to
enable page locks on those indexes that were created with it turned off.

Also, is there a way to change SMSS such that the default setting for "Use
page locks when accessing the index" is ticked? Seems strange to have this
defaulted to off.

Dan

> Is there an easy way to pull up the AllowPageLocks option value for all
> indexes across a server in one go?

You can use a query like the one below as a basis for generating the script:

SELECT
    s.name, t.name, i.name
FROM sys.schemas s
JOIN sys.tables t ON
    t.schema_id  = s.schema_id
JOIN sys.indexes i ON
    i.object_id = t.object_id
WHERE
    i.index_id > 0
    AND INDEXPROPERTY(i.object_id, i.name, 'IsPageLockDisallowed') = 0
    AND INDEXPROPERTY(t.object_id, i.name, 'IsStatistics') = 0
    AND NOT EXISTS
    (
        SELECT *
        FROM sys.objects keys
        WHERE
            keys.parent_object_id = i.object_id AND
            keys.name = i.name AND
            keys.type IN('PK', 'UQ')
    )

> Also, is there a way to change SMSS such that the default setting for "Use
> page locks when accessing the index" is ticked? Seems strange to have this
> defaulted to off.

My SSMS defaults to this option checked.  Are you running the latest service
pack (SP2) on your client?  Personally, I prefer to use script rather than
the GUI for DDL.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Daniel Crichton" <msn@worldofspack.com> wrote in message

news:u6AR2vhlHHA.596@TK2MSFTNGP06.phx.gbl...

Dan wrote  on Mon, 14 May 2007 08:03:58 -0500:

>> Is there an easy way to pull up the AllowPageLocks option value for all
>> indexes across a server in one go?

> You can use a query like the one below as a basis for generating the script:

Thanks. It's looking like I have a lot of indexes that need adjusting.

>> Also, is there a way to change SMSS such that the default setting for
>> "Use page locks when accessing the index" is ticked? Seems strange to
>> have this defaulted to off.

> My SSMS defaults to this option checked.  Are you running the latest
> service pack (SP2) on your client?  Personally, I prefer to use script
> rather than the GUI for DDL.

I thought I had SP2 installed on my client, but it appears that I only have
SP1. I'll get it updated now and see if it changes the setting.

Dan

-----------------------------------------------Reply-----------------------------------------------

Daniel wrote to Dan Guzman on Mon, 14 May 2007 14:27:37 +0100:

> Dan wrote  on Mon, 14 May 2007 08:03:58 -0500:

>>> Is there an easy way to pull up the AllowPageLocks option value for all
>>> indexes across a server in one go?

>> You can use a query like the one below as a basis for generating the script:

> Thanks. It's looking like I have a lot of indexes that need adjusting.

Actually, scrub that. I didn't spot that you had set the criteria for
IsPageLockDisallowed to 0, rather than 1 that I needed to look for. After
adding a loop through all my user databases, I've now got zero indexes with
page locks disabled. Thanks :)

Dan

-----------------------------------------------Reply-----------------------------------------------

Try this to create all of the necessary ALTER statements for you:

set quoted_identifier off
go
SELECT "alter index [" + i.name + "] ON [" + s.name + "].[" + t.name + "]
SET (ALLOW_PAGE_LOCKS = ON)
go"
--    s.name, t.name, i.name
FROM sys.schemas s
JOIN sys.tables t ON
    t.schema_id  = s.schema_id
JOIN sys.indexes i ON
    i.object_id = t.object_id
WHERE
    i.index_id > 0
    AND INDEXPROPERTY(i.object_id, i.name, 'IsPageLockDisallowed') = 0
    AND INDEXPROPERTY(t.object_id, i.name, 'IsStatistics') = 0
    AND NOT EXISTS
    (
        SELECT *
        FROM sys.objects keys
        WHERE
            keys.parent_object_id = i.object_id AND
            keys.name = i.name AND
            keys.type IN('PK', 'UQ')
    )

Simply copy the output into a query window and execute.

--
TheSQLGuru
President
Indicium Resources, Inc.

"Daniel Crichton" <msn@worldofspack.com> wrote in message

news:eTGBluilHHA.1156@TK2MSFTNGP05.phx.gbl...

> Dan wrote  on Mon, 14 May 2007 08:03:58 -0500:
>> My SSMS defaults to this option checked.  Are you running the latest
>> service pack (SP2) on your client?  Personally, I prefer to use script
>> rather than the GUI for DDL.

> I thought I had SP2 installed on my client, but it appears that I only
> have SP1. I'll get it updated now and see if it changes the setting.

OK, installed SP2 and it does indeed change the default for that option to
checked. Thanks.

Dan

-----------------------------------------------Reply-----------------------------------------------

> Actually, scrub that. I didn't spot that you had set the criteria for
> IsPageLockDisallowed to 0, rather than 1 that I needed to look for. After
> adding a loop through all my user databases, I've now got zero indexes
> with page locks disabled. Thanks :)

Sorry, I used the 0 value to test the script and forgot to change it to 1.
I'm glad you got it going.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Daniel Crichton" <msn@worldofspack.com> wrote in message

news:%23VjmnyilHHA.1216@TK2MSFTNGP03.phx.gbl...

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc