Changing the initial size of db file

  • I need to shrink database and log files to less than their inital size, thus change the initial size of the dabase file.

    How do I do this?

  • 1. Backup your log file

    2. DBCC SHRINKDATABASE(Databasename)

    ----------------------------------------------------------------------------------------------------------------------------------------------------
    Roshan Joe

    Jeff Moden -Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • I need to shrink the database files to less than the current initial size of the database. Shrinkfile, shrinkdatabase and logbackup only shrinks to the initial size of the database files.

    Thus, I do not want to shrink, I want to change the initial size of the files.

  • Its seems to be an open issue in both sql server 2000 and SQL Server 2005. We cannot shrink the database less than the initial size.

  • You would think that if you cannot shrink the file below the initial size they'd at least give us the possibility to be able to decrease the initial size then.... :hehe:

  • DBCC SHOINKDATABASE will not allow a shrink below the original size, but DBCC SHRINKFILE will allow you to shrink to any desired size. (provided this size is larger than the currently used space!)

    Mike John

  • TDP (1/19/2009)


    You would think that if you cannot shrink the file below the initial size they'd at least give us the possibility to be able to decrease the initial size then.... :hehe:

    Actually shrink file does let you shrink the files so theyโ€™ll be smaller then the initial size. Check the script bellow that shows it:

    --Create the database. Notice the size of the files

    CREATE DATABASE MyDB

    ON

    ( NAME = MyDB_dat,

    FILENAME = 'c:\MyDB.mdf',

    SIZE = 10MB,

    MAXSIZE = 50,

    FILEGROWTH = 5 )

    LOG ON

    ( NAME = MyDB_log,

    FILENAME = 'c:\MyDB.ldf',

    SIZE = 3MB,

    MAXSIZE = 25MB,

    FILEGROWTH = 5MB )

    go

    use MyDB

    go

    --Get the file's size

    select name, size from MyDB.sys.database_files

    --Srinking both log and data files

    dbcc shrinkfile('MyDB_Dat',1)

    go

    dbcc shrinkfile('MyDB_log',1)

    go

    --Compare the new size with the size before the use of dbcc shrinkfile

    select name, size from MyDB.sys.database_files

    go

    --Cleanup the mess:-)

    use master

    go

    drop database MyDB

    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/

  • Thanks guys. Think there might have been open transactions or replication that were not allowing me to shrink the file to less than the initial size. ๐Ÿ™‚

  • You can't shrink below the initial size. Your only option is to back up the database, drop and recreate it with a lower initial size, and then restore. You should only set the initial size when you know you will always need at least that much space.

  • Mike John (1/19/2009)


    DBCC SHOINKDATABASE

    Mike John

    New in SQL 2005???? ๐Ÿ˜›

    -- You can't be late until you show up.

  • binary lumberjack (1/19/2009)


    You can't shrink below the initial size. Your only option is to back up the database, drop and recreate it with a lower initial size, and then restore. You should only set the initial size when you know you will always need at least that much space.

    Again - if you use shrinkdatabase, that might be true, but shrinkfile DOES in fact allow you to make the initial size smaller.....

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • It looks like shrinkfile worked as I can see all the expected size from sys.database_files and sqlperf(logspace). But the actual size of the logfile still keeps the same physical size as the initial size.

  • Make sure the log has been backed up first or set the recovery model to simple.

    This will allow the log file to be shrunk to a size smaller than the original file size specified.

  • shrinkfile will let you go below the initial size. I shrunk the file and tried to lower the initial size, stopped and restarted the sql service and it went right back to the original initial size. Does that make any sense?

  • From BOL:

    You can reduce the default size of an empty file by using DBCC SHRINKFILE target_size. For example, if you create a 5-MB file and then shrink the file to 3 MB while the file is still empty, the default file size is set to 3 MB. This applies only to empty files that have never contained data.

Viewing 15 posts - 1 through 14 (of 14 total)

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