Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Clustered Index Rebuild Space Requirements ? Expand / Collapse
Author
Message
Posted Tuesday, December 24, 2013 8:50 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Saturday, April 12, 2014 11:40 AM
Points: 2,795, Visits: 8,297
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.



Post #1525765
Posted Tuesday, December 24, 2013 9:01 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 1:11 PM
Points: 3,081, Visits: 11,230
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.



Post #1525767
Posted Tuesday, December 24, 2013 9:08 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Saturday, April 12, 2014 11:40 AM
Points: 2,795, Visits: 8,297
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)



Post #1525770
Posted Tuesday, December 24, 2013 10:58 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 11:47 PM
Points: 35,959, Visits: 30,252
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." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1525787
Posted Monday, January 06, 2014 9:58 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, February 14, 2014 1:18 PM
Points: 36, Visits: 100
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?
Post #1528162
Posted Monday, January 06, 2014 1:56 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 11:47 PM
Points: 35,959, Visits: 30,252
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." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1528247
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse