<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'Monitoring' and 'DMVs'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Monitoring,DMVs&amp;orTags=0</link><description>Search results matching tags 'Monitoring' and 'DMVs'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Your Transaction is in Jeopardy -- and You Can't Even Know It!</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2012/06/26/your-transaction-is-in-jeorpardy-and-you-can-t-even-know-it.aspx</link><pubDate>Wed, 27 Jun 2012 01:10:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:44102</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;If you're reading this, &lt;b&gt;please take one minute out of your day and vote for the following Connect item&lt;/b&gt;:&lt;/p&gt;&lt;p&gt;&lt;a href="https://connect.microsoft.com/SQLServer/feedback/details/444030/sys-dm-tran-active-transactions-transaction-state-not-updated-when-an-attention-event-occurs"&gt;https://connect.microsoft.com/SQLServer/feedback/details/444030/sys-dm-tran-active-transactions-transaction-state-not-updated-when-an-attention-event-occurs &lt;/a&gt;&lt;/p&gt;&lt;p&gt;If you're really interested, take three minutes: run the steps to reproduce the issue, and then check the box that says that you were able to reproduce the issue.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Why?&lt;/b&gt; &lt;/p&gt;&lt;p&gt;Imagine that ten hours ago you started a big transaction. &lt;b&gt;You're sitting there waiting for it to finish&lt;/b&gt;, and it's running, and running, and running. At some point, you notice that the drive with the transaction log has filled up, so you create a second log file. And the transaction is sitting there running, and running, and running. Is it still doing work? Or did it catch the low disk space issue and start rolling back? Wouldn't it be great if you could actually answer that question? &lt;b&gt;Are you surprised to learn that you can't answer that question?&lt;/b&gt; &lt;br&gt;&lt;/p&gt;&lt;p&gt;SQL Server currently has a few DMVs that are supposed to tell us the status of a given request, transaction, and so on. &lt;b&gt;These DMVs are unreliable in the vast majority of situations&lt;/b&gt;. That means that we are unable to answer important questions like, "is my transaction still doing any work, or did it die three hours ago?"&lt;/p&gt;&lt;p&gt;&lt;b&gt;The SQL Server team needs to fix this&lt;/b&gt;. End of story. Please vote and help me convince the powers that be to do the right thing. &lt;br&gt;&lt;/p&gt;</description></item><item><title>A Warning to Those Using sys.dm_exec_query_stats</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2010/04/22/a-warning-to-those-using-sys-dm-exec-query-stats.aspx</link><pubDate>Fri, 23 Apr 2010 02:15:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:24515</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;The sys.dm_exec_query_stats view is one of my favorite DMVs. It has replaced a large chunk of what I used to use SQL Trace for--pulling metrics about what queries are running and how often--and it makes this kind of data collection painless and automatic. What's not to love? But use cases for the view are a topic for another post. Today I want to quickly point out an inconsistency.&lt;/p&gt;
&lt;p&gt;If you're using this view heavily, as I am, you should know that in some cases your queries will not get a row. One such case, as it turns out, is any time an ALTER TABLE appears in your batch. "No big deal," you might be thinking. "I don't regularly alter tables in stored procedures." But think again. Do you ever create a temporary table using SELECT INTO? Do you ever create indexes on the resultant table? I know I do--and quite often those indexes are primary keys, or unique constraints.&lt;/p&gt;
&lt;p&gt;The interesting thing is that CREATE INDEX does not suffer from this problem. You can create unique indexes all day long and still get entries in the query stats DMV. And thus the inconsistency: Using ALTER TABLE to create a primary key or unique constraint on a temporary table is, for all intents and purposes &lt;i&gt;exactly the same thing&lt;/i&gt; as creating a unique index using CREATE INDEX. But one works with the query_stats DMV and the other doesn't.&lt;/p&gt;
&lt;p&gt;It's not difficult to imagine how this inconsistency arose; just rather annoying in practice. I went through a bunch of code today and changed several instances of ALTER TABLE to CREATE INDEX, and my monitoring scripts are already working better as a result. I recommend that you take the time to do the same, if you use this view.&lt;br&gt;&lt;/p&gt;
&lt;p&gt;To conclude this post, a quick repro so that you can see the issue:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'abc' AS a&lt;br&gt;INTO #x&lt;br&gt;&lt;br&gt;ALTER TABLE #x&lt;br&gt;ADD UNIQUE (a)&lt;br&gt;&lt;br&gt;SELECT *&lt;br&gt;FROM sys.dm_exec_query_stats&lt;br&gt;WHERE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; plan_handle IN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; plan_handle&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM sys.dm_exec_requests&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; session_id = @@SPID&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;br&gt;&lt;br&gt;DROP TABLE #x&lt;br&gt;GO&lt;br&gt;&lt;br&gt;&lt;br&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'abc' AS a&lt;br&gt;INTO #x&lt;br&gt;&lt;br&gt;CREATE UNIQUE INDEX whatever&lt;br&gt;ON #x (a)&lt;br&gt;&lt;br&gt;SELECT *&lt;br&gt;FROM sys.dm_exec_query_stats&lt;br&gt;WHERE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; plan_handle IN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; plan_handle&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM sys.dm_exec_requests&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; session_id = @@SPID&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;br&gt;&lt;br&gt;DROP TABLE #x&lt;br&gt;GO&lt;br&gt;&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Enjoy, and best of luck in all of your monitoring endeavors. &lt;br&gt;&lt;/p&gt;</description></item><item><title>Who is Active? v9.57: Fast, Comprehensive DMV Collection - What's Really Happening on Your Server?</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/12/03/who-is-active-v9-57-fast-comprehensive-dmv-collection.aspx</link><pubDate>Thu, 03 Dec 2009 19:59:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:19489</guid><dc:creator>Adam Machanic</dc:creator><description>
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;h1&gt;&lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2011/04/27/who-is-active-v11-00-a-month-of-activity-monitoring-part-27-of-30.aspx"&gt;&lt;b&gt;UPDATE, April 28 2011: Who is Active v9.57 is outdated. Please use v11.00 instead.&lt;/b&gt;&lt;/a&gt;&lt;/h1&gt;&lt;br&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;hr&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Happy December, SQLblog readers! My gift to you, just in time for the holidays: The newest "official" release of your favorite &lt;b&gt;SQL Server activity monitoring stored procedure&lt;/b&gt;.&lt;span class="status"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://sqlblog.com/files/folders/19491/download.aspx"&gt;&lt;b&gt;Click here to download Who is Active? v9.57&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Since the last release--&lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2009/08/20/who-is-active-v8-82-harder-better-faster-stronger.aspx"&gt;v8.82, from August of this year&lt;/a&gt;--I've made a number of modifications to the script, resulting in six interim "beta" releases. The uniting theme of all of these changes is &lt;b&gt;more, better quality data, faster&lt;/b&gt;. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;More data&lt;/b&gt;. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Two new core options were added at the behest of users: &lt;b&gt;@show_sleeping_spids&lt;/b&gt; and &lt;b&gt;@show_system_spids&lt;/b&gt;. These options cause the procedure to return information that wasn't previously available via Who is Active, about--you guessed it--sleeping and system sessions, respectively. &lt;br&gt;&lt;/li&gt;
&lt;li&gt;Another major change was adding a feature so that &lt;b&gt;the script now shows blocking sessions whether or not they're included in the default filter criteria&lt;/b&gt;. This is not something you turn on or off--it just happens--and will ensure that if you're debugging a blocking scenario you'll automatically have all the information you need. &lt;br&gt;&lt;/li&gt;
&lt;li&gt;And for you query plan geeks out there, the full wait stats collection mode (see the "Faster data" section below) now returns node identifier information with CXPACKET waits--helping you to &lt;b&gt;track progress of tasks as a plan is executed&lt;/b&gt;. &lt;br&gt;&lt;/li&gt;
&lt;li&gt;Finally, a small modification. The online help system (@help=1) now returns information about both the available input parameters as well as all of the available output columns.&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Better data&lt;/b&gt;.&lt;b&gt; &lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A few minor &lt;b&gt;bugs were fixed&lt;/b&gt;, mostly &lt;b&gt;having to do with the evils of MARS&lt;/b&gt; and the fact that the DMVs don't properly deal with MARS sessions in many cases. &lt;br&gt;&lt;/li&gt;
&lt;li&gt;Workarounds were also added for inconsistencies in how the DMVs report SQL handles, even without MARS. &lt;br&gt;&lt;/li&gt;
&lt;li&gt;Two features were added to help you get only the data you need when you need it, and not the data you don't:&amp;nbsp;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Dynamic sort ordering&lt;/b&gt;, via a parameter called @sort_order, lets you pass in a list of columns and column directions by which to sort the output. &lt;br&gt;&lt;/li&gt;
&lt;li&gt;And &lt;b&gt;"not" filters&lt;/b&gt;, implemented using parameters @not_filter and @not_filter_type, work exactly the opposite of regular filters. These are useful in those cases where you have a bunch of sessions that aren't of interest, and you don't want them cluttering your output. &lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;Finally, I've &lt;b&gt;changed the default output column order&lt;/b&gt; to something I think is a bit more useful. Don't like my selections? No problem--override me using the @output_column_list parameter.&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Faster data&lt;/b&gt;. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This is the area in which I made the most modifications. &lt;b&gt;A monitoring tool borders on useless when it takes a minute or more to return key metrics&lt;/b&gt; when your server is on fire, and alas, previous versions of Who is Active were doing just that for some users. &lt;br&gt;&lt;/li&gt;
&lt;li&gt;I've made major changes to the core queries in this version of Who is Active, &lt;b&gt;bringing down query times from minutes to a few seconds&lt;/b&gt; in many cases. &lt;br&gt;&lt;/li&gt;
&lt;li&gt;In conjunction with these changes I added a new &lt;b&gt;lightweight wait stats collection&lt;/b&gt; mode, which is the new default. This mode collects only the top non-CXPACKET wait, giving preference to blocked waits, so that you can see the worst problems without having to sort through a lot of output that may or may not apply. &lt;br&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;If you miss the complete stats collection mode, it's still there--simply set @get_task_info=2 when calling the procedure.&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;p&gt;I'm quite happy with this release, and I hope that it will help people quickly solve a number of tricky SQL Server problems. &lt;b&gt;As always, your feedback is very much appreciated!&lt;/b&gt; Leave me a comment here, e-mail me (my address is in the script), or track me down at a conference. Most of the features in the past few versions are a direct result of requests I've gotten from users. &lt;/p&gt;
&lt;p&gt;A &lt;b&gt;huge thank you to those who tested and gave me feedback&lt;/b&gt; since the last version! Aaron Bertrand, Rajiv Jain, Michelle Ufford, Uri Dimant, and everyone else, I really am thankful for your efforts. To these people and all of my readers, &lt;b&gt;I wish you a happy December and a prosperous 2010&lt;/b&gt;. &lt;/p&gt;
&lt;p&gt;Until next time, enjoy!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;a href="http://sqlblog.com/files/folders/19491/download.aspx"&gt;&lt;b&gt;Click here to download Who is Active? v9.57&lt;/b&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please ignore the text below. Putting in it for search purposes.&lt;/p&gt;
&lt;p&gt;sp_whoisactive whoisactive sp_who sp_who2 sp_who3 sp_who4 sp_who5&lt;br&gt;&lt;/p&gt;</description></item><item><title>Who is Active? v8.82 - Harder, Better, Faster, Stronger</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/08/20/who-is-active-v8-82-harder-better-faster-stronger.aspx</link><pubDate>Thu, 20 Aug 2009 15:03:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:16149</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;I've had a lot of great feedback since my last "official" Who is Active? release--&lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2009/03/30/who-is-active-v8-40-now-with-delta-power.aspx"&gt;v8.40, back in March&lt;/a&gt;--and since then I've made 42 distinct changes, bringing us all the way to v8.82. My versioning scheme is quite simple: one change, one increment, with occasional numbers skipped or major version incrementation if I do a really major change. &lt;/p&gt;&lt;p&gt;If you've been watching the SQLblog closely you may have noticed that I've spun up a &lt;a href="http://sqlblog.com/files/folders/beta/tags/who+is+active/default.aspx"&gt;"beta" program&lt;/a&gt; where I've been posting intermediate "builds" of the stored procedure. These builds represent the latest updates and are published pretty much immediately, which means I haven't tested them enough to declare them stable. Builds posted here on my main blog--such as this one--have been tested fairly heavily and I believe them to be in very good shape.&lt;/p&gt;&lt;p&gt;In the case of v8.82 I've made only one minor change in the past month and a half, and in the meantime I've been heavily using the code and have not encountered any issues. Nor have I received any change requests. So I am declaring v8.82 stable and ready to roll. You can get it from the following link, or at the bottom of this post.&lt;br&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/adam_machanic/attachment/16149.ashx"&gt;&lt;b&gt;Click here to download Who is Active? v8.82&lt;/b&gt;&lt;/a&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;u&gt;&lt;b&gt;So What Has Changed?&lt;/b&gt;&lt;/u&gt;&lt;/p&gt;&lt;p&gt;If you've been watching the beta builds you will have noticed the change log I've been keeping since v8.67. But that leaves around 20 changes unaccounted for. Between 8.40 and 8.67 I did a number of things: I implemented a number of &lt;b&gt;minor bug fixes&lt;/b&gt; and several &lt;b&gt;workarounds for strange ways that data is exposed by the various DMVs&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;One change you'll quickly notice is that &lt;b&gt;all of the numbers have been right-aligned&lt;/b&gt;. This is something that was originally requested by &lt;a href="http://sqlblog.com/blogs/aaron_bertrand/"&gt;Aaron Bertrand&lt;/a&gt;, who later was unable to use the feature as-is because, as it turns out, his font choice in SSMS is not compatible with the way I made the feature work. I did a poll here on SQLblog and discovered that Aaron is fairly unique with regard to fonts, so I'm keeping the feature as-is. Personally, after the 10 minutes it took me to get used to seeing the data a new way, I found it to be a really great enhancement. I'm quite interested in hearing your feedback on how you like the change.&lt;/p&gt;&lt;p&gt;From 8.67 on I have a comprehensive change log, and next I'll go over some of the &lt;b&gt;more important enhancements&lt;/b&gt;, in chronological order based on when I implemented them. There is a central theme here: &lt;b&gt;each of these changes directly resulted from someone giving me feedback&lt;/b&gt;. But more on that below.&lt;/p&gt;&lt;p&gt;At the request of &lt;a href="http://blogs.msdn.com/joesack/"&gt;Joe Sack&lt;/a&gt; I added a parameter called &lt;b&gt;@help&lt;/b&gt; which, when set to 1, &lt;b&gt;returns information about all of the available options&lt;/b&gt;. Online help, in other words. This is much easier than pulling up the definition for the stored procedure and I've found it to be quite helpful on a number of occasions since making the change.&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.msdn.com/jimmymay/"&gt;Jimmy May&lt;/a&gt; asked for an &lt;b&gt;option to help find "block leaders"&lt;/b&gt;, SPIDs that are at the front of the blocking chain. From this the @find_block_leaders parameter was born. It causes the stored procedure to add a new column, blocked_session_count, which is an integer representing the number of SPIDs blocked downstream. Sort by this descending (@sort_column='[blocked_session_count]', @sort_direction='DESC') and the block leader(s) will all sort to the top. I've already been able to use this one to debug a production blocking problem in a matter of around 30 seconds, which may have otherwise taken me minutes. Thanks, Jimmy!&lt;/p&gt;&lt;p&gt;After an e-mail thread with &lt;a href="http://sqlfool.com/"&gt;Michelle Ufford&lt;/a&gt; I decided to &lt;b&gt;support simple wildcards in the @output_column_list&lt;/b&gt; parameter. Interested primarily in information about tempdb? No problem: @output_column_list='[temp%][%]'. Now everything about tempdb will show up in the leftmost columns, and every other column will show up afterward. No need to mess around and try to re-construct the complete column list.&lt;/p&gt;&lt;p&gt;Around this time I received a few requests for &lt;b&gt;better filtering capabilities&lt;/b&gt;. I removed the @spid parameter and replaced it with @filter and @filter_type. The default filter type is "session" in order to support some form of backward-compatibility. Other valid filter types are "program", "database", "login", and "host". Wildcards are supported, so if you're interested in everyone logging in with hosts that start with the letter "C", I've got you covered: @filter='C%', @filter_type='host'.&lt;/p&gt;&lt;p&gt;An e-mail exchange including both Jimmy May and Joe Sack got me really interested in the Runnable Queue, and yet another enhancement was created. I &lt;b&gt;added a wait type called "RUNNABLE" to the wait_info column&lt;/b&gt;. This wait type doesn't actually exist, but is rather an indication of how long tasks have been sitting on the queue. It's a way to quickly see when you're experiencing scheduler pressure.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;u&gt;&lt;b&gt;Next Steps&lt;/b&gt;&lt;/u&gt;&lt;/p&gt;&lt;p&gt;At some point I'm going to fully document this thing. Really. But to be honest I'm much more interested in continuing to enhance it. If you've found it to be useful, please let me know. If you have feature requests, definitely let me know what they are. And if you find a bug, drop everything and e-mail me right away (well, within reason). &lt;b&gt;My e-mail address is in the stored procedure&lt;/b&gt; on purpose; most of the enhancements to this stored procedure have come about thanks to users, and &lt;b&gt;I really do want to hear from you&lt;/b&gt;. Don't be shy. &lt;br&gt;&lt;/p&gt;&lt;p&gt;So without further ado, enjoy. And &lt;b&gt;thank you to everyone&lt;/b&gt;--both those listed and not listed in this post--&lt;b&gt;who helped make this version what it is&lt;/b&gt;. I really appreciate your help. &lt;br&gt;&lt;/p&gt;</description></item><item><title>Working with SQLFool's Index Defrag Script</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2009/04/13/working-with-sqlfool-s-index-defrag-script.aspx</link><pubDate>Mon, 13 Apr 2009 14:16:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13262</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;Last week I decided to play with &lt;a href="http://sqlfool.com/2009/03/automated-index-defrag-script/" title="http://sqlfool.com/2009/03/automated-index-defrag-script/" target="_blank"&gt;SQLFool's Automated Index Defrag Script&lt;/a&gt; and found it very usable and worthwhile.&amp;nbsp; Terrific work Michelle!&amp;nbsp; The script rivals &lt;a href="http://ola.hallengren.com/" title="http://ola.hallengren.com/" target="_blank"&gt;Ola Hallengren's broader maintenance scripts&lt;/a&gt; that I use often.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;On smaller databases it ran quite quickly and with the correct and desired effects.&amp;nbsp; On larger databases, due to the amount of time it takes to run, I found a couple of things lacking on the reporting side.&amp;nbsp; Not serious things, mind you, and nothing that is really all that hard to work around.&amp;nbsp; But I thought I would share them anyway, in case you were using the script and coming across similar issues.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;What index is currently being reorganized?&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;There is a great output table that records the index reorganize tasks, called dbo.dba_indexDefragLog.&amp;nbsp; This records an entry as each index reorganize statement completes.&amp;nbsp; A great enhancement would be to record an entry when each index reorganize command *starts*, so that I can track its progress (for log entries like this I typically have a Start/End column pair, with Start populated by default, and End updated after the task is complete).&amp;nbsp; In the meantime, assuming you know the session_id (SPID) that is running the script, you can figure it out easily by using the following query... which not only tells you which index is being reorganized, but also an estimated completion time (lucky us, ALTER INDEX REORGANIZE is one of the commands that shows percent_complete in sys.dm_exec_requests):&lt;/p&gt;


