Tuesday, December 6, 2011

You Should Never Use Backup Log Truncate_Only Except...



http://www.flickr.com/photos/paulhagon/369576792/
I want to start this blog out with a Warning Dear Reader.  The technique that I am going to describe to you today is how to use Truncate_Only to NUKE your transaction log.  This is a topic that a quick search on will find you this Blog by Brent Ozar(@BrentO| Blog) and this MSDN forum conversation that has a link to a Paul Randal (@PaulRandal | Blog) Blog on why you should not use this as well.

"So Balls", you say, "Why are you blogging about something we should not use?"

Great question Dear Reader, the answer lies in the details.   With the one place that I would say this is okay to use.

WHY THIS IS BAD

http://www.flickr.com/photos/pawprintscharming/5077934899/
So let's start off first on why this is bad, so you will understand that you should use this with caution.  Your Transaction log is an essential part of your database.  This is an understatement.   This is like saying your Brain is an important part of your body. 

You cannot operate without it.  Period.  It remembers everything that you have done in your life, Transactions that have been committed and flushed to disk for the Database.  If you get knocked out when you wake up you start piecing what you did and how you got there.  In the database work we call this Recovery.

You cannot recover your database if your transaction log is gone, the database won't start up.   Not only that if you have a very important database, you cannot loose any of the transactions that you commit, ie you need to remember everything.   If you have a pharmacy database that track prescriptions, a bank database that tracks customer deposits, or a hospital database that tracks what was given to a patient and when.   You cannot lose any of that information. 

When your database is this important it SHOULD be in Full Recovery Model and we should be backing up our transaction logs in accordance with our Service Level Agreements, SLA's,  in order to meet our Recovery Time Objective, RTO.   If you use the command I will speak about in a moment on a Fully logged database it will wipe out your Transaction Log, good bye memories.  The structure will still be there, but this will make it to where you lose your ability to recover to a point in time.

CAN I GET A CHECKPOINT

"So Balls", you say, "What's a Checkpoint and what in the SQL Internals does it have to do with my database?"

Great question Dear Reader, man you are on top of your game today!  A checkpoint is a process that flushes Dirty pages from the buffer pool to the disk.   Sticking with the biology terms it takes what your eyes are seeing and flushes it to your brain to make, commit, the memory.

In SQL 2000 there was a known issue where occasionally the checkpoint process would go to sleep.  So why is this a bad thing?  Well your transaction log tracks the transactions that are flushed to disk, and when checkpoint went to sleep the transaction log would continue to grow and fill.

In a situation like this what should you do?  Simple open up Query Analyzer or SSMS and simple go to the database in question and type "Checkpoint".  That simple.  Checkpoint the database, execute a DBCC SQLPERF(LOGSPACE) and examine the free space for your database log to see that you now have plenty of room.

THE COMMAND THAT SHALL NOT BE NAMED

So when should you use the unspeakable command that I'm speaking of? 

