Subscribe to SQL Server Magazine | See More Backup and Recovery Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

In Can the Transaction Log Tell Us What Happened?, I talked about whether Microsoft should take responsibility for providing SQL Server users with a tool for reading the actual contents of the transaction log. I admitted that such a tool might be nice, but it really wasn’t something that I felt was a requirement from a database vendor. You need to take responsibility for monitoring what your system is doing, and if you want to know every command that’s sent you can set up a trace. In fact, with the log, you have no way of finding out who is reading your data because the log records only changes. For very sensitive data, you might want to know every time someone reads it, and for that you’re completely on your own.

Lately, I’ve heard people commenting (or perhaps complaining?) that not only do they want Microsoft to tell them what they’ve done when something unexpected happens, but also to warn them before it happens! The particular behavior that has come up several times recently in discussions with colleagues and clients is called auto_truncate. Most people are aware that SQL Server will automatically truncate the transaction log every time a checkpoint occurs if a database is in the SIMPLE recovery model. But it turns out that there are other situations in which the log will automatically be truncated. If SQL Server can’t back up the log, it won’t bother keeping the log records available, and it will truncate the log at every checkpoint. This behavior occurs if you've truncated the log without backing it up, using the BACKUP LOG WITH TRUNCATE_ONLY command. It also happens if you’ve never made a full database backup, or if you haven’t made a full backup since running the BACKUP LOG WITH TRUNCATE_ONLY command. So even though your database properties indicate your database is in the FULL recovery model, the log can’t be backed up.

If you’re not aware of this behavior, it might cause problems for you, so some of my clients have suggested that Microsoft should warn you of potential problems. But what form should this warning take? Should it be an informational message in the Database Properties dialog box? (However, if you use only T-SQL commands to change database properties, you’ll never see that information.) Should you get a message when you first create a database that warns you that your database is vulnerable until you take your first full backup? People with automated scripts might not appreciate extra messages being returned, especially if they aren’t error messages. I’ll admit, SQL Server Books Online (BOL) could do a better job of documenting this behavior, but that’s where all warnings of this type belong—in the documentation.

If Microsoft were expected to warn you of every potential problem, there are hundreds, or perhaps even thousands, of possible messages it could generate. Would you really want a message to be generated every time you did something that just might cause a problem? A potentially enormous number of warning messages could clutter up your application log or error log, and possibly cause additional problems just by generating the messages about potential problems. Rather than expending resources to figure out all the possible actions that could have negative consequences, I’d much prefer the engineers spend their time enhancing the database engine, polishing the documentation, and investing in white papers and other educational material to help people use SQL Server most effectively.

End of Article




Post Your Comments Here

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now

Reader Comments

Thanks for this article. I've been advocating this for past year in many discussion groups!! To be more technical, what happens is the log chain is broken when a check point occurs; which BOL is very clear about if you read the BACKUP (Transact-SQL) syntax for SQL 2005 for BACKUP LOG portion (mentioned in SQL 2000 also, not as clear though). NOTE: SQL 2008 has discontinued support of the NO_LOG and TRUNCATE_ONLY options in the BACKUP LOG syntax, thus no warning in that version of BOL.

I second the point it needs to be clearly stated in other areas, such as the DBCC SHRINKFILE (Transact-SQL) doesn't mention any warnings of this possibility. I'd also like to add it'd be helpful to see BOL provide some examples of what causes the log chain to break (or not exist)...such as DBCC SHRINKFILE command, new databases, etc.

Also be aware that it's false pretense to assume that during the time your database log chain is broken you can still create a tail-log backup to recover in the case of a database corruption/failure...you won't have tail-log backup capability until you've performed a full backup to start the log chain!!

This is particularly important to know for new databases, the log chain doesn't start until you've done that first full database backup. Don't start adding data before the backup. Data loss potential is at the highest 'unaware' point here!

Another common scenario is when users manually shrink their transaction log with the SHRINKFILE command, the log chain is broken when the file is shrunk because it causes a checkpoint to occur. A new log chain won't start again until a full backup is performed (as stated in this article). I'm not saying not to shrink the log; there are circumstances that absolutely call for it, but know what you're doing and the importance to get that full backup performed immediately after. Again, tail-log backups won't work in this scenario either...until you've made that first full database backup.

jrea8830

Article Rating 5 out of 5

Opensource YourSqlDba maintenance tool does that. By default it sets up two tasks for backups, one for full backup and other heavy maintenance, and one for log backups.

Log backup task is backing up the logs of all databases in full recovery mode at every 15 minutes. If the full backup was never taken, it lends to an error that is reported by e-mail through database mail.

It is particularely usefull after a restore, because people often forget to do a first full backup after restore. Without this backup all attempts to do log backup fails, until the next full backup. With this warning we avoid a window between restore and next full backup where log backups for this database are unavailable.

The tools also permit to specify fancy databases filter name. If such a filter is specified, for log backup job, the behavior of log job changes as if specifying a database filter means that you really expect to find theses databases in full recovery mode. If one of the selected database is not found in full recovery mode an error is sent.

This is usefull for cases where recovery model is turned off temporary by accident.

The all trick here is to have a maintenance tool that does what it needs to protect your data, and warns you properly if it can't.

pelsql

Article Rating 4 out of 5

I was thinking a little more in regards to if Microsoft needs to do better at warning us of potential data loss from actions we perform when using SQL. I had a thought, of Microsoft already has enabled us to help ourselves and each other out through BOL....why don't we do this???

There's no question that Microsoft has some responsibility in detailing potential hazardous commands we can issue. The question is where does this responsibility end? Also, where does it fall onto the DBA (or end-user) shoulders to piece together all of this information and understand how we are utilizing the data platform and the data loss potential being created by this usage?

The first thing that comes to my mind is that Microsoft has taken a step in adding a way for the user's of BOL to add in their content that can point this type of stuff out. Why is it that we DBAs aren't doing this?

Example is we (and one of us DBAs) could add into BOL on the CREATE DATABASE (Transact-SQL) page a community content that states the transaction log cannot be backed up (i.e. BACKUP LOG commands), and is a potential data loss point, until a full database backup is made.

Simple enough to understand. Maybe that will save a few DBAs frustration of losing unrecoverable data.

I hope after reading this maybe our community will take a moment or two to place a useful comment (especially warning of potential data loss areas) in BOL for the other less knowledgeable DBAs.

jrea8830

Article Rating 5 out of 5

I agree! Besides, the documentation exists to be read!

MarcosGalvani

Article Rating 5 out of 5

 
 

ADS BY GOOGLE