&lt;table cellpadding="0" cellspacing="0" bgcolor="#eeeeee"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;r.percent_complete&lt;/font&gt;&lt;font color="gray"&gt;, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;estimated_finish_time&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;DATEADD&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;MILLISECOND&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;estimated_completion_time&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;CURRENT_TIMESTAMP&lt;/font&gt;&lt;font color="gray"&gt;),&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;t.[text]&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="green"&gt;sys.dm_exec_requests&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;r&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;CROSS&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;APPLY&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="green"&gt;sys.dm_exec_sql_text&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;r.[sql_handle]&lt;/font&gt;&lt;font color="gray"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;t &lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;WHERE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;r.session_id&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;= &lt;font color="black"&gt;&amp;lt;SPID&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt;&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;&lt;b&gt;Before vs. After Fragmentation &lt;/b&gt;&lt;/p&gt;

&lt;p&gt;The output table dbo.dba_indexDefragLog shows the fragmentation of the index *before* the reorganize happened.&amp;nbsp; An excellent addendum to the logging table would be to show the fragmentation level *after* the reorganize was complete.&amp;nbsp; Currently, to see the before and after picture, I would need to go look at
sys.dm_db_index_physical_stats for each index (since you cannot use
CROSS APPLY against this particular DMV).&amp;nbsp; Paul Randal to the rescue: he explains &lt;a href="http://sqlskills.com/BLOGS/PAUL/post/Indexes-From-Every-Angle-Using-CROSS-APPLY-with-sysdm_db_index_physical_stats.aspx" title="http://sqlskills.com/BLOGS/PAUL/post/Indexes-From-Every-Angle-Using-CROSS-APPLY-with-sysdm_db_index_physical_stats.aspx" target="_blank"&gt;how to work around this issue&lt;/a&gt;.&amp;nbsp; So taking that information, I created the same function, and then wrote the following, which queries the dbo.dba_indexDefragLog table and then runs a CROSS APPLY against the new function to get the *after* picture.&lt;br&gt;&lt;/p&gt;

