Solved

Index Rebuild causing blocking issue

Posted on 2011-09-14
10
320 Views
Last Modified: 2012-05-12
Hi,

The attached script is causing blocking issue on our prod servers. Please let me know how to avoid the blocking issue i.e., is there any modifications required in that attached script.

Thanks in advance.
Index-Rebild.txt
0
Comment
Question by:sg05121983
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 21

Expert Comment

by:JestersGrind
ID: 36536588
ALTER INDEX IndexName ON TableName REBUILD WITH (ONLINE = ON)

Greg

0
 
LVL 21

Accepted Solution

by:
JestersGrind earned 250 total points
ID: 36536602
Sorry, didn't see that you had a script file.  Change this line

 SET @command = N''ALTER INDEX '' + @indexname + N'' ON '' + @schemaname + N''.'' + @objectname + N'' REBUILD '' ;

to

 SET @command = N''ALTER INDEX '' + @indexname + N'' ON '' + @schemaname + N''.'' + @objectname + N'' REBUILD  WITH (ONLINE = ON)'' ;

Greg

0
 

Author Comment

by:sg05121983
ID: 36536774
Thnaks Mr. JestersGrind.

I will try your suggestion and let your know the results.

Any other suggestions on my script?
0
 
LVL 21

Expert Comment

by:JestersGrind
ID: 36536891
The rest of the script looks fine.

Greg

0
 
LVL 24

Expert Comment

by:DBAduck - Ben Miller
ID: 36537030
Just remember in your scripts you use the dm_db_index_physical_stats and that is a function that will go out and take some locks.  Not always will there be extreme blocking, but it is not a lightweight operation.  That will block things the way you are doing it, but it will always be the case and should be done at a time that there is less activity on the database.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 22

Expert Comment

by:8080_Diver
ID: 36537244
You might also want to try to do that during "off hours" . . . doing it during "business hours" is not a Best Practice.
0
 
LVL 10

Expert Comment

by:sqlservr
ID: 36541926
JestersGrind:

ALTER INDEX IndexName ON TableName REBUILD WITH (ONLINE = ON)
online index rebuild runs only in the enterprise editon ?
0
 
LVL 21

Expert Comment

by:JestersGrind
ID: 36542643
@sqlservr

That's a good point.  Online index operations are available only in SQL Server Enterprise, Developer, and Evaluation editions in SQL 2008.  

Greg

0
 

Author Closing Comment

by:sg05121983
ID: 36547172
--
0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 36552207
I take it the author has the Enterprise version of SQL Server. ;-)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now