<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Erin Stellato</title>
	<atom:link href="http://www.sqlskills.com/blogs/erin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sqlskills.com/blogs/erin</link>
	<description>The SQL Sequel</description>
	<lastBuildDate>Wed, 19 Jun 2013 13:00:43 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>The Accidental DBA (Day 19 of 30): Tools for On-Going Monitoring</title>
		<link>http://www.sqlskills.com/blogs/erin/the-accidental-dba-tools-for-on-going-monitoring/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-accidental-dba-tools-for-on-going-monitoring</link>
		<comments>http://www.sqlskills.com/blogs/erin/the-accidental-dba-tools-for-on-going-monitoring/#comments</comments>
		<pubDate>Wed, 19 Jun 2013 13:00:43 +0000</pubDate>
		<dc:creator>Erin Stellato</dc:creator>
				<category><![CDATA[Baselines]]></category>
		<category><![CDATA[IE0: Accidental DBA]]></category>

		<guid isPermaLink="false">http://www.sqlskills.com/blogs/erin/?p=587</guid>
		<description><![CDATA[<p>This month the SQLskills team is presenting a series of blog posts aimed at helping Accidental DBAs ‘keep the SQL Server lights on’. It’s a little taster to let you know what we’ll be covering in our brand new Immersion Event for The Accidental DBA, which we’ll be presenting for the first time in September [...]</p><p>The post <a href="http://www.sqlskills.com/blogs/erin/the-accidental-dba-tools-for-on-going-monitoring/">The Accidental DBA (Day 19 of 30): Tools for On-Going Monitoring</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><em>This month the SQLskills team is presenting a series of blog posts aimed at helping Accidental DBAs ‘keep the SQL Server lights on’. It’s a little taster to let you know what we’ll be covering in our brand new <a href="http://www.sqlskills.com/sql-server-training/ie0/?utm_source=accidentaldba&amp;utm_medium=blogs&amp;utm_campaign=training" target="_blank">Immersion Event for The Accidental DBA</a>, which we’ll be presenting for the first time in <a href="http://www.sqlskills.com/sql-server-training/bellevue-ie0-20130930/?utm_source=accidentaldba&amp;utm_medium=blogs&amp;utm_campaign=training">September 2013 in Bellevue, WA</a>. You can find all the other posts in this series at <a href="http://www.SQLskills.com/help/AccidentalDBA?utm_source=accidentaldba&amp;utm_medium=blogs&amp;utm_campaign=training">http://www.SQLskills.com/help/AccidentalDBA</a>. Enjoy!</em></p>
<p>In <a title="The Accidental DBA: Baselines" href="http://www.sqlskills.com/blogs/erin/the-accidental-dba-baselines/">yesterday’s post</a> I covered the basics of baselines and how to get started.  In addition to setting up baselines, it’s a good idea to get familiar with some of the free tools available to DBAs that help with continued monitoring of a SQL Server environment.</p>
<p><strong>Performance Monitor and PAL</strong></p>
<p>I want to start with Performance Monitor (PerfMon).  I’ve been using PerfMon since I started working with computers and it is still one of my go-to tools.  Beginning in SQL Server 2005, Dynamic Management Views and Functions (DMVs and DMFs) were all the rage, as they exposed so much more information than had been available to DBAs before.  (If you don’t believe me, try troubleshooting a parameter sniffing issue in SQL Server 2000.)  But PerfMon is still a viable option because it provides information about Windows as well as SQL Server.  There are times that it’s valuable to look at that data side-by-side.  PerfMon is on every Windows machine, it’s reliable, and it’s flexible.  It provides numerous configuration options, not to mention all the different counters that you can collect.  You have the ability to tweak it for different servers if needed, or just use the same template every time.  It allows you to generate a comprehensive performance profile of a system for a specified time period, and you can look at performance real-time.</p>
<p>If you’re going to use PerfMon regularly, take some time to get familiar it. When viewing live data, I like to use <a title="Customizing the Default Counters for Performance Monitor" href="http://www.sqlskills.com/blogs/erin/customizing-the-default-counters-for-performance-monitor/">config files</a> to quickly view counters of interest.  If I’ve captured data over a period of time and I want to get a quickly view and analyze the data, I use PAL.  PAL stands for Performance Analysis of Logs and it’s written and managed by some folks at Microsoft.  You can download PAL from <a title="Download PAL from Codeplex" href="http://pal.codeplex.com/">CodePlex</a>, and if you don’t already have it installed, I recommend you do it now.</p>
<p>Ok, once PAL is installed, set up PerfMon to capture some data for you.  If you don’t know which counters to capture, don’t worry.  PAL comes with default templates that you can export and then import into PerfMon and use immediately.  That’s a good start, but to get a better idea of what counters are relevant for your SQL Server solution, plan to read Jonathan’s post on essential PerfMon counters (it goes live this Friday, the 21<sup>st</sup>).  Once you’ve captured your data, you can then run it through PAL, which will do all the analysis for you and create pretty graphs.  For step-by-step instructions on how to use PAL, <i>and</i> to view some of those lovely graphs, check out this post from Jonathan, <a title="Free Tools for the DBA: PAL Tool" href="https://www.simple-talk.com/content/article.aspx?article=1606">Free Tools for the DBA: PAL Tool</a>.  Did you have any plans for this afternoon?  Cancel them; you’ll probably have more fun playing with data.</p>
<p><strong>SQL Trace and Trace Analysis Tools</strong></p>
<p>After PerfMon, my other go-to utility was SQL Trace.  Notice I said “was.”  As much as I love SQL Trace and its GUI Profiler, they’re deprecated in SQL Server 2012.  I’ve finally finished my mourning period and moved on to Extended Events.  However, many of you are still running SQL Server 2008R2 and earlier so I know you’re still using Trace.  How many of you are still doing analysis by pushing the data into a table and then querying it?  Ok, put your hands down, it’s time to change that.  Now you need to download <a title="ClearTrace" href="http://www.scalesql.com/cleartrace/">ClearTrace</a> and install it.</p>
<p>ClearTrace is a fantastic, light-weight utility that will parse and normalize trace files.  It uses a database to store the parsed information, then queries it to show aggregated information from one trace file, or a set of files.  The tool is very easy to use – you can sort queries based on reads, CPU, duration, etc.  And because the queries are normalized, if you group by the query text you can see the execution count for the queries.</p>
<p>A second utility, ReadTrace, provides the same functionality as ClearTrace, and more.  It’s part of <a title="RML Utilities" href="http://support.microsoft.com/kb/944837">RML Utilities</a>, a set of tools developed and used by Microsoft.  ReadTrace provides the ability to dig a little deeper into the trace files, and one of the big benefits is that it allows you to compare two trace files.  ReadTrace also stores information in a database, and normalizes the data so you can group by query text, or sort by resource usage.  I recommend starting with ClearTrace because it’s very intuitive to use, but once you’re ready for more powerful analysis, start working with ReadTrace.  Both tools include well-written documentation.</p>
<p><em>Note: If you’re a newer DBA and haven’t done much with Trace, that’s ok.  Pretend you’ve never heard of it, embrace Extended Events.</em></p>
<p><strong>SQLNexus</strong></p>
<p>If you’re already familiar with the tools I’ve mentioned above, and you want to up your game, then the next utility to conquer is <a title="SQLNexus" href="http://sqlnexus.codeplex.com/">SQLNexus</a>.  SQLNexus analyzes data captured by SQLDiag and PSSDiag, utilities shipped with SQL Server that Microsoft Product Support uses when troubleshooting customer issues.  The default templates for SQLDiag and PSSDiag can be customized, by you, to capture any and all information that’s useful and relevant for your environment, and you can then run that data through SQLNexus for your analysis.  It’s pretty slick and can be a significant time-saver, but the start-up time is higher than with the other tools I’ve mentioned.  It’s powerful in that you can use it to quickly capture point-in-time representations of performance, either as a baseline or as a troubleshooting step.  Either way, you’re provided with a comprehensive set of information about the solution – and again, you can customize it as much as you want.</p>
<p><strong>Essential DMVs for Monitoring</strong></p>
<p>In SQL Server 2012 SP1 there are 178 Dynamic Management Views and Functions.  How do you know which ones are the most useful when you’re looking at performance?  Luckily, Glenn had a great set of diagnostic queries to use for monitoring and troubleshooting.  You can find the queries on <a title="Glenn's DMV Queries" href="http://sqlserverperformance.wordpress.com/tag/dmv-queries/">Glenn’s blog</a>, and he updates them as needed, so make sure you follow his blog or check back regularly to get the latest version.  And even though I rely on Glenn’s scripts, I wanted to call out a few of my own favorite DMVs:</p>
<ul>
<li><a title="sys.dm_os_wait_stats" href="http://msdn.microsoft.com/en-us/library/ms179984.aspx">sys.dm_os_wait_stats</a> – I want to know what SQL Server is waiting on, when there is a problem and when there isn’t.  If you’re not familiar with wait statistics, read Paul’s post, <a title="Wait statistics, or please tell me where it hurts" href="http://www.sqlskills.com/blogs/paul/wait-statistics-or-please-tell-me-where-it-hurts/ ">Wait statistics, or please tell me where it hurts</a> (I still chuckle at that title).</li>
<li><a title="sys.dm_exec_requests" href="http://msdn.microsoft.com/en-us/library/ms177648.aspx">sys.dm_exec_requests</a> – When I want to see what’s executing currently, this is where I start.</li>
<li><a title="sys.dm_os_waiting_tasks" href="http://msdn.microsoft.com/en-us/library/ms188743.aspx">sys.dm_os_waiting_tasks</a> – In addition to the overall waits, I want to know what tasks are waiting <i>right now </i>(and the wait_type).</li>
<li><a title="sys.dm_exec_query_stats" href="http://msdn.microsoft.com/en-us/library/ms189741.aspx">sys.dm_exec_query_stats</a> – I usually join to other DMVs such as sys.dm_exec_sql_text to get additional information, but there’s some great stuff in here including execution count and resource usage.</li>
<li><a title="sys.dm_exec_query_plan" href="http://msdn.microsoft.com/en-us/library/ms189747.aspx">sys.dm_exec_query_plan</a> – Very often you just want to see the plan. This DMV has cached plans as well as those for queries that are currently executing.</li>
<li><a title="sys.dm_db_stats_properties" href="http://msdn.microsoft.com/en-us/library/jj553546%28v=sql.110%29.aspx">sys.dm_db_stats_properties</a> – I always take a look at statistics in new systems, and when there’s a performance issue, initially just to check when they were last updated and the sample size.  <a title="New Statistics DMF in SQL Server 2008R2PS2" href="http://www.sqlskills.com/blogs/erin/new-statistics-dmf-in-sql-server-2008r2-sp2/">This DMF</a> lets me do that quickly for a table, or entire database (only for SQL 2008R2 SP2 and SQL 2012 SP1).</li>
</ul>
<p>Kimberly will dive into a few of her favorite DMVs in tomorrow&#8217;s post.</p>
<p><strong>Wrap Up</strong></p>
<p>All of the utilities mentioned in this post are available for free.  But it’s worth mentioning that there are tools you can purchase that provide much of the same functionality and more.  As an Accidental DBA, you may not always have a budget to cover the cost of these products, which is why it’s important to know what’s readily available.  And while the free tools may require more effort on your part, using them to dig into your data and figure out what’s <i>really</i> going on in your system is one of the best ways to learn about SQL Server and how it works.</p>
<p>The post <a href="http://www.sqlskills.com/blogs/erin/the-accidental-dba-tools-for-on-going-monitoring/">The Accidental DBA (Day 19 of 30): Tools for On-Going Monitoring</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.sqlskills.com/blogs/erin/the-accidental-dba-tools-for-on-going-monitoring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Accidental DBA (Day 18 of 30): Baselines</title>
		<link>http://www.sqlskills.com/blogs/erin/the-accidental-dba-baselines/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-accidental-dba-baselines</link>
		<comments>http://www.sqlskills.com/blogs/erin/the-accidental-dba-baselines/#comments</comments>
		<pubDate>Tue, 18 Jun 2013 15:29:35 +0000</pubDate>
		<dc:creator>Erin Stellato</dc:creator>
				<category><![CDATA[Baselines]]></category>
		<category><![CDATA[IE0: Accidental DBA]]></category>

		<guid isPermaLink="false">http://www.sqlskills.com/blogs/erin/?p=586</guid>
		<description><![CDATA[<p>This month the SQLskills team is presenting a series of blog posts aimed at helping Accidental DBAs ‘keep the SQL Server lights on’. It’s a little taster to let you know what we’ll be covering in our brand new Immersion Event for The Accidental DBA, which we’ll be presenting for the first time in September [...]</p><p>The post <a href="http://www.sqlskills.com/blogs/erin/the-accidental-dba-baselines/">The Accidental DBA (Day 18 of 30): Baselines</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><em>This month the SQLskills team is presenting a series of blog posts aimed at helping Accidental DBAs ‘keep the SQL Server lights on’. It’s a little taster to let you know what we’ll be covering in our brand new <a href="http://www.sqlskills.com/sql-server-training/ie0/?utm_source=accidentaldba&amp;utm_medium=blogs&amp;utm_campaign=training" target="_blank">Immersion Event for The Accidental DBA</a>, which we’ll be presenting for the first time in <a href="http://www.sqlskills.com/sql-server-training/bellevue-ie0-20130930/?utm_source=accidentaldba&amp;utm_medium=blogs&amp;utm_campaign=training">September 2013 in Bellevue, WA</a>. You can find all the other posts in this series at <a href="http://www.SQLskills.com/help/AccidentalDBA?utm_source=accidentaldba&amp;utm_medium=blogs&amp;utm_campaign=training">http://www.SQLskills.com/help/AccidentalDBA</a>. Enjoy!</em></p>
<p>Baselines are a part of our normal, daily life.  It usually takes 25 minutes to get to work?  Baseline.  You need 7 hours of sleep each night to feel human and be productive?  Baseline.  Your weight is…  Ok, we won’t go there, but you get my point.  Your database server is no different, it has baselines as well.  As a DBA it’s critical that you know what they are and how to use them.</p>
<p><strong>The why…</strong></p>
<p>“But wait,” you say, “why do I need baselines for my server?  It’s always working so there’s no commute, it hopefully never sleeps, and its weight never changes (so unfair).”  You need them; trust me.  A baseline of your database server:</p>
<ul>
<li>Helps you find what’s changed <i>before</i> it becomes a problem</li>
<li>Allows you to proactively tune your databases</li>
<li>Allows you to use historical information when troubleshooting a problem</li>
<li>Provides data to use for trending of the environment <i>and</i> data</li>
<li>Captures data – actual numbers – to provide to management, and both server <i>and</i> storage administrators, for resource and capacity planning</li>
</ul>
<p>There are many, viable reasons to capture baselines.  The challenge is the time it takes to figure out where to store the information, what to capture, and when to capture it.  You also need to create methods to report on it and really <i>use</i> that data.</p>
<p><strong>Where to store your baseline data</strong></p>
<p>You’re a DBA or developer, and you know T-SQL, so the most obvious place to store your baseline information is in a database.  This is your chance to not only exercise your database design skills, but put your DBA skills to work for your <i>own</i> database.  Beyond design, you also need space for the database, you need to schedule regular backups, and you also want to verify integrity and perform index and statistics maintenance regularly.  Most of the posts that have appeared in this <a href="http://www.sqlskills.com/help/accidentaldba/?utm_source=accidentaldba&amp;utm_medium=blogs&amp;utm_campaign=training" target="_blank">Accidental DBA series</a> are applicable for <i>this</i> database, as well as your Productions databases.</p>
<p>To get you started, here’s a CREATE DATABASE script that you can use to create a database to hold your baseline data (adjust file locations as necessary, and file size and growth settings as you see fit):</p>
<pre class="brush: sql; title: ; notranslate">
USE [master];
GO

CREATE DATABASE [BaselineData] ON PRIMARY
( NAME = N'BaselineData',
  FILENAME = N'M:\UserDBs\BaselineData.mdf',
  SIZE = 512MB,
  FILEGROWTH = 512MB
) LOG ON
( NAME = N'BaselineData_log',
  FILENAME = N'M:\UserDBs\BaselineData_log.ldf',
  SIZE = 128MB,
  FILEGROWTH = 512MB
);

ALTER DATABASE [BaselineData] SET RECOVERY SIMPLE;
</pre>
<p><strong>What to capture</strong></p>
<p>Now that you have a place to store your data, you need to decide what information to collect.  It’s very easy to start capturing baseline data with SQL Server, particularly in version 2005 and higher.  DMVs and catalog views provide a plethora of information to accumulate and mine.  Windows Performance Monitor is a built-in utility used to log metrics related to not just SQL Server but also the resources it uses such as CPU, memory, and disk.  Finally, SQL Trace and Extended Events can capture real-time query activity, which can be saved to a file and reviewed later for analysis or comparison.</p>
<p>It’s easy to get overwhelmed with all the options available, so I recommend starting with one or two data points and then adding on over time.  Data file sizes are a great place to start.  Acquiring more space for a database isn’t always a quick operation; it really depends on how your IT department is organized – and also depends on your company having unused storage available.  As a DBA, you want to avoid the situation where your drives are full, and you also want to make sure your data files aren’t auto-growing.</p>
<p>With the statements below, you can create a simple table that will list each drive and the amount of free space, as well as the snapshot date:</p>
<pre class="brush: sql; title: ; notranslate">
USE [BaselineData];
GO
IF EXISTS ( SELECT  1
     FROM    [sys].[tables]
     WHERE   [name] = N'FreeSpace' )
  DROP TABLE [dbo].[FileInfo]

CREATE TABLE [dbo].[FreeSpace] (
   [LogicalVolume] NVARCHAR(256),
   [MBAvailable] BIGINT,
   [CaptureDate] SMALLDATETIME
)
ON [PRIMARY];
GO
</pre>
<p>Then you can set up a SQL Agent job to capture the data at a regular interval with the query below:</p>
<pre class="brush: sql; title: ; notranslate">
INSERT INTO [dbo].[FreeSpace](
   [LogicalVolume],
   [AvailableBytes],
   [CaptureDate]
)
SELECT DISTINCT
   ([vs].[logical_volume_name]),
   ([vs].[available_bytes] / 1048576),
   GETDATE()
FROM [sys].[master_files] AS [f]
CROSS APPLY [sys].[dm_os_volume_stats]([f].[database_id],[f].[file_id]) AS [vs];
GO
</pre>
<p>There is a catch with the above query – it’s only applicable if you’re running SQL Server 2008 R2 SP1 and higher (including SQL Server 2012).  If you’re using a previous version, you can use xp_fixeddrives to capture the data:</p>
<pre class="brush: sql; title: ; notranslate">
INSERT INTO [dbo].[FreeSpace](
   [LogicalVolume],
   [MBAvailable]
)
EXEC xp_fixeddrives;

UPDATE [dbo].[FreeSpace]
SET [CaptureDate] = GETDATE()
WHERE [CaptureDate] IS NULL;
GO
</pre>
<p>Capturing free space is a great start, but if you’ve pre-sized your database files (which is recommended) the free space value probably won’t change for quite a while.  Therefore, it’s a good idea to capture file sizes and available space within as well.  You can find scripts to capture this information in my Capturing <a href="http://www.sqlservercentral.com/articles/baselines/96059/">Baselines on SQL Server: Where’s My Space?</a> article.</p>
<p><strong>When to capture</strong></p>
<p>Deciding when you will collect data will depend on the data itself.  For the file and disk information, the data doesn’t change often enough that you need it to collect hourly.  Daily is sufficient – perhaps even weekly if the systems are low volume.  If you’re capturing Performance Monitor data, however, then you would collect at shorter intervals, perhaps every 1 minute or every 5 minutes.  For any data collection, you have to find the right balance between capturing it often enough to accumulate the interesting data points, and not gathering so much data that it becomes unwieldy and hard to find what’s really of value.</p>
<p>Separate from the interval at which to capture, for some data you also need to consider the timeframes.  Performance Monitor is a great example.  You may decide to collect counters every 5 minutes, but then you have to determine whether you want to sample 24&#215;7, only on weekdays, or only during business hours.   Or perhaps you only want to capture metrics during peak usage times.  When in doubt, start small.  While you can always change your collection interval and timeframe later on, it’s much easier to start small to avoid getting overwhelmed, rather than collect everything and then try to figure out what to remove.</p>
<p><strong>Using baseline data</strong></p>
<p>Once you’ve set up your process for data capture, what’s next?  It’s very easy to sit back and let the data accumulate, but you need to be proactive.  You won’t want to keep data forever, so put a job in place that will delete data after a specified time.  For the free space example above, it might make sense to add a clustered index on the [CaptureDate] column, and then purge data older than three months (or six months – how long you keep the data will depend on how you’re using it).</p>
<p>Finally, you need to use that data in some way.  You can simply report on it – the query below will give you free disk information for a selected volume for the past 30 days:</p>
<pre class="brush: sql; title: ; notranslate">
SELECT
   [LogicalVolume],
   [MBAvailable],
   [CaptureDate]
FROM [dbo].[FreeSpace]
WHERE [LogicalVolume] = 'C'
   AND [CaptureDate] &gt; GETDATE() - 30
ORDER BY [CaptureDate];
GO
</pre>
<p>This type of query is great for trending and analysis, but to take full advantage of the data, as part of your daily Agent job, set up a second step that queries the current day’s values and if there is less than 10GB of free space, send you an email to notify you that disk space is low.</p>
<p><strong>Getting started</strong></p>
<p>At this point you should have a basic understanding of baselines, and you have a few queries to get you started.  If you want to learn more you can peruse my <a title="SQL Server Baselines Series on SQLServerCentral.com" href="http://www.sqlskills.com/blogs/erin/sql-server-baselines-series-on-sqlservercentral-com/">Baselines series</a> on <a href="http://www.sqlservercentral.com/Authors/Articles/Erin_Stellato/351331/">SQLServerCentral.com</a>, and for an in-depth review, you can head over to Pluralsight to view my <a title="SQL Server Benchmarking and Baselines on Pluralsight" href="http://pluralsight.com/training/Courses/TableOfContents/sqlserver-benchmarking">SQL Server: Benchmarking and Baselines</a> course.  Once you’ve set up your baselines, you will be ready to explore quick methods to review or process the data.  There are many free tools that a DBA can use to not only see what happens in real-time, but also review captured data for analysis and trending.  In tomorrow’s post, we’ll look at a few of those utilities in more detail.</p>
<p>The post <a href="http://www.sqlskills.com/blogs/erin/the-accidental-dba-baselines/">The Accidental DBA (Day 18 of 30): Baselines</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.sqlskills.com/blogs/erin/the-accidental-dba-baselines/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Accidental DBA (Day 13 of 30): Consistency Checking</title>
		<link>http://www.sqlskills.com/blogs/erin/the-accidental-dba-day-13-of-30-consistency-checking/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-accidental-dba-day-13-of-30-consistency-checking</link>
		<comments>http://www.sqlskills.com/blogs/erin/the-accidental-dba-day-13-of-30-consistency-checking/#comments</comments>
		<pubDate>Thu, 13 Jun 2013 15:00:06 +0000</pubDate>
		<dc:creator>Erin Stellato</dc:creator>
				<category><![CDATA[DBCC]]></category>
		<category><![CDATA[IE0: Accidental DBA]]></category>

		<guid isPermaLink="false">http://www.sqlskills.com/blogs/erin/?p=582</guid>
		<description><![CDATA[<p>This month the SQLskills team is presenting a series of blog posts aimed at helping Accidental DBAs ‘keep the SQL Server lights on’. It’s a little taster to let you know what we’ll be covering in our brand new Immersion Event for The Accidental DBA, which we’ll be presenting for the first time in September [...]</p><p>The post <a href="http://www.sqlskills.com/blogs/erin/the-accidental-dba-day-13-of-30-consistency-checking/">The Accidental DBA (Day 13 of 30): Consistency Checking</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><em>This month the SQLskills team is presenting a series of blog posts aimed at helping Accidental DBAs ‘keep the SQL Server lights on’. It’s a little taster to let you know what we’ll be covering in our brand new <a href="http://www.sqlskills.com/sql-server-training/ie0/?utm_source=accidentaldba&amp;utm_medium=blogs&amp;utm_campaign=training" target="_blank">Immersion Event for The Accidental DBA</a>, which we’ll be presenting for the first time in <a href="http://www.sqlskills.com/sql-server-training/bellevue-ie0-20130930/?utm_source=accidentaldba&amp;utm_medium=blogs&amp;utm_campaign=training">September 2013 in Bellevue, WA</a>. You can find all the other posts in this series at <a href="http://www.SQLskills.com/help/AccidentalDBA?utm_source=accidentaldba&amp;utm_medium=blogs&amp;utm_campaign=training">http://www.SQLskills.com/help/AccidentalDBA</a>. Enjoy!</em></p>
<p>If you&#8217;ve been following along with our Accidental DBA series, you&#8217;ll know that the posts for the last week covered topics related to one of the most important tasks (if not the most important) for a DBA: backups.  I consider consistency checks, often referred to as CHECKDB, as one of the next most important tasks for a DBA.  And if you&#8217;ve been a DBA for a while, and if you know how much I love statistics, you might wonder why fragmentation and statistics take third place.  Well, I can fix fragmentation and out-of-date/inaccurate statistics at any point.  I can&#8217;t always “fix” corruption.  But let&#8217;s take a step back and start at the beginning.</p>
<p><strong>What are consistency checks?</strong><b></b></p>
<p>A consistency check in SQL Server verifies the logical and physical integrity of the objects in a database. A check of the entire database is accomplished with the <a title="DBCC CHECKDB" href="http://msdn.microsoft.com/en-us/library/ms176064.aspx">DBCC CHECKDB</a> command, but there are other variations that can be used to selectively check objects in the database: <a title="DBCC CHECKALLOC" href="http://msdn.microsoft.com/en-us/library/ms188422.aspx">DBCC CHECKALLOC</a>, <a title="DBCC CHECKCATALOG" href="http://msdn.microsoft.com/en-us/library/ms186720.aspx">DBCC CHECKCATALOG</a>, <a title="DBCC CHECKTABLE" href="http://msdn.microsoft.com/en-us/library/ms174338.aspx">DBCC CHECKTABLE</a> and <a title="DBCC CHECKFILEGROUP" href="http://msdn.microsoft.com/en-us/library/ms187332.aspx">DBCC CHECKFILEGROUP</a>. Each command performs a specific set of validation commands, and it&#8217;s easy to think that to in order to perform a complete check of the database you need to execute all of them. <b>This is not correct.</b></p>
<p>When you execute CHECKDB, it runs CHECKALLOC, CHECKTABLE for every table and view (system and user) in the database, and CHECKCATALOG. It also includes some additional checks, such as those for Service Broker, which do not exist in any other command. CHECKDB is the most comprehensive check and is the easiest way to verify the integrity of the database in one shot. You can read an in-depth description of what it does from Paul, it&#8217;s author, <a href="http://www.sqlskills.com/blogs/paul/checkdb-from-every-angle-complete-description-of-all-checkdb-stages/" target="_blank">here</a>.</p>
<p>CHECKFILEGROUP runs CHECKALLOC and then CHECKTABLE for every table in the specified filegroup. If you have a VLDB (Very Large DataBase) you may opt to run CHECKFILEGROUP for different filegroups on different days, and run CHECKCATALOG another day, to break up the work.</p>
<p><strong>How often should I run Consistency Checks?</strong><b></b></p>
<p>If you can run a consistency check every day for your database, I recommend that you do so. But it&#8217;s quite common that a daily execution of CHECKDB doesn&#8217;t fit into your maintenance window – <a title="The Importance of Running Regular Consistency Checks" href="http://www.sqlskills.com/blogs/paul/importance-of-running-regular-consistency-checks/">see Paul’s post on how often most people do run checks</a>. In that case, I recommend you run your checks once a week. And if CHECKDB for your entire database doesn&#8217;t complete in your weekly maintenance window, then you have to figure out what&#8217;s possible within the time-frame available. I mentioned VLDBs earlier, and Paul has a nice post on <a title="Consistency Checking Option for a VLDB" href="http://www.sqlskills.com/blogs/paul/checkdb-from-every-angle-consistency-checking-options-for-a-vldb/">options for breaking up checks for large database</a>. You will have to determine out what works best for your system – there isn&#8217;t a one-size-fits-all solution. You may need to get creative, which is one of the fun aspects of being DBA. But don&#8217;t avoid running consistency checks simply because you have a large database or a small maintenance window.</p>
<p><strong>Why do I need to run consistency checks?</strong><b></b></p>
<p>Consistency checks are critical because hardware fails and accidents happen. The majority of database corruption occurs because of issues with the I/O subsystem, as Paul mentions <a title="Myths Around Causing Corruption" href="http://www.sqlskills.com/blogs/paul/search-engine-qa-26-myths-around-causing-corruption/">here</a>. Most of the time these are events that are out of your control, and all you can do is be prepared. If you haven&#8217;t experienced database corruption yet in your career, consider yourself lucky, but don&#8217;t think you&#8217;re exempt. It&#8217;s much more common that many DBAs realize and you should expect that it&#8217;s going to occur in one of your databases, on a day that you have meetings booked back-to-back, need to leave early, and while every other DBA is on vacation.</p>
<p><strong>What if I find corruption?</strong><b></b></p>
<p>If you encounter database corruption, the first thing to do is run DBCC CHECKDB and let it finish. Realize that a DBCC command isn&#8217;t the only way to find corruption – if a page checksum comes up as invalid as part of a normal operation, SQL Server will generate an error. If a page cannot be read from disk, SQL Server will generate an error. However it&#8217;s encountered, make sure that CHECKDB has completed and once you have the output from it, <a title="Tips and Tricks for Interpreting CHECKDB Output" href="http://www.sqlskills.com/blogs/paul/checkdb-from-every-angle-tips-and-tricks-for-interpreting-checkdb-output/">start to analyze it</a> (it&#8217;s a good idea to save a copy of the output). Output from CHECKDB is not immediately intuitive. If you need help reviewing it, post to one of the MSDN or StackOverflow forums, or use the #sqlhelp hashtag on Twitter.</p>
<p>Understand exactly what you&#8217;re facing in terms of corruption before you take your next step, which is deciding whether you&#8217;re going to run repair or restore from backup. This decision depends on numerous factors, and this is where your disaster recovery run-book comes into play. Two important considerations are how much data you might lose (and CHECKDB won&#8217;t tell you what data you will lose if you run repair, you&#8217;ll have to go back and try to figure that afterwards) and how long the system will be unavailable – either during repair or restore. This is not an easy decision. If you decide to repair, make certain you take a full backup of the database first. You always want a copy of the database, just in case. I would also recommend that if you decide to run repair, run it against a copy of the database first, so you can see what it does. This may also help you understand how much data you would lose. Finally, after you&#8217;ve either run repair or restored from backup, run CHECKDB again. You need to confirm that the database no longer has integrity issues.</p>
<p>Please understand that I have greatly simplified the steps to go through if you find corruption. For a deeper understanding of what you need to consider when you find corruption, and options for recovering, I recommend a session that Paul did a few years ago on <a title="Corruption Survival Techniques Presentation" href="http://www.sqlskills.com/blogs/paul/teched-80-minute-video-of-corruption-survival-techniques-presentation/">Corruption Survival Techniques</a>, as what he discussed still holds true today.</p>
<p><strong>What about CHECKIDENT and CHECKCONSTRAINTS?</strong><b></b></p>
<p>There are two additional DBCC validation commands: <a title="DBCC CHECKIDENT" href="http://msdn.microsoft.com/en-us/library/ms176057.aspx">DBCC CHECKIDENT</a> and <a title="DBCC CHECKCONSTRAINTS" href="http://msdn.microsoft.com/en-us/library/ms189496.aspx">DBCC CHECKCONSTRAINTS</a>. These commands are not part of the normal check process. I blogged about CHECKIDENT <a title="The Nuance of DBCC CHECKIDENT That Drives Me Crazy" href="http://www.sqlskills.com/blogs/erin/the-nuance-of-dbcc-checkident-that-drives-me-crazy/">here</a>, and you use this command to check and re-seed values for an identity column. CHECKCONSTRAINTS is a command to verify that data in a column or table adheres to the defined constraints. This command should be run any time you run CHECKDB with the REPAIR_ALLOW_DATA_LOSS option. Repair in DBCC will fix corruption, and it doesn&#8217;t take constraints into consideration; it just alters data structures as needed so that data can be read and modified. As such, after running repair, constraint violations can exist, and you need to run CHECKCONSTRAINTS for the entire database to find them.</p>
<p><strong>What’s next?</strong><b></b></p>
<p>We&#8217;ve only scratched the surface of consistency checking. This is a topic worthy of hours of discussion – not just in the how and why, but also what to do when corruption exists. If you plan on attending our Immersion Event for the Accidental DBA, and want to get a jump on the material, I recommend reading through the posts to which I&#8217;ve linked throughout, and also going through Paul’s <a title="Paul's CHECKDB From Every Angle Category" href="http://www.sqlskills.com/blogs/paul/category/checkdb-from-every-angle/">CHECKDB From Every Angle blog category</a>, starting with the oldest post and working your way forward. Hopefully your experience with database corruption will be limited to testing and what you hear about from colleagues&#8230;but don&#8217;t bet on it <img src='http://www.sqlskills.com/blogs/erin/wp-includes/images/smilies/icon_smile.gif' alt="icon smile The Accidental DBA (Day 13 of 30): Consistency Checking" class='wp-smiley' title="The Accidental DBA (Day 13 of 30): Consistency Checking" /> </p>
<p>The post <a href="http://www.sqlskills.com/blogs/erin/the-accidental-dba-day-13-of-30-consistency-checking/">The Accidental DBA (Day 13 of 30): Consistency Checking</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.sqlskills.com/blogs/erin/the-accidental-dba-day-13-of-30-consistency-checking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Nuance of DBCC CHECKIDENT That Drives Me Crazy</title>
		<link>http://www.sqlskills.com/blogs/erin/the-nuance-of-dbcc-checkident-that-drives-me-crazy/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-nuance-of-dbcc-checkident-that-drives-me-crazy</link>
		<comments>http://www.sqlskills.com/blogs/erin/the-nuance-of-dbcc-checkident-that-drives-me-crazy/#comments</comments>
		<pubDate>Wed, 05 Jun 2013 16:17:35 +0000</pubDate>
		<dc:creator>Erin Stellato</dc:creator>
				<category><![CDATA[DBCC]]></category>
		<category><![CDATA[dbcc checkident]]></category>
		<category><![CDATA[reseed identity]]></category>

		<guid isPermaLink="false">http://www.sqlskills.com/blogs/erin/?p=581</guid>
		<description><![CDATA[<p>When I put together my DBCC presentation a couple years ago I created a demo for the CHECKIDENT command.  I had used it a few times and figured it was a pretty straight-forward command.  In truth, it is, but there is one thing that I don’t find intuitive about it.  And maybe I’m the only [...]</p><p>The post <a href="http://www.sqlskills.com/blogs/erin/the-nuance-of-dbcc-checkident-that-drives-me-crazy/">The Nuance of DBCC CHECKIDENT That Drives Me Crazy</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>When I put together my DBCC presentation a couple years ago I created a demo for the <a title="DBCC CHECKIDENT" href="http://msdn.microsoft.com/en-us/library/ms176057.aspx">CHECKIDENT </a>command.  I had used it a few times and figured it was a pretty straight-forward command.  In truth, it is, but there is one thing that I don’t find intuitive about it.  And maybe I’m the only one, but just in case, I figured I’d write a quick post about it.</p>
<p>CHECKIDENT is used to check the current value for an identity column in a table, and it can also be used to change the identity value.  The syntax is:</p>
<pre class="brush: sql; title: ; notranslate">
DBCC CHECKIDENT
 (
   table_name
     [, { NORESEED | { RESEED [, new_reseed_value ] } } ]
 )
[ WITH NO_INFOMSGS ]
</pre>
<p>To see it in action, let’s connect to a copy of the AdventureWorks2012 database and run it against the SalesOrderHeader table:</p>
<pre class="brush: sql; title: ; notranslate">
USE [AdventureWorks2012];
GO

DBCC CHECKIDENT ('Sales.SalesOrderHeader');
</pre>
<p>In the output we get:</p>
<p><code>Checking identity information: current identity value '75123', current column value '75123'.<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.</code></p>
<p>Hooray, seems pretty basic, right?  Well, did you know that running the command as I did above <i>can</i> change the identity seed if the identity value and column value do not match?  This is what I meant initially when I said it wasn’t intuitive.  I didn’t include any options with the command, therefore I do <i>not</i> expect it to make any changes.  In fact, you have to <i>include</i> an option to ensure you do <i>not </i>make a change.  Let’s take a look.</p>
<p>First we’ll create a table with an identity column and populate it with 1000 rows:</p>
<pre class="brush: sql; title: ; notranslate">
USE [AdventureWorks2012];
GO

CREATE TABLE [dbo].[identity_test] (
   id INT IDENTITY (1,1),
   info VARCHAR(10));
GO

SET NOCOUNT ON;
GO

INSERT INTO [dbo].[identity_test] (
   [info]
   )
   VALUES ('test data');
GO 1000
</pre>
<p>Now we’ll run CHECKIDENT, as we did above:</p>
<pre class="brush: sql; title: ; notranslate">
DBCC CHECKIDENT ('dbo.identity_test');
</pre>
<p><code>Checking identity information: current identity value '1000', current column value '1000'.<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.</code></p>
<p>Our results are what we expect.  Now let’s reseed the identity value down to 10:</p>
<pre class="brush: sql; title: ; notranslate">
DBCC CHECKIDENT ('dbo.identity_test', RESEED, 10);
</pre>
<p><code>Checking identity information: current identity value '1000'.<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.</code></p>
<p>The output doesn’t tell us specifically that the identity has been reseeded, so we’ll run CHECKIDENT again, but this time with the NORESEED option (different than what we ran initially):</p>
<pre class="brush: sql; title: ; notranslate">
DBCC CHECKIDENT ('dbo.identity_test', NORESEED);
</pre>
<p><code>Checking identity information: current identity value '10', current column value '1000'.<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.</code></p>
<p>Now we can see that the identity value and the current column are different, and because we included the NORESEED option, nothing happened.  And this is my point: if you do <i>not</i> include the NORESEED option, if the identity and column values do not match, the identity will reseed:</p>
<pre class="brush: sql; title: ; notranslate">
--first execution
DBCC CHECKIDENT ('dbo.identity_test');
PRINT ('first execution done');

--second execution
DBCC CHECKIDENT ('dbo.identity_test');
PRINT ('second execution done');
</pre>
<p><code>Checking identity information: current identity value '10', current column value '1000'.<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.<br />
first execution done</code></p>
<p><code>Checking identity information: current identity value '1000', current column value '1000'.<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.<br />
second execution done</code></p>
<p>So just in case I’m not the only one for whom this isn’t obvious: <b>Make sure to include the NORESEED option when running DBCC CHECKIDENT</b>.  Most of the time, the identity value probably matches the value for the column.  But that one time where it doesn’t, you may not want to reseed it…at least not right away.</p>
<p>The post <a href="http://www.sqlskills.com/blogs/erin/the-nuance-of-dbcc-checkident-that-drives-me-crazy/">The Nuance of DBCC CHECKIDENT That Drives Me Crazy</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.sqlskills.com/blogs/erin/the-nuance-of-dbcc-checkident-that-drives-me-crazy/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SQL Server Training and Conferences for the Fall</title>
		<link>http://www.sqlskills.com/blogs/erin/sql-server-training-conferences-fall-2013/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sql-server-training-conferences-fall-2013</link>
		<comments>http://www.sqlskills.com/blogs/erin/sql-server-training-conferences-fall-2013/#comments</comments>
		<pubDate>Fri, 24 May 2013 18:52:10 +0000</pubDate>
		<dc:creator>Erin Stellato</dc:creator>
				<category><![CDATA[IE0: Accidental DBA]]></category>
		<category><![CDATA[PASS Summit]]></category>
		<category><![CDATA[Presenting]]></category>
		<category><![CDATA[accidental DBA training]]></category>
		<category><![CDATA[IE0]]></category>
		<category><![CDATA[sqlintersection]]></category>

		<guid isPermaLink="false">http://www.sqlskills.com/blogs/erin/?p=578</guid>
		<description><![CDATA[<p>There has been a lot of conversation this week in Twitterverse related to training and conferences in the SQL Server community.  I wanted to share some details and my own thoughts related to a few specific events in which I am involved (and it&#8217;s all very exciting!). Training First, Paul announced a new IE event [...]</p><p>The post <a href="http://www.sqlskills.com/blogs/erin/sql-server-training-conferences-fall-2013/">SQL Server Training and Conferences for the Fall</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>There has been a lot of conversation this week in Twitterverse related to training and conferences in the SQL Server community.  I wanted to share some details and my own thoughts related to a few specific events in which I am involved (and it&#8217;s all very exciting!).</p>
<p><strong>Training</strong></p>
<p>First, <a title="New Immersion Event for Accidental/Involuntary/Junior DBAs" href="http://www.sqlskills.com/blogs/paul/new-immersion-event-for-accidentalinvoluntaryjunior-dbas/">Paul announced</a> a new IE event that will kick off at the end of September: IE0: Immersion Event for the Accidental DBA.  I am thrilled to be an instructor for this course, and I’m <em>really</em> looking forward to teaching with Jonathan.  I worked with <i>so</i> many Accidental DBAs in my previous job – people who were the application administrator and also had to manage the application database.  We had a fairly general class that talked about databases, and we ended up tweaking that content to create a class solely focused on teaching those application administrators what they needed to do to support their SQL Server database.  In the beginning it was a half day class, but we kept coming up with more content we wanted to cover, and had expanded the training to a full day before I left.  How happy am I that Jon and I now have three days to help SQL Server application administrators, Accidental DBAs, and Junior DBAs learn the basics?!</p>
<p>If you’re interested in attending our class, or know someone who might like attend, please check out the <a title="IE0: Immersion Event for the Accidental DBA" href="http://www.sqlskills.com/sql-server-training/ie0/?utm_source=blog&amp;utm_medium=web&amp;utm_campaign=erinpost052413">syllabus</a> and <a title="Immersion Event Registration Page" href="http://www.sqlskills.com/bellevue-ie0-20130930/?utm_source=blog&amp;utm_medium=web&amp;utm_campaign=erinpost052413">registration page</a>.  And if you have any questions about the course, please do not hesitate to contact me or Jon!</p>
<p><strong>Conferences</strong></p>
<p>Second, I am speaking at the SQLIntersection conference in Las Vegas this fall.  Kimberly <a title="SQLintersection Fall Conference It's All About ROI" href="http://www.sqlskills.com/blogs/kimberly/sqlintersections-fall-conference-its-all-about-roi/">blogged</a> about it on Monday and you can see the entire lineup of sessions <a title="SQL Intersection Sessions" href="http://www.sqlintersection.com/sessions.aspx?s=118">here</a>.  I’ll be presenting three sessions:</p>
<ul>
<li>Making the Leap From Profiler to Extended Events</li>
<li>Free Tools for More Free Time</li>
<li>Key Considerations for Better Schema Design</li>
</ul>
<p>SQLintersection is a unique conference because it is pairs with DEVintersection and SharePointintersection, and attendees have access to sessions across multiple Windows technologies.  I have more detail about my Extended Events session below, and the Free Tools session will cover usage scenarios for some of the applications I’ve discussed before in my Baselines sessions (e.g. PAL, RMLUtilities).  The last session on schema design is geared toward developers – but is also appropriate for DBAs – and I have a lot of great ideas for the content as I’ve just finished recording my next <a title="Pluralsight Online Training" href="http://www.sqlskills.com/sql-server-training/online-training/?utm_source=blog&amp;utm_medium=web&amp;utm_campaign=erinpost052413">Pluralsight course</a>, Developing and Deploying SQL Server ISV Applications, which should go live next week!</p>
<p>And finally, I will be speaking at the <a title="PASS Summit 2013" href="http://www.sqlpass.org/summit/2013/">PASS Summit</a> this October in Charlotte, NC!  I am very honored to had the following session selected:</p>
<p style="padding-left: 30px;"><a title="Making the Leap From Profiler to Extended Events" href="http://www.sqlpass.org/summit/2013/Sessions/SessionDetails.aspx?sid=4427">Making the Leap From Profiler to Extended Events</a></p>
<p>You know how you discover something wonderful and you want everyone you meet to try it?  That’s this session.  I had my light bulb moment with Extended Events and believe that everyone else should use it too.  But I get that there’s some hesitation, for a whole host of reasons, so I created this session to help people understand Extended Events better, using what they already know about Profiler and SQL Trace.  Change is hard, I get that, and people have used Profiler and Trace for years…over a decade in some cases!  But both are deprecated in 2012 and Extended Events is here to stay.  You need to learn XEvents not just because it’s what you’ll use for tracing going forward, but also because it can help you troubleshoot issues in ways you’ve never been able to before.</p>
<p>I will also be part of a panel discussion:</p>
<p style="padding-left: 30px;"><a title="How to Avoid LIving at Work: Lessons from Working at Home" href="http://www.sqlpass.org/summit/2013/Sessions/SessionDetails.aspx?sid=4375">How to Avoid Living at Work: Lessons from Working at Home</a></p>
<p>When I joined SQLskills last summer and started working from home, I had to make significant adjustments.  Some days, working at home was just as challenging as work itself.  But 10 months in, I can&#8217;t imagine <em>not</em> working at home.  I’m really looking forward to being able to share my experiences, and also hear what my rock star colleagues have learned.  If you’re thinking of working from home, or even if you currently work from home, please join me, <a title="Thomas LaRock" href="http://www.twitter.com/SQLRockstar">Tom LaRock</a>,  <a title="Aaron Bertrand" href="http://www.twitter.com/AaronBertrand">Aaron Bertrand</a>,  <a title="Andy Leonard" href="http://www.twitter.com/AndyLeonard">Andy Leonard</a>,  <a title="Steve Jones" href="http://www.twitter.com/way0utwest">Steve Jones</a>,  <a title="Grant Fritchey" href="http://www.twitter.com/gfritchey">Grant Fritchey</a>,  <a title="Karen Lopez" href="http://www.twitter.com/datachick">Karen Lopez</a>, and  <a title="Kevin Kline" href="http://www.twitter.com/kekline">Kevin Kline</a> for what I’m sure will be an invaluable and engaging discussion.</p>
<p>Whew!  It’s going to be a busy fall filled with SQL Server events, but I wouldn’t have it any other way.  I am very much looking forward to all of these events – and I hope to see you at one of them!</p>
<p>The post <a href="http://www.sqlskills.com/blogs/erin/sql-server-training-conferences-fall-2013/">SQL Server Training and Conferences for the Fall</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.sqlskills.com/blogs/erin/sql-server-training-conferences-fall-2013/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>T-SQL Tuesday #41: Presenting and Loving It</title>
		<link>http://www.sqlskills.com/blogs/erin/t-sql-tuesday-41-presenting-and-loving-it/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=t-sql-tuesday-41-presenting-and-loving-it</link>
		<comments>http://www.sqlskills.com/blogs/erin/t-sql-tuesday-41-presenting-and-loving-it/#comments</comments>
		<pubDate>Tue, 09 Apr 2013 13:34:15 +0000</pubDate>
		<dc:creator>Erin Stellato</dc:creator>
				<category><![CDATA[Presenting]]></category>
		<category><![CDATA[T-SQL Tuesday]]></category>

		<guid isPermaLink="false">http://www.sqlskills.com/blogs/erin/?p=570</guid>
		<description><![CDATA[<p>I’ve been on a TSQL Tuesday hiatus, which was completely unintentional.  When I read Bob Pusateri’s topic for this month I knew I had to end my sabbatical and get back in the swing of these posts.  Bob’s question was, “How did you come to love presenting?”  Oh Bob…how much time do you have?  It [...]</p><p>The post <a href="http://www.sqlskills.com/blogs/erin/t-sql-tuesday-41-presenting-and-loving-it/">T-SQL Tuesday #41: Presenting and Loving It</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.bobpusateri.com/archive/2013/04/invitation-to-t-sql-tuesday-41-presenting-and-loving-it/"><img class="size-full wp-image-571 alignright" alt="TSQL2sDay150x150 T SQL Tuesday #41: Presenting and Loving It" src="http://www.sqlskills.com/blogs/erin/wp-content/uploads/2013/04/TSQL2sDay150x150.jpg" width="150" height="150" title="T SQL Tuesday #41: Presenting and Loving It" /></a></p>
<p>I’ve been on a TSQL Tuesday hiatus, which was completely unintentional.  When I read <a title="Invitation to T-SQL Tuesday #41" href="http://www.bobpusateri.com/archive/2013/04/invitation-to-t-sql-tuesday-41-presenting-and-loving-it/">Bob Pusateri’s topic</a> for this month I knew I had to end my sabbatical and get back in the swing of these posts.  Bob’s question was, “How did you come to love presenting?”  Oh Bob…how much time do you have?  <img src='http://www.sqlskills.com/blogs/erin/wp-includes/images/smilies/icon_smile.gif' alt="icon smile T SQL Tuesday #41: Presenting and Loving It" class='wp-smiley' title="T SQL Tuesday #41: Presenting and Loving It" /> </p>
<p>It goes back to graduate school.  I’ve <a title="83" href="http://erinstellato.com/2011/03/sb/">blogged before</a> about my mentor, <a title="Susan's Profile Page" href="http://www.kines.umich.edu/profile/susan-brown-phd">Susan Brown</a>, and in my original homage I mentioned that I would not be the speaker that I am today, were it not for her.  And I said that then, and still believe it now, because she found and created opportunities for me to speak publicly, and she provided feedback and encouragement – two things absolutely vital for any speaker to improve and succeed.</p>
<p>During my first year of graduate school the <a title="University of Michigan School of Kinesiology" href="http://www.kines.umich.edu/">School of Kinesiology</a> held a research day, designed to bring the entire department together to showcase our research efforts.  It’s very easy to have no idea what other researchers are doing not just within the University, but even within a small department like Kinesiology.  The idea was to explain our research, what we’d learned, and share ideas.  I gave a 10 minute session on the <a href="http://www.archives-pmr.org/article/S0003-9993%2800%2984942-4/fulltext">research</a> we were doing with botulinum toxin (yes, Botox before it was cool for cosmetic reasons) and its effects on upper limb function in children with spasticity.  I was terrified.  I had spoken in front of groups before &#8211; I took a Communications (read: public speaking) class my junior year, I was a leader in my sorority (yes, you read that right) and spoke often, and I had done campus tours during my senior year (Bob has a <a title="Bob's T-SQL Tuesday post" href="http://www.bobpusateri.com/archive/2013/04/t-sql-tuesday-41-how-i-came-to-love-presenting/">great story</a> about tours in his post).  But speaking to hundreds of people, who were my peers and professors?  That was a whole new ballgame.</p>
<p>I can’t remember how many slides I created, at least 10, before Susan told me that she typically used one slide for each 10 minutes of a talk.  I remember thinking she was crazy…talking for 10 minutes in front of the entire department (and many other researchers from different areas of the University) seemed like an eternity.  [What’s ironic is that I can’t always finish recording a SQLskills Insider Video in less than 10 minutes these days.]</p>
<p>At any rate, I remember standing at the front of the room in the <a href="http://uunions.umich.edu/league/">Michigan League Ballroom</a> feeling incredibly uncomfortable.  Not only were there hundreds of people there, but I was wearing a dress (if you know me, you’re laughing).  I made it through my 10 minutes with one slight timing issue &#8211; I had someone play a video, which taught me the importance of having the entire presentation under my control &#8211; and I cannot remember if it was great or horrible.  But I didn’t walk away thinking, “I’ll never do this again.”</p>
<p>Soon after Susan asked if I would like to take over teaching the Motor Control portion of the <a href="http://www.kines.umich.edu/course/movesci-110">introductory Movement Science course</a> required for all Kinesiology students.  The course was broken into three sections, Motor Control, Biomechanics and Exercise Physiology, with students rotating between the sections and a different instructor for each.  This meant I would teach the same material three times in a semester, which sounds boring but was ideal as a first time instructor.  And I would get paid.  I said yes.</p>
<p>Susan gave me all of her materials, and I converted all of her overheads (yes, overheads) to PowerPoint.  Then I started reading.  While I had taken the same class myself as a sophomore, had taken many advanced Motor Control classes since then, and was getting a master’s degree in Motor Control, teaching the course was something else entirely.  You have to know the information at a different level.  During those early days I often thought of the learning model followed in medicine, “See one, do one, teach one.”  I’d learned it, I’d been tested on it, now it was time for me to teach it.</p>
<p>Some may state that teaching is not the same as presenting.  If you get down into the details, that’s probably true, but it’s not a topic I want to debate here.  To me, they are one and the same.  For me, when I present at a User Group, a SQLSaturday or a conference like the PASS Summit, I am teaching.</p>
<p>And that is what I love: teaching.  And I realized it in graduate school, when I was teaching that introductory Movement Science course.  It happened in the first semester, in the very first rotation.  I cannot remember the name of the student, but she grasped what I was teaching, she <i>understood</i>.  She asked questions during class, she took notes, and she aced the quizzes and the test.  I taught, she learned.  That was pretty cool.</p>
<p>Now…do I believe that I had <em>that</em> much of an impact on her learning?  No.  Do I believe that if I weren’t such a fantastic teacher that she wouldn’t have done so well?  Absolutely not.  She was a smart kid, motivated, and interested in the material.  She would have done well no matter what.  But in those few weeks I realized that I had something to teach those who wanted to learn, and I realized that I wanted to be good at teaching – for them.</p>
<p>As a student, I appreciated good instructors.  Not every instructor is fully “on” every single day – teaching is hard, and the semester is long.  But there were many instructors whose classes I enjoyed, not just for the material, but for the way they explained it.  Susan was that type of instructor.  I wanted to be that type of instructor.  So I worked at it.  For some, teaching and presenting come naturally.  For many, we have to work at it.  And to work at it, you practice.  I taught that same section of that same course for two years.  Yes, 12 times.  But that experience established a foundation upon which I’ve been building ever since.</p>
<p>In my first technology job I wore many hats, and one of them was software trainer.  In my next job, I sought out opportunities to teach others, and eventually, I found the SQL Community and realized that I could present at User Groups, SQLSaturdays and conferences, like so many others.  And here I am.  I still love teaching, I love it when you see the light bulb go on for someone. I love it when you hear that someone took what they learned and applied it to their environment, and then learned something new.  And I really appreciate it when attendees come back and tell me what they learned – as I have not seen every use case and am always, <i>always</i> learning myself.</p>
<p>One of the things that I value most about SQL Server is that it’s vast and it’s always changing.  As such, my learning never ends, and the opportunity to find new things to teach never ends.  As my good friend Allen White ( <a title="Allen's blog" href="http://sqlblog.com/blogs/allen_white/default.aspx">b</a> | <a title="Allen on Twitter" href="http://www.twitter.com/sqlrunr">t</a> ) always says, “I can learn from all of you” (and that means you, dear reader).  If you want to share what you learn, <a title="Recommendations for New Speakers" href="http://www.sqlskills.com/blogs/erin/a-poll-recommendations-for-new-speakers/">I encourage you teach</a>.  Don’t think of it as presenting – that word can be scary.  Think of it as teaching.  Everyone has great and interesting experiences.  Learn how to tell a story, and share what you know.</p>
<p>The post <a href="http://www.sqlskills.com/blogs/erin/t-sql-tuesday-41-presenting-and-loving-it/">T-SQL Tuesday #41: Presenting and Loving It</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.sqlskills.com/blogs/erin/t-sql-tuesday-41-presenting-and-loving-it/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL Server Maintenance Plans and Parallelism &#8211; Index Rebuilds</title>
		<link>http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-index-rebuild/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sql-server-maintenance-plans-and-parallelism-index-rebuild</link>
		<comments>http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-index-rebuild/#comments</comments>
		<pubDate>Fri, 08 Mar 2013 14:51:10 +0000</pubDate>
		<dc:creator>Erin Stellato</dc:creator>
				<category><![CDATA[Database Maintenance]]></category>
		<category><![CDATA[DBCC]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[database maintenance]]></category>
		<category><![CDATA[index rebuild; parallelism;]]></category>

		<guid isPermaLink="false">http://www.sqlskills.com/blogs/erin/?p=550</guid>
		<description><![CDATA[<p>In my previous post, SQL Server Maintenance Plans and Parallelism &#8211; CHECKDB, we looked at the degree of parallelism used when CHECKDB is run.  It ultimately depends on SQL Server Edition and the max degree of parallelism setting for the instance, which is not the case for index rebuilds (today&#8217;s topic, as you probably surmised!). [...]</p><p>The post <a href="http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-index-rebuild/">SQL Server Maintenance Plans and Parallelism &#8211; Index Rebuilds</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>In my previous post, <a title="SQL Server Maintenance Plans and Parallelism – CHECKDB" href="http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-checkdb/">SQL Server Maintenance Plans and Parallelism &#8211; CHECKDB</a>, we looked at the degree of parallelism used when CHECKDB is run.  It ultimately depends on SQL Server Edition and the max degree of parallelism setting for the instance, which is not the case for index rebuilds (today&#8217;s topic, as you probably surmised!).</p>
<p><strong>Index Rebuilds</strong></p>
<p>The max degree of parallelism can be <a title="Configure Parallel Index Operations" href="http://technet.microsoft.com/en-us/library/ms189329.aspx">configured for index rebuilds</a> using WITH (MAXDOP = <em>n</em>):</p>
<pre class="brush: sql; title: ; notranslate">
USE [AdventureWords2012];
GO

ALTER INDEX [IX_SalesOrderDetail_ProductID] ON [Sales].[SalesOrderDetail]
     REBUILD WITH (MAXDOP = 8);
GO
</pre>
<p>If this option is included, it overrides the max degree of parallelism value configured for the instance. For example, I can rebuild the IX_SalesOrderDetail_ProductID index on Sales.SalesOrderDetail with MAXDOP set to 8, even though MAXDOP is set to 4 for the instance.  If WITH (MAXDOP = <em>n</em>) is not specified for an ALTER INDEX &#8230; REBUILD statement, then SQL Server will use the MAXDOP value set for the instance.</p>
<p>Now, unfortunately, <a title="Features Supported by the Editions of SQL Server 2012" href="http://msdn.microsoft.com/en-us/library/cc645993.aspx">parallel index operations are only permitted in Enterprise Edition</a>.  If you&#8217;re running Standard Edition, you&#8217;re stuck with single threaded rebuilds, just like you&#8217;re stuck with single threaded integrity checks.  Despite this sad news, I thought I&#8217;d run through a demo that shows the max degree of parallelism used during the index rebuild. I&#8217;m going to run ALTER INDEX REBUILD for a selected index in the AdventureWorks2012 database, and I&#8217;ll use Extended Events to capture each statement executed (sp_statement_completed event), and the actual query plan for the statement (query_post_execution_showplan event).</p>
<p><span style="color: #ff0000;">**Important note here again: it is <strong><em>NOT</em> </strong>recommended to capture the query_post_execution_showplan event against a live, production system.  This event generates <strong><em>significant</em> </strong>performance overhead, and you are warned of this when configuring the session via the GUI.  If you repeat any of the demos here, please make sure to execute them against a test environment.  It&#8217;s very important to me that you do not bring down your production environment.**</span></p>
<p>Here are the statements to create the event session, start it, run the ALTER INDEX &#8230; REBUILD statements, then stop the event session.  As in my previous post, I am using a file target to capture the output, and the path is C:\temp.  You may need to modify this path for your environment.  I still have max degree of parallelism set to 4 for my instance, but we&#8217;ll set it before we run anything just for good measure.</p>
<pre class="brush: sql; title: ; notranslate">
sp_configure 'show advanced options', 1;
GO
RECONFIGURE WITH OVERRIDE;
GO
sp_configure 'max degree of parallelism', 4;
GO
RECONFIGURE WITH OVERRIDE;
GO

CREATE EVENT SESSION [CapturePlans] ON SERVER
ADD EVENT sqlserver.query_post_execution_showplan(
     ACTION(sqlserver.plan_handle,sqlserver.sql_text)),
ADD EVENT sqlserver.sp_statement_completed(
     ACTION(sqlserver.sql_text))
ADD TARGET package0.event_file(SET filename=N'C:\temp\CapturePlans.xel'),
ADD TARGET package0.ring_buffer(SET max_memory=(102400))
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,
     MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF);
GO

ALTER EVENT SESSION [CapturePlans]
     ON SERVER
     STATE=START;
GO

USE [AdventureWords2012];
GO

ALTER INDEX [IX_SalesOrderDetailEnlarged_ProductID] ON [Sales].[SalesOrderDetailEnlarged]
     REBUILD WITH (MAXDOP = 8);
GO

ALTER INDEX [IX_SalesOrderDetailEnlarged_ProductID] ON [Sales].[SalesOrderDetailEnlarged]
     REBUILD;
GO

ALTER EVENT SESSION [CapturePlans]
     ON SERVER
     STATE=STOP;
GO
</pre>
<p>Note that I used a different version of the SalesOrderDetail table named SalesOrderDetailEnlarged.  This table has over 4 million rows in it and was populated using <a title="Enlarging the AdventureWorks Sample Databases" href="http://www.sqlskills.com/blogs/jonathan/enlarging-the-adventureworks-sample-databases/">Jonathan&#8217;s <em>Create Enlarged AdventureWorks Table </em>script</a> to ensure I&#8217;d have a table large enough to warrant a parallel rebuild.  After I stopped the event session I opened the .xel file from C:\temp in Management Studio and added the sql_text column to the display so I could easily find the ALTER INDEX statements.</p>
<p>The screen shot below is from the ALTER INDEX statement with MAXDOP = 8 included.  The query_post_execution_showplan event is highlighted, you can see the sql_text, and I hovered over the showplan_xml to show the first part of the xml version of the plan.  Note the red box around QueryPlan DegreeofParallelism&#8230;it&#8217;s 8, as expected:</p>
<div id="attachment_553" class="wp-caption alignnone" style="width: 825px"><a href="http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-index-rebuild/indexrebuild_8/" rel="attachment wp-att-553"><img class="wp-image-553  " alt="indexrebuild 8 SQL Server Maintenance Plans and Parallelism   Index Rebuilds" MAXDOP=8)" src="http://www.sqlskills.com/blogs/erin/wp-content/uploads/2013/02/indexrebuild_8.png" width="815" height="393" title="SQL Server Maintenance Plans and Parallelism   Index Rebuilds" /></a><p class="wp-caption-text">ALTER INDEX &#8230; REBUILD WITH (MAXDOP = 8)</p></div>
<p>If you&#8217;re playing along at home in your test environment, you can click on the Query Plan to see the graphical view, or double-click the XML to view that plan that way.  Now check out the screen capture below, which is for the ALTER INDEX statement that did not include the MAXDOP option:</p>
<div id="attachment_552" class="wp-caption alignnone" style="width: 825px"><a href="http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-index-rebuild/indexrebuild_default/" rel="attachment wp-att-552"><img class="wp-image-552  " alt="indexrebuild default SQL Server Maintenance Plans and Parallelism   Index Rebuilds" src="http://www.sqlskills.com/blogs/erin/wp-content/uploads/2013/02/indexrebuild_default.png" width="815" height="406" title="SQL Server Maintenance Plans and Parallelism   Index Rebuilds" /></a><p class="wp-caption-text">ALTER INDEX &#8230; REBUILD (default option)</p></div>
<p>The max degree of parallelism for the plan is 4 because if the MAXDOP option is not included, SQL Server uses the max degree of parallelism set for the instance.  Note that this holds true when parallelism is disabled for an instance (max degree of parallelism = 1):</p>
<pre class="brush: sql; title: ; notranslate">
sp_configure 'max degree of parallelism', 1;
GO
RECONFIGURE WITH OVERRIDE;
GO

ALTER EVENT SESSION [CapturePlans]
 ON SERVER
 STATE=START;
GO

USE [AdventureWords2012];
GO

ALTER INDEX [IX_SalesOrderDetailEnlarged_ProductID] ON [Sales].[SalesOrderDetailEnlarged]
     REBUILD;
GO

ALTER EVENT SESSION [CapturePlans]
 ON SERVER
 STATE=STOP;
GO
</pre>
<div id="attachment_561" class="wp-caption alignnone" style="width: 829px"><a href="http://www.sqlskills.com/blogs/erin/wp-content/uploads/2013/03/indexrebuild_default_maxdop1.png"><img class=" wp-image-561  " alt="indexrebuild default maxdop1 1024x509 SQL Server Maintenance Plans and Parallelism   Index Rebuilds" MAXDOP=1 for instance" src="http://www.sqlskills.com/blogs/erin/wp-content/uploads/2013/03/indexrebuild_default_maxdop1-1024x509.png" width="819" height="407" title="SQL Server Maintenance Plans and Parallelism   Index Rebuilds" /></a><p class="wp-caption-text">ALTER INDEX &#8230; REBUILD (default option) &#8211; MAXDOP = 1 for instance</p></div>
<div id="imcontent">The plan shows a DegreeOfParallelism of 0 &#8211; this means that the query did not use parallelism &#8211; and that the plan includes a NonParallelPlanReason* of &#8220;MaxDOPSetToOne&#8221;.  Therefore, if MAXDOP is set to 1 for an instance, and the default ALTER INDEX &#8230; REBUILD statements are used to rebuild indexes &#8211; where the MAXDOP option is <em>not</em> included &#8211; then rebuilds will be single-threaded.  For some well-known applications (e.g. SharePoint, SAP, BizTalk)  it <em>is</em> recommended to set the max degree of parallelism to 1 for the instance.  While that option may be appropriate for application-specific queries, it means that your index rebuild operations may run longer than if parallelism was enabled.  It may be worth modifying your index maintenance script to include the MAXDOP option for ALTER INDEX REBUILD statements.</div>
<p>In the event that you have a max degree of parallelism value above 1 specified for the instance, but you&#8217;re not sure what the &#8220;right&#8221; MAXDOP value should be for your index rebuilds, you can let SQL Server decide.  If you include the WITH (MAXDOP = 0) option in your rebuild syntax, then the optimizer will determine how many CPUs to use, which could be anywhere from 1 to all of the CPUs available to SQL Server.  This is the recommended setting per Books Online, but I would caution you to use this option only if you&#8217;re comfortable with SQL Server potentially using all CPUs for a rebuild.  If you happen to be running other tasks or processes in the database while the rebuilds run &#8211; not ideal, but for a 24&#215;7 solution you often don&#8217;t have a choice &#8211; then you should specify a MAXDOP value below the total number of CPUs available.</p>
<p>Finally, in case you&#8217;re wondering about parallelism and reorganizing indexes&#8230;the WITH (MAXDOP = <em>n</em>) option is not available for ALTER INDEX REORGANIZE, as index reorganization is always a single-threaded operation.  The final post in this series will cover parallelism and the UPDATE STATISTICS command, and if you&#8217;re manually managing statistics and specifying the sample, you don&#8217;t want to miss it!</p>
<p><em>*If you&#8217;re interested, Joe talks about the NonParallelPlanReason attribute  in his post, <a title="SQL Server 2012 Execution Plan's NonParallelPlanReason" href="http://www.sqlskills.com/blogs/joe/sql-server-2012-execution-plans-nonparallelplanreason/">SQL Server 2012 Execution Plan&#8217;s NonParallelPlanReason</a>, which may be useful when you&#8217;re digging into execution plans in SQL Server 2012 and higher. </em></p>
<p>The post <a href="http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-index-rebuild/">SQL Server Maintenance Plans and Parallelism &#8211; Index Rebuilds</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-index-rebuild/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL Server Maintenance Plans and Parallelism &#8211; CHECKDB</title>
		<link>http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-checkdb/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sql-server-maintenance-plans-and-parallelism-checkdb</link>
		<comments>http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-checkdb/#comments</comments>
		<pubDate>Thu, 28 Feb 2013 19:25:35 +0000</pubDate>
		<dc:creator>Erin Stellato</dc:creator>
				<category><![CDATA[Database Maintenance]]></category>
		<category><![CDATA[DBCC]]></category>
		<category><![CDATA[dbcc checkdb]]></category>
		<category><![CDATA[parallelism]]></category>
		<category><![CDATA[sql server maintenenace tasks]]></category>

		<guid isPermaLink="false">http://www.sqlskills.com/blogs/erin/?p=555</guid>
		<description><![CDATA[<p>Many posts and articles that discuss parallelism and SQL Server revolve around query performance and query optimization. Parallelism can affect performance, and some DBAs and database developers spend a great amount of time trying to find the “right” max degree of parallelism (MAXDOP) setting for an instance. Finding that right value is a science and [...]</p><p>The post <a href="http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-checkdb/">SQL Server Maintenance Plans and Parallelism &#8211; CHECKDB</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Many posts and articles that discuss parallelism and SQL Server revolve around query performance and query optimization. Parallelism can affect performance, and some DBAs and database developers spend a great amount of time trying to find the “right” max degree of parallelism (MAXDOP) setting for an instance. Finding that right value is a science and an art, but understanding what degree of parallelism is used by SQL Server for standard maintenance tasks is straight science.</p>
<p><strong>Parallelism and Instance Configuration</strong></p>
<p>To start, I’m working under the assumption that you are familiar with parallelism and understand the implications of leaving max degree of parallelism set to 0, changing it to 1, or setting it to another value. <em>Note: If you’re looking for background reading, I recommend Adam Machanic’s SQL University Parallelism Week posts (<a title="SQL University: Parallelism Week - Introduction" href="http://sqlblog.com/blogs/adam_machanic/archive/2010/05/24/sql-university-parallelism-week-introduction.aspx">Part 1</a>, <a title="SQL University: Parallelism Week - Part 2, Query Processing" href="http://sqlblog.com/blogs/adam_machanic/archive/2010/05/26/sql-university-parallelism-week-part-2-query-processing.aspx">Part 2</a>, and <a title="SQL University: Parallelism Week - Part 3, Settings and Options" href="http://sqlblog.com/blogs/adam_machanic/archive/2010/05/28/sql-university-parallelism-week-part-3-settings-and-options.aspx">Part 3</a>), and Paul White’s article, <a title="Understanding and Using Parallelism in SQL Server" href="http://www.simple-talk.com/sql/learn-sql-server/understanding-and-using-parallelism-in-sql-server/">Understanding and Using Parallelism in SQL Server</a>.</em> To understand what impact max degree of parallelism has on maintenance tasks, we need to know its value for an instance, and the easiest way to find it is via sys.configurations:</p>
<pre class="brush: sql; title: ; notranslate">
SELECT [name], [value], [value_in_use]
FROM [sys].[configurations]
WHERE [name] = 'max degree of parallelism';
</pre>
<p>In my environment, it’s set to 4 for purposes of this demo (I have 8 logical processors on my laptop):</p>
<div id="attachment_551" class="wp-caption alignnone" style="width: 495px"><a href="http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-index-rebuild/maxdop/" rel="attachment wp-att-551"><img class="size-full wp-image-551" alt="MAXDOP SQL Server Maintenance Plans and Parallelism   CHECKDB" src="http://www.sqlskills.com/blogs/erin/wp-content/uploads/2013/02/MAXDOP.jpg" width="485" height="86" title="SQL Server Maintenance Plans and Parallelism   CHECKDB" /></a><p class="wp-caption-text">max degree of parallelism configuration</p></div>
<p>The three maintenance tasks I want to cover in this series are database consistency checks, index rebuilds, and statistic updates.  As you might have guessed from the title, this first post will cover consistency checks.</p>
<p><strong>Database Consistency Checks</strong></p>
<p>In November of last year I blogged about <a title="DBCC CHECKDB Parallel Checks and SQL Server Edition" href="http://www.sqlskills.com/blogs/erin/dbcc-checkdb-parallel-checks-and-sql-server-edition/">DBCC CHECKDB and parallel checks</a> due to an inconsistency I found in Books Online. The inconsistency has since been fixed in BOL (hooray for Connect items!), and the short story is that any consistency check (CHECKDB, CHECKTABLE, CHECKFILEGROUP, and CHECKCATALOG) is single-threaded in Standard Edition. Regardless of the number of cores in your server and the MAXDOP setting for the instance, any CHECK command will be single-threaded.</p>
<p>In Enterprise Edition, checks can be done in parallel, and the max degree of parallelism is determined by the Query Processor. The Query Processor respects the max degree of parallelism setting for the instance, therefore since I have MAXDOP = 4 for my instance, up to four processors can be used by a CHECK command. There is no MAXDOP option that can be included with a CHECK command; it always respects the value set for the instance.  We can prove this using Extended Events and the sp_statement_completed and query_post_execution_showplan events.</p>
<p><span style="color: #ff0000;">**Important note here: it is <strong><em>NOT</em> </strong>recommended to capture the query_post_execution_showplan event against a live, production system. This event generates <strong><em>significant</em> </strong>performance overhead, and you are warned of this when configuring the session via the GUI. If you repeat any of the demos here, please make sure to execute them against a test environment. I really do not want you to bring down your production environment.**</span></p>
<p>Here are the statements to create the event session, start it, run CHECKDB, then stop the event session. I am using a file target to capture the output, and the path is C:\temp. You may need to modify this path for your environment.</p>
<pre class="brush: sql; title: ; notranslate">
CREATE EVENT SESSION [CapturePlans] ON SERVER
ADD EVENT sqlserver.query_post_execution_showplan(
ACTION(sqlserver.plan_handle,sqlserver.sql_text)),
ADD EVENT sqlserver.sp_statement_completed(
ACTION(sqlserver.sql_text))
ADD TARGET package0.event_file(SET filename=N'C:\temp\CapturePlans.xel'),
ADD TARGET package0.ring_buffer(SET max_memory=(102400))
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,
MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF);
GO

ALTER EVENT SESSION [CapturePlans]
ON SERVER
STATE=START;
GO

DBCC CHECKDB (AdventureWorks2012) WITH NO_INFOMSGS;
GO

ALTER EVENT SESSION [CapturePlans]
ON SERVER
STATE=STOP;
GO
</pre>
<p>After stopping the event session, open the .xel file from C:\temp in Management Studio and add the sql_text column to the display to easily find the CHECKDB statement.  In the  screen shot below the query_post_execution_showplan event is highlighted, you can see the sql_text, and I hovered over the showplan_xml to show the first part of the xml version of the plan. Note the red box around QueryPlan DegreeofParallelism&#8230;it&#8217;s 4, as expected because it&#8217;s set to that for the instance.  The query plan is also included in the screen shot to show the full plan.</p>
<div id="attachment_557" class="wp-caption alignnone" style="width: 1034px"><a href="http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-checkdb/checkdb_isparallel/" rel="attachment wp-att-557"><img class="size-large wp-image-557" alt="checkdb isparallel 1024x420 SQL Server Maintenance Plans and Parallelism   CHECKDB" src="http://www.sqlskills.com/blogs/erin/wp-content/uploads/2013/02/checkdb_isparallel-1024x420.png" width="1024" height="420" title="SQL Server Maintenance Plans and Parallelism   CHECKDB" /></a><p class="wp-caption-text">DBCC CHECKDB with parallelism</p></div>
<p>To view the full XML for the plan, just double-click the showplan_xml value and it will open in a new window. Just for fun, if we change MAXDOP for the instance to 1 (which I&#8217;ve seen in some OLTP environments) note that CHECKDB now runs single-threaded, regardless of SQL Server version.</p>
<pre class="brush: sql; title: ; notranslate">
sp_configure 'show advanced options', 1;
GO
RECONFIGURE WITH OVERRIDE;
GO
sp_configure 'max degree of parallelism', 1;
GO
RECONFIGURE WITH OVERRIDE;
GO

ALTER EVENT SESSION [CapturePlans]
ON SERVER
STATE=START;
GO

DBCC CHECKDB (AdventureWorks2012) WITH NO_INFOMSGS;
GO

ALTER EVENT SESSION [CapturePlans]
ON SERVER
STATE=STOP;
GO
</pre>
<p>Again, if we open the most recent .xel file in C:\temp and add the sql_text column, we can see that CHECKDB runs single-threaded:</p>
<div id="attachment_556" class="wp-caption alignnone" style="width: 1034px"><a href="http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-checkdb/checkdb_noparallel/" rel="attachment wp-att-556"><img class="size-large wp-image-556" alt="checkdb noparallel 1024x420 SQL Server Maintenance Plans and Parallelism   CHECKDB" src="http://www.sqlskills.com/blogs/erin/wp-content/uploads/2013/02/checkdb_noparallel-1024x420.png" width="1024" height="420" title="SQL Server Maintenance Plans and Parallelism   CHECKDB" /></a><p class="wp-caption-text">DBCC CHECKDB single-threaded</p></div>
<p>Realize that if max degree of parallelism is set to 1 for instance, and you&#8217;re running Enterprise Edition, your consistency checks could be taking longer than necessary.  The only way to work around this in Enterprise Edition is to change the max degree of parallelism for the instance, run the check, then change it back.  Alternatively, in some enterprise environments that are 24/7, it may not be desirable to have CHECK commands use a high number of threads.  In that case, lowering max degree of parallelism while CHECKs run may not be an option &#8211; you may not want to impact the performance of your regular queries.  Instead, you could disable parallel checking for CHECK commands entirely using <a title="Trace Flags" href="http://msdn.microsoft.com/en-us/library/ms188396.aspx">trace flag 2528</a>, or you could use Resource Governor to limit CPU use. And one final, interesting note (thanks Paul): CHECKALLOC is always single-threaded, regardless of Edition.</p>
<p>In the next post we&#8217;ll look at parallelism and index maintenance.</p>
<p>The post <a href="http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-checkdb/">SQL Server Maintenance Plans and Parallelism &#8211; CHECKDB</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.sqlskills.com/blogs/erin/sql-server-maintenance-plans-and-parallelism-checkdb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL Server Baselines Series on SQLServerCentral.com</title>
		<link>http://www.sqlskills.com/blogs/erin/sql-server-baselines-series-on-sqlservercentral-com/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sql-server-baselines-series-on-sqlservercentral-com</link>
		<comments>http://www.sqlskills.com/blogs/erin/sql-server-baselines-series-on-sqlservercentral-com/#comments</comments>
		<pubDate>Mon, 04 Feb 2013 14:24:59 +0000</pubDate>
		<dc:creator>Erin Stellato</dc:creator>
				<category><![CDATA[Baselines]]></category>
		<category><![CDATA[sql server baselines]]></category>

		<guid isPermaLink="false">http://www.sqlskills.com/blogs/erin/?p=545</guid>
		<description><![CDATA[<p>Today the fourth article in my baselines series was published on SQLServerCentral.com.  Listed below are the links to all of the articles, and I’ve decided to continue the series on my blog here.  I truly believe that every SQL Server environment can benefit from having baselines.  I say that all the time, I know, and [...]</p><p>The post <a href="http://www.sqlskills.com/blogs/erin/sql-server-baselines-series-on-sqlservercentral-com/">SQL Server Baselines Series on SQLServerCentral.com</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Today the fourth article in my baselines series was published on SQLServerCentral.com.  Listed below are the links to all of the articles, and I’ve decided to continue the series on my blog here.  I truly believe that every SQL Server environment can benefit from having baselines.  I say that all the time, I know, and people seem to agree with me <img src='http://www.sqlskills.com/blogs/erin/wp-includes/images/smilies/icon_smile.gif' alt="icon smile SQL Server Baselines Series on SQLServerCentral.com" class='wp-smiley' title="SQL Server Baselines Series on SQLServerCentral.com" />   But yet there are <i>many</i> systems out there that don’t have baseline data.  The biggest roadblock that I see is deciding <i>what</i> to capture, and then writing the scripts to capture what you want.  The goal of the series I wrote for SQLServerCentral.com was to provide background about why baselines are important, and provide a set of scripts to get started.  The value of baselines may seem obvious to you, but for new DBAs the benefits may not be as apparent, so taking a few minutes to step through them is useful.  The scripts I provide are straight-forward and there’s a reason for that: It’s not rocket science.  Capturing baseline data is really easy to do, and my goal is to provide scripts so DBAs can quickly and easily start capturing data, and hopefully once people realize how simple it was, they will develop their own scripts.</p>
<p>But just because I’ve provided a few scripts doesn’t mean I’m done.  I am going to continue to develop and post scripts here that DBAs can use to set up baselines in their own environment. I recognize that there are some excellent applications available from third party vendors that will capture baseline data, and if your company has the budget to purchase such an application, I would highly recommend doing so. My scripts are not a replacement for any of those applications. But for those of you who don’t have the budget, or perhaps need some data in order to make a case for <i>why</i> you need one of those applications, these scripts will get you started.</p>
<p>If you have any feedback about the scripts, or requests for what I write next, feel free to email me! The scripts are a work in progress and I plan to continually work to make them better.</p>
<p><a href="http://www.sqlservercentral.com/articles/baselines/94657/">5 Reasons You Must Start Capturing Baseline Data</a></p>
<p><a href="http://www.sqlservercentral.com/articles/baselines/94656/">Back to Basics: Capturing Baselines on Production SQL Servers</a></p>
<p><a href="http://www.sqlservercentral.com/articles/baselines/96059/">Capturing Baselines on SQL Server: Where’s My Space?</a></p>
<p><a href="http://www.sqlservercentral.com/articles/baselines/96270/">Capturing Baselines on SQL Server: Wait Statistics</a></p>
<p>The post <a href="http://www.sqlskills.com/blogs/erin/sql-server-baselines-series-on-sqlservercentral-com/">SQL Server Baselines Series on SQLServerCentral.com</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.sqlskills.com/blogs/erin/sql-server-baselines-series-on-sqlservercentral-com/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Understanding When Statistics Will Automatically Update</title>
		<link>http://www.sqlskills.com/blogs/erin/understanding-when-statistics-will-automatically-update/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=understanding-when-statistics-will-automatically-update</link>
		<comments>http://www.sqlskills.com/blogs/erin/understanding-when-statistics-will-automatically-update/#comments</comments>
		<pubDate>Fri, 04 Jan 2013 15:35:54 +0000</pubDate>
		<dc:creator>Erin Stellato</dc:creator>
				<category><![CDATA[Statistics]]></category>

		<guid isPermaLink="false">http://www.sqlskills.com/blogs/erin/?p=500</guid>
		<description><![CDATA[<p>During the PASS Summit in November I presented a session on Demystifying Database Statistics (if you attended Summit but missed it, you can stream it from here). During the session I went through a demo that showed the automatic update of a statistic. The database had the Auto Update Statistics option enabled, and I had [...]</p><p>The post <a href="http://www.sqlskills.com/blogs/erin/understanding-when-statistics-will-automatically-update/">Understanding When Statistics Will Automatically Update</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>During the PASS Summit in November I presented a session on <a title="Demystifying Database Statistics" href="http://www.sqlpass.org/summit/2012/Sessions/SessionDetails.aspx?sid=3376">Demystifying Database Statistics</a> (if you attended Summit but missed it, you can stream it from <a title="Demystifying Database Statistics stream" href="http://archive.pass.bethereglobal.com/archive/3376/" target="_blank">here</a>). During the session I went through a demo that showed the automatic update of a statistic. The database had the <b>Auto Update Statistics</b> option enabled, and I had added almost 25,000 rows to a table with 121,000 rows. The number of rows added via the bulk import was just over the limit to trigger an auto-update of statistics for the next query, which I showed. I had many people ask why statistics did not update immediately <i>after</i> the bulk load of the 25,000 rows completed, so I want to step through the demo that I did at Summit to clarify when an automatic update will occur.</p>
<p><strong>The Setup</strong></p>
<p>Start with a copy of the <code>AdventureWorks2012</code> database, which you can download from <a title="SQL Server databases on Code Plex" href="https://msftdbprodsamples.codeplex.com/">CodePlex</a>. Ensure that the <b>Auto Update Statistics </b>option is enabled:</p>
<pre class="brush: sql; title: ; notranslate">
IF (SELECT COUNT(*) FROM [sys].[databases] WHERE [name] = 'AdventureWorks2012' AND [is_auto_create_stats_on] = 0) = 0
BEGIN
ALTER DATABASE [AdventureWorks2012] SET AUTO_UPDATE_STATISTICS ON
END;
</pre>
<p>We’re going to use a copy of the <code>Sales.SalesOrderDetail</code> table for the demo. After we create the table, we will check to see when statistics last updated. We can use various methods to check statistics date, such as <code><a href="http://msdn.microsoft.com/en-us/library/ms174384.aspx">DBCC SHOW_STATISTICS</a></code> or <code><a href="http://msdn.microsoft.com/en-us/library/ms190330.aspx">STATS_DATE</a></code>, but since the release of SP1 for SQL Server 2012, I have exclusively used <code><a href="http://msdn.microsoft.com/en-us/library/jj553546%28v=sql.105%29.aspx">sys.dm_db_stats_properties</a></code> to get this information.</p>
<pre class="brush: sql; title: ; notranslate">
USE [AdventureWorks2012];
GO
SELECT *
INTO [Sales].[TestSalesOrderDetail]
FROM [Sales].[SalesOrderDetail];
GO
CREATE CLUSTERED INDEX [PK_SalesOrderDetail_SalesOrderID_SalesOrderDetailID] ON [Sales].[TestSalesOrderDetail] ([SalesOrderID], [SalesOrderDetailID]);
GO
CREATE UNIQUE NONCLUSTERED INDEX [AK_TestSalesOrderDetail_rowguid] ON [Sales].[TestSalesOrderDetail] ([rowguid]);
GO
CREATE NONCLUSTERED INDEX [IX_TestSalesOrderDetail_ProductID] ON [Sales].[TestSalesOrderDetail] ([ProductID]);
GO
SELECT
OBJECT_NAME([sp].[object_id]) AS &quot;Table&quot;,
[sp].[stats_id] AS &quot;Statistic ID&quot;,
[s].[name] AS &quot;Statistic&quot;,
[sp].[last_updated] AS &quot;Last Updated&quot;,
[sp].[rows],
[sp].[rows_sampled],
[sp].[unfiltered_rows],
[sp].[modification_counter] AS &quot;Modifications&quot;
FROM [sys].[stats] AS [s]
OUTER APPLY sys.dm_db_stats_properties ([s].[object_id],[s].[stats_id]) AS [sp]
WHERE [s].[object_id] = OBJECT_ID(N'Sales.TestSalesOrderDetail');
</pre>
<p>Here&#8217;s the output:</p>
<div id="attachment_502" class="wp-caption alignnone" style="width: 1034px"><a href="http://www.sqlskills.com/blogs/erin/understanding-when-statistics-will-automatically-update/stats_auto_update_1/" rel="attachment wp-att-502"><img class="size-large wp-image-502 " alt="stats auto update 1 1024x82 Understanding When Statistics Will Automatically Update" src="http://www.sqlskills.com/blogs/erin/wp-content/uploads/2013/01/stats_auto_update_1-1024x82.jpg" width="1024" height="82" title="Understanding When Statistics Will Automatically Update" /></a><p class="wp-caption-text">sys.dm_db_stats_properties after initially creating the table</p></div>
<p>This is my go-to DMV for statistics because in addition to including the date that statistics were last updated and row information, I also get a count of modifications since the last statistic update. I just created the table, so the Last Updated date is current, and I have not made any changes so the modification count is 0.</p>
<p><strong>Invalidating Statistics</strong></p>
<p>For my demo I want to bulk insert enough rows to invalidate the statistics. SQL Server has pre-determined thresholds where it considers statistics to be out-of-date and therefore invalid. The technical article, <a href="http://msdn.microsoft.com/en-us/library/dd535534%28v=sql.100%29.aspx">Statistics Used by the Query Optimizer in Microsoft SQL Server 2008</a>, documents these thresholds. For a regular table, statistics are out of date when:</p>
<blockquote><p><span style="font-family: Times New Roman; font-size: medium;">o The table size has gone from 0 to &gt;0 rows (test 1).</span></p>
<p><span style="font-family: Times New Roman; font-size: medium;">o The number of rows in the table when the statistics were gathered was 500 or less, and the colmodctr of the leading column of the statistics object has changed by more than 500 since then (test 2).</span></p>
<p><span style="font-family: Times New Roman; font-size: medium;">o The table had more than 500 rows when the statistics were gathered, and the colmodctr of the leading column of the statistics object has changed by more than 500 + 20% of the number of rows in the table when the statistics were gathered (test 3).</span></p></blockquote>
<p>The Sales.SalesOrderDetail table has 121317 rows:</p>
<p style="padding-left: 30px;">(121317 * 0.20) + 500 = 24764</p>
<p>The bulk insert below loads 24775 rows, which should be enough to invalidate statistics. Download the .txt file for the bulk insert <a href="http://www.sqlskills.com/blogs/erin/wp-content/uploads/2013/01/sod.zip">here</a>.</p>
<pre class="brush: sql; title: ; notranslate">
BULK INSERT AdventureWorks2012.Sales.TestSalesOrderDetail
FROM 'C:\SQLStuff\Statistics\Data\sod.txt'
WITH
(
DATAFILETYPE = 'native',
TABLOCK
);
(24775 row(s) affected)
</pre>
<p>After the bulk load completes, re-run the query against <code>sys.dm_db_stats_properties</code> and review the output:</p>
<div id="attachment_503" class="wp-caption alignnone" style="width: 1034px"><a href="http://www.sqlskills.com/blogs/erin/understanding-when-statistics-will-automatically-update/stats_auto_update_2/" rel="attachment wp-att-503"><img class="size-large wp-image-503 " alt="stats auto update 2 1024x82 Understanding When Statistics Will Automatically Update" src="http://www.sqlskills.com/blogs/erin/wp-content/uploads/2013/01/stats_auto_update_2-1024x82.jpg" width="1024" height="82" title="Understanding When Statistics Will Automatically Update" /></a><p class="wp-caption-text">sys.dm_db_stats_properties after the bulk import</p></div>
<p>The statistics have not updated, but the modification counter has changed, as expected. The statistics are now out of date based on the threshold defined previously, and we would expect that a query or data modification against <code>Sales.TestSalesOrderDetail</code> would trigger an update of statistics. But before we try that, let’s review what causes the automatic update.</p>
<p>The aforementioned article states:</p>
<blockquote><p><span style="font-family: Times New Roman; font-size: medium;">The statistics auto update is triggered by query optimization or by execution of a compiled plan, and it involves only a subset of the columns referred to in the query.</span></p>
<p><span style="font-family: Times New Roman; font-size: medium;">When a query is first compiled, if the optimizer needs a particular statistics object, and that statistics object exists, the statistics object is updated if it is out of date. When a query is executed and its plan is in the cache, the statistics the plan depends on are checked to see if they are out of date. If so, the plan is removed from the cache, and during recompilation of the query, the statistics are updated. The plan also is removed from the cache if any of the statistics it depends on have changed.</span></p></blockquote>
<p>To be clear, if a query plan exists in cache and that plan uses specific statistics, when the query executes SQL Server checks to see if any of the statistics used in the plan are out of date. If they are, then the automatic update of those statistics occurs.</p>
<p>If a plan does not exist in cache for a query, then if the optimizer uses a statistics object that is out of date when the plan compiles, SQL Server will automatically update those statistics.</p>
<p><strong>Invoking the Automatic Update</strong></p>
<p>We have not run any query against <code>Sales.TestSalesOrderDetail</code> except our bulk insert. At the time that the query compiled for the bulk insert, no statistics for Sales.TestSalesOrderDetail were out of date; therefore no statistics required an automatic update.</p>
<p>Now let’s issue an update against <code>Sales.TestSalesOrderDetail</code> that will change the <code>ProductID</code> for a specific <code>SalesOrderID</code>, and then query <code>sys.dm_db_stats_properties</code>:</p>
<pre class="brush: sql; title: ; notranslate">
UPDATE Sales.TestSalesOrderDetail SET ProductID = 717 WHERE SalesOrderID = 75123;
GO
(3 row(s) affected)
</pre>
<p>Output:</p>
<div id="attachment_504" class="wp-caption alignnone" style="width: 1034px"><a href="http://www.sqlskills.com/blogs/erin/understanding-when-statistics-will-automatically-update/stats_auto_update_3/" rel="attachment wp-att-504"><img class="size-large wp-image-504 " alt="stats auto update 3 1024x82 Understanding When Statistics Will Automatically Update" src="http://www.sqlskills.com/blogs/erin/wp-content/uploads/2013/01/stats_auto_update_3-1024x82.jpg" width="1024" height="82" title="Understanding When Statistics Will Automatically Update" /></a><p class="wp-caption-text">sys.dm_db_stats_properties after the update</p></div>
<p>We can see that the <code>PK_SalesOrderDetail_SalesOrderID_SalesOrderDetailID</code> statistic object automatically updated. We could simply assume that the optimizer used this object in the plan. However, in SQL Server 2012 we can look at the plan XML and confirm this.</p>
<p>In his post, <a href="http://blogfabiano.com/2012/07/03/statistics-used-in-a-cached-query-plan/">Statistics used in a cached query plan</a>, Fabiano Neves Amorim describes a method to capture statistics information from the plan. <em>Please</em> note the following:</p>
<ul>
<li>This information is only available in SQL Server 2012 and higher.</li>
<li>This query requires use of an undocumented trace flag. I do not recommend using this trace flag in a Production environment.</li>
<li>This query interrogates the plan cache. The plan cache may be very large for your system, depending on the amount of memory on the server. Before querying the plan, I recommend setting the transaction isolation level to READ UNCOMMITTED, and also recommend using OPTION (MAXDOP 1) to limit CPU utilization. The query may take longer to execute, but it reduces the impact on other queries executing concurrently.</li>
</ul>
<p>If we query the plan cache using Fabio’s query, we get the following information:</p>
<pre class="brush: sql; title: ; notranslate">
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
GO
DBCC TRACEON (8666);
GO
WITH XMLNAMESPACES ('http://schemas.microsoft.com/sqlserver/2004/07/showplan' as p)
SELECT qt.text AS SQLCommand,
qp.query_plan,
StatsUsed.XMLCol.value('@FieldValue','NVarChar(500)') AS StatsName
FROM sys.dm_exec_cached_plans cp
CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) qp
CROSS APPLY sys.dm_exec_sql_text (cp.plan_handle) qt
CROSS APPLY query_plan.nodes('//p:Field[@FieldName=&quot;wszStatName&quot;]') StatsUsed(XMLCol)
WHERE qt.text LIKE '%UPDATE%'
AND qt.text LIKE '%ProductID%';
GO
DBCC TRACEOFF(8666);
GO
</pre>
<p>Output:</p>
<div id="attachment_505" class="wp-caption alignnone" style="width: 1034px"><a href="http://www.sqlskills.com/blogs/erin/understanding-when-statistics-will-automatically-update/stats_auto_update_4/" rel="attachment wp-att-505"><img class="size-large wp-image-505 " alt="stats auto update 4 1024x47 Understanding When Statistics Will Automatically Update" src="http://www.sqlskills.com/blogs/erin/wp-content/uploads/2013/01/stats_auto_update_4-1024x47.jpg" width="1024" height="47" title="Understanding When Statistics Will Automatically Update" /></a><p class="wp-caption-text">statistic object used in the query plan</p></div>
<p>The output confirms that the optimizer used the <code>PK_SalesOrderDetail_SalesOrderID_SalesOrderDetailID</code> statistic object in the query plan, and because it was out of date, SQL Server automatically updated it.</p>
<p>If you are running earlier versions of SQL Server, you can see what statistics the optimizer loads using the undocumented trace flags 9292 and 9204. Paul White has an excellent post, <a href="http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx">How to Find the Statistics Used to Compile an Execution Plan</a>, which I recommend reading if you’re interested.</p>
<p>One thing I want to point out: the <code>IX_TestSalesOrderDetail_ProductID</code> statistic, which has <code>ProductID</code> as its key, did not update automatically when the UPDATE query executed. This is expected. Even though the statement modified <code>ProductID</code> for three rows (the modification counter for the statistic increased from 24775 to 24778), the optimizer did not use that statistic in the plan. If the plan does not use a statistic, the statistic will not automatically update, even if the query modifies columns in said statistic key.</p>
<p><strong>Summary</strong></p>
<p>As I stated initially, I wanted to write this post to clear up any confusion surrounding automatic updates for statistics. Even if a statistic becomes outdated as <i>the result of</i> a modification, it will not automatically update <i>after</i> the modification completes. The statistic will automatically update the <i>next time</i> a query plan uses it.</p>
<p>To reiterate (yes, this might be overkill), SQL Server will automatically update a statistic when:</p>
<ul>
<li>A query compiles for the first time, and a statistic used in the plan is out of date</li>
<li>A query has an existing query plan, but a statistic in the plan is out of date</li>
</ul>
<p>For those that attended my session at Summit, I hope this helps address any questions you might have still had. If not, please leave a comment and I will get back to you!</p>
<p>The post <a href="http://www.sqlskills.com/blogs/erin/understanding-when-statistics-will-automatically-update/">Understanding When Statistics Will Automatically Update</a> appeared first on <a href="http://www.sqlskills.com/blogs/erin">Erin Stellato</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.sqlskills.com/blogs/erin/understanding-when-statistics-will-automatically-update/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using wincache
Database Caching 19/39 queries in 0.015 seconds using wincache
Object Caching 1994/2012 objects using wincache

 Served from: www.sqlskills.com @ 2013-06-19 17:33:58 by W3 Total Cache -->