T-SQL Tuesday #104: Code I Have Written That I Would Hate to Live Without

Bert Wagner (b/t) is hosting T-SQL Tuesday #104. The invitation is to write about code you’ve written that you would hate to live without. For me, this is almost a no-brainer!

My DMV Diagnostic Queries represent a lot of code that I would hate to live without. I use them on a daily basis to gather information about SQL Server instances and databases and to help more quickly understand what configuration and performance issues they have. I’ve been publicly posting these queries since 2009, but I actually started developing them for my own personal use back in 2006. The story about how they came about is kind of interesting…

Back in about August of 2006, I was the sole DBA for NewsGator, which was (at that time) an RSS aggregation company. Our main product/service was the ability to let people “subscribe” to RSS feeds for web sites and blogs, and then have us download the RSS feeds of those sites. We would also manage the “read state” of the RS feeds that you subscribed to, so that as you read through your subscribed content and marked posts as read, we would synchronize your progress across different devices.

I had only been at the company about three months, and we had recently migrated from 32-bit SQL Server 2000 to 64-bit SQL Server 2005 SP1 on a two-node FCI running on new hardware. Performance had been pretty good since the migration, and it was about 4:30PM on a Friday afternoon, when I started making some final quick checks of the health of my instance before getting ready to leave for the weekend.

I noticed that my CPU utilization was running about 90-95%, which was much higher than normal. I tried a few of my standard DBA tricks (at that time) to correct the issue, such as running sp_updatestats, running DBCC FREEPROCCACHE, etc. with no real improvement. I even took the emergency step of “shutting down” the content servers (which were application servers that downloaded the RSS feeds, that typically generated about 90% of my database load). This had no appreciable effect on my CPU utilization.

By now, I was getting worried, since we had a problem that I did not immediately know how to diagnose and correct. By this time, our support team and many of the senior executives in the company were aware that we had a problem because our applications were starting to time out and throw errors. I had a literal parade of different people coming to my desk asking some variation/combination of “What’s wrong with the database?” or “What can we do to help?”.

This got so bad that the CTO/Founder of NewsGator (Greg Reinaker) grabbed a large rolling whiteboard, and wrote something like “Glenn knows there is a problem. He is working on it. Please leave him alone”, which was actually pretty helpful.

So after some time, it ended up being just me and the best developer on the Platform Team (Jeff Tingley) staying late into the night and next morning, on a call with Microsoft Premier Support trying to diagnose and troubleshoot the issue. Eventually, we figured out that our problem was mainly caused by parameter sniffing in one stored procedure where we were getting one very inefficient plan stuck in the plan cache.

The short-term fix was to use a local variable to store an input parameter for that stored procedure to disable parameter sniffing for that stored procedure, and to periodically recompile a few other stored procedures that were also part of the problem. Jeff and I finally left around 3AM, with the system being relatively stable. I was exhausted from the time and the stress of feeling like the fate of the company rested on my shoulders. I was convinced that I was in big trouble and was possibly going to be fired since it had taken us so long to figure out the problem. Little did I know…

As it turned out, my boss’s boss decided to give both Jeff and I a $500.00 bonus, plus we got a big round of applause at a company meeting the next Monday (which I appreciated much more).

This incident was the genesis of my DMV Diagnostic queries. I never wanted to be in that situation again! Anytime there was any application slowdown, people always assumed that it was a database problem (which was not always the case). Having a set of queries that I could run to figure out what was going on with the database and database server was the key to being able to answer the “What’s wrong with the database?” question.

Many thousands of people around the world use my queries on a regular basis, and seem to find them very useful, at least based on the feedback I have gotten over the years. Now you know the story of how they came into being.

Figure 1: Link to Invitation Post

T-SQL Tuesday #99: Home Brewing

It is T-SQL Tuesday time for February 2018, which is being hosted by Aaron Bertrand. One of the choices that Aaron offered was to write about something you are passionate about, outside of the SQL Server or tech community.


T-SQL Tuesday


Making Beer at Home

About 18 months ago, encouraged by my friend Mike Witcher, I became somewhat serious about making beer at home. This was not my first foray into making beer, since I had made about four small two-gallon batches of beer with a Mr. Beer kit about fifteen years ago. Many home brewers get their first start on Mr. Beer kits, which let you make drinkable beer at a very low starting cost, as long as you can follow some basic directions and you pay attention to cleanliness and sanitation.



Mr. Beer Little Brown Keg

Using a Mr. Beer kit to make beer is kind of like making mac-n-cheese from a box. It is possible to make beer while having very little idea what you are actually doing. It is also very similar to using Microsoft Access as a database, which is something you might do as a beginner, that you don’t want to admit to later!

Fast-forward to 2016, and I was thinking about making larger batches of beer, using somewhat more serious equipment. I had met Mike when he bought my previous house in Parker, and we had become friends. He was a veteran home brewer, with many years of experience under his belt who urged me to give it a try.

