Question

Transaction Log is Big! How can i clear the Log? (SQL 2005 Std)

Asked by: KenshiroM

I am currently doing a Backup Plan for my Databases.(FULL Mode)

I have a database of 28MB but its log file is around 8000MB! How will i manage to clear the Logs?

I tried the following:
1. Full backup of the Database.
    (Size of Full Backup: 28MB)
2. Backing up the Transaction Log.(Radio button: 'Truncate the Trasaction Log' Ticked).
    (Size of Transaction Log Backup: around 8000MB)
3. Shrinking up Transaction Log to 4000MB and 2000MB repeatedly.
    (Right Click on the Database --> Tasks --> Shrink --> Files --> Data Type: Log --> Shrink To 2000MB

But the Transaction Remains around 8000MB!

is it safe to just delete the Log after i performed a Full backup of the Database even if its only 28MB?

Thanks in advance and Happy Easter.

David

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-04-07 at 10:40:20ID22497894
Tags

log

,

sql

,

transaction

,

2005

,

clear

Topics

SQL Server 2005

,

Databases Miscellaneous

,

MS SQL Server

Participating Experts
10
Points
500
Comments
26

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. SQL-7 EXPERTS - Shrink and Truncate
    Hi: Could someone please indicate the best way to use 'AUTO SHRINK' and 'TRUNCATE LOG ON CHECKPOINT' options? Can Auto Shrink work without selecting the Truncate Log on CheckPoint option? Does Auto Shrink shrink both the database and the tlog? Are any transactions actual...
  2. shrink a transaction log
    In this instance we are not interested in keeping a copy of the transaction log, but just want to shrink it as effectively as possible. I have found the following two methods is one prefered over another? Method 1.) BACKUP LOG dbname WITH TRUNCATE_ONLY DBCC SHRINKFILE(dbn...
  3. Transaction Log will not shrink.
    USE DWH GO DBCC SHRINKFILE (2,TRUNCATEONLY) GO I checked the sysfiles for the number identifying the log I want to shrink and as you can see from the message below it has picked the correct file (DWH_Log). Is there anything else I need to do to get it to shrink. I run a scr...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: rmaranhaoPosted on 2007-04-07 at 10:45:21ID: 18870001

I think it's safe, once you performed a FULL database backup.

To truncate my log, I use the following commands:
DBCC SHRINKFILE('logfilename', 1)
BACKUP LOG redeoba WITH TRUNCATE_ONLY DBCC SHRINKFILE('logfilename', 1)

LogfileName is usually databasename_log, I.E. 'northwind_log'

Roberto.

 

by: angelIIIPosted on 2007-04-07 at 11:07:57ID: 18870054

hi,

  transaction log has 2 possible configuration:
  * SIMPLE
     means that any transaction get's written to the transaction log, but once it is committed, it is overwritable in the log.
     you cannot perform transaction log backups
     you cannot perform restore to a point of time
     you should let the transaction log file size as it is, because if you shrink it (regulary) to a small size, it has to grow again.

  * FULL
     means that any transaction get's written to the transaction log, but only once the transaction log backup has been performed, it is overwritable in the log
     you have to (should) perform transaction log backups
     you can perform restore to a point of time
     you should let the transaction log file size as it is, because if you shrink it (regulary) to a small size, it has to grow again.

note: if you had a database in full recovery mode, but did not do any transaction log backups, the log file will indeed grow endlessy until it fills the hard disk(s) completely.
if that happened, you should change to SIMPLE, and try several times the DBCC SHRINKFILE ( log_name, <some size here) until the file shrinks (as the log file is internally a circular buffer, and in case the pointer is at the end of the file, the file won't shrink, hence the retries)

 

by: Kevin3NFPosted on 2007-04-07 at 12:09:41ID: 18870167

I have found that running a manual checkpoint command helps get a stubborn T-log to a point where it will shrink.  Run this multiple times (a dozen or more) in the query window:

Use YourDatabase
go

Checkpoint



--then run your shrink command

 

by: rcicottePosted on 2007-04-07 at 15:55:20ID: 18870589

Look at the actual transaction log file to see if it is actually 8GB in size.  The interface could be reporting the size incorrectly.  The log file when shrunk to its minimum should be only 1 or 2k.  If you have done a complete Full backup of the database as you say then you can shrink your log file immediately after the backup and it should be no more than about 2k.  You can find the location of your database and log files in the management studio by selecting your database | right click | properties | files.
Use windows explorer to go to the drive location and verify the size of the file.  If the file size is being reported correctly and none of the above answers work then try restarting the server.  This will usually allow the shrink file to work.



 

by: nigelrivettPosted on 2007-04-08 at 02:48:47ID: 18871968

 

by: KenshiroMPosted on 2007-04-09 at 06:50:27ID: 18875682

Thanks for your quick replies.

I Confirmed that the log file is actually 8GB

Will try the following tonight:

1.DBCC SHRINKFILE('logfilename', 1)
   BACKUP LOG redeoba WITH TRUNCATE_ONLY DBCC SHRINKFILE('logfilename', 1)

   LogfileName is usually databasename_log, I.E. 'northwind_log'

2.Use YourDatabase
go

Checkpoint



--then run your shrink command

 

by: rmaranhaoPosted on 2007-04-09 at 06:54:05ID: 18875696

KenshiroM
redeoba is my database name and MUST be replaced.

 

by: KenshiroMPosted on 2007-04-09 at 06:54:10ID: 18875697


3. Will change to SIMPLE, and try several times the DBCC SHRINKFILE ( log_name, <some size here) until the file shrinks (as the log file is internally a circular buffer, and in case the pointer is at the end of the file, the file won't shrink, hence the retries)

If one of these will not work i would have to delete the log file! hoping that it won't do any damage to the Database in question.

Thanks. will get back with any news.

David

 

by: Kevin3NFPosted on 2007-04-09 at 06:58:27ID: 18875733

If you delete the log file, your database will become unuseable.

Run my Checkpoint suggestion BEFORE trying the shrink (and substitue the corerct database name for where I type 'YourDatabase'

 

by: rmaranhaoPosted on 2007-04-09 at 07:01:31ID: 18875755

Kevin3NF is right. Do not delete the log FILE!

 

by: KenshiroMPosted on 2007-04-09 at 10:25:47ID: 18877120

Hi Guys

I did the CHECKPOINT and DNCC SHRINK commands and the log file is less than 1 MB!

How is that possible?

Is it normal that a Log file 8GB in size shrinks to just under 1 MB??

Thanks in advance.

David

 

by: rmaranhaoPosted on 2007-04-09 at 10:31:37ID: 18877157

All the information about the commands run on the database has been deleted. All the data is still there, but the information about how and when the records were created is gone.

 

by: Kevin3NFPosted on 2007-04-09 at 10:37:40ID: 18877194

Yes....that data had already been backed up by your t-log backup job.  You just had empty space between a couple of transactions.  Checkpoint/Shrink simply "defragged" the T-log (not the correct term, but conceptually the same) and allowed it to shrink.

The best idea is to set the T-log to a reasonable size (in your case, maybe 20MB?) and perform regular database and log backups.  You are not likely to see this issue again.


>>All the information about the commands run on the database has been deleted. All the data is still there, but the information about how and when the records were created is gone.<<
You say this like its a bad thing...all that information is supposed to be gone from the t-log eventually, once it has been committed to the database

 

by: rmaranhaoPosted on 2007-04-09 at 10:41:07ID: 18877218

Sorry if I somehow said it as a bad thing, English is not my native language... I flush my logs every day...

 

by: Kevin3NFPosted on 2007-04-09 at 10:43:22ID: 18877235

Ah...ok.  Just wanted to make it clear for any that might read it down the road.  Cheers!

 

by: KenshiroMPosted on 2007-04-09 at 13:00:11ID: 18878222

Hi Guys,

Thanks for all your valid solutions.

These are the steps i followed:

1.(Kevin3NF)
   Use YourDatabase
   go

   Checkpoint

2.(rmaranhao):
   To truncate my log, I use the following commands:
   DBCC SHRINKFILE('logfilename', 1)
   BACKUP LOG redeoba WITH TRUNCATE_ONLY DBCC SHRINKFILE('logfilename', 1)

   LogfileName is usually databasename_log, I.E. 'northwind_log'

Thanks a million for your help

Dave

 

by: KenshiroMPosted on 2007-04-09 at 13:32:23ID: 18878471

Hi Guys,

Just one other little question.

Where did the backup of the database log file go to with this command?

BACKUP LOG databasename WITH TRUNCATE_ONLY DBCC SHRINKFILE('logfilename', 1)

Regards,

Dave

 

by: Kevin3NFPosted on 2007-04-09 at 13:48:22ID: 18878555

NO_LOG | TRUNCATE_ONLY

Removes the inactive part of the log without making a backup copy of it and truncates the log. This option frees space. Specifying a backup device is unnecessary because the log backup is not saved. NO_LOG and TRUNCATE_ONLY are synonyms.

After backing up the log using either NO_LOG or TRUNCATE_ONLY, the changes recorded in the log are not recoverable. For recovery purposes, immediately execute BACKUP DATABASE.

 

by: KenshiroMPosted on 2007-04-10 at 04:25:52ID: 18881499

Thanks Kevin for clearing my doubts!

Here is my backup strategy and scripts(I Have 3 Steps). Could you kindly check it out and tell me what you think needs to be changed:

1.Full Backup on each Database will occur every Sunday at 10:00 pm. It will overwrite the previous Backup.

BACKUP DATABASE database TO [database-Data]
      WITH NAME = N'database-Full Database Backup', DESCRIPTION = N'Full Production Instance', MEDIANAME = N'databaseMedia', MEDIADESCRIPTION = N'database Backup Media Set', FORMAT, INIT

2.Log Backup on each Database will occur Daily at an interval of 4 Hours. It will not overwrite the previous Log Backups.

BACKUP LOG database TO [database-Log]
      WITH NAME = N'database-Transaction log Backup', DESCRIPTION = N'Full Production Instance'

3.Log Backup on each Database will occur every Sunday at 10:00 pm. It will overwrite the previous Log Backups.

BACKUP LOG database TO [database-Log]
      WITH NAME = N'database-Transaction log Backup', DESCRIPTION = N'Full Production Instance', MEDIANAME = N'databaseLogMedia', MEDIADESCRIPTION = N'database Log Backup Media Set', FORMAT, INIT

Thanks and regards,

Dave

 

by: Kevin3NFPosted on 2007-04-10 at 05:36:40ID: 18881769

From a recovery standpoint, if you lose the database on Saturday night, you will have to restore about 40 files using the above plan (Sunday Full plus 6 t-logs per day)

Change the Full backup to run daily, not weekly (keep one or two previous days on disk incase the .bak is corrupt)

 

by: KenshiroMPosted on 2007-04-10 at 06:07:24ID: 18881953

Thanks Kev

 

by: ShadowMoboPosted on 2007-12-18 at 09:21:25ID: 20493708

Wow this is a great post, very informational when it comes to Transaction logs. Thanks everyone! You just helped me with a problem I was going to ask about.

 

by: Lord_DeathPosted on 2008-09-23 at 00:17:00ID: 22547020

  1. backup log [dbname] with truncate_only  
   2. go  
   3. DBCC SHRINKDATABASE ([dbname], 10, TRUNCATEONLY)  
   4. go  

 

by: RiteshShahPosted on 2009-03-27 at 06:09:17ID: 24000423

sometime if you just truncate transaction log, it will not take effect in very big database then you have to follow

USE DBName
GO
DBCC SHRINKFILE(transactionlogfilename, 1)
BACKUP LOG WITH TRUNCATE_ONLY
DBCC SHRINKFILE(transactionlogfilename, 1)

all details at http://www.sqlhub.com/2008/05/sql-server-truncate-transaction-log.html

 

by: jingallsPosted on 2009-12-08 at 07:09:06ID: 25998523

Thanks Much Kevin3NF !

Your running the Checkpoint command has helped solve an issue I have had trying to run automated commands to shrink my T-Logs.  Adding this command in front of the shrink command has solved my issue.

 

by: dportasPosted on 2011-08-11 at 05:40:30ID: 36349615

The TRUNCATE_ONLY option is deprecated and does not work at all in SQL Server 2008 and later. In SQL Server 2005 the TRUNCATE_ONLY option has the potentially undesirable effect of breaking the chain of log backups - so you will be at increased risk of data loss until you do another full backup.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...