Why shrinking the data file is bad?

Hi All,
Why shrinking the data file is bad?
If it is bad, Then why SQL server has this option?

There are several reasons why shrinking is bad. One of the reasons were recorded already by Louis Jordan around 1950 where he sang What's the Use of Getting Sober, when You Are Gonna Get Drunk Again?" That is, why shrink something that will grow
again? Growing a database file takes some resources, since it has to be zero-initialised. For a data file this can be avoided by granting the service account for SQL Server the permission "Perform Volume Operations" (if I recall the name correctly).
For a log file it is unevitable. While SQL Server grows the file, this causes a standstill for the process that triggered the file to grow, and can easily cause a bigger outage.
Another reason that shirnk is bad is that it adds a lot of fragmentation to the database. In difference to the above, there is no reason it has to be that way. It's simply not an optimal implementation.
Shrinking can be really poor when you have big LOB columns.
So why does shrink exist? Because sometimes, shrinking a data file or a log file is a perfectly legit operation. Say that you have a transaction database, and you decide to move transactions that are more than 12 months old to an archive database,
and you also implement a process to move data to the archive database on quarterly basis. Before you implemented the archive database, the transaction database was 1.5 TB, but after you moved ten years worth of data, you now have a 250 GB database. In this
case, it would be perfectly reasonable to shrink the data file to, say, 300 GB to make it more managable.
Or say that you make a change to your reindex job so that it runs with bulk_logged recovery rather than full. This may permit you to reduce the size of the log file with 50% (a number taken out of thin air).
There are lot of other situations, but the key is: you have reason to believe that the data file will stay within the size you shrink it to. Some people are obesseed with space and shrink whenever they get the occasion, but that is a bad idea.
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • How to defrag after Shrinking the data and log every night

    OK, my shop has a shrink job that runs every night. It shrinks the data and log files. DBCC SHRINKFILE (filename,1). We have recovery model Simple.
    So reading that SHRINK is horrible for the data file because of fragmentation, so looking to stop the daily job. BUt this job has been running everyday for years right after the ETL. We have a big nightly ETL process that (1) truncates several
    hundred SQL tables and then BULK INSERT from the AS400 (2) for really large tables we just bring in the last X number of days from the AS400 and insert those records into the SQL table. We have very few indexes, but do have some on the really
    large tables. FYI - The SQL Servers are at the clients' sites.
    What kind of fragmentation has the SHRINK on the data file caused? how would it affect the ETL, and retrieval of data during the day? how can the fragmentation be fixed? 

    Hello,
    Databases suffer from fragmentation on indexes as explained
    here, but they suffer from physical fragmentation at the storage level also. 
    When the shrinking process shrinks a data file and recover space from the disk and the data file needs to grow again as part of your ETL process the new portion of the data file will rarely be contiguous to the rest of the data file on disk, and if this
    shrink process happens many times, the data file may be spread among many tracks on the disk. This increases the disk requests required to write data on a fragmented data file and increases disk requests to create new data files. In general, fragmentation
    will originate that what should be a simple I/O request has to be broken on many disk requests, making disk activity and performance less predictable and making disk queues larger.
    My suggestion is to stop sql server services during maintenance window, defragment disk using the Windows Defrag tool or a third party tool, when finish start SQL Server services again, then defrag indexes on your databases.
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Distributing the data files

    Hi All,
    We are working on the redistribution process of data files in SQL level. We knew that by doing the empty files options through shrink we could achieve it.  But I would like to know, Is there any things which I need to consider in terms of number of data files(Any Formula to arrive a total number of data files for the better performance in SQL database level).
    In my environment, the current database size is 420GB and its running with 24 data files, SAP advised us to minimize the data files because the data files are not in order (Like 1 data file having GB and some having 40GB and few having 90GB) - So, SAP recommended us to maintain the data file size as common and distribute the data equally among the files.
    So, wondering the data file size and also number according to our environment (It would be kind if you suggest on it)
    Database size :420GB
    Database version : SQL 2005
    CPU core : 4 cores running and its a Xeon processor
    Regards
    Vijay

    Hi,
    But I would like to know, Is there any things which I need to consider
    in terms of number of data files (Any Formula to arrive a total number of data files
    for the better performance in SQL database level).
    You can refer Topic "Number and Size of SQL Server Data Files" of this [Best Practice document|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/4ab89e84-0d01-0010-cda2-82ddc3548c65&overridelayout=true] (Page no.37 to 44 ). I hope you will get all the required information ,which can be considered for File Management in SQL server.
    Also you can refer the following SAP Notes to get more information.
    Note 987961 - FAQ: SQL Server I/O performance
    Note 363018 - File management for SQL Server
    Note 1488135 - Database compression for SQL Server
    Regards,
    Bhavik G. Shroff

  • Why does the Date Created metadata change when images are exported?How do I stop it from changing?

    why does the Date Created metadata change when images are exported?  How do I stop it from changing? I must have a prefernce set up wrong.

    I don't know what OS you are using, or what application you are using to view the data about your exported files, but on Windows and using Windows Explorer the "Date Created" field relates only to the date that the exported file was created, i.e. if viewed immediately after export it will show the date created as being the same date. In order to view "Capture Date" in something like Explorer, you first have to ensure you have included the Metadata as Conrad outlined above, then you have to adjust the display properties of Explorer to show the "Date Taken" field. Here is an example, part of a folder I exported back on March 3rd, note the difference between that last two dates:

  • Updating iTunes always deletes the data file behind my music in my library

    Hopefully, someone can help me. Everytime I update my iTunes, it somehow deletes the data files for my songs even though the song still appears in my library. When I go to listen or sync to my ipod it says it can't find the original data files and so I have to re-load all my CDs again, so I just basically don't update itunes anymore.
    Can anyone tell me why this is going on and how I can stop this from happening so that I can update itunes without losing all my songs?
    Thanks a bunch in advance!

    This appears to be a common problem lately on some computers ...try the following:
    Disconnect any iPod from the computer
    Temporarily remove any hackies or beta apps
    Make sure iTunes is in the original Apple install location=Applicatons Folder
    Refer to these Apple info docs:
    http://docs.info.apple.com/article.html?artnum=301749e
    http://docs.info.apple.com/article.html?artnum=93313
    Remember .... Seek and Ye shall find!!
    DIXIE

  • SQL Loader and foreign characters in the data file problem

    Hello,
    I have run into an issue which I can't find an answer for. When I run SQL Loader, one of my control files is used to get file content (LOBFILE) and one of the fields in the data file has a path to that file. The control file looks like:
    LOAD DATA
    INFILE 'PLACE_HOLDER.dat'
    INTO TABLE iceberg.rpt_document_core APPEND
    FIELDS TERMINATED BY ','
    doc_core_id "iceberg.seq_rpt_document_core.nextval",
    -- created_date POSITION(1) date "yyyy-mm-dd:hh24:mi:ss",
    created_date date "yyyy-mm-dd:hh24:mi:ss",
    document_size,
    hash,
    body_format,
    is_generic_doc,
    is_legacy_doc,
    external_filename FILLER char(275) ENCLOSED by '"',
    body LOBFILE(external_filename) terminated by EOF
    A sample data file looks like:
    0,2012-10-22:10:09:35,21,BB51344DD2127002118E286A197ECD4A,text,N,N,"E:\tmp\misc_files\index_testers\foreign\شیمیایی.txt"
    0,2012-10-22:10:09:35,17,CF85BE76B1E20704180534E19D363CF8,text,N,N,"E:\tmp\misc_files\index_testers\foreign\ลอบวางระเบิด.txt"
    0,2012-10-22:10:09:35,23552,47DB382558D69F170227AA18179FD0F0,binary,N,N,"E:\tmp\misc_files\index_testers\foreign\leesburgis_á_ñ_é_í_ó_ú_¿_¡_ü_99.doc"
    0,2012-10-22:10:09:35,17,83FCA0377445B60CE422DE8994900A79,binary,N,N,"E:\tmp\misc_files\index_testers\foreign\làm thế nào bạn làm ngày hôm nay"
    The problem is that whan I run this, SQL Loader throws an error that it can't find the file. It appears that it can't interpret the foreign characters in a way that allows it to find that path. I have tried adding a CHARACTERSET (using AL32UTF8 or UTF8) value in the control file but that only has some success with Western languages, not the ones listed above. Also, there is no set of defined languages that could be found in the data file. It essentaially could be any language.
    Does anyone know if there is a way to somehow get SQL Loader to "understand" the file system paths when a folder and/or file name could be in some other langauge?
    Thanks for any thoughts - Peter

    Thanks for the reply Harry. If I try to open the file in various text editors like Wordpad, Notepad, GVIM, andTextpad, they all display the foreign characters differently. Only Notepad comes close to displaying the characters properly. I have a C# app that will read the file and display the contents and it renders it fine. If you look at the directory of files in Windows Explorer, they all are displayed properly. So it seems things like .Net and Windows have some mechanism to understand the characters in order to render them properly. Other applications, again like Wordpad, do not know how to render them properly. It would seem that whatever SQL Loader is using to "read" the data files also is not rendering the characters properly which prevents it from finding the directory path to the file. If I add "CHARACTERSET AL32UTF8" in the control file, all is fine when dealing with Western langauges (ex, German, Spanish) but not for the Eastern languages (ex. Thai, Chinese). So .... telling SQL Loader to use a characterset seems to work, but not in all cases. The AL32UTF8 is the characterset that the Oracle database was created with. I have not had any luck if I try to set the CHARACTERSET to whatever the Thai character set is, for example. There problem there though is that even if that did work, I can't target specific lagauages because the data could come from anywhere. It's like I need some sort of global "super set" characterset to use. It seems like the CHARACTERSET is the right track to follow but I am not sure, and even if it is, is there a way to handle all languages.
    Thanks - Peter

  • Clear Data package - "The data file is empty." Error

    Hi,
    When I run the Clear package in Data Manager, I get the error "The data file is empty". We are running BPC 7.5 SP3. There are no calculated members selected. Any suggestions?
    Thanks.
    Tom

    Hi Tom,
    If i'm not mistaken when we run the clear data package, BPC inserts -ve values for the combination of dimensions selected.
    For ex if you have selected time as 2010.DEC it would reverse out all these values by inserting negative values which would then total up to zero.
    So i still think it could be a problem with the Transformation file.
    P.S. Maybe you can try using the Clear from Fact table package.
    Santosh

  • I have written a binary file with a specific header format in LABVIEW 8.6 and tried to Read the same Data File, Using LABVIEW 7.1.Here i Found some difficulty.Is there any way to Read the Data File(of LABVIEW 8.6), Using LABVIEW 7.1?

    I have written a binary file with a specific header format in LABVIEW 8.6 and tried  to Read the same Data File, Using LABVIEW 7.1.Here i Found some difficulty.Is there any way to Read the Data File(of LABVIEW 8.6), Using LABVIEW 7.1?

    I can think of two possible stumbling blocks:
    What are your 8.6 options for "byte order" and "prepend array or string size"?
    Overall, many file IO functions have changed with LabVIEW 8.0, so there might not be an exact 1:1 code conversion. You might need to make some modifications. For example, in 7.1, you should use "write file", the "binary file VIs" are special purpose (I16 or SGL). What is your data type?
    LabVIEW Champion . Do more with less code and in less time .

  • Why is the version file smaller than the original file, although I didn't make changes in the file? And why is the keywords don't exporting with original files?

    Hi! Why is the version file smaller than the original file, although I didn't make changes in the file? And why is the keywords don't exporting with original files?

    Wild guess: you're using the the wrong export settings. You'll need to tell us more before we can help you - like the export settings you're usng, the size and format of the originals etc.

  • Why is the picture quality so bad? It just doesn't take good picture it's blurry.

    Why is the picture quality so bad? It just doesn't take good pictures it's blurry.

    Hi there Amitabhavin,
    You may find the troubleshooting steps in the article below helpful.
    iPhone: Hardware troubleshooting
    http://support.apple.com/kb/ts2802
    Camera isn't functioning or has undesired image quality
    If the screen shows a closed lens or black image, force quit the Camera app.
    If you do not see the Camera app on the Home screen, try searching for it in Spotlight. If the camera does not show up in the search, check to make sure that Restrictions are not turned on by tappingSettings > General > Restrictions.
    Ensure the camera lens is clean and free from any obstructions. Use a microfiber polishing cloth to clean the lens.
    Cases can interfere with the camera and the flash. Try gently cleaning the lens with a clean dry cloth or removing the case if you see image or color-quality issues with photos.
    Try turning iPhone off and then back on.
    Tap to focus the camera on the subject. The image may pulse or briefly go in and out of focus as it adjusts.
    Try to remain steady while focusing:Still images: Remain steady while taking the picture. If you move too far in any direction, the camera automatically refocuses to the center.
    Note: If you take a picture with iPhone turned sideways, it is automatically saved in landscape orientation.
    Video: Adjust focus before you begin recording. You can also tap to readjust focus while recording. Exiting the Camera application while recording will stop recording and will save the video to the Camera Roll.
    Note: Video-recording features are not available on original iPhone or iPhone 3G.
    If your iPhone has a front and rear camera, try switching between them to verify if the issue persists on both.
    -Griff W. 

  • Why is the vcf file is empty?

    Why is the vcf file is empty (0kb) when I drag a contact directly from Contacts 8.0 to Mail 7.1?

    Wild guess: you're using the the wrong export settings. You'll need to tell us more before we can help you - like the export settings you're usng, the size and format of the originals etc.

  • Data Integrator has no read permissions to get the data file using FTP

    Hi,
    I wonder if you could help.
    We have installed the data integrator and are using FTP to get the data file from the SAP server to the DI server. The files are created by the SAP admin user with permissions 660. The FTP user is not in the sapsys group so cannot read the files.
    Has anyone come accross this problem and how did you solve it?
    Many thanks.

    Hi,
    you might want to put you entry into the EIM forum where also the Data Integrator topics are being handled:
    Data Services and Data Quality
    Ingo

  • How can I put the signature into the data file.

    Hi all,
    I want to put the signature into the data file, mean the data file will be on the top and the signature will be at the buttom.how can i do that?
    Thanks.
    example:-
    dataFile.txt
    Name=...
    Address=...
    Signature=6A07C70E....123FEAB(Hex)

    Thanks for your reply.
    First, i have a keypair (public key and private key).
    I use the private key to initialize the Signature and
    use the Signature to sign a data file ( dataFile.txt) .
    So when i need to comfirm the data file not being modify
    I have to verify the data file with the Signature and the public key.
    I hardcoded the public key in my program so my client (receiver of data)
    need only the Signature file and the data file (2 files).
    So how can i combine the Signature file and the data file into 1 file?

  • Why doesn't flash player stay installed and why does the saved file disappear.

    Why doesn't flash player stay installed and why does the saved file disappear.  I have downloaded and installed flash player several times on my Win7 Vaio laptop. I have uninstalled and deleted all versions.  I am the administrator and I have also turned off my Security Software, but the same thing keeps happening over and over.  The Java Script is enabled and I have tried both downloading via IE and firefox.  It is rediculous that it keeps disappearing and I keep getting messages that the newest version is needed.  I am downloading directly from adobe and they say it is the latest.  Getting very frustrated.  They ask if we have any problems when we go to the finish line, but there is no place for comments.  I guess they don't really care if it works or not.

    So is it actually installed, or is it not?  If not, download and run the offline installers:
    Flash Player for ActiveX (Internet Explorer)
    Flash Player Plug-in (All other browsers)
    If it still does not work correctly, check
    http://forums.adobe.com/thread/885448
    http://forums.adobe.com/thread/867968
    In Firefox also check if the Shockwave Flash plugin is enabled.

  • Pls help me to count the no of occurence of each word in the data file

    I want to count the no of occurence of each word the data file..
    anybody help me out to solve this ,,
    I have attached my code hereby...
    import java.io.*;
    import java.util.*;
    import java.util.Collections;
    import javax.print.attribute.standard.Media;
    class WordCounter1 {
    String s;
    String word;
    public static void main (String[] args){
         WordCounter1 simpleCounter= new WordCounter1();
    try
    File firstFile=new File("C:/Documents and Settings/janmala/file4.txt");
    simpleCounter.countWords(firstFile);
    catch(Exception e)
    System.err.println(e);
    void countWords(File inputFile)
    int count=0;
    int key=0;
    LinkedHashMap lhm=new LinkedHashMap();
    try{
    FileInputStream fin=new FileInputStream(inputFile);
    DataInputStream din=new DataInputStream(fin);
    while(din.available()!=0){
    s=din.readLine();
    StringTokenizer st=new StringTokenizer(s);
    while(st.hasMoreTokens())
    word=st.nextToken();
    lhm.put(word,count);
    if(lhm.containsKey(word))
    lhm.get(word);
    count++;
    System.out.println(word);
    System.out.println(count);
    int a=lhm.size();
    System.out.println("The size of Hash map"+a);
    Set set = lhm.entrySet();
    Iterator it = set.iterator();
    while(it.hasNext())
    Map.Entry me = (Map.Entry)it.next();
    System.out.println(me.getValue()+":"+me.getKey());
    catch(Exception e)
    System.err.println(e);
    }}

    jan07 wrote:
    anybody help me out to solve this ,,Solve what?
    Don't just dump a pile of unformatted code and expect someone to magically fix it for you.
    Post code, hightlight it and click the CODE button to retain formatting
    Include error messages if you get them
    Ask an actual question

Maybe you are looking for

  • How to use blutooth client in example s in 7.1

                  sir ,                     sorry for giving invalid information regarding my problem.          now i am  giving clearly.                                i am having one file consists of 3000 values(3000 samples of ecg data)           with

  • Blackberry desktop manager wont detect blackberry

    i have looked everywhere for a solution to my problem and i simply cannot find a fix. my blackberry curve 8520 wont connect to my desktop manager. i have tried everything i could think of however nothing has proven successful. here is what i have so

  • Unistalling acrobat 9 standard

    I have Windows Vista, prior to that I had Windows XP with Acrobat 5, now with the new machine (vista) i got the upgrade of Acrobat (9). I can't get it install on my Vista PC. I am told I need to remove the 5 version and possibly need to create a new

  • Geting  Error in Controller

    Hi friends In controller am geting below error... java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(String.java:1937)at java.lang.String.substring(String.java:1904)at xxuss.oracle.apps.xp2p.fnd.fra

  • Only first IDOC stucked with 64 in BD87

    Hello Experts , scheduled a batchjob for processing the IDoc's , Issue is when i check in BD87 only the first IDOC is gtting stucked with status 64 and rest all are in 53 . Note : - No lock entry created for idoc in Sm12 - Processing mode in we20 is