views:

1754

answers:

2

DBCC SHRINKFILE always works when I run it manually on a log file, even when I get the following message:

'Cannot shrink log file 2 (Claim_Log) because all logical log files are in use.'

When I run it from a job, however, it only shrinks the log about one third of the time. The other times, it just remains large (about 150Gb). There is never any error other than the one listed above. This is the statement that I use:

DBCC SHRINKFILE (N'Claim_log' , 0, TRUNCATEONLY)

I have "Include step output in history" enabled on the job step. Is there something else I can do to get more information on why this isn't working?

Edit: Here is the full message from the log:

'Executed as user: *. Cannot shrink log file 2 (Claim_Log) because all logical
log files are in use. [SQLSTATE 01000] (Message 9008)  DBCC execution completed. 
If DBCC printed error messages, contact your system administrator. [SQLSTATE 01000]
(Message 2528).  The step succeeded.'

I have already tried kicking users out of the db and setting it to single user mode.

+2  A: 

try issuing the CHECKPOINT command first, then shrinking the logs

taken from BOL (http://msdn.microsoft.com/en-us/library/aa226036(SQL.80).aspx)

Forces all dirty pages for the current database to be written to disk. Dirty pages are data or log pages modified after entered into the buffer cache, but the modifications have not yet been written to disk. For more information about log truncation, see Truncating the Transaction Log.

rip747
I'll add that to my jobs and give it a try
Keith Walton
It didn't work.
Keith Walton
make sure that you are backing up the transaction logs every hour or so. this will release any locks on that particular portion of the log and allow it to shrink. If you want to completely get rid of the log, you can issue a backup using the no_log" option:BACKUP LOG {mydb} WITH NO_LOG
rip747
I do back up the log every hour, starting at 3 AM. The shrink job runs at 7, and works sometimes. When I manually run it at 8, it always works. This morning, the job worked on one database but not the other.
Keith Walton
A: 

Means Currently the Log file is in Use and issue check point where Check point will writes to datfile that was not written to the datafile from transaction log file (Dirty pages). Check is there any current Activity is going on or Not,

Check using for Active Transaction In 2005 SELECT * FROM sys.dm_tran_session_transactions

2000 DBCC LOGINFO

make good Plan =>1.Create maintenace plan For Backing up the log (Made Plan).