Clustered Index Rebuild Space Requirements ?

  • 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.

  • 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.

  • 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)

  • 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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • 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?

  • 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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply