• Mike Scalise (9/27/2016)


    ...

    However, it can't be sized below what its initial size of 500MB was. Is my understanding correct, and is everything I've written accurate?

    ...

    Actually, that's not really true.

    The log file can be shrunk below its initial size. The ultimate limit for a shrink of the log file is actually determined by the fact that a log file must have at minimum two VLFs (as George pointed out). The larger the initial size of the log file, the bigger those initial VLFs are (determined by the algorithm mentioned at http://www.sqlskills.com/blogs/paul/important-change-vlf-creation-algorithm-sql-server-2014/).

    It's true that with SHRINKDATABASE the entire database cannot be shrunk below its initial size, however that does not apply to SHRINKFILE.

    From https://technet.microsoft.com/en-us/library/ms189080(v=sql.105).aspx:

    When using the DBCC SHRINKDATABASE statement, you cannot shrink a whole database to be smaller than its original size. Therefore, if a database was created with a size of 10 MB and grew to 100 MB, the smallest the database could be reduced to is 10 MB, even if all the data in the database has been deleted.

    However, you can shrink the individual database files to a smaller size than their initial size by using the DBCC SHRINKFILE statement. You must shrink each file individually, instead of trying to shrink the whole database.[/i]

    (my emphasis)

    Also, from https://msdn.microsoft.com/en-us/library/ms189493.aspx:

    You can shrink a file to a size that is less than the size specified when it was created.

    It's also fairly easy to demonstrate with these steps:

    1) Create a DB with a log file of, say, 64 MB and put it in the full recovery model

    2) Generate enough log to force the log to grow

    3) Back up the log to allow it to truncate

    4) Generate just enough activity to move the head of the active portion of the log to the first or second VLF (since you can't shrink past last active VLF)

    5) Back up the log again to allow it to truncate

    6) After confirming that only the first VLF or first two are active, shrink the log down as far as possible.

    You'll be left with just two of your initial VLFs, which will be about 32 MB if you decided to do this with a 64 MB initial size. In your case, with a 500 MB initial log file size, shrinking down to the minimum of 2 VLFs would leave the file around 125 MB.

    It can be demonstrated much more simply by just creating a database and then shrinking the log file as far as it will go, but I wanted to cover the fact that neither of 1) being in the full recovery model or 2) having had the log grow at some point prevents shrinking below the initial size.

    Having said all that, while you can shrink log files below their initial size, the advice given by others previously in the thread still holds. If drive space is at a premium, then it's a decent idea to keep the size at creation small and then manually grow it out to an appropriate size for the workload, so you can shrink down as low as possible in a crunch.

    Cheers!