question

r_balaji_g avatar image
r_balaji_g asked

dbcc shrinkfile question

Hello, I do understand all the negative side of dbcc shrinkfile (that it causes severe fragmentation, single threaded, would take a long time, never run autoshrink, etc). We have a necessity to shrink our mutli-terabyte DB. Our DB consists of multiple datafiles. Even though I see general recommendation from Microsoft to run shrinks one file at a time to avoid system tables blocking, I took risk, went ahead & ran dbcc shrinkfile on two data files at the same time in parallel to cut down total time to shrink all DB files Now the two shrinks threads are blocking each-other on system tables and are stuck for more than a day. We had same situation couple times previously and 1. we tried killing one of the shrinkfile SPID - rollback was never progressing/complete and was stuck. We re-started SQLServer, and the DB went to suspect mode. We had to restore the DB from the backup 2. On another similar occation, we just recycled the SQLServer without trying to kill one of SPIDs first, again the DB went to suspect mode and had to restore the DB from backup Is there any way that we resolve this & bring the server to a fully funcational mode without re-restoring the DB?OR just consider this as a hard lesson learnt and in future never run more than one shrinkfile at a time? Many Thanks for your input & guidance.
shrink
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
raadee avatar image
raadee answered
You might have to do a combination of rebuilding indexes (or moving heaps pages internally) and incrementally shrinking your file to succeed. Have a look at these two articles, the solution could be a combination of them. [Shrinking databases with index maintenance][1] [Incrementally shrinking a large SQL Server data file using PowerShell][2] [1]: http://sqltrees.wordpress.com/2013/08/11/shrinking-databases/ [2]: http://www.mssqltips.com/sqlservertip/3178/incrementally-shrinking-a-large-sql-server-data-file-using-powershell/
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.