Link to home
Start Free TrialLog in
Avatar of altonyoung
altonyoung

asked on

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

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.
SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of altonyoung
altonyoung

ASKER

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?
Sorry.   I meant reuse the log space even in Simple recovery mode.   Thanks.
Yes.  The log is a sequential / "flat" file.  Any record that is still in use prevents clearing anything from that record forward.
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.
@Vitor:

That was the first sentence of the first reply :-).
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.
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.
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).
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> 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.
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.