MDF File Size

  • My database Backup file size 20 GB. i Restore this database another server that time MDF file will take 135 GB. i already tried shrink the database.but no use. give me a solution.

    I am using Sqlserver 2005 enterprice edition.

  • are you using compressed backups?

    how much free space is in the MDF file? run the below SQL it will loop through all DB's giving used and free space

    DECLARE @sql NVARCHAR(MAX)

    SELECT @sql = REPLACE(

    CAST(

    (

    SELECT 'USE ' + QUOTENAME(name) +';' + CHAR(13) + CHAR(10) +

    'SELECT ' + CHAR(13) + CHAR(10) +

    'DatabaseName = DB_NAME(), ' + CHAR(13) + CHAR(10) +

    'a.FILEID, ' + CHAR(13) + CHAR(10) +

    '[FILE_SIZE_MB] = CONVERT(DECIMAL(12, 2), ROUND(a.size / 128.000, 2)), ' + CHAR(13) + CHAR(10) +

    '[SPACE_USED_MB] = CONVERT(DECIMAL(12, 2), ROUND(fileproperty(a.NAME, ' + CHAR(39) + 'SpaceUsed' + CHAR(39) +') / 128.000, 2)), ' + CHAR(13) + CHAR(10) +

    '[FREE_SPACE_MB] = CONVERT(DECIMAL(12, 2), ROUND((a.size - fileproperty(a.NAME, ' + CHAR(39) + 'SpaceUsed' + CHAR(39) +')) / 128.000, 2)), ' + CHAR(13) + CHAR(10) +

    'a.NAME, a.FILENAME ' + CHAR(13) + CHAR(10) +

    'FROM dbo.sysfiles a;' + CHAR(13) + CHAR(10)

    FROM sys.databases

    FOR XML PATH('')

    )

    AS NVARCHAR(MAX)

    ),

    ' ',CHAR(13) + CHAR(10)

    )

    --SELECT @sql

    EXECUTE sp_executesql @sql

  • Thanks for ur reply

    No i am not taken compressed backup.just i took normal backup.

  • and what about free space?

  • File Size in MB

    MDF File : 137337.75

    Log File : 22867.38

    Space Used in MB

    MDF File : 15225.63

    Log File : 22303.33

    Free Space MB

    MDF File : 122112.13

    Log File : 564.05

  • ok try shrinking in small chunks as this can sometimes be faster than shrinking in one big go

    also I take it you are fully aware that you will need to rebuild all your indexes after shrinking which will result in your file growing again, but not to 135GB

  • ok thank you i will try

  • i done index rebuilding and then shrinking also. but still size not changesd.

  • What command exactly are you using to shrink it. Any error message?

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Try this:

    DBCC SHRINKDATABASE(database_name, NOTRUNCATE);

    Then try shrinking it again.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Its returned this result

    DBCC SHRINKDATABASE(iedb, NOTRUNCATE);

    19 1 17579232 128 1992792 1992768

    19 2 63 63 56 56

  • Try this:

    DBCC SHRINKDATABASE(iedb, 10);

    Go

    I usually find specifying the % free size works the best

  • vs.satheesh (3/28/2012)


    Its returned this result

    DBCC SHRINKDATABASE(iedb, NOTRUNCATE);

    19 1 17579232 128 1992792 1992768

    19 2 63 63 56 56

    That looks good, now, as I said, try shrinking the database after running NOTRUNCATE.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 13 posts - 1 through 12 (of 12 total)

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