In part 1 of this series, I discussed how to connect to the Exchange database cache and the importance of transaction logs in database transactions. In this next part, you'll learn how transaction logging and recovery work in Exchange.
The following blog post is a trimmed-down excerpt from the e-book Exchange Server Troubleshooting Companion.
Of course, there is another reason that Exchange writes transactions to the log files before being committed to the database (.edb) file. By quickly committing transactions to disk (via transaction logs), it means that the transactions exist in two locations; memory and disk. If a failure occurs that causes the Information Store to terminate unexpectedly, the most recent transactions are still available and can be replayed into the database from the transaction logs after the database is mounted and to bring the database up-to-date.
For a long time, it was recommended to place your Exchange database file (.edb) onto different spindles than your transaction logs. This is still the recommendation when only one copy of a database exists (non-DAG protected). In fact, this is not for performance reasons but to assist recovery in the event of a storage failure. Say you lost your database drive, leaving you only with the transaction logs. Technically, if you still had every transaction log present since the database was first created, you could use ESEUTIL to generate a new database and commit every transaction from the logs into it. However, this is not usually the case. People usually resort to an Exchange-Aware backup, which leads us to why an Exchange-Aware backup truncates log files. When a Full Exchange-Aware backup is performed against a database, the .edb file is copied to the backup location, as well as any transaction logs present for the database. With these files, the database can be restored and the database can be brought into a Clean Shutdown state, meaning all transactions in the logs have been committed to the .edb file and the database can be mounted. As the backup completes, it sends a command to the ESE database engine stating that any transaction logs older than a certain point can be truncated (deleted). These logs are no longer required on the Exchange server because we now possess a copy of them in the backup set.
Note: Technically, once a transaction log has been written to disk, it is no longer needed. When the time comes to commit transactions to the database (.edb) file, this action occurs from cache to the .edb file, not from the transaction logs to the .edb file. However, you should not manually delete transaction logs as these are vital for recovery purposes. |
Back to our scenario where the .edb file was lost due to a storage failure. We would simply restore the database and transaction logs from our Exchange-Aware backup, and replay both the restored and whatever logs are available into the .edb file. If a complete set of logs are available, the result is that Exchange can replay a continuous stream of transaction logs from the point where the backup was created to the time when the failure occurred and result in no data loss.
This brings me to the question: “Why can’t I use Circular Logging to delete my transaction logs automatically so they don’t fill up my drive?” First we need to understand that Circular Logging is a property on a database. When circular logging is enabled, the Information Store deletes transaction log files as soon as the transactions contained within them have been committed from cache to the .edb file. A much smaller set of logs is maintained as the set never grows over time because logs are continuously deleted.
The command to enable circular logging is as follows:
[PS] C:\> Set-MailboxDatabase –Identity <DatabaseFileName> -CircularLoggingEnabled $True |
The question then comes into play as to why not enable circular logging for every database? Having read the series up to this point, the answer is obvious. If your database subsequently becomes unusable due to a failure, no transaction logs will be available for replay into the database, as all but the most recent logs will have been automatically deleted by Exchange. Since all transaction logs must be replayed into the database in their proper sequence, your only choice would be to restore the most recent database backup, and lose all Exchange transactions that occurred between the time of the backup and the time of failure.
It’s at this point that I should define the differences between traditional (JET) Circular Logging and Continuous Replication Circular Logging (CRCL). What I described above is JET Circular Logging and is used on standalone Exchange Servers, or databases on Exchange Servers which do not have replicated copies. CRCL is used when a database has replicated copies in a DAG and is enabled using the same command. When using traditional backup methods, neither should be enabled as the backup program’s consistency check will fail due to missing logs.
Note: After executing this command, the database must be dismounted and remounted before the change takes effect. Once enabled, any transaction logs that have been committed to the database will be automatically removed. So if there were 50k transaction logs present, they would be automatically deleted. |
In my opinion, JET Circular Logging should only ever be enabled in a lab or when you are in dire need of disk space during a recovery or during transaction-intense operations such as moving mailboxes. This is because if you encounter a failure and lose the database, you will lose all transactions that occurred between the last backup and the failure. CRCL should only be enabled in a DAG environment where Exchange Native Data Protection is being used, as traditional backups are not performed. In this configuration, since backups are not performed, no transaction logs will ever be truncated and database drives would ultimately reach capacity.
The logic used to determine when logs will be truncated is as follows (for more information, see this reference):
For truncation to occur on highly available (non-lagged) mailbox database copies, the answer must be "Yes" to the following questions:
For truncation to occur on lagged database copies, the answer must be "Yes" to the following questions:
Simply put, the DAG ensures a transaction log has been inspected by all database copies in the DAG before it can be deleted. The log file must also be below the Checkpoint Depth Target, which is 100 transaction logs in DAG-protected databases. Knowing this target is important for understanding expected behavior when verifying transaction log truncation after a successful Exchange-Aware backup. On a standalone database there will always be ~20 transaction logs and on a DAG-protected database there will always be ~100 transaction logs, even after a successful Exchange-Aware backup. This is because only logs that have reached the Checkpoint Depth Target are eligible for truncation. On several occasions I’ve been asked why transaction logs within a DAG were not truncating after a successful backup because there always seemed to be transaction logs in the log directory. The short answer is there will always ~100 logs in these directories. If you want to verify successful log truncation following a backup in a DAG, I recommend the following article. Similarly, in lab environments truncation may not occur because the database is new and has yet to generate 100 transaction logs, so there’s nothing to truncate.
Note: While CRCL is enabled on a DAG-protected database, additional copies cannot be added. CRCL must be disabled, and the database must be dismounted/remounted before additional copies can be added. |
Understanding the inner workings of Exchange databases helps to determine why a backup might not be successful and the steps needed to remedy it.
I work for Dell as a Principal Engineer in the Global Support & Deployment organization; serving as a senior point of escalation for Microsoft technologies to Dell's ProSupport & Consulting Services customers. My specialties are Exchange, Office 365, & Directory Services; while also being responsible for internal training development/delivery & managing various projects. I'm a Microsoft Certified Master in Exchange 2010 & a Microsoft Certified Solutions Master in Exchange 2013. I enjoy getting to work with a wide variety of customers, as it allows me to assist in resolving the various complexities & challenges they encounter. I try to use that experience to help others by blogging at Exchangemaster.wordpress.com with a few of my fellow MCM's at Dell. I also co-founded an Exchange Server community on Reddit (Reddit.com/r/ExchangeServer) where I answer questions on the product & help lead discussion around Exchange/Office 365. You'll also find me blogging about various other topics at ashdrewness.wordpress.com. I'm also the co-author of the Exchange Server Troubleshooting Companion (http://exchangeserverpro.com/ebooks/exchange-server-troubleshooting-companion/) I enjoy spending time with my lovely wife Lindsay, am a Texas Longhorns/Houston Texans fan, & try to sneak out onto a golf course every chance I get.
Often times I’ll find myself writing a blog post because the topic recently became...