&lt;table cellpadding="0" cellspacing="0" bgcolor="#eeeeee"&gt;
&lt;tr&gt;
&lt;td&gt;

&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;IF&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;OBJECT_ID&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="red"&gt;'dbo.dba_index_physical_stats'&lt;/font&gt;&lt;font color="gray"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;IS&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;NOT&amp;nbsp;NULL&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;DROP&amp;nbsp;FUNCTION&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.dba_index_physical_stats&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;FUNCTION&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.dba_index_physical_stats&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@database_id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@object_id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@index_id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@partition_number&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@mode&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="blue"&gt;SYSNAME&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;RETURNS&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@result&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;TABLE&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;database_id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;SMALLINT&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[object_id]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;index_id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;partition_number&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;index_type_desc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;NVARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;60&lt;/font&gt;&lt;font color="gray"&gt;),&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;alloc_unit_type_desc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;NVARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;60&lt;/font&gt;&lt;font color="gray"&gt;),&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;index_depth&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;TINYINT&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;index_level&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;TINYINT&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;avg_fragmentation_in_percent&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;FLOAT&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;fragment_count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;BIGINT&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;avg_fragment_size_in_pages&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;FLOAT&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;page_count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;BIGINT&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;avg_page_space_used_in_percent&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;FLOAT&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;record_count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;BIGINT&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;ghost_record_count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;BIGINT&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;version_ghost_record_count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;BIGINT&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;min_record_size_in_bytes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;max_record_size_in_bytes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;avg_record_size_in_bytes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;FLOAT&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;forwarded_record_count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;BIGINT&lt;/font&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;INSERT&amp;nbsp;INTO&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@result &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;SELECT&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;*&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&lt;/font&gt;&lt;font color="green"&gt;sys.dm_db_index_physical_stats&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@database_id&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@object_id&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@index_id&lt;/font&gt;&lt;font color="gray"&gt;, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@partition_number&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@mode&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;RETURN&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;END&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;GO&lt;br&gt;&lt;br&gt;&lt;font color="green"&gt;-- now I can run queries like:&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SELECT&amp;nbsp;TOP &lt;/font&gt;&lt;font color="black"&gt;(10) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;l.databaseName&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;l.objectName&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;l.indexName&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;l.dateTimeStart&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dateTimeFinish&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;DATEADD&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;SECOND&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;l.durationSeconds&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;l.dateTimeStart&lt;/font&gt;&lt;font color="gray"&gt;),&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;l.durationSeconds&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;fragmentation_before&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;l.fragmentation&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;fragmentation_after&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;s.avg_fragmentation_in_percent&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;page_count_before&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;l.page_count&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;page_count_after&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;s.page_count&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.dba_indexDefragLog&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;l&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;CROSS&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;APPLY&lt;/font&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp; dbo.dba_index_physical_stats&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;l.DatabaseID&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;l.ObjectID&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;l.IndexID&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;l.PartitionNumber&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;)&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;s&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;ORDER&amp;nbsp;BY&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;indexDefrag_id&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;DESC&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;Obviously this function is pretty expensive, which is why it would be better if it were called once per index at the end of the task, instead of querying every time.&amp;nbsp; But I don't want to touch Michelle's script... if she thinks these enhancements are worthwhile, I am sure she will add them.&lt;br&gt;&lt;/p&gt;</description></item><item><title>Who is Active? v8.40 - Now With Delta Power!</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/03/30/who-is-active-v8-40-now-with-delta-power.aspx</link><pubDate>Mon, 30 Mar 2009 16:41:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13006</guid><dc:creator>Adam Machanic</dc:creator><description>
&lt;p&gt;&lt;b style="font-size:200%;"&gt;NOTE: v8.40 is outdated at this time. Please try v9.57, &lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2009/12/03/who-is-active-v9-57-fast-comprehensive-dmv-collection.aspx"&gt;which you can find here&lt;/a&gt;.&lt;/b&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;It has been only a month and a half since I posted the last version of Who is Active? (&lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2009/02/18/who-is-active-v7-30.aspx"&gt;v7.30&lt;/a&gt;),
but in that time I've made a huge number of changes, fixes, and
enhancements. &lt;a href="http://sqlblog.com/blogs/adam_machanic/attachment/13006.ashx"&gt;The new version, v8.40&lt;/a&gt;, is faster, more robust, and
includes a few exciting features. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/adam_machanic/attachment/13006.ashx"&gt;&lt;b&gt;Click here to download Who is Active? v8.40&lt;/b&gt;&lt;/a&gt; &lt;br&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Following is a list of some of the
things I've done with it, in no particular order, along with
descriptions where applicable.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Added a &lt;b&gt;collection interval&lt;/b&gt;
option, @DELTA_INTERVAL. This option causes the script to collect
numeric metrics -- such as reads, writes, and context switches --
twice. The script will wait between collections, based on the duration
passed into the parameter (in seconds). The script will then calculate
the differences (deltas), between the first and second collections, for
any requests that were active for each collection. These deltas will be
output in a new set of columns, reads_delta, writes_delta,
context_switches_delta, etc.&lt;/p&gt;

