We have a lovely Availability Group that holds A LOT of data that is broken into partitions. We have 42 partitions and they are usually moving information around daily between them. The index rebuilds on them were making our logs HUGE because the the Availability Group was taking too long to catch up, we tried both Synchronous and Asynchronous mode. We would see all kinds of errors. We were doing horrible things like auto shrinking our transaction log after the indexing finished and ignoring alarms during the time the database was rebuilding. We had requested more and more space from our storage team and sometimes the job wouldn’t even finish because it ran out of space. Our first idea was to split out the index rebuilds so that we could do one partition at a time.
It looks like this:
ALTER INDEX IndexName ON [dbo].Table REBUILD PARTITION = 42
By splitting this out, we were able to get the job to finish, but with tons of alarms, and log growth.
Then we had a thought, maybe the server is just spinning too fast and we need to give the Availability Group time to catch up. So we added some simple waits in between each step.
WAITFOR DELAY '00:10';
As an example this is in minutes and will wait for 10 minutes before running the next step.
It has now been a quiet week and we are looking forward to the Sound of Silence.
Nice blogg you have