question

ak1516 avatar image
ak1516 asked

shrinking large data file

i have dropped all the non clustered indexes on the database and can see a lot of free space in the data files. dbcc shrink file is really taking long time to shrink.any tricks to have the magic ? there are two datafiles mdf - 1 tb -- 600gb occupied rest all free ndf - 580 gb -- 10gb occupied rest all free ???
shrink-database
10 |1200

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

Cyborg avatar image
Cyborg answered
You can use the DBCC SHRINKFILE to shrink particular database file. But if you are not concern with your disk space and you have plenty of it, then i recommend not to shrink because your Database can reuse this space and you can reduce the DB auto-growth(if enabled) and the performance impact of auto-growth. If you really want to do it then, shrink your file so that you have reserved enough free space for your future db growth. The following command shrink the myDBFileto 10 GB DBCC SHRINKFILE(myDBFile,10240)
10 |1200

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

Sharma avatar image
Sharma answered
I suppose that you are already aware about the disadvantage of shrink database but you have drop many cluster index in your database and you want to claim space from database then you can shrink the database, personally I found that for fast shrink that database you could put database in single user mode and then shrink database then it will be 30% faster than your normal shrink. Please take care of given below things if you want to shrink the database- (1) Do not run shrink database command on live database, please disconnect all connection then only run this command. (2) If possible then put database in single user mode for fast shrink. (3) Rebuild or Re-Organize indexes after shrink the database otherwise database performance will be decrease. (Use SORT_IN_TEMPDB=ON) for rebuild the indexes.
10 |1200

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

Håkan Winther avatar image
Håkan Winther answered
By removing all your non clustered indexes you'll get a lot of free space in your DB, but you'll loose a lot of that space when you add them again. Are you really sure you need to shrink the files? I guess you already know the disadvantages of shrinking the files. I wouldn't use shrink unless I have dropped a some large tables that's not used anymore, or when I've implemented DATA_COMPRESSION on the indexes.
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.