&lt;p&gt;For example, to use the default options and wait two seconds between collections, you would use the following:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;EXEC sp_WhoIsActive @DELTA_INTERVAL = 2;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;If
you played with Who is Active? in the past you know that the script
outputs a lot of data in a lot of different columns. I started feeling
that the column list was getting unwieldy, so I implemented &lt;b&gt;dynamic column lists&lt;/b&gt;
as a fix. There are two changes here. First of all, the default column
list will only contain columns associated with those features you have
turned on. So for example, if you don't have @GET_LOCKS enabled, the
locks column won't appear.&lt;/p&gt;

&lt;p&gt;The second part of this fix is a new feature to make things even more dynamic: &lt;b&gt;custom column lists&lt;/b&gt;. I sent a slightly earlier test version to &lt;a href="http://blogs.msdn.com/jimmymay/"&gt;Jimmy May&lt;/a&gt;,
and his response was something along the lines of, "it's pretty good,
but I really don't like the column order." To make Jimmy happy, I
implemented the @OUTPUT_COLUMN_LIST option. To use this option, simply
pass in whatever columns you would like to see, in whatever order you
would like to see them, and the script will do the rest. Note that the
output will be the intersection of whatever options are enabled and
whatever columns are found in the list.&lt;/p&gt;

&lt;p&gt;Here's an example I've been using in my own work recently:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;EXEC sp_WhoIsActive &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @OUTPUT_COLUMN_LIST = &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; '[login_name],[dd hh:mm:ss.mss],[sql_text],[reads],[writes],&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; [context_switches],[physical_io],[wait_info],[blocking_session_id],&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; [tempdb_writes],[tran_log_writes],[query_plan],[session_id]';&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Another feature I added that makes things a bit more dynamic and customizable is the &lt;b&gt;ability to sort the output&lt;/b&gt;
based on whatever column and direction you would like. Interested in
seeing the requests that are currently blocked? No need to scroll, just
ask for them to sort high:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;EXEC sp_WhoIsActive &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @SORT_COLUMN = '[blocking_session_id]',&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @SORT_COLUMN_DIRECTION = 'DESC';&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;While
viewing the results on the screen in SSMS is great, sometimes I like to
capture the results to a table for later analysis. So I added a few
features in this most recent version to support &lt;b&gt;automated collection&lt;/b&gt;. &lt;/p&gt;

