Dangerous Things
Custom gadgetry for the discerning hacker

The Store is now open! Check out the gadgetry »
Like what you're reading?
Share It.

Emergency SQL transaction log truncation procedure

Sometimes you find yourself with an MS-SQL transaction log that grows in size very rapidly, quickly out-pacing your scheduled backup/truncation routines. I found when such events occur, you can manually truncate the log file without doing a huge time/space consuming backup by issuing these commands in sequence;

  • DBCC SHRINKFILE(‘LFLFLFLFLFLF‘,1)
  • BACKUP LOG DDDDDDD WITH TRUNCATE_ONLY
  • DBCC SHRINKFILE(‘LFLFLFLFLFLF‘,1)
  • BACKUP LOG DDDDDDD WITH TRUNCATE_ONLY
  • DBCC SHRINKFILE(‘LFLFLFLFLFLF‘,1)

    LFLFLFLFLFLF= The actual file system name of the log file you want to shrink.
    DDDDDDD= The registered name of the database the log file belongs to.

    It may seem redundant, but the sequence will essentially force your log file to purge into the main MDF file and clear it’s pages out. The file system will be left with a nearly empty log file, however you will have no recourse if your MDF file is lost or becomes corrupted until your next fully successful backup routine completes. Use with care!

    Also, performing this procedure on a system that is under load would result in a serious loss of productivity as the SQL server grinds away at the disk in an effort to ensure the entire log file’s transaction list is properly represented in the MDF database file. This could easily introduce a lot of latency or even database timeouts for end users trying to utilize the database during this procedure. Again, use with care!

  • Leave a Reply

    Get Adobe Flash player