Can I Shrink my SQL Server 2008 R2 Transaction files without fragmentation?

Experts - a preemptive strike here (hopefully)

My SQL Server 2008 R2 log files are not too big yet, but they will be someday...  someday sooner than I care to admit. Our "Recovery Model" is "Bulk Logged" (instead of "Simple" or "FULL").

Will his option work on a "Bulk Logged"  DB?

Please First Read this post before you give me your best answer... it was a painful revelation to me (who is a big fan of the truncate) .. shrinks everything so well... but fragments your DB almost as much as possible.

I need a better way... any ideas!!
LVL 2
dantheanswermanAsked:
Who is Participating?
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.

hafeezmcaCommented:
Hi,

Sometime, it looks impossible to shrink the Truncated Log file. Following code always shrinks the Truncated Log File to minimum size possible.
 
USE DatabaseName
 GO
 DBCC SHRINKFILE(<TransactionLogName>, 1)
 BACKUP LOG <DatabaseName> WITH TRUNCATE_ONLY
 DBCC SHRINKFILE(<TransactionLogName>, 1)
 GO

Read this article as well.

http://blog.sqlauthority.com/2010/05/03/sql-server-shrinkfile-and-truncate-log-file-in-sql-server-2008/
0
Anthony PerkinsCommented:
hafeezmca,

Sometime, it looks impossible to shrink the Truncated Log file. Following code always shrinks the Truncated Log File to minimum size possible.
There are two problems with this:
1.  It is a very bad idea.
2. The author is using SQL Server 2008R2 and thankfully TRUNCATE_ONLY is no longer supported.  If you had actually read the article you posted you would have seen that.
0
Anthony PerkinsCommented:
My SQL Server 2008 R2 log files are not too big yet, but they will be someday
You need to size your Transaction Log so that there is no need to shrink it.  It does not get more complicated than that.

You should only shrink your data files if it is an emergency.  Is that what you are asking?  If the answer is yes, than it is quite simple:
1.  Find a window when there is little or no activity and back up the Transaction Log.
2.  Shrink the Transaction Log to the appropriate size.
0

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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

DBAduck - Ben MillerPrincipal ConsultantCommented:
In your question you specifically say Transaction Log files.  Truncating Transaction log files do not fragment your database.  Only shrinking your Data files will fragment your database.  Log files are circular and you should only have one, so shrinking your t-log file will only release space back to the last open transaction, but it is not going to fragment your database.
As was mentioned, you should size your t-log file so that you are not growing it or shrinking it.   The most important thing about the t-log file is that you have less Virtual Log Files (DBCC LOGINFO) and that the file be as contiguous on the disk as possible because it is circular and benefits from sequential reads and writes.
0
Anthony PerkinsCommented:
Truncating Transaction log files do not fragment your database.
Absolutely.  However truncating the Transaction Log file has the potential to be far more dangerous, in that you have rendered your restore plan based on the Transaction Log useless.
0
DBAduck - Ben MillerPrincipal ConsultantCommented:
acperkins:
Do you mean if you run BACKUP LOG WITH TRUNCATE_ONLY?  Because if you use DBCC SHRINKFILE on the T-Log you are not rendering the restore plan useless as it only releases the unused space.  But you are right, TRUNCATE_ONLY will ruin the last log recovery for restores.  But TRUNCATE_ONLY is deprecated and does not exist in 2005 or 2008 +.

I hope I read your answer right.
0
Anthony PerkinsCommented:
Do you mean if you run BACKUP LOG WITH TRUNCATE_ONLY?
Yes.  You break the backup chain, so that unless you do an immediate Full backup you will not be able to do a point-in-time restore.

Because if you use DBCC SHRINKFILE on the T-Log you are not rendering the restore plan useless as it only releases the unused space.
Correct.

But TRUNCATE_ONLY is deprecated and does not exist in 2005 or 2008 +.
Actually it did exist in SQL Server 2005 and could be used, although it was deprecated. SQL Server 2005 BOL had the following note:
The BACKUP LOG WITH NO_LOG and WITH TRUNCATE_ONLY options have been discontinued. If you are using the full or bulk-logged recovery model recovery and you must remove the log backup chain from a database, switch to the simple recovery model. For more information, see View or Change the Recovery Model of a Database (SQL Server).

It is no longer supported as of SQL Server 2008.  Thankfully.
0
SJCFL-AdminCommented:
Can I reframe the question?

What do I need to look at to keep my log files from getting out of hand?

Applications that are not taking frequent enough commits.
Back to back index rebuilds without intervening transaction log backups
    (and I prefer a method that only rebuilds indexes exceeding a certain level of fragmentation. Run it more frequently to rebuild fewer indexes at a time and space out the transaction log activity.)
Replication activity with long lag times. (leaving transaction log records non-deletable)

Keep an eye on the above and the logs take better care of themselves...
0
dantheanswermanAuthor Commented:
Thanks both of you for your excellent, informative comments... I am really taking a good hard look at these DB's and determining the best plan. Knowing a little more, my real question (which I will ask in a separate question - and give credit you guys for your hard work) ..

New question -

What is a good plan for DR (Disaster Recovery) for a MAS_500 7.4 DB?

I want to keep the transaction log and data files a reasonable size and be able to recover if needed. We are using the bulk-logged method (which I inherited).
0
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
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.