&lt;p&gt;To
begin with, I realized that the default, nicely-formatted output of the
script, while great for on-screen viewing, isn't good if you want to do
your own analysis later. So I added a new option, @FORMAT_OUTPUT, that
lets you &lt;b&gt;control whether the output is or is not formatted&lt;/b&gt;. The default value for the parameter is 1, keeping with the previous behavior.&lt;/p&gt;

&lt;p&gt;I
also figured that if you want to do some later analysis it might be
nice to know what time period you're working with. So I added a column
called collection_time, which outputs a datetime instance representing
the &lt;b&gt;time that the script finished running&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;Taking things
one step further, I decided that with all of the dynamic column options
it would be a pain to put together a table matching the output schema
if you start playing with different settings. So I made things easy; no
need to figure out what the output looks like; &lt;b&gt;the script will write a CREATE TABLE statement for you&lt;/b&gt;. Simply enable the @RETURN_SCHEMA option and collect the output value from the @SCHEMA parameter.&lt;/p&gt;

&lt;p&gt;Finally,
due to nested INSERT/EXEC limitations, it's impossible to insert the
result into a table when calling the stored procedure. No worries, the
script will &lt;b&gt;insert its output into a table&lt;/b&gt; for you. Just tell it where to send the data, via the @DESTINATION_TABLE option.&lt;/p&gt;

