Sql-server – Shrinking large DB file not working

shrinksql serversql-server-2008-r2vldb

I have a 5 TB database file (don't ask why) that I am cleaning up. I was already able to free over a TB and I will probably end up at 2.5 TB.

All best-practice advice aside, I need to now shrink this file. I am currently running this statement:

DBCC SHRINKFILE(1,4000000)

I can see that it is doing something, as it is sometimes waiting for a pageiolatch_sh and sometimes for a pageiolatch_ex. However, after 24 hours of execution time, the database has not shrunk by a single page. Usually when executing a file shrink like the above, you can see an impact on the file size immediately. Before, I tried to shrink the database by just a single GB and that also did not cause the file size to change at all. I stopped it after 24 hours.

This problem has been lingering for a while but we are at a point were we need to make progress, as the drive space is urgently required for other databases.

BTW, DBCC CHECKDB does not find any problems with that database, so this behaviour can't be caused by some circular page linkage.

Best Answer

A colleague of mine had a similar-ish problem with long-running shrinks. He took some time to investigate it and found that he had lots of indexes at the 'end' of the file.

A little index maintenance, and then the shrink operation ran fine. You can read his blog about it here: http://sqltrees.wordpress.com/2013/08/11/shrinking-databases/