Solved

Diskspace For Index Rebuild

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL HELP 2 88
Sql Permission 6 59
Not selecting duplicate data 6 53
SQL Trigger or Function that updates table with old values 5 42
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

773 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