&lt;p&gt;Here's
an example of asking for the unformatted output schema, creating a
destination table based on the current day, and collecting data 10
times, waiting 15 seconds between each collection:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;DECLARE @destination_table VARCHAR(4000);&lt;br&gt;SET @destination_table = 'WhoIsActive_' + CONVERT(VARCHAR, GETDATE(), 112);&lt;br&gt;&lt;br&gt;DECLARE @schema VARCHAR(4000);&lt;br&gt;EXEC sp_WhoIsActive&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @FORMAT_OUTPUT = 0,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @RETURN_SCHEMA = 1,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @SCHEMA = @schema OUTPUT;&lt;br&gt;&lt;br&gt;SET @schema = &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; REPLACE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; @schema, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; '&amp;lt;table_name&amp;gt;', &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; @destination_table&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;br&gt;&lt;br&gt;EXEC(@schema);&lt;br&gt;&lt;br&gt;DECLARE @i INT;&lt;br&gt;SET @i = 0;&lt;br&gt;&lt;br&gt;WHILE @i &amp;lt; 10&lt;br&gt;BEGIN;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_WhoIsActive&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; @FORMAT_OUTPUT = 0,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; @DESTINATION_TABLE = @destination_table;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET @i = @i + 1;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WAITFOR DELAY '00:00:15'&lt;br&gt;END;&lt;br&gt;GO&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;One of the key reasons I created the &lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx"&gt;original version&lt;/a&gt; of Who is Active? was to help &lt;b&gt;identify blocked and blocking SPIDs&lt;/b&gt;. And I thought it worked pretty well for that purpose until recently, when I discovered that &lt;a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2009/03/21/six-reasons-you-should-be-nervous-about-parallelism.aspx"&gt;sys.dm_exec_requests fails to properly identify blocking when queries go parallel&lt;/a&gt;. Oops. Fixed in the new version; it now uses the waiting tasks DMV for this purpose, instead of the requests DMV.&lt;/p&gt;

