Search code examples
sql-servertransaction-log

Transaction log file size carry over when performing a backup on another SQL Server


Our production server has a large .ldf file (300 gb) associated with a .mdf file. On our DEV server, we restore the DEV database using the production backup from time to time. As our DEV server should not have many transactions associated with it, but the .ldf file is 300 gb also. I shrank the .ldf file to 50 gigs in size. Will the DEV .ldf file grow again after a restore from a production backup?


Solution

  • Will the DEV .ldf file grow again after a restore from a production backup?

    Yes, in case if your production database log file still has such size - 300 GB your database on dev will again have such log file.

    We do not know what is the baseline of your live database.

    However, if your production database has no regular heavy DML operations that result in long-running transactions, consider reducing the size of the log file on production to smaller size, for instance to 50 GB.

    Also, this reduction will significantly reduce restore time, because LDF files are to be zeroed internally before RESTORE starts writing actual data. It means that SQL Server firstly has to create 300 GB file and write zeroes in it. In contrast with log files, data files can benefit from "instant file initialization" and such zeroing can be skipped if SQL Server instance service account correctly configured to have enough permissions.

    Otherwise, every time when you do a restore to a dev environment such maintenance task to be done:

    USE yourDev
    ALTER DATABASE yourDev SET RECOVERY SIMPLE
    -- assumption: only one ldf in db
    DBCC SHRINKFILE(2, 1024)