Shrink DB

  • I have 300 GB user database I can see around 150 free space on data file.

    When I tried to shrink database my MDF file still shows me 300 GB how to shrink this.

    I ran DBCC command and shrink Database but no impact.

  • Hi,

    Try to shrink file instead of database, this would make the file shrink.

    If this does not help, then you must see what the initial size of database(datafile) is set to.

  • I did that when I do shrink file I am getting this error below:

    A server error occured on the current command. The results, if any, should be discarded File ID 1 of database ID 7 canot be shrunk as it is either being shrunk by another process or is empty

  • Hi,

    Ok This means that your original job to shrink is still running in the background.

    Do a sp_who2 and a sp_lock to see which process is holding that database. then once you have that then you can do a dbcc inputbuffer (spid) to check the command that is running.

    You are going to have to wait for it to stop, don't restart sql server as you will get a corruption on the databases.

    Hope this helps

  • Nope nothing is been running, I checked earlier and I didnow as well.

  • Hi

    What is the error code it gives you with the last error??

  • Are you trying to shrink this down to 150MB? You want to keep free space in the file in general.

    The shrinking can be slow or fast, depending on the load your DB experiences and the locks that might be held on files. It can take some time.

    Can you restart the instance and then try shrinking if you really need to?

  • Nita,

    Please make sure AUTOSHRINK option is turned OFF for the database in question.

    Also, try shrinking database file in chunks rather than specifying a big size in one shot. Use dbcc shrinkfile(fileid,DesiredSize)

    Size--Specify the desired size which is 150,200 MB or 1 GB(it is based on the server I/O subsystem) less than the current size.

    For 300 GB database specify dbcc shrinkfile(1,299000) first if it works fine and completes in less than 10 minutes than go ahead with reducing the shrink size during later executions.

    Perform this activity when database is used at minimum.

    Manu

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply