Online rebuild consuming lot of log space

All we need is an easy explanation of the problem, so here it is.

why the online rebuild on a primary key clustered index in taking almost equal to the space of non clustered index size which is untouched.


  • We have a table with primary key clustered index (bigint type) of
    index size 7GB.
  • We have another non-clustered filtered index on same table (varchar(36) type) of index size nearly 1.5TB.
  • Online rebuild on primary key clustered index is consuming almost 1.6TB of transaction log size.
    Options used for rebuild – (DATA_COMPRESSION = PAGE, ONLINE = ON, SORT_IN_TEMPDB = ON)
  • Another observation, the previous index was created without compression, not sure if that is what causing such a huge growth.
  • Could someone please shed some internals about it?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

The clustered index is the table. It includes all columns. It is (basically) impossible for the clustered index to be smaller than any one non-clustered index. You probably looked at only the clustered key column size or only the non-leaf level when you read that 7GB size.

So if you rebuild the clustered index, then you rebuild all columns – including the compression setting. Rebuild of the clustered index in the end copies the data to a new location and after its done, it removes the data from the old location.

If you were on 2017, you could do resumable index rebuild, which allow you to pause the rebuild, empty the log and then resume the rebuild again.

Method 2

REBUILD is an atomic transactional operation so this is expected.
If you were to cancel it would need the logged information to roll back.

One possible alternative is to set up a copy table with the compression on and then copy across the rows in batches – of course you still take up extra space in the data file.
You can use sp_rename to change the copy table’s name when you are finished

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply