I have 1GB databases that grow several GB log files. How do you safely clear those logs? Well, probably the best practice includes backing them up. That was overkill for me, and sifting through all the documentation and forums (eventually) led me to this simple pair of statements that do the trick immediately:
backup log [dbname] with truncate_only go DBCC SHRINKDATABASE ([dbname], 10, TRUNCATEONLY) go
Update: Mathias added a comment that deserves calling out:
Warning: Clearing the transaction log with TRUNCATE_ONLY will break your backup chain needed for FULL recovery. A FULL database backup should be executes right after truncating the logs. More info.
with 400 users and a report dept that suddenly started “trying things out”, I had a log file almost as large as the VM I was running in.
Thanks for your blog entry ! You’re a lifesaver !
Great code. Thanks. You saved me 50 GB of my server’s hard drive.
Thank for sharing this SQL. I’ve been looking for this for a very long time.
thanx a lot dude
It’s my turn to say : “Thanks, man!” π
awesome, finally someone with the answer i’m looking for…
so simple so great! bro you saved my life! π
Wonderful, I’m so happy π
GOD BLESS YOU, DUDE !
It’s so nice to see the .ldf file just 1.25 MB ! π thx a lot
thanks a Lot Man, I am really happy, trying to email the database since long, but fail due to file size.
Muhammad Sharjeel Ahsan
thanks a lot man
Thanks a lot!!!
ΰΉYou solve my problem.
Thank you very much.
Does this work on SQL 2008?
I tried it and got the error:
Msg 155, Level 15, State 1, Line 1
'truncate_only' is not a recognized BACKUP option.
Thanks a lot !!!!
Thanks Much – This info helped greatly
I Like π
Thank you π
Warning: Clearing the transaction log with TRUNCATE_ONLY will break your backup chain needed for FULL recovery. A FULL database backup should be executes right after truncating the logs.
Source: http://social.msdn.microsoft.com/Forums/en/sqldatabaseengine/thread/9997e75e-f126-4901-9379-de540a708ec9#352c6a1d-1866-4737-ada4-7eeff91cbcda
Thank you!
You've saved the world !
Thanks !
PS. This does not work on 2008
hi i tried this in sql server 2008 enterpirse
following error got
Msg 155, Level 15, State 1, Line 2
'truncate_only' is not a recognized BACKUP option.
mine too 'truncate_only' is not a recognized BACKUP option.
Interesting post⦠good info, This is one example of why I get frustrated with SQL Server. I have found another helpful post see here: http://www.sqlserverlogexplorer.com/how-to-clear-transaction-with-dbcc-shrinkfile/
This is Awsome!!!! Thank you so much! You safe my HDD!!