Solved

Transaction Log keeps growing even continue to run Backup Log with Truncate_only on DB

Posted on 2014-12-23
12
118 Views
Last Modified: 2015-01-03
On my MS SQL 2005 test db server, I made a change to use a store procedure to update about 35K records in the database.   The transaction log kept growing when the procedure was run until I ran out of disk space (Log file grew more than 250GB).   I set the database recovery mode to Simple and scheduled backup of log using "with Truncate_only" to happen every five minutes, but that didn't stop the log from growing.  Any suggestion on how to stop the log from growing?  I can't modify the store procedure which came in on a commercial product that is locked.   I like to use this procedure to update the db, so I won't risk introducing any database integrity issues into the db.  

Thank you very much in advance for your help.
0
Comment
Question by:altonyoung
12 Comments
 
LVL 69

Assisted Solution

by:ScottPletcher
ScottPletcher earned 500 total points
Comment Utility
If the recovery model is simple, you can't do log backups.

But the log will automatically truncate at every checkpoint, which is roughly every 5 mins or so, depending on your server load and other internal factors and settings.

You need to run:
DBCC OPENTRAN
on the db is see if something is keeping the log from being truncated.

You also need to look at sys.databases row for that db and see what the "log_reuse_wait_desc" has in it.  For the log to truncate, it needs to be "NOTHING"; anything else and the log can't truncate.
0
 

Author Comment

by:altonyoung
Comment Utility
ScottPletcher,

Thanks for the quick reply.   Does this mean if there's update statement that the procedure continues to run, hence keeping an open traction on the database, then I won't be able to truncate the log?
0
 

Author Comment

by:altonyoung
Comment Utility
Sorry.   I meant reuse the log space even in Simple recovery mode.   Thanks.
0
 
LVL 69

Expert Comment

by:ScottPletcher
Comment Utility
Yes.  The log is a sequential / "flat" file.  Any record that is still in use prevents clearing anything from that record forward.
0
 
LVL 45

Expert Comment

by:Vitor Montalvão
Comment Utility
I set the database recovery mode to Simple and scheduled backup of log using "with Truncate_only"
Would like to know how you did that since in Simple Recovery model you aren't allow to perform a transaction log backup.
0
 
LVL 69

Expert Comment

by:ScottPletcher
Comment Utility
@Vitor:

That was the first sentence of the first reply :-).
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:altonyoung
Comment Utility
I restored the database, set recovery mode to Full and try it again.  

Here is the result of dbcc opentran:
Oldest active transaction:
    SPID (server process ID): 58
    UID (user ID) : -1
    Name          : user_transaction
    LSN           : (36457:129703:175)
    Start time    : Dec 24 2014  7:42:26:023AM
    SID           : 0x01050000000000051500000077026014a1776d5cc811bf7b72080000
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

Also sys.databases show the db log_reuse_wait_desc is ACTIVE_TRANSACTION.

Looks like even with Full recovery mode and backup log with truncate_only every five minutes and I am still not able to reuse the log space.   Any idea what I can do, so I can reuse the log space, so my LDF file won't continue to grow until I am out of disk space?  

Thank you.
0
 
LVL 69

Expert Comment

by:ScottPletcher
Comment Utility
That transaction isn't that old:
Dec 24 2014  7:42:26:023AM
so your log space should be truncating fine.

Keep in mind that the log file won't shrink -- get physically smaller on disk -- until and unless you explicitly shrink it (DBCC SHRINKFILE).  But SQL will truncate the log -- mark the log records as "reusable" -- as soon as it can.

In simple recovery, "as soon as it can" is immediately after the transaction is committed (barring other things such as replication, CDC, etc.).  In other than simple recov, the trans must be committed and that record in the log must have been backed up (BACKUP LOG ...) before it can be truncated.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Looks like even with Full recovery mode and backup log with truncate_only every five minutes
Not the answer to your quesion but: Either use Simple Recovery Model or do a Transaction Log backup.  Using Full Recover Model and doing a backup log with TRUNCATE_ONLY is pointless and dangerous (you may actually think you can do a point in time restore).
0
 

Accepted Solution

by:
altonyoung earned 0 total points
Comment Utility
For some reason I just can't keep the log small even using the Simple recovery model.  The tempdb log also grows to over 50GB.    My work around was to figured out a way to manually update the database tables instead of using the store procedure.  Lots of work, but I got it done.  

Thank you all for your response.
0
 
LVL 69

Expert Comment

by:ScottPletcher
Comment Utility
>> For some reason I just can't keep the log small even using the Simple recovery model. <<

SQL still has to log transactions, and the log space must be kept until the transaction is committed.

If your stored procedure has its own "BEGIN TRANSACTION" statement, then you might be able to reduce the log space needed at one time by issuing a "COMMIT TRANSACTION"(s) sooner or more often.  It sounds like that may be the case if running it outside the stored proc uses less total log space.

But if a single INSERT or UPDATE statement is causing the logging, there's no way you can reduce the size of that except to do the INSERT or UPDATE in smaller batches.
0
 

Author Closing Comment

by:altonyoung
Comment Utility
ScottPletcher,  since you are the first one the respond and provided useful information about recovery model and transaction logs, I will award you the 500 points.    Thank you.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now