I have a database file that's currently 150GB, but only 75GB is being used - it's because I moved all the indexes (the other 75GB) to a new data file. I'd like to reclaim at least part of the space from this data file, but when I attempt to shrink the file, it "Executes" indefinitely, eventually being cancelled because of a network interruption or something else out of my control (after a day of running). Even using the "shrink to specific size" feature and specifying that it just trim off 10MB never seems to return - it just sits until the process is interrupted.
Is there another way that I can reclaim this space, even a little at a time?
EDIT: Somebody posted a link explaining why I shouldn't shrink my database. I understand, and I want to shrink it anyways. Disk space is at a premium on this server, and the database will not expand again into this unused space for a very long time - as I stated earlier, I migrated indexes out of the data file to free up this space, so now it's wasted.
No, using
DBCC SHRINKFILE ('filename', target_size)
is the right way to do it.If you want to do it in "chunks", you can either set progressively smaller target sizes, or just let it run as long as you can before it gets cancelled.
A few comments:
DBCC SHRINKFILE ('filename', TRUNCATEONLY)
. It should recover all the space its already freed at the end of the file (see my prior point)We have approached several options in our environment:
Good Luck
If you don't want to simply reclaim the space (which you specifically have refused to want to do) but insist on attempting to shrink the database expect this to take a very very long time and your transaction log expansion should just about cover any space you reclaimed from the database. As a bonus, watch your DB performance go thru the floor afterward. If Paul Randal can't convince you (Which JL commented with but I will repost here:Why you should not shrink your data files that shrinking is an awful idea, I'm not sure anyone can. With any luck shrink will be removed from SQL server (or at least be changed so it works like Paul recommends) in the next revision.