Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I shrink a transaction log file, even after backup?

I have a database that has a 28gig transaction log file. Recovery mode is simple. I just took a full backup of the database, and then ran both:

backup log dbmcms with truncate_only

DBCC SHRINKFILE ('Wxlog0', TRUNCATEONLY)

The name of the db is db_mcms and the name of the transaction log file is Wxlog0.

Neither has helped. I'm not sure what to do next.

like image 954
Jordan Hudson Avatar asked Apr 22 '09 20:04

Jordan Hudson


People also ask

Does transaction log shrink after backup?

Full backups won't reset the logs - you have to do a backup of just the transaction logs. They don't shrink on their own - you'll still have to shrink them manually if they've gotten out of hand. However, your logs should keep a certain size if you're backing up the logs on a regular basis.

How do I force a transaction log to shrink?

Shrink the transaction logRight-click the database and select Tasks -> Shrink -> Files. Change the type to Log . Under Shrink action, select Release unused space and click OK.

Can not Shrink SQL log file?

Typically it's the log file that appears not to shrink. This non-shrinking is usually the result of a log file that hasn't been truncated. To truncate the log, you can set the database recovery model to SIMPLE, or back up the log and then run the DBCC SHRINKFILE operation again.

How do I force a SQL log to shrink?

To shrink a data or log file. In Object Explorer, connect to an instance of the SQL Server Database Engine and then expand that instance. Expand Databases and then right-click the database that you want to shrink. Point to Tasks, point to Shrink, and then select Files.


1 Answers

Thank you to everyone for answering.

We finally found the issue. In sys.databases, log_reuse_wait_desc was equal to 'replication'. Apparently this means something to the effect of SQL Server waiting for a replication task to finish before it can reuse the log space.

Replication has never been used on this DB or this server was toyed with once upon a time on this db. We cleared the incorrect state by running sp_removedbreplication. After we ran this, backup log and dbcc shrinkfile worked just fine.

Definitely one for the bag-of-tricks.

Sources:

http://social.technet.microsoft.com/Forums/pt-BR/sqlreplication/thread/34ab68ad-706d-43c4-8def-38c09e3bfc3b

http://www.eggheadcafe.com/conversation.aspx?messageid=34020486&threadid=33890705

like image 170
Jordan Hudson Avatar answered Sep 21 '22 00:09

Jordan Hudson