Solution - Decreasing initial datafile size of an user database

  • The following issue occurred:

    The datafile of the database has an initial size of 48GB while the data only occupies 29GB of the file.

    DBCC SHRINKFILE only shrinks the MDF file to the initial size, but doesn't release the space held by the initial filesize or decreases the size of the datafile. Database files are not meant to be shrunk, however sometimes the "overhead" of free space claimed is not in scope with the size of the database.

    Following steps solved the issue for me:

    * Make a full database backup, of the database you want to change.

    * Make sure you have sysadmin rights and bring the database into restricted user mode.

    * Select tasks --> shrink --> files from the database menu.

    * Choose the “Reorganize pages before...” option and enter the desired file size.

    Make sure the file size is larger than the minimum needed space for the data.

    * Check the properties of the database files and decrease the initial size of the datafile (if not already changed)

    * After finishing bring the database back in Multi User mode.

    This shrinks the files to the desired file size, without having to migrate data between datafiles (empty file solution) or having to bring the database or instance down.

    As any DBA can tell you, be aware of (and know) what you're doing, before you start an action like this. It's not certain this will solve a similar issue for anyone else, but it's worth to investigate.

  • .and then reindex your database, it will be badly fragmented following the shrink.

    ---------------------------------------------------------------------

  • arjen.schrier (10/7/2011)


    The following issue occurred:

    The datafile of the database has an initial size of 48GB while the data only occupies 29GB of the file.

    DBCC SHRINKFILE only shrinks the MDF file to the initial size, but doesn't release the space held by the initial filesize or decreases the size of the datafile. Database files are not meant to be shrunk, however sometimes the "overhead" of free space claimed is not in scope with the size of the database.

    Following steps solved the issue for me:

    * Make a full database backup, of the database you want to change.

    * Make sure you have sysadmin rights and bring the database into restricted user mode.

    you only need to be db-owner group member for that !

    * Select tasks --> shrink --> files from the database menu.

    * Choose the “Reorganize pages before...” option and enter the desired file size.

    Make sure the file size is larger than the minimum needed space for the data.

    * Check the properties of the database files and decrease the initial size of the datafile (if not already changed)

    * After finishing bring the database back in Multi User mode.

    This shrinks the files to the desired file size, without having to migrate data between datafiles (empty file solution) or having to bring the database or instance down.

    As any DBA can tell you, be aware of (and know) what you're doing, before you start an action like this. It's not certain this will solve a similar issue for anyone else, but it's worth to investigate.

    As already mentioned, you should perform full db maintenance after a shrink operation !

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

Viewing 3 posts - 1 through 2 (of 2 total)

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