question

skpani avatar image
skpani asked

Index fragmentation level

What would be the fragmentation level for Rebuilding or Re-indexing an Index ?
sql-server-2008-r2
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
To make this question and these answers as helpful for others as possible, remember to please indicate every helpful answer by clicking on the thumbs up next to it. If any one answer helped to solve your problem, indicate that by clicking on the check mark next to it.
0 Likes 0 ·
sqlaj 1 avatar image
sqlaj 1 answered
Best Practice and general rule of thumb is 30%. Keep in mind that may need to be adjusted depending on the size of the database and your maintenance window time frame. SQLFool (Michelle Ufford) has an awesome script you might want to look at that can help with that tasking. http://sqlfool.com/2011/06/index-defrag-script-v4-1/
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
+1 for Michelle's scripts. They're wonderful.
1 Like 1 ·
ThomasRushton avatar image ThomasRushton ♦♦ commented ·
Agreed. However, seeing as you've mentioned SQLFool, I will also mention Ola Hallengren's set of scripts. http://ola.hallengren.com. These two scripts helped when I was having to write similar for SQL 2000 (yes, I work on elderly systems).
1 Like 1 ·
Fatherjack avatar image Fatherjack ♦♦ commented ·
for a roll-your-own version, books online has a good starting point. Its very basic but is essentially what the others have in their core.
1 Like 1 ·
raadee avatar image
raadee answered
avg_fragmentation_in_percent value ALTER INDEX REORGANIZE > 5% and 30%
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Grant Fritchey avatar image
Grant Fritchey answered
I'm going to buck the trend and suggest you completely toss reorganize and only rebuild the index based on a combination of the fragmentation and it's size. The standard rule of thumb for size is 1000 pages, but I would generally go a little lower, between 200 & 500 pages. But, for indexes less than about 10,000 or so pages, I wouldn't defrag until it got about 60% or so. The number of pages is just too small to sweat. After that, I'd probably go with the standard 30% everyone else is suggesting.
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·
An opportunity for the standard answer of "it depends" wasted... Shame on you, @Grant, shame on you. But yeah - absolutely top advice there.
1 Like 1 ·
Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
Ha! You're right. I totally blew that opportunity. What was I thinking?
1 Like 1 ·
Fatherjack avatar image
Fatherjack answered
others have given you thresholds pertaining to the fragmentation and I wouldnt argue against any of them. What you do need to is to control when you do the defrag (to refer to rebuild or reorganise). if you blindly see an index has reached 30% (or whatever you choose as your 'tipping point') and instantly defrag it you will potentially bring your system to its knees until the defrag is complete. Schedule you scans for fragmentation for out of hours so that the defrag can take care of your indexes when other users are not pounding the data.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·
Good point. The bit I found helpful was to put in a cut-off point - in other words, don't blindly do the whole lot, but just get it to do an hour or so a night. That way, the indexes will get sorted out, but activity will be limited to out-of-hours / low-use hours.
1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.