SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to reduce MDF data file?


How to reduce MDF data file?

Author
Message
thang_ngo_2002
thang_ngo_2002
SSC-Addicted
SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)

Group: General Forum Members
Points: 405 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
Vee
Vee
SSC Eights!
SSC Eights! (945 reputation)SSC Eights! (945 reputation)SSC Eights! (945 reputation)SSC Eights! (945 reputation)SSC Eights! (945 reputation)SSC Eights! (945 reputation)SSC Eights! (945 reputation)SSC Eights! (945 reputation)

Group: General Forum Members
Points: 945 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
Adi Cohn
Adi Cohn
SSCrazy Eights
SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)

Group: General Forum Members
Points: 8103 Visits: 6594
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/
thang_ngo_2002
thang_ngo_2002
SSC-Addicted
SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)

Group: General Forum Members
Points: 405 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
MANU-J.
MANU-J.
SSCertifiable
SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)

Group: General Forum Members
Points: 7268 Visits: 8766
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
thang_ngo_2002
thang_ngo_2002
SSC-Addicted
SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)

Group: General Forum Members
Points: 405 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
MANU-J.
MANU-J.
SSCertifiable
SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)

Group: General Forum Members
Points: 7268 Visits: 8766
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
Jeffrey Williams 3188
Jeffrey Williams 3188
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18969 Visits: 10042
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 opportunities brilliantly disguised as insurmountable obstacles.

How to post questions to get better answers faster
Managing Transaction Logs

Steve Jones
Steve Jones
SSC Guru
SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)

Group: Administrators
Points: 145435 Visits: 19425
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
My Blog: www.voiceofthedba.com
thang_ngo_2002
thang_ngo_2002
SSC-Addicted
SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)

Group: General Forum Members
Points: 405 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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search