MSSQLTips.com - your daily source for SQL Server tips

Google
 
Web mssqltips.com

ESSENTIALS: Home | Tips | Search | Categories | Top 10 | Products | Authors | Blogs | Forums | Webcasts | Advertise | About
Related Tips
Auto generate SQL Server database restore scripts
Automate Restoration of Log Shipping Databases for Failover in SQL Server 2000
Automating SQL Server 2005 Express Backups and Deletion of Older Backup Files
Automating the SQL Server RESTORE VERIFYONLY Process with Maintenance Tasks
Automating Transaction Log Backups for All SQL Server Databases
Backup to multiple files for faster and smaller SQL Server backup files
COPY_ONLY Backups with SQL Server 2005
Differential Database Backups for SQL Server
Do you really know if your SQL Server database backups are successful?
Encrypt and safeguard your SQL Server database backups
Getting exclusive access to restore SQL Server databases
How to stop logging all successful backups in your SQL Server error logs
Issues with running backup log with no_log or truncate_only in SQL Server
Scheduling Backups for SQL Server 2005 Express
Selecting the SQL Server database recovery model to ensure proper backups
Simple script to backup all SQL Server databases
SQL Server 2000 Database Restores Mapping Users to Logins
SQL Server 2005 Backup Product Options
SQL Server backup and restore across the network
SQL Server backup and restore of the Resource database
SQL Server Backup Checklist
SQL Server Database Backup and Restore Failure Notifications
SQL Server Database Backup Retention Periods
SQL Server Database Restore Verification Script
SQL Server point in time recovery
Verifying Backups with the RESTORE VERIFYONLY Statement
What is in your SQL Server backup files?
Sponsor



Issues with running backup log with no_log or truncate_only in SQL Server

Written By: Edgewood Solutions Engineers -- 3/27/2008 -- 3 comments
Get our newsletter!       

Problem
On my database server I have my databases set to the full recovery model, but the transaction logs get quite big, so I am issuing a BACKUP LOG with NO_LOG.  I am not exactly sure if this causes any issues, but I know that I am able to free up space in my transaction log and shrink the file.  Is this the correct way to handle this situation?

Solution
When managing transaction log growth, the first thought that may come to mind is to use the NO_LOG or the TRUNCATE_ONLY commands.  These commands allow you to reset the data that is stored in the transaction logs, so that you are able to reuse the space without having to continue to grow the transaction log or having to do a log backup.  In some cases this may be what you want to do, but this should not be done as a general practice.

Let's take a look at an example of what happens and how this could impact your backup processing.

First we created a database called "Test" and then executed these statements.

-- create a table
create table dbo.test (id int identity (1,1), description varchar(50))

-- insert a record
insert into dbo.test (description) values ('test')
go

-- do a full backup
backup database test to disk='C:\test.bak' with init

-- insert another record
insert into dbo.test (description) values ('test')
go

-- do a log backup with no_log (or truncate_only)
backup log test with no_log

-- insert another record
insert into dbo.test (description) values ('test')
go

-- do a log backup
backup log test to disk = 'C:\test_1.trn'

SQL Server 2000 Behavior

When these statements are run on SQL Server 2000 the process works, but when we run the last command we get this error message, but the backup still runs and the file is created.

There is no current database backup. This log backup cannot be used to roll forward a preceding database backup.
Processed 1 pages for database 'test', file 'test_Log' on file 1.
BACKUP LOG successfully processed 1 pages in 0.012 seconds (0.426 MB/sec).

SQL Server 2005 Behavior

When this is run on SQL Server 2005 the process does not complete and we get this different error message.  The message is a little misleading because it says there is no current database backup, but we already ran the full backup without issue.  The real issue is that we truncated the transaction log prior to this backup and broke the log chain and that is what is causing this error.

Msg 4214, Level 16, State 1, Line 1
BACKUP LOG cannot be performed because there is no current database backup.
Msg 3013, Level 16, State 1, Line 1
BACKUP LOG is terminating abnormally.

Restore Process

So for SQL Server 2005 we know that we did not create a log backup, so there is no log backup to restore, but what happens if we try to restore the full backup and transaction log backup from SQL Server 2000.  Below are the commands to do the restore.

-- restore the full backup using the norecovery option
restore database test from disk = 'C:\test.bak' with norecovery

-- restore the log backup
restore database test from disk = 'C:\test_1.trn'

The restore of the full backup works fine, but when we try to restore the transaction log backup we get this error message:

Server: Msg 4330, Level 16, State 4, Line 1
The log in this backup set cannot be applied because it is on a recovery path inconsistent with the database.
Server: Msg 3013, Level 16, State 1, Line 1
RESTORE LOG is terminating abnormally.

So what does this mean?

It means a few things, first using no_log or truncate_only invalidates any transaction log backup that is performed after this statement is run.  Therefore if you have a process in your nightly routine where you are truncating the transaction log to free up space and shrink the log any transaction log backups that you run after that will not do you any good.  So by trying to not let your transaction log size get out of control you have actually caused worst issues for yourself.

Another thing this means is that Microsoft has gotten smarter with SQL Server 2005 and does not allow you to perform additional transaction log backups after you issue a no_log or truncate_only.  In SQL Server 2005 books online it says the following:

We recommend that you never use NO_LOG or TRUNCATE_ONLY to manually truncate the transaction log, because this breaks the log chain. Until the next full or differential database backup, the database is not protected from media failure. Use manual log truncation in only very special circumstances, and create backups of the data immediately.

In addition:

This option will be removed in a future version of SQL Server. Avoid using it in new development work, and plan to modify applications that currently use it.

There is a time and place where this comes in handy, if you have a huge transaction log and you do not want to do a backup, this option allows you to free up the space and then shrink the transaction log, but it was not intended to use as a general practice to be used every day.

For SQL Server 2005 and 2008, Microsoft recommends changing the recovery model to SIMPLE instead of using no_log or truncate_only.

Removed from SQL 2008

In SQL Server 2008 this option no longer exists.  Take a look at this list of depreciated features.

Next Steps

  • If you are using the no_log or truncate_only option take a look at your recovery path and what your potential exposure may be
  • Instead of just issuing a backup log with no_log you should either put your database in the SIMPLE recovery mode or issue transaction log backups on a regular basis
Related Tips Forum Posts

Additional Sponsor Info



Get our newsletter!


Try Idera’s new SQL admin toolset: 24 essential tools for SQL Server Management

SQL Backup: high-performance tool to compress, encrypt and monitor backups. Free 14-day trial.

Trouble-free SQL Servers. No 1-size-fits-all solution. Focus on your servers and keep them healthy!

Failover/Failback and High Availability for SQL Servers. Learn how you can easily meet your needs by using SonaSafe from Sonasoft

SQL Nitro allows DBA’s to boost SQL transaction speeds and reduce network bandwidth without using network gear. Now SQL Server DBA’s can add network optimization to their tuning checklist.


Idera - SQL diagnostic manager

SQL diagnostic manager provides an unprecedented level of diagnostic information about the health, performance and status of all SQL Servers in an environment from a central point of control. Using a unique agentless architecture with a low footprint, SQL diagnostic manager continuously monitors cri

Download now!

More SQL Server Tools
SQL diagnostic manager

DBTuna for Microsoft SQL Server

SQL<>secure

SQL Nitro

Capacity Manager for SQL Server




Copyright (c) 2006-2008 Edgewood Solutions, LLC All rights reserved
privacy statement | disclaimer | copyright | advertise | write for us
Some names and products listed are the registered trademarks of their respective owners.