SQL 2008 an Above: Shrinking the Transaction Log

Hello:  

We all know that, if a database is at the Full Recovery model but the transaction log is not being backed up, the transaction log size can grow exponentially.

I know that the remedy for this, in general, is to shrink the database while in Simple Recovery mode, switch to Full Recovery mode, and make sure that maintenance plans are backing up the transaction log at least every hour if possible.

But, prior to running the shrink statement, do you need to back up the transaction log?  Or, is this piece optional?

Below are scripts that I tend to run in this situation to backup the transaction log first and then shrink:

BACKUP LOG KLAI to disk = 'C:\SQLServerBackups\Logs\KLAI.BAK'
DBCC SHRINKFILE (2,20)

Again, is that first backup script necessary?

Thanks!

TBSupport
LVL 1
TBSupportAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott PletcherSenior DBACommented:
No, it's optional.  Typically you would not want to back it up once it's gotten that large, since it would take too long to re-apply it anyway, you'll never use that log backup.

Put the db into simple mode, do a db checkpoint, shrink the log, then take a full backup as a base for future log backups.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Aneesh RetnakaranDatabase AdministratorCommented:
that depends on how valuable your data and the transaction logs are. If you sense the data is not at all worthy recovering from the log, then you can avoid it. In a true world I wouldn't shrink the log files as it increases the fragmentation.  Also the shrinkfile wont work until the virtual log files are released  that's why the backup log statement.  
here is an example how it should be done (again not recommended )

USE AdventureWorks2012;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE AdventureWorks2012
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (AdventureWorks2012_Log, 1);
GO
-- Reset the database recovery model.
ALTER DATABASE AdventureWorks2012
SET RECOVERY FULL;
GO
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.