&lt;p&gt;As
part of this process I discovered that the joins to the tasks DMVs were
slightly flawed in v7.30, so I fixed them up. And I was able to play
some games to improve performance--enough that I decided to eliminate
the @TASK_INFO option, making this the default behavior. This means
that you'll always get &lt;b&gt;correct blocker identification&lt;/b&gt; from Who
is Active? v.8.40, along with a few bonus task-based metrics including
physical I/O stats and the number of context switches.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Interested in information about transactions? So are most DBAs, which is why I &lt;b&gt;promoted the transaction start time&lt;/b&gt;, which was previously embedded in the tran_log_writes column, &lt;b&gt;to a top-level column&lt;/b&gt;
of its own. This will still populate only with transactions that have
actually done a write, but from what my testers tell me this is okay
behavior. Let me know if you disagree. While I was in there I played
even more performance games, and greatly improved the speed of the
query when the @GET_TRANSACTION_INFO option is enabled.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;A few smaller fixes are also worth mentioning here. First of all, I tested the script against a &lt;b&gt;case-sensitive instance&lt;/b&gt;, and fixed a few issues there. So it should work for you no matter what collation you're using. Second, thanks to &lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2009/03/15/the-grouped-string-concatenation-challenge-is-closed.aspx#comments"&gt;a discussion I had with Roman Nowak&lt;/a&gt;, I was able to finally &lt;b&gt;solve the entitization problem&lt;/b&gt; that plagued the "clickable" query output produced by the script. Third, I put on my security hat and added some code to &lt;b&gt;verify input arguments&lt;/b&gt;, as well as did a review of all of the dynamic SQL used by the script to make sure that &lt;b&gt;it is not injectable&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Thank
you to everyone who sent me feedback and/or feature requests! If you
have an idea for th script, please make sure to send it my way. I have
quite a bit of momentum at the moment and want to keep going and see
just how far I can take this thing. &lt;b&gt;I can only do this with your help&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;Enjoy! &lt;/p&gt;

&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/adam_machanic/attachment/13006.ashx"&gt;&lt;b&gt;Click here to download Who is Active? v8.40&lt;/b&gt;&lt;/a&gt;&lt;br&gt;&lt;/p&gt;</description></item><item><title>Who is Active? v7.30</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/02/18/who-is-active-v7-30.aspx</link><pubDate>Wed, 18 Feb 2009 15:34:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:11971</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/adam_machanic/attachment/11971.ashx"&gt;Who is Active?&lt;/a&gt; is a comprehensive DMV-based monitoring script, designed to tell you at a glance what processes are active on your SQL Server and what they're up to. It has a number of optional features so that you can get results quickly, or monitor deeply, depending on your needs when you happen to be using the script. Today I'm happy to present a new version, v7.30, which includes a few bug fixes an a new feature.&lt;/p&gt;&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/adam_machanic/attachment/11971.ashx"&gt;&lt;b&gt;Click here to download Who is Active? v7.30&lt;/b&gt;&lt;/a&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Now that I've covered that (for people who haven't been paying attention to this blog as of late), a bit of commentary. After posting Who is Active? &lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2008/12/31/a-gift-of-script-for-2009-who-is-active-redux.aspx"&gt;v7.22 on December 31&lt;/a&gt;, I expected to receive a huge amount of feedback from the community. Alas, there were a few issues:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;It turns out that December 31 is not a great day for a blog post that you would like to get lots of hits.&lt;/li&gt;&lt;li&gt;Apparently many readers were confused about where to actually download the script.&lt;/li&gt;&lt;li&gt;I was told that I need to document the thing better.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Luckily, some users did manage to download it, and I even received some feedback. Great feedback, primarily from a reader named Bill Kan. Thanks for all of your time, Bill!&amp;nbsp; I also discovered a couple of issues on my own, and added a new feature that I thought of while watching &lt;a href="http://scarydba.wordpress.com/"&gt;Grant Fritchey&lt;/a&gt; do an excellent talk at &lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2009/01/16/new-england-data-camp-v1-0-complete-schedule.aspx"&gt;New England Data Camp v1.0&lt;/a&gt;.&lt;br&gt;&lt;br&gt;So now to address those three issues. I'm posting this post on a Wednesday, it's not a holiday, and it will hit midday, so that covers issue #1. For issue #2, see above and see below.&amp;nbsp; I think the download links are painfully obvious at this point.&amp;nbsp; And as for issue #3, well, I'm sorry to say that today is not the day for that one.&amp;nbsp; I've done a fairly good job of documenting the script in the script (download it and take a look), and I think most readers will be able to feel their way around well enough.&amp;nbsp; If you have any questions, post them here and I will be happy to answer. And eventually I will write up a comprehensive document on the thing. But until then, two out of three isn't bad... &lt;br&gt;&lt;br&gt;&lt;a href="http://sqlblog.com/blogs/adam_machanic/attachment/11971.ashx"&gt;&lt;b&gt;Click here to download Who is Active? v7.30&lt;/b&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;Please give it a try and let me know what you think. I've run out of new feature ideas for the moment and could certainly use some input. If you are using it, please let me know what features you've found to
be helpful and how you're integrating it into your work. I'm hoping to
identify a number of use cases as talking points for the forthcoming
document on the script and actual user feedback will be key.&lt;/p&gt;&lt;p&gt;And, most importantly, enjoy! As I mentioned in December, this script has become a vital part of my toolkit; I have to say that it's made certain aspects of monitoring a lot easier and more interesting for me and I hope it does the same for you. &lt;br&gt;&lt;/p&gt;</description></item><item><title>A Gift of Script for 2009: Who is Active, Redux</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2008/12/31/a-gift-of-script-for-2009-who-is-active-redux.aspx</link><pubDate>Wed, 31 Dec 2008 14:49:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:10841</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Last year on December 31 &lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx"&gt;I posted part of a larger monitoring script that I had been working on for a few months&lt;/a&gt;. I received lots of great feedback on the little script in both the comments and from people I was working with, and over the course of the last year I estimate that I have invested at least a couple of hundred hours in the script. &lt;a href="http://sqlblog.com/blogs/adam_machanic/attachment/10841.ashx"&gt;The result of all of this time is attached&lt;/a&gt;, and I hope that this script is as useful for others as it has been for me; I've been using it pretty much nonstop while modifying it and it has become an indispensable part of my toolkit. &lt;/p&gt;
&lt;p&gt;Alas, while I had planned to write a comprehensive blog post on the script for publication today, I simply don't have time to do it correctly at the moment--but I wanted to get the script out on the 31st in order to create a kind of tradition. So instead of telling you everything it can do, I will ask that you instead take a look inside the script, where I've done a fairly good job documenting both the parameters and the outputs.&amp;nbsp; I'll do a followup post soon (I hope) and do a better job of telling you about the various options.&amp;nbsp; In the meantime, I'll leave you with a list of the script's major features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Wait stats collection&lt;/b&gt;, if you enable the GET_WAITS switch. This mode aggregates the various resources that the tasks associated with the session are waiting on, and lets you know how long the tasks have been waiting.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Collection of lock information&lt;/b&gt;, if you enable the GET_LOCKS switch. A lot of effort went into this particular feature--all of the locks for each session are aggregated in an XML format, and work is done to map the various identifiers associated with each lock to actual object names so that you don't have to do the footwork yourself.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Information about sleeping SPIDs&lt;/b&gt; holding open transactions, if you enable the GET_TRANSACTION_INFO switch. If you're being blocked by a SPID that is not active, you should be able to find out about it. This option lets you do it.&amp;nbsp; As a bonus, it also pulls information about transaction log writes in any database in which the transaction has done a write.&lt;br&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Collection of the "outer" command/batch&lt;/b&gt;, if you enable the GET_OUTER_COMMAND switch. One of the comments on the script I posted last year asked why, if you issue SQL like "ALTER TABLE dbo.xx ALTER COLUMN yyy FLOAT NULL", you'll end up with statement text that looks like "UPDATE [zzz].[dbo].[xxx] SET [yyy] = [yyy]". This is an internal representation of what's actually happening, but in many cases is not esepecially useful for end-users. So if you want to see what was actually run, now you can.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Every expensive or potentially expensive option is now parameterized&lt;/b&gt;. I spent a lot of time tweaking performance and with no options running the thing is pretty fast. Enable some options--especially lock collection--and it will slow down considerably, so use these advanced features with care.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Enjoy, and &lt;b&gt;please keep sending feedback&lt;/b&gt;!&amp;nbsp; Let me know what else you would like to see, if you find bugs, etc.&amp;nbsp; I'll post updated versions as major changes are made. &lt;/p&gt;
&lt;p&gt;To finish I would like to thank a few of the people who had an impact on the evolution of this script over the past&amp;nbsp;12 months: Michael Condon, &lt;a href="http://sommarskog.se/"&gt;Erland Sommarskog&lt;/a&gt;, &lt;a href="http://sqlblog.com/blogs/aaron_bertrand/default.aspx"&gt;Aaron Bertrand&lt;/a&gt;, &lt;a href="http://sqlblog.com/blogs/louis_davidson/default.aspx"&gt;Louis Davidson&lt;/a&gt;, and &lt;a href="http://jmkehayias.blogspot.com/"&gt;Jonathan Kehayias&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Have a great 2009, everyone! &lt;br&gt;&lt;/p&gt;</description></item></channel></rss>