Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to reduce MDF data file? Expand / Collapse
Author
Message
Posted Thursday, January 1, 2009 12:53 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, June 20, 2012 9:11 AM
Points: 85, Visits: 363
My database has MDF datafile 20G bytes, when I backup DB, the backup file = 20G also

After I delete many records, many backup tables in database, the backup file reduce to 10G. I use Shrink database, the LDF file reduces size, but MDF file is still big with 20G. The number of record in DB is reduced but MDF file is not reduced

So how to reduce it?

Thanks
Post #628377
Posted Thursday, January 1, 2009 1:00 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Monday, October 7, 2013 9:29 AM
Points: 409, Visits: 421
Can you please run the maintenance plan to defrag if any tables are fragemented and then run the dbcc shrinkfile to reduce the size
Post #628378
Posted Thursday, January 1, 2009 1:29 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 7:19 AM
Points: 2,112, Visits: 5,477
You can use dbcc shrinkfile instead of dbcc shrinkdb. This enables you to select the file that you want to shrink and set the new size. The question is – why? Shrinking the file causes unwanted effects such as fragmentation. Also if the database reached this size there is a good chance that it will reach this size again, so why shrink it at all?

Adi


--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #628379
Posted Thursday, January 1, 2009 4:19 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, June 20, 2012 9:11 AM
Points: 85, Visits: 363
As I understand, we need to run SHRINKFILE twice
- First with "NOTRUNCATE" to reallocate spaces
- Second with "TRUNCATEONLY" to reduce size
Is it correct?
And how to calculate "target_size" value of SHRINKFILE?
Thanks
Post #628395
Posted Thursday, January 1, 2009 4:26 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, May 22, 2014 7:04 AM
Points: 1,688, Visits: 8,766
Normally you shouldn't shrink.
http://www.karaszi.com/SQLServer/info_dont_shrink.asp


If you have decided then decide the target size based on how much space you want to leave in mdf file after shrink operation is done. For example if your db is 10GB used up then leave 2-3GB for future expansion and set the target size to 12000.

MJ
Post #628397
Posted Thursday, January 1, 2009 4:39 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, June 20, 2012 9:11 AM
Points: 85, Visits: 363
MANU (1/1/2009)
Normally you shouldn't shrink.
http://www.karaszi.com/SQLServer/info_dont_shrink.asp


If you have decided then decide the target size based on how much space you want to leave in mdf file after shrink operation is done. For example if your db is 10GB used up then leave 2-3GB for future expansion and set the target size to 12000.

MJ


Database is so big, there are many unused backup tables in database, so I delete them and reduce Database size to easy manage. That's why I want to shrink
As your article, after shrinking, the log file size will increase. Then can I continue to shrink Log file after that?
What the matter if I setup target size smaller, ex 8GB? Can it automatically to be 10G?
Thanks
Post #628402
Posted Thursday, January 1, 2009 5:02 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, May 22, 2014 7:04 AM
Points: 1,688, Visits: 8,766
Set target size to used space+Some breathing space. Yes, you can shring log file after that. Don't forget to do reindexing/defrag after shrink.

MJ
Post #628406
Posted Thursday, January 1, 2009 11:38 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 7:26 AM
Points: 4,358, Visits: 9,536
Database is so big, there are many unused backup tables in database, so I delete them and reduce Database size to easy manage. That's why I want to shrink
As your article, after shrinking, the log file size will increase. [b]Then can I continue to shrink Log file after that?[b]
What the matter if I setup target size smaller, ex 8GB? Can it automatically to be 10G?
Thanks


No - you don't want to shrink either the data file or the log file on a regular/scheduled basis. Do so will cause more problems than it is worth.

Please review the article I link to in my signature on how the manage transaction logs.


Jeffrey Williams
Problems are opportunites brilliantly disguised as insurmountable obstacles.

How to post questions to get better answers faster
Managing Transaction Logs
Post #628452
Posted Thursday, January 1, 2009 11:48 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 4:16 PM
Points: 31,018, Visits: 15,456
I agree with Jeffrey, shrinking causes fragmentation on data files and is a waste of resources on log files. Set the files to be the amount of space you need for normal activity and leave them there. Monitor the data files to add space as data grows.







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #628458
Posted Friday, January 2, 2009 10:58 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, June 20, 2012 9:11 AM
Points: 85, Visits: 363
Jeffrey Williams (1/1/2009)
Database is so big, there are many unused backup tables in database, so I delete them and reduce Database size to easy manage. That's why I want to shrink
As your article, after shrinking, the log file size will increase. [b]Then can I continue to shrink Log file after that?[b]
What the matter if I setup target size smaller, ex 8GB? Can it automatically to be 10G?
Thanks


No - you don't want to shrink either the data file or the log file on a regular/scheduled basis. Do so will cause more problems than it is worth.

Please review the article I link to in my signature on how the manage transaction logs.


No, I don't shrink it regular. I just want to do once now to reduce MDF size because I just delete so many unused records in this DB
Post #628986
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse