Link to home
Start Free TrialLog in
Avatar of kwoznica
kwoznica

asked on

Shrink tlog while mirroring a database

Hello all,

I am trying to find information on the best way to shrink a transaction log while the database is being mirrored. Typically I set the recovery to simple and then run dbcc shrinkfile to bring the tlog down. With mirroring this is not possible as the mirror must be in Full recovery mode. My question then is two fold.
1.) Can a transaction log be shrunk while mirroring? Since the db is in full recovery mode and I run dbcc shrinkfile I usually get an error message unless I set recovery to simple.
2.) If I do set recovery to simple while mirroring what happens to the mirror and if it breaks is there a quick method for reestablishing the mirror?

I appreiciate anyone's help.

Keith
Avatar of chapmandew
chapmandew
Flag of United States of America image

1.  sure
2.  No

remember, truncating the log is different than shrinking the file.  If you're doing regular log backups (hopefully you are) then you can just use dbcc shrinkfile to shirnk the log file.
The only way to clear up space inside a transaction log (also known as truncating) if the database is in the Full Recovery Model (as is required by mirroring) is to back it up.

So back it up regularly. Like... every few minutes. You don't need to keep the file if you're not interested in it (and clearly you're not if you're used to setting the database to Simple). If you do this, the transaction log shouldn't grow much, and you shouldn't need to shrink the log file at all (which ultimately just makes it have to grow more often - and growing log files is a painful operation).

Honestly - you should be trying to avoid having to shrink log files. I think it's only very exceptional circumstances that should make you want to shrink a log file.

Rob
Avatar of kwoznica
kwoznica

ASKER

Rob,

I understand your point about backups. During the day we do run log backups. The issue that I have is on weekends we also run a reorginize on the database to keep the database efficient and also as compact as possible. It is during this maintenance task that the log file will fill up to 120GB. I also run tlog backups during the maintenance reorginize but drive space has become an issue. This is the reason I will run dbcc shrinkfile.

In a circumstance such as this what would you recommend?
Since you can't switch to Bulk Logged (because you're doing mirroring), you're better off doing what you're thinking about doing a shrink after a log backup.
You should remember that if you're mirroring, then that 120GB of log will have to be sent to the mirror as well.

Depending on how large your database is, you may prefer to stop mirroring, switch to Simple, do your reorg, then switch back to Full and re-establish your mirroring.

Or else ask yourself why you really need to do a reorg? Are you checking for index fragmentation before rebuilding them, for example?

Rob
Rob,

I appreciate your suggestions. I am going to look into scripting out a job for switching back from mirroring, Simple mode, reorg, Full and back to the mirror.

I have to ask you one more question based on your last question. Should I check for index fragmentation and if so based on what statistical value should I kick off a reorg?

Thanks. The points are yours.

Keith
ASKER CERTIFIED SOLUTION
Avatar of Rob Farley
Rob Farley
Flag of Australia 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
Rob, I appreciate your time in making your response. It is people like you that help a young dba like myself make progress. Thanks.
No problem - any time.

Rob