I was already aware of The Brew Hut, which is the largest home brew supply store in Colorado. I made a couple of reconnaissance visits to the store, before I ended up buying a “Super Deluxe” brewing equipment kit very similar to this one.


Beginners Super Brewing Equipment Kit

A kit like this gives you just about everything you really need to make five-gallon extract batches of beer. This includes a couple of carboys, a four-gallon brew kettle, an immersion chiller, a thermometer, a hydrometer, and various other small accessories. This type of kit lets you do a partial boil, usually on a stovetop in your kitchen, which is often how brewers first really get started (after Mr. Beer). Many brewers successfully use kits like this for many years, with very good results. It is not necessary to spend a lot of money on equipment.

Of course, since I am a gadget nut, I could not resist immediately upgrading my brewing equipment, even before I brewed my first batch of extract beer! My first upgrades were a 10-gallon Anvil brew kettle, and an Anvil High Performance burner, with leg extensions. Anvil is the mid-level line of equipment from Blichmann Engineering, endorsed by John Palmer, who is the author of How to Brew. I also bought a 7.9 gallon FastFerment plastic conical fermenter.

Armed with this fancy new gear, I made a couple of Brewer’s Best extract batches (a Milk Stout and a Belgian Tripel), that seemed to turn out pretty well (at least to an uncritical audience of family and friends). Encouraged, I took an “Introduction to All-Grain Brewing” class, subscribed to several brewing magazines and bought a number of home brewing books. I also made the switch from using bottles to using five-gallon kegs to package my beer.

Then, I made a crazy, early jump to all-grain brewing on batch #3, brewing a pretty challenging Scottish Wee Heavy with a 26lb grain bill! Amazingly, this first all-grain batch turned out pretty well (even though it took me about six hours on brew day). I made one more extract batch (which was a gift from someone), but it has been all-grain ever since.


Equipment Fever

The equipment upgrade fever kicked into high gear during the autumn of 2016, which actually made my brewing days harder as I was learning the quirks of a new piece of equipment with nearly every new batch, while I was still very much a beginning brewer.

Batch #5 was a New England style IPA, using a new Ss Brewtech 7-gallon Chronical Brewmaster Edition stainless steel fermenter and a 10-gallon Infussion Mash Tun. This batch was all late hop additions and then dry hopping in the fermenter.


DSC_9184-1_2000x        DSC_9419_2000x

7-Gallon Chronical Fermenter                                                                10-Gallon Infussion Mash Tun


Later that autumn, I built a wooden brewing cart that currently houses my three vessel brewing system. This includes a 15-gallon kettle that I use as a hot liquor tank (HLT), a 10-gallon mash tun (MT), and a 10-gallon Ss Brewtech Brewmaster Edition boil kettle that sits on a Blichmann HellFire burner. The boil kettle is set up so I can do a whirlpool for late hop additions and during wort cooling. I have two Blichmann RipTide pumps for moving strike and sparge water from the HLT to the MT, and for running the whirlpool.




Brewing Cart   



 Beer Samples

Since then, I have joined a local home brew club (The Parker Hop-Aholics), and I have been entering lots of local home brew competitions. I even managed to win a medal at a very small competition in Castle Rock. Entering competitions is a great way to get unbiased feedback and recommendations for improvement from certified beer judges. It also gives you more incentive to improve your brewing skills.


22519693_10155935771012904_3165160489530286159_o   22519781_10155933197612904_7504047673338257974_o

First Medal                                                                                                                             14-gallon Fermenter in Action

I have brewed 16, five-gallon batches of beer so far (which is almost 2.5 barrels). Every batch has the details recorded in a log book.


Brewing Log Book  



   Mash Tun Full of Grain

Even though this setup may seem pretty complicated, I am still just a beginner with a lot to learn. Brewing beer is similar to cooking or baking, where the basics are pretty easy, but becoming a master takes a lot more time and experience. The reason I enjoy brewing so much is because of how it makes me feel during and after the process. I love the smell of the grain during the mash, and how sweet it tastes as the starches are converted to sugars. The smell of the wort during the boil is also very nice.

The whole experience of a brew day is a lot of fun (and a lot of work). Going through all of the steps, trying to hit your numbers, as you listen to good music and drink some good beer is very enjoyable! Doing all of the required cleaning and sanitizing is not as much fun, but it is easier with a large sink and hot water out in my garage. After brew day, you get the chance to sample your beer as it is fermenting, and then finally get to taste the final product a week or two later.

February 19 Update:

I found out over the past weekend that I won medals in two different home brew competitions in Colorado. The first was a silver medal in the 13th Annual Peterson AFB Home Brew Competition for a 25C:Belgian Golden Strong Ale (in Table 16). The second was a gold medal in the Sweethearts Revenge 2018 for an Imperial Pumpkin Stout in the 30B: Autumn Seasonal Beer category.