SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Clustered Index Rebuild Space Requirements ?


Clustered Index Rebuild Space Requirements ?

Author
Message
homebrew01
homebrew01
SSCarpal Tunnel
SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)

Group: General Forum Members
Points: 4961 Visits: 9108
I have a 100 Gig table and I have cleared data from a lot of columns to reclaim space, and now I want to rebuild the clustered index over a small column. Any idea how to estimate how much free space will be needed during the process ? I don't want to run out of disk while it runs.

Sql 2008 r0, std ed.



Michael Valentine Jones
Michael Valentine Jones
SSCertifiable
SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)

Group: General Forum Members
Points: 5878 Visits: 11771
The space needed will be about the size of the clustered index and a little more.

You should probably allow enough free space equal to the size of the current table and a bit more.

An additional item to consider is that a rebuild will need about an equal amount to space or more in the transaction log.


If you are short on space, you should consider doing a defrag instead of a rebuild. It will still generate a log of transaction log usage, but you can keep that under control by doing transaction log backups very often while the defrag is running, say every 5 minutes.
homebrew01
homebrew01
SSCarpal Tunnel
SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)

Group: General Forum Members
Points: 4961 Visits: 9108
Thanks.

It is a table in an archive database that is in simple recovery mode.

The index itself is 1 or 2 gig. The database has 2 files (mdf & ndf), I think on 2 different drives. I think each drive has 40 or 50 gig free. (We have an internet outage locally, so I can't log in)



Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)

Group: General Forum Members
Points: 88288 Visits: 41128
homebrew01 (12/24/2013)
Thanks.

It is a table in an archive database that is in simple recovery mode.

The index itself is 1 or 2 gig. The database has 2 files (mdf & ndf), I think on 2 different drives. I think each drive has 40 or 50 gig free. (We have an internet outage locally, so I can't log in)


The recovery mode probably won't matter because, unless the table is partitioned, a rebuild is (IIRC) a single transaction that will be stored in the logfile until the transaction is complete.

The MDF/LDF file will also grow, perhaps unacceptably, because for any rebuild over 128 extents, it builds a separate copy of the CI (and, therefor, a copy of the table itself) and only flops over to the new copy when the transaction completes.

Serendipitously, I've recently created a way to be able to release all of that extra free space if the table lives in its own FileGroup. It's fairly complicated and requires a bit of offline time (the time it takes to rebuild the CI) and works best if the PRIMARY FileGroup of the Archive Database is mostly empty and has no tables in it. That would also require a little up front work because, to recover the space using the method, the PRIMARY FileGroup Files would need to be shrunk and we all know what that does to fragmentation levels of any tables it they contain. That means that any tables in the PRIMARY FileGroup should probably be moved to their own FileGroups and Files.

Still, it might not be worth it for this (it was worth it to me because of the Partitioning that I'm doing to huge, mostly static, "insert only" audit tables) unless you need to keep the restore footprint as small as possible to be able to do restores to smaller machines. I say that because the drives for your problem are dedicated to the archive database, so let them be dedicated. Free space isn't backed up to tape.

Of course, consideration for any of this would be a totally unnecessary exercise if MS actually did index rebuilds and file shrinks in an ages-old Peter Norton style instead of the current methods, which they do't seem interested in fixing.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
ELLEN-610393
ELLEN-610393
SSC Journeyman
SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)

Group: General Forum Members
Points: 82 Visits: 102
In the case of a very large table, 1.4 TB, that is not partitioned, what is the least amount of space that will need to be available to build an index? Does it make a difference if the index is clustered [or not]?

I am trying to determine before we start the build or rebuild of the index how much free space will be needed 1) in the data files that make up the filegroup where the table resides, 2) in the DB transaction log and 3) in tempdb.

Does recovery mode of the DB matter? if so, which is better?
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)

Group: General Forum Members
Points: 88288 Visits: 41128
ELLEN-610393 (1/6/2014)
In the case of a very large table, 1.4 TB, that is not partitioned, what is the least amount of space that will need to be available to build an index? Does it make a difference if the index is clustered [or not]?

I am trying to determine before we start the build or rebuild of the index how much free space will be needed 1) in the data files that make up the filegroup where the table resides, 2) in the DB transaction log and 3) in tempdb.

Does recovery mode of the DB matter? if so, which is better?


I'd plan on 1.5TB extra in the MDF file for the Clustered Index. The other indexes should be smaller. Also, unless the database is in BULK-LOGGED or SIMPLE recovery mode, you can plan on similar logfile growth. I do recommend using the SORT IN TEMPDB option which will prevent additional growth of the MDF file.

My recommendation would be that if the Clustered Index is based on an IDENTITY column or the date inserted, you don't need to rebuild the Clustered Index.

It may also be sufficient to "just" do a REORGANIZE on the Non-Clustered indexes which won't require huge amounts of extra room. REORGANIZE does NOT rebuild or reorganize the BTREE but that may not matter.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search