You get a call for a server, it just so happens to be a SQL 2000 server on SP 4 (awe hotfix or security patch that takes you up to build (8.0.2055 i've seen it in both).  You've gotten reports that the TempDB has run out of log space.

You log in when you type:
USE tempdb
GO
CHECKPOINT

You get an error stating that a Checkpoint could not be committed because the transaction log was full.  At this point you have queries that are failing because tempDB is used, ALOT.  In order by, sort, and group by queries.  By Queries that need temp tables, variable tables, and work space tables.

Your only option at this point would be to restart your instance.  Why restart your instance because TempDB is destroyed and Re-Created each time your instance is restarted.

So before you do that, what can you do?  You can execute the following command.  Again only on a database where you do not care AT ALL about the transactional consistency of the database log.  Also you want your database to be in Simple Recovery Model by default.  And you are on a critical SYSTEM DATABASE that is destroyed and recreated on each restart.  Before you take an outage of your system try this.
Backup Log Tempdb with truncate_only

This command was depriceated in SQL 2005 and is not there in SQL 2008.  There is a work around, but I'm not posting the work around for SQL 2008.  Why because in my humble opinion Dear Reader you would only want to do this when the checkpoint has gone to sleep in the tempdb.  While I have see this A LOT in 2000.  I have yet to see it in 2008 and above.

So once again, be cautious and my recommendation is to only ever use this as a last ditch method of freeing up TempDB space as a means to avoid a reboot.


Thanks,

Brad  

Sunday, November 27, 2011

What Opportunity Are You Looking For?



http://www.flickr.com/photos/mencho-22/6218974134/

A lot has been happening this year.  I decided to throw my hat in the ring at being a blogger and a presenter on SQL topics a little over a year ago.  What started out as a nudge into getting out into the community resulted in a full fledged dive into the deep end.  This has been a year that professionally, I don't know that I could ever duplicate.  Before this year I'd never been to a PASS Summit.  I'd never spoken at a conference, never been invited to submit to a conference, heck I'd never attended a SQL Server User Group (and I had to look up the acronym SSUG).  And it all gets back to one word.

"So Balls", you say, "What word is that?"

The word Dear Reader is Opportunity.  This is a word that has been weighing very heavily on me lately.  You see this word, like all words, can be taken many different ways. 


THE EASY OPPORTUNITY

http://www.flickr.com/photos/wallyg/169975724/

These are the kind of opportunities that just fall into your lap, and are a windfall.  You fly into Chicago and one of your buddies just happens to have an extra Cub's ticket for the game that night.  You check into your coach flight and get automatically upgraded to first class.  Your walking by a ride at Disney and someone who is leaving says "Hey would you and your kid's like our fast passes".

There is no downside to this opportunity.  No one is put out, the timing is perfect, and everything just fits into place. 

When we lived in Virginia we took our first family vacation every and we drove down to Orlando Fl to go to Disney world.  Since we had the boys my wife and I had been dreaming with stars in our eyes about the day we would take our kids to Disney.  It was her hard work, late nights at her job being a manager for a restaurant, and a 401k loan, but we made it down there. 


While we were down there we had a day where the boys crashed early, and the park was going to be open till 4 am.  So when everybody woke up we had a late dinner and headed to the Magic Kingdom around 11 pm.  While we were standing in line for the Tea Cups a Disney Cast Member came over and offered us a "Magic" experience.  They filled out a card for us commemorating where we were and it was made out to the kids with the date on it, and gave us a pass to go to the front of the line.   The line was short, so we didn't make anyone "miss out" on the ride.  But it was a very special experience, and it helped make a great night just a little bit better.


THE LEARNING OPPORTUNITY


Okay so you F***ed up.  It happens.  It's happened to me it's happened to you.  It happens.


"Balls", you say, " WHOA! You just went from Magical Moment at Disney to You F***ed up WHOA WHOA WHOA!"

Ahh Dear Reader, but that is typically the way these things work out.  Ever done a reply all and not realized the whole company was on it? How about getting auto corrected and telling instead of telling the company VP's "Sorry for the inconvenience" that the main server is offline; you send out "Sorry for the incontinence" (incase you need to look it up it means losing control of one's bowels), yep told the senior management sorry about making you wet yourself over a server outage. I was lucky it was a Japanese company, I only heard from the American staff and they were laughing their @$$es off.  How about locking out a production domain account?  How about having your SQL Server page to your C Drive so the first time you present live in front of people your demo that should take 30 seconds takes 5 minutes and 40 seconds.

Yep these are all mistakes I've made (many more than that), and thanks to them I'm wicked paranoid about auto correct, always check to see who I'm replying to, when a demo goes wrong I've got a backup plan, and Keypass is a wonderful thing.

But that is how things go.  One second the world is going fine.  The next you discover that the chair you were sitting in is broken and you are lying on your back.  Nope I haven't done that but I did one pretty close to that.

These are the learning opportunities.  This is the school of hard knox.  Where you learn that you stretch to keep from pulling a muscle, that you hydrate so you can avoid a cramp, and that you will make darn sure not to repeat.  Because you did it once, you got the T-Shirt, and you don't want to ride that ride again.

THE HARD WORK OPPORTUNITY

http://www.flickr.com/photos/friarsbalsam/4609212148/


We know these as well.  This is the opportunity that nobody handed to you.  That you earned with blood, sweat, and not a little determination.  A couple jobs ago in a land far far away, Virginia, I was working at a job.  I enjoyed it I was working hard, and I really liked the people I was working for and with.  I was busting my hump trying to make myself one of the Key people, one of the linchpins, and I felt I was deserving of a promotion and a raise. 

In one year's time I had gotten some certifications, worked on many different efforts, volunteered for more, and had taken the time to mentor some of the Jr guys on the team.  I was working on Programming stuff, Database stuff, Server Engineer Stuff, Training Stuff, needless to say I was doing a lot of stuff.

The time came for my review and it was the typical company review.  There were some sections that didn't pertain to me or my job, that were normally rated middle of the road so as not to sink my score but ground it from getting to high.   This year I felt in all the extra work that I'd done I'd  found some ways to actually rate pretty high on that stuff, and I needed to because I wasn't yet a Sr guy and I wanted to be one. 
 
The review process consisted of us writing our initial review.  Our managers reviewing and adjusting it, and then meeting with us to come to a consensus on a final review that would get accepted and sent off to HR.  I wrote the heck out of my review.  It was stacked full of arguments of why I should be a Sr guy and why I deserved a big raise, and I was ready to go into my review and argue it out and come out on top.

Funny thing happened on the way to the forum, my managers agreed with me.  I was working for a company that really valued me and what I was doing.   I grinned ear to ear, and jumped up and clicked my heels when no one was looking.  But hard work had gotten me there, and I just needed to ask for the Opportunity to be recognized.


THE MISSED OPPORTUNITY


http://www.flickr.com/photos/56654886@N00/508734856/
Simply put these are the things that you miss.  Either by accident or on purpose.  This could be missing meeting up with friends because your phone died.  Passing on presenting at an event so you can attend a family gathering.  These are the things that we miss out on in this game of life.  Forget to follow up with a business contact, go back three spaces.

You only go around on this rock once.  Whatever awaits us after this, you only get once chance.  The missed opportunities could be passing on a job opportunity.  Or they could be the time you spend away from your family while you attend a conference.

When the baby has a nightmare, or there is thunder outside she clings to me.  99.99% of the time she wants Mom.   But when she is scared she wants Dad.  It's a little thing I know.  But it makes me happy to be there for her.  I'm not a jerk I'm not happy that she is scared, but knowing that this little person loves and trusts me so much that just by being beside her she believes I can make thunder and lightning go away is earth shatteringly awesome.  Being a Dad means that you are more powerful that lightning, able to scare away a monster in a closet just by being awake, and able to bring comfort just by being there.  My kids will not be little forever and the baby won't be a baby much longer.

Some missed opportunities are going to a movie.  Some are much bigger than that. 

Sometimes we work late, sometimes we have conference calls during dinner, sometimes we have trouble calls that keep us away nights and weekends, training that makes us travel.  It is part of the job we take on as IT professionals.  We need to do work when it will not affect other people.  Sometimes that means you are working Saturday morning 12 am to 4 am, sometimes it's Saturday morning 7 am to 12 noon.  Other days its Thursday from 10 pm to 4 am Friday.  It happens to me, it happens to you, it happens to all of us

The most important thing about missed opportunities is that it gives us a chance to have a better understanding of what is important.  Because when we realize that these things are important we can do a better job of minimizing what we miss.


WHAT OPPORTUNITY ARE YOU LOOKING FOR
http://www.flickr.com/photos/gavinweaver/4016179739/

Your Mission should you choose to accept it Dear Reader, is to figure out what the Opportunity you are looking for is.  It could be one born out of Hard Work.  It could be that as the day goes along you will have a Learning Opportunity, hopefully it will just be an Easy Opportunity.   And if it is a Missed Opportunity then I hope you learn a little about what was most important, and I hope you made the right choice.

Whatever it is, whether you know it or not you are looking for an opportunity right now.  So Good luck and I'll see you next time.

Thanks,

Brad

Tuesday, November 1, 2011

Presenting on SQL Internals, Recovery Models, & Backups! OH MY Today


 Today I’m presenting “SQL Internals, Recovery Model’s, and Backups. OH MY!”, for Pragmatic Works.  I did this presentation once before for SQL Saturday 79 and it was a big hit.  I had a lot of great feedback from the people in the audience that day, and my friend Kendal Van Dyke (@SQLDBA | Blog) attended and gave me some great notes and tips. 

My goal is not to make you an expert, but to give you a good base knowledge so you can continue to learn on the subject.  There is a lot to cover and we will scratch the surface of a lot of topics.

“So Balls”, you say, “Why should I come listen to you talk about Internals if I’m not going to become an expert?”

Great question Dear Reader, let’s dive right in!

WHY LEARN ABOUT INTERNALS?

I’m not a mechanic, but if I was I would expect that I could look at that picture to the right and tell you what I see.  And I’m not talking, it’s a car and an engine, but what are the components.  What is that pink thing?   What about the blue thing?  I look at that picture and I know the basics and that’s about it.

I am a DBA, and if someone shows me a SQL Instance, a Database, or asks me to perform a task then I should be able to tell them a thing or two about it.  The more you learn about internals the more you know about what you use every day.

As I’ve continued to learn about SQL I’ve noticed some common terms, some information that formed a common baseline.  I want to pass that information on to you because l want to make it easier on you.  I want you to go out and learn, and this information will help you.

You need to understand how a Transaction Log works, that SQL has internal components, what the data hierarchy is, what Recovery Model’s are, how they affect the backups you will take, and how that will affect Service Level Agreements you have with your user. 

From ACID to Transaction Isolation Level’s we are going to make a run at it.  I’ll upload the deck and the Demo’s when the presentation is over.  Click HERE to go to my Resource Page and get a copy of the presentation and the Scripts. 

Click HERE to sign up and join me today!  I hope to see you at 11 am.

Thanks,

Brad