[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Diskspace For Index Rebuild

Posted on 2013-01-09
2
Medium Priority
?
396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

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 70

Accepted Solution

by:
Scott Pletcher earned 1500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

649 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