Tuesday, December 27, 2005

Huge SQL Log growing out of control

SOLUTION:

In Query Analyzer:
--Delete inactive transactions
BACKUP LOG WITH TRUNCATE_ONLY
GO
-- Shrink the log file to 10 MB
DBCC SHRINKFILE(_log,10)
GO



STORY:
Well, today I had another surprise comming into work...No disk space! This has happened many times and for many reasons. So I downloaded 'Disk Space Inspector' to see what might be happening.

I noticed in my data directory (where I keep my SQL databases) that one of my log files was at 2.5 GB! I know better to set the Truncate at Checkpoint, but I guess I didn't...who knows. Anyway, I couldn't remember what to do about it...so a google we shall go...

I read a couple of articles, but basically the theme was the same. You need to backup the log file, which will delete the invalid transactions and then shrink the database. Since my HD was full, I couldn't back it up there. I found an article that explained how to back it up to the network here (but don't do that if you don't want a backup!)

Finally, I came upon the right solution for the job at Microsoft's KB Q272318.