SQL Server 2008 - Shrinking the Transaction Log - Any way to automate?

后端 未结 6 501
醉酒成梦
醉酒成梦 2021-02-03 14:30

I went in and checked my Transaction log the other day and it was something crazy like 15GB. I ran the following code:

USE mydb
GO
BACKUP LOG mydb WITH TRUNCATE         


        
6条回答
  •  执笔经年
    2021-02-03 15:01

    If you file grows every night at 500 MB there is only one correct action: pre-grow the file to 500MB and leave it there. Shrinking the log file is damaging. Having the log file auto-grow is also damaging.

    • you hit the file growth zero fill initialization during normal operations, reducing performance
    • your log grows in small increments creating many virtual log files, resulting in poorer operational performance
    • your log gets fragmented during shrinkage. While not as bad as a data file fragmentation, log file fragmentation still impact performance
    • one day the daily growth of 500MB will run out of disk space and you'd wish the file was pre-grown

    You don't have to take my word for it, you can read on some of the MVP blogs what they have to say about the practice of log and file shrinkage on a regular basis:

    • Auto-shrink – turn it OFF!
    • Oh, the horror! Please stop telling people they should shrink their log files!
    • Why you want to be restrictive with shrink of database files
    • Don't Touch that Shrink Button!
    • Do not truncate your ldf files!

    There are more, I just got tired of linking them.

    Every time you shrink a log file, a fairy loses her wings.

提交回复
热议问题