Index Rebuild causing blocking issue

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
sg05121983Asked:
Who is Participating?
 
JestersGrindCommented:
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
 
JestersGrindCommented:
ALTER INDEX IndexName ON TableName REBUILD WITH (ONLINE = ON)

Greg

0
 
sg05121983Author Commented:
Thnaks Mr. JestersGrind.

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

Any other suggestions on my script?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
JestersGrindCommented:
The rest of the script looks fine.

Greg

0
 
DBAduck - Ben MillerPrincipal ConsultantCommented:
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
 
8080_DiverCommented:
You might also want to try to do that during "off hours" . . . doing it during "business hours" is not a Best Practice.
0
 
Ramesh Babu VavillaCommented:
JestersGrind:

ALTER INDEX IndexName ON TableName REBUILD WITH (ONLINE = ON)
online index rebuild runs only in the enterprise editon ?
0
 
JestersGrindCommented:
@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
 
sg05121983Author Commented:
--
0
 
8080_DiverCommented:
I take it the author has the Enterprise version of SQL Server. ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.