Sunday, March 25, 2012

Cleaning out Log file

Can someone give me some advise on how to clean out my log file?
Thanks :confused:1. Don't
2. Stop SQL Server, delete the files in the log-dir, start SQL Server.
3. erhm...|||So do I just want to delete the ldf file attached to the database? If so will it just create a new ldf file?|||oh no! I misunderstood! please don't delete the ldf file!|||Sometimes I execute the following:

USE MONKEY

DBCC OPENTRAN ('MONKEY')

BACKUP LOG MONKEY WITH TRUNCATE_ONLY
CHECKPOINT
BACKUP LOG MONKEY WITH TRUNCATE_ONLY
CHECKPOINT
BACKUP LOG MONKEY WITH TRUNCATE_ONLY
CHECKPOINT
BACKUP LOG MONKEY WITH TRUNCATE_ONLY
CHECKPOINT

DBCC SHRINKDATABASE (MONKEY)
DBCC SHRINKDATABASE (MONKEY, TRUNCATEONLY)

Works for me, I'm sure there's a saver or better way to have a log file shrunk. Make sure though there are no transactions open on that database, also, I'd like to pick a time when there's no user activity on that db. The DBCC SHINK can take a while though.

No comments:

Post a Comment