Solved

Diskspace For Index Rebuild

Posted on 2013-01-09
2
374 Views
Last Modified: 2013-01-15
Hi ,

How to reduce .mdf file size after Index Rebuild (Offline)  in SQL Server 2005
Before doing index rebuild i changed recovery mode to bulk.
0
Comment
Question by:spkvijay
2 Comments
 
LVL 22

Expert Comment

by:Steve Wales
ID: 38758789
To answer your question, I will tell you that the way to shrink a data file in SQL Server is with DBCC SHRINKFILE.

However, just because you CAN do it, doesn't mean you SHOULD do it.

It is generally accepted that running SHRINKFILE on a datafile is a bad idea.  It causes internal file fragmentation and can cause bad performance.

If the file grew to the size it currently is, it obviously needed the space and the next time you perform index rebuilds (if that was the reason the file grew), then it's only going to grow again.

A quick search produced any number of articles on why you shouldn't shrink your datafiles:

http://www.karaszi.com/sqlserver/info_dont_shrink.asp
http://dba.stackexchange.com/questions/17277/when-is-it-ok-to-shrink-a-database
http://ask.sqlservercentral.com/questions/1872/is-using-shrink-bad-for-your-database.html
http://www.brentozar.com/archive/2009/08/stop-shrinking-your-database-files-seriously-now/

(Brent Ozar's post also links to another half a dozen articles from people like Paul Randall, Kimberly Tripp and Tom LaRock saying the same thing).
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 38760421
>> the next time you perform index rebuilds (if that was the reason the file grew), then it's only going to grow again <<

Not necessarily.  And index rebuilds do indeed by default use some extra disk space in the db, although much less than in earlier SQL versions (SQL 2000 and before).

I suggest using option SORT_IN_TEMPDB = ON when doing index rebuilds.  I've found it lessens total disk space used in the main db (even more than MS's docs claim it will), and usually makes the rebuilt index more contiguous besides.  It also can help performance, esp. if you have tempdb on a separate disk/raid set.

That option does require that you have enough free space in tempdb to hold the entire index.  That's not normally an issue nowadays, as tempdb is usually large anyway; however, it could prevent an extremely large index from using that option.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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