Printed 2017/07/21 03:32PM

Truncating the Log and Database Mirroring

By Steve Jones, 2010/06/30

I saw someone post recently that they wanted to run this code on their principal server in database mirroring to clean out a large transaction log and shrink it.

alter database <mydb> set recovery simple
alter database <mydb> set recovery full
backup database pubs to disk = 'c:\mydb.bak' with init
dbcc shrinkfile (N'mydb_log' , 1)

I responded, and a few others as well, that this will break your mirroring session. However I wanted to do some research, and I started googling around to see what I could find.

While I haven’t found an explicit reference, I did note that Paul Randal has a note that you can switch to Bulk Logged mode without breaking the log chain, but I knew that.

I don’t have a definitive reference, though I’m hoping one appears soon. The documentation for Books Online does say that full recovery mode is required.

If you have a log file that’s too large, you can run shrinkfile on it, even if it is mirrored. That will work, but don’t set the database to Simple mode. Manage the log backups, and make sure you have them running regularly. And if you need help shrinking the log, try this script.

Copyright © 2002-2017 Redgate. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.