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
Solved

Diskspace For Index Rebuild

Posted on 2013-01-09
2
373 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
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 …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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