<?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>Strate SQL &#187; Deadlocks</title>
	<atom:link href="http://www.jasonstrate.com/index.php/category/performancetuning/deadlocks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jasonstrate.com</link>
	<description>Questions, answers, opinions and scripts from a SQL Server DBA</description>
	<lastBuildDate>Wed, 08 Sep 2010 13:30:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Index Those Foreign Keys</title>
		<link>http://www.jasonstrate.com/index.php/2010/06/index-those-foreign-keys/</link>
		<comments>http://www.jasonstrate.com/index.php/2010/06/index-those-foreign-keys/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 21:00:59 +0000</pubDate>
		<dc:creator>jstrate</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Deadlocks]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[SQLServerSyndication]]></category>
		<category><![CDATA[Indexing]]></category>

		<guid isPermaLink="false">http://www.jasonstrate.com/?p=486</guid>
		<description><![CDATA[Today started with some quality time getting to know a deadlock that had occurred. While working through the deadlock, I noticed that there were a number of foreign key relationships that weren&#8217;t indexed on the parent side of the relationship.
I am going to skip over the why to index foreign keys and save that for [...]


Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2009/01/find-duplicate-foreign-keys/' rel='bookmark' title='Permanent Link: Find Duplicate Foreign Keys'>Find Duplicate Foreign Keys</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/07/gotta-stop-violating-foreign-keys/' rel='bookmark' title='Permanent Link: Gotta Stop Violating Foreign Keys'>Gotta Stop Violating Foreign Keys</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/02/change-trusted-state-of-foreign-keys/' rel='bookmark' title='Permanent Link: Change Trusted State of Foreign Keys'>Change Trusted State of Foreign Keys</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F06%2Findex-those-foreign-keys%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F06%2Findex-those-foreign-keys%2F" height="61" width="51" /></a></div><p><a title="Lego Deadlock" href="http://www.flickr.com/photos/oskay/265879129/"><img style="margin: 0px 0px 5px 5px; display: inline;" src="http://farm1.static.flickr.com/119/265879129_2b6b17edf2.jpg" border="0" alt="Lego Deadlock" width="199" height="132" align="right" /></a>Today started with some quality time getting to know a deadlock that had occurred. While working through the deadlock, I noticed that there were a number of foreign key relationships that weren&#8217;t indexed on the parent side of the relationship.</p>
<p>I am going to skip over the why to index foreign keys and save that for a later point when I have more time to go through it with some really pretty pictures. Today though, I want to share the scripts that I put together to look for these situations and help prevent issues related to them.</p>
<h2>Brute Force Indexing</h2>
<p>This first script is a brute force attack on this need. If you set the output for text results in SQL Server Management Studio (SSMS) you&#8217;ll get a script with all of the indexes you&#8217;ll need to cover all of your foreign key relationships.</p>
<pre class="brush: sql; ">

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SET NOCOUNT ON

;WITH cIndexes
AS (
SELECT i.object_id
,i.name
,(SELECT QUOTENAME(ic.column_id,&#039;(&#039;)
FROM sys.index_columns ic
WHERE i.object_id = ic.object_id
AND i.index_id = ic.index_id
AND is_included_column = 0
ORDER BY key_ordinal ASC
FOR XML PATH(&#039;&#039;)) AS indexed_compare
FROM sys.indexes i
), cForeignKeys
AS (
SELECT fk.name AS foreign_key_name
,&#039;PARENT&#039; as foreign_key_type
,fkc.parent_object_id AS object_id
,STUFF((SELECT &#039;, &#039; + QUOTENAME(c.name)
FROM sys.foreign_key_columns ifkc
INNER JOIN sys.columns c ON ifkc.parent_object_id = c.object_id AND ifkc.parent_column_id = c.column_id
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)), 1, 2, &#039;&#039;) AS fk_columns
,(SELECT QUOTENAME(ifkc.parent_column_id,&#039;(&#039;)
FROM sys.foreign_key_columns ifkc
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)) AS fk_columns_compare
FROM sys.foreign_keys fk
INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id
WHERE fkc.constraint_column_id = 1
UNION ALL
SELECT fk.name AS foreign_key_name
,&#039;REFERENCED&#039; as foreign_key_type
,fkc.referenced_object_id AS object_id
,STUFF((SELECT &#039;, &#039; + QUOTENAME(c.name)
FROM sys.foreign_key_columns ifkc
INNER JOIN sys.columns c ON ifkc.referenced_object_id = c.object_id AND ifkc.referenced_column_id = c.column_id
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)), 1, 2, &#039;&#039;) AS fk_columns
,(SELECT QUOTENAME(ifkc.referenced_column_id,&#039;(&#039;)
FROM sys.foreign_key_columns ifkc
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)) AS fk_columns_compare
FROM sys.foreign_keys fk
INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id
WHERE fkc.constraint_column_id = 1
), cRowCount
AS (
SELECT object_id
,SUM(row_count) AS row_count
FROM sys.dm_db_partition_stats ps
WHERE index_id IN (1,0)
GROUP BY object_id
)
SELECT
&#039;--Missing foreign key index for &#039;+fk.foreign_key_name+CHAR(13)+CHAR(10)+&#039;GO&#039;+CHAR(13)+CHAR(10)+
+&#039;CREATE NONCLUSTERED INDEX FKIX_&#039;+OBJECT_NAME(fk.object_id)+&#039;_&#039;+REPLACE(REPLACE(REPLACE(REPLACE(fk.fk_columns,&#039;,&#039;,&#039;&#039;),&#039;[&#039;,&#039;&#039;),&#039;]&#039;,&#039;&#039;),&#039; &#039;,&#039;&#039;)
+CHAR(13)+CHAR(10)+
+&#039;ON [dbo].[&#039;+OBJECT_NAME(fk.object_id)+&#039;] (&#039;+fk.fk_columns+&#039;)&#039;+CHAR(13)+CHAR(10)+
+&#039;GO&#039;+CHAR(13)+CHAR(10)+CHAR(13)+CHAR(10)
FROM cForeignKeys fk
INNER JOIN cRowCount rc ON fk.object_id = rc.object_id
LEFT OUTER JOIN cIndexes i ON fk.object_id = i.object_id AND i.indexed_compare LIKE fk.fk_columns_compare + &#039;%&#039;
WHERE i.name IS NULL
ORDER BY OBJECT_NAME(fk.object_id), fk.fk_columns
</pre>
<h2>Foreign Key Monitoring</h2>
<p>This second script accommodates for those situations when you may not want to just index every foreign key that is out there. Maybe there&#8217;s a really old table in the database with a foreign key relationship that just doesn&#8217;t matter any more. Is it worth indexing along a vector that won&#8217;t lead to any performance impact &#8211; either negative or positive? Most likely not.</p>
<p>For this script, the results output a list of foreign keys relationships that are not fully indexed. Included in the result script is a column with XML data in it that contains a script for creating an index. You may notice that the format for this is very similar to the schema created when outputtingmmissing Indexes from execution plans.</p>
<pre class="brush: sql; ">

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

;WITH cIndexes
AS (
SELECT i.object_id
,i.name
,(SELECT QUOTENAME(ic.column_id,&#039;(&#039;)
FROM sys.index_columns ic
WHERE i.object_id = ic.object_id
AND i.index_id = ic.index_id
AND is_included_column = 0
ORDER BY key_ordinal ASC
FOR XML PATH(&#039;&#039;)) AS indexed_compare
FROM sys.indexes i
), cForeignKeys
AS (
SELECT fk.name AS foreign_key_name
,&#039;PARENT&#039; as foreign_key_type
,fkc.parent_object_id AS object_id
,STUFF((SELECT &#039;, &#039; + QUOTENAME(c.name)
FROM sys.foreign_key_columns ifkc
INNER JOIN sys.columns c ON ifkc.parent_object_id = c.object_id AND ifkc.parent_column_id = c.column_id
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)), 1, 2, &#039;&#039;) AS fk_columns
,(SELECT QUOTENAME(ifkc.parent_column_id,&#039;(&#039;)
FROM sys.foreign_key_columns ifkc
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)) AS fk_columns_compare
FROM sys.foreign_keys fk
INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id
WHERE fkc.constraint_column_id = 1
UNION ALL
SELECT fk.name AS foreign_key_name
,&#039;REFERENCED&#039; as foreign_key_type
,fkc.referenced_object_id AS object_id
,STUFF((SELECT &#039;, &#039; + QUOTENAME(c.name)
FROM sys.foreign_key_columns ifkc
INNER JOIN sys.columns c ON ifkc.referenced_object_id = c.object_id AND ifkc.referenced_column_id = c.column_id
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)), 1, 2, &#039;&#039;) AS fk_columns
,(SELECT QUOTENAME(ifkc.referenced_column_id,&#039;(&#039;)
FROM sys.foreign_key_columns ifkc
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)) AS fk_columns_compare
FROM sys.foreign_keys fk
INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id
WHERE fkc.constraint_column_id = 1
), cRowCount
AS (
SELECT object_id
,SUM(row_count) AS row_count
FROM sys.dm_db_partition_stats ps
WHERE index_id IN (1,0)
GROUP BY object_id
)
SELECT
fk.foreign_key_name
,OBJECT_NAME(fk.object_id) AS fk_table_name
,fk.fk_columns
,rc.row_count AS row_count
,CAST(&#039;&lt;!--dex  &#039;+CHAR(13)+CHAR(10)+&#039;Missing foreign key index for &#039;+fk.foreign_key_name+CHAR(13)+CHAR(10)+CHAR(13)+CHAR(10)+&#039;USE [&#039;+DB_NAME()+&#039;]&#039;&lt;br--&gt; +CHAR(13)+CHAR(10)+&#039;GO&#039;+CHAR(13)+CHAR(10)+
+&#039;CREATE NONCLUSTERED INDEX []&#039;+CHAR(13)+CHAR(10)+
+&#039;ON [dbo].[&#039;+OBJECT_NAME(fk.object_id)+&#039;] (&#039;+fk.fk_columns+&#039;)&#039;+CHAR(13)+CHAR(10)+
+&#039;GO&#039;+CHAR(13)+CHAR(10)+&#039;--?&gt;&#039; AS xml) foreign_key_index_schema
FROM cForeignKeys fk
INNER JOIN cRowCount rc ON fk.object_id = rc.object_id
LEFT OUTER JOIN cIndexes i ON fk.object_id = i.object_id AND i.indexed_compare LIKE fk.fk_columns_compare + &#039;%&#039;
WHERE i.name IS NULL
ORDER BY OBJECT_NAME(fk.object_id), fk.fk_columns
</pre>
<h2>Closing Up</h2>
<p>The DDL schema output in these scripts is very basic. It doesn&#8217;t account for potentially important things like partitions and filegroups. Obviously, you&#8217;ll need to modify this for your own environment and don&#8217;t just run this on production.</p>
<p>I see a lot of potential in these scripts and am planning to include them as part of preparing for releases when I am clients. A good way to dot the i&#8217;s and cross the t&#8217;s.</p>
<p>Individual results may vary. No Legos were harmed in the writing on this post.</p>


<p>Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2009/01/find-duplicate-foreign-keys/' rel='bookmark' title='Permanent Link: Find Duplicate Foreign Keys'>Find Duplicate Foreign Keys</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/07/gotta-stop-violating-foreign-keys/' rel='bookmark' title='Permanent Link: Gotta Stop Violating Foreign Keys'>Gotta Stop Violating Foreign Keys</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/02/change-trusted-state-of-foreign-keys/' rel='bookmark' title='Permanent Link: Change Trusted State of Foreign Keys'>Change Trusted State of Foreign Keys</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jasonstrate.com/index.php/2010/06/index-those-foreign-keys/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Does Your Stored Procedure Grant Itself Permissions?</title>
		<link>http://www.jasonstrate.com/index.php/2009/12/does-your-stored-procedure-grant-itself-permissions/</link>
		<comments>http://www.jasonstrate.com/index.php/2009/12/does-your-stored-procedure-grant-itself-permissions/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 13:00:00 +0000</pubDate>
		<dc:creator>jstrate</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Deadlocks]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQLServerSyndication]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.jasonstrate.com/index.php/2009/12/does-your-stored-procedure-grant-itself-permissions/</guid>
		<description><![CDATA[ It’s a very good question. One that might not seem to insidious. Nothing that should be able to bring down the system and cause failures. Or will it?
I’ve been to a number of clients and done it myself before where I start to check out a stored procedure with some performance issues and sitting [...]


Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2009/01/scripting-object-level-permissions/' rel='bookmark' title='Permanent Link: Scripting Object Level Permissions'>Scripting Object Level Permissions</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2006/05/room-with-a-view/' rel='bookmark' title='Permanent Link: Room with a View'>Room with a View</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/06/index-those-foreign-keys/' rel='bookmark' title='Permanent Link: Index Those Foreign Keys'>Index Those Foreign Keys</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2009%2F12%2Fdoes-your-stored-procedure-grant-itself-permissions%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2009%2F12%2Fdoes-your-stored-procedure-grant-itself-permissions%2F" height="61" width="51" /></a></div><p><a href="http://www.jasonstrate.com/images/DoesYourStoredProcedureGrantItselfPermis_DEA/hamsterwheel.jpg"><img style="border-bottom: 0px; border-left: 0px; margin: 0px; display: inline; border-top: 0px; border-right: 0px" title="hamster-wheel" border="0" alt="hamster-wheel" align="right" src="http://www.jasonstrate.com/images/DoesYourStoredProcedureGrantItselfPermis_DEA/hamsterwheel_thumb.jpg" width="109" height="159" /></a> It’s a very good question. One that might not seem to insidious. Nothing that should be able to bring down the system and cause failures. Or will it?</p>
<p>I’ve been to a number of clients and done it myself before where I start to check out a stored procedure with some performance issues and sitting all pretty at the bottom is a GRANT EXEC statement. When I script out the stored procedure I get something similar to the following:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">CREATE</span> <span style="color: #0000ff">PROCEDURE</span> dbo.FooGetTableA</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    (</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    @<span style="color: #0000ff">Parameter</span> <span style="color: #0000ff">varchar</span>(4)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    )</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">AS</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">SELECT</span> Column1 </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">FROM</span> dbo.TableA</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">WHERE</span> Column2 = @<span style="color: #0000ff">Parameter</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">GRANT</span> <span style="color: #0000ff">EXEC</span> <span style="color: #0000ff">ON</span> dbo.FooGetTableA <span style="color: #0000ff">TO</span> ApplicationRole</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">GO</pre>
<p><!--CRLF--></div>
</div>
<p>But if you look carefully, there is something missing, or one could say included that shouldn’t be.&#160; Look again if you don’t see it. It’s hidden in plain sight.&#160; The permissions for the procedure are included in the body of the stored procedure.&#160; When the procedure was written, someone thought ahead to add permissions to the script but forgot the GO statement between the stored procedure </p>
<p>In a better world this script would have looked like this:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">CREATE</span> <span style="color: #0000ff">PROCEDURE</span> dbo.FooGetTableA</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    (</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    @<span style="color: #0000ff">Parameter</span> <span style="color: #0000ff">varchar</span>(4)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    )</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">AS</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">SELECT</span> Column1 </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">FROM</span> dbo.TableA</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">WHERE</span> Column2 = @<span style="color: #0000ff">Parameter</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">GO</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">GRANT</span> <span style="color: #0000ff">EXEC</span> <span style="color: #0000ff">ON</span> dbo.FooGetTableA <span style="color: #0000ff">TO</span> ApplicationRole</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">GO</pre>
<p><!--CRLF--></div>
</div>
<h4>It’s Just a Permission Statement</h4>
<p>Who cares, right?&#160; So you are assigning some permissions every time that procedure executes.&#160; What harm could possibly come of it.&#160; I’ve seen this so many times and usually it’s one of things I’ll point out and say, “oops, you should take care of that”.&#160; When I should be saying, “yeah, fellas.&#160; You’ve got a time bomb there waiting for your business to take off.”</p>
<p>And the time bomb is deadlocks.&#160; Completely preventable deadlocks.</p>
<p>If you have procedures that grant themselves permissions, then as the volume of activity in your database increases you may start to see deadlock graphs similar to the following:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">deadlock-list deadlock victim=process30108bac8  process-list   process id=processec55dd68 taskpriority=0 logused=0 waitresource=METADATA: database_id = 10 PERMISSIONS(<span style="color: #0000ff">class</span> = 1, major_id = 219199881) waittime=15000 ownerId=746424569 transactionname=<span style="color: #0000ff">Load</span> Permission <span style="color: #0000ff">Object</span> Cache lasttranstarted=2009-10-22T23:06:59.287 XDES=0x3712a8e98 lockMode=Sch-S schedulerid=1 kpid=5832 status=suspended spid=157 sbid=2 ecid=0 priority=0 transcount=1 lastbatchstarted=2009-10-22T23:06:59.287 lastbatchcompleted=2009-10-22T23:06:59.280 clientapp=.Net SqlClient <span style="color: #0000ff">Data</span> Provider hostname=PRDWB0111 hostpid=5640 loginname=portaluser isolationlevel=serializable (4) xactid=746424394 currentdb=10 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056    executionStack     frame procname=AdventureWorks2008.dbo.FooGetTableA line=1 sqlhandle=0x03000a0089b9100d0e527800669c00000100000000000000<span style="color: #0000ff">CREATE</span> <span style="color: #0000ff">PROCEDURE</span> dbo.FooGetTableA    (    @<span style="color: #0000ff">Parameter</span> <span style="color: #0000ff">varchar</span>(4)    )<span style="color: #0000ff">AS</span>

<span style="color: #0000ff">SELECT</span> Column1 <span style="color: #0000ff">FROM</span> dbo.TableA<span style="color: #0000ff">WHERE</span> Column2 = @<span style="color: #0000ff">Parameter</span>

<span style="color: #0000ff">GRANT</span> <span style="color: #0000ff">EXEC</span> <span style="color: #0000ff">ON</span> dbo.FooGetTableA <span style="color: #0000ff">TO</span> ApplicationRole    inputbuf<span style="color: #0000ff">Proc</span> [<span style="color: #0000ff">Database</span> Id = 10 <span style="color: #0000ff">Object</span> Id = 219199881]       process id=process30108bac8 taskpriority=0 logused=0 waitresource=METADATA: database_id = 10 PERMISSIONS(<span style="color: #0000ff">class</span> = 1, major_id = 1746157316) waittime=2125 ownerId=746479249 transactionname=<span style="color: #0000ff">Load</span> Permission <span style="color: #0000ff">Object</span> Cache lasttranstarted=2009-10-22T23:07:12.180 XDES=0x3786c61c8 lockMode=Sch-S schedulerid=3 kpid=4048 status=suspended spid=69 sbid=2 ecid=0 priority=0 transcount=1 lastbatchstarted=2009-10-22T23:07:12.180 lastbatchcompleted=2009-10-22T23:07:12.167 clientapp=.Net SqlClient <span style="color: #0000ff">Data</span> Provider hostname=AMBER hostpid=568 loginname=portaluser isolationlevel=serializable (4) xactid=746372404 currentdb=10 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056    executionStack     frame procname=AdventureWorks2008.dbo.FooGetTableB line=1 sqlhandle=0x03000a00043f146882564201a09b00000100000000000000<span style="color: #0000ff">CREATE</span> <span style="color: #0000ff">PROCEDURE</span> dbo.FooGetTableB    (    @<span style="color: #0000ff">Parameter</span> <span style="color: #0000ff">varchar</span>(4)    )<span style="color: #0000ff">AS</span>

<span style="color: #0000ff">SELECT</span> Column1 <span style="color: #0000ff">FROM</span> dbo.TableB<span style="color: #0000ff">WHERE</span> Column2 = @<span style="color: #0000ff">Parameter</span>

<span style="color: #0000ff">GRANT</span> <span style="color: #0000ff">EXEC</span> <span style="color: #0000ff">ON</span> dbo.FooGetTableB <span style="color: #0000ff">TO</span> ApplicationRole    inputbuf<span style="color: #0000ff">Proc</span> [<span style="color: #0000ff">Database</span> Id = 10 <span style="color: #0000ff">Object</span> Id = 1746157316]      resource-list   metadatalock subresource=PERMISSIONS classid=<span style="color: #0000ff">class</span> = 1, major_id = 219199881 dbid=10 id=lock4153ec880 mode=Sch-M    owner-list     owner id=process30108bac8 mode=Sch-M    waiter-list     waiter id=processec55dd68 mode=Sch-S requestType=wait   metadatalock subresource=PERMISSIONS classid=<span style="color: #0000ff">class</span> = 1, major_id = 1746157316 dbid=10 id=lock415451780 mode=Sch-M    owner-list     owner id=processec55dd68 mode=Sch-M    waiter-list     waiter id=process30108bac8 mode=Sch-S requestType=wait</pre>
<p></div>
<h4>Breaking It Down</h4>
<p>When I first started looking at these there are a few things I noted right away:</p>
<ol>
<li>The procedures were access completely different tables with no common objects between them.&#160; In the sample above there is TableA and TableB and no relationship.</li>
<li>Looking at each of the processes in the deadlock both of them have the following attributes</li>
<ol>
<li>waitresource=METADATA: database_id = 10 PERMISSIONS</li>
<li>transactionname=Load Permission Object Cache</li>
</ol>
</ol>
<p>So nothing in common and a deadlock on a metadata resource for permissions.&#160; This made me start to re-think how the two procedures were related.&#160; With a metadata resource wait, there seems to be an issue above the data in the table.&#160; Since both procedures point to the Load Permission Object Cache, maybe there is an issue there.</p>
<p>If you take a look, each of the procedures has a GRANT EXEC permission statement in it.&#160; This is the area of commonality and where the two executions deadlocked.&#160; Removing the GRANT EXEC permissions statements stop this deadlock from occurring.</p>
<p>After going through and removing these permission statements from a number of procedures that had this issue, all of the deadlocks with these types of issues disappeared.&#160; And it is smooth sailing once again.</p>
<h4>Cautionary Tale</h4>
<p>Hopefully this is a scenario that only I’ve run into.&#160; But if it’s not then this should serve as a reminder that little details that seem like a little non-issue, could be the crack that breaks the damn when there’s enough water behind it.&#160; The thing that gets you on this issue is that it isn’t until execution start to really grow before it pops out and it will only hit when you’re the busiest.&#160; This is something I’ll be keeping an eye out for in the future and I’d recommend the same for others as well.</p>


<p>Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2009/01/scripting-object-level-permissions/' rel='bookmark' title='Permanent Link: Scripting Object Level Permissions'>Scripting Object Level Permissions</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2006/05/room-with-a-view/' rel='bookmark' title='Permanent Link: Room with a View'>Room with a View</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/06/index-those-foreign-keys/' rel='bookmark' title='Permanent Link: Index Those Foreign Keys'>Index Those Foreign Keys</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jasonstrate.com/index.php/2009/12/does-your-stored-procedure-grant-itself-permissions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Deadlocks on exchangeEvent and threadpool</title>
		<link>http://www.jasonstrate.com/index.php/2009/12/deadlocks-on-exchangeevent-and-threadpool/</link>
		<comments>http://www.jasonstrate.com/index.php/2009/12/deadlocks-on-exchangeevent-and-threadpool/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 13:00:00 +0000</pubDate>
		<dc:creator>jstrate</dc:creator>
				<category><![CDATA[Deadlocks]]></category>
		<category><![CDATA[Parallelism]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQLServerSyndication]]></category>
		<category><![CDATA[Wait Stat]]></category>

		<guid isPermaLink="false">http://www.jasonstrate.com/index.php/2009/12/deadlocks-on-exchangeevent-and-threadpool/</guid>
		<description><![CDATA[ I got to work with deadlocks quite a bit recently.  There were quite a few interesting ones that came up that I had the chance to research.  Since I like easy, I’ll start with the one that I forgot to grab the deadlock details for.
Well, maybe not all of the details… in this case [...]


Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2010/06/index-those-foreign-keys/' rel='bookmark' title='Permanent Link: Index Those Foreign Keys'>Index Those Foreign Keys</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2007/09/deadlock-resources/' rel='bookmark' title='Permanent Link: Deadlock Resources'>Deadlock Resources</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/12/does-your-stored-procedure-grant-itself-permissions/' rel='bookmark' title='Permanent Link: Does Your Stored Procedure Grant Itself Permissions?'>Does Your Stored Procedure Grant Itself Permissions?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2009%2F12%2Fdeadlocks-on-exchangeevent-and-threadpool%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2009%2F12%2Fdeadlocks-on-exchangeevent-and-threadpool%2F" height="61" width="51" /></a></div><p><a href="http://www.jasonstrate.com/images/DeadlocksonexchangeEventandthreadpool_14E48/80771711.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="80771711" src="http://www.jasonstrate.com/images/DeadlocksonexchangeEventandthreadpool_14E48/80771711_thumb.jpg" border="0" alt="80771711" width="157" height="120" align="right" /></a> I got to work with deadlocks quite a bit recently.  There were quite a few interesting ones that came up that I had the chance to research.  Since I like easy, I’ll start with the one that I forgot to grab the deadlock details for.</p>
<p>Well, maybe not all of the details… in this case as the title states I was looking at deadlocks with the events exchangeEvent and threadpool.  I managed to come across a <a href="http://blogs.msdn.com/bartd/archive/2008/09/24/today-s-annoyingly-unwieldy-term-intra-query-parallel-thread-deadlocks.aspx">post from Bart Duncan that went through and deciphered this deadlock</a>.  The long and the short of it… parallelism deadlocks.</p>
<p>Bart does a better job explaining this than I can do here, especially since I didn’t take the time to grab the deadlock details for review.  Maybe I’ll have that one the next one…</p>
<p>Fortunately, a large part of the issue that I was reviewing for the client had to do with parallelism and so solving this issue actually occurred as a side effect of dealing with parallelism issues.  But I will share my little secret that I used to resolve this and most of the parallelism…</p>
<h4>Indexes!!</h4>
<p>There I said it.  True, you can have too many indexes.  But no indexes is too few.  No clustered indexes can lead to too many scans.  I could pulpit here on indexes and making sure that you have them, but I’ll save that for another time.</p>
<p>Overall, I used Bart’s Workaround #1.  Hopefully this helps… direct you to a post that is more prescriptive.</p>


<p>Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2010/06/index-those-foreign-keys/' rel='bookmark' title='Permanent Link: Index Those Foreign Keys'>Index Those Foreign Keys</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2007/09/deadlock-resources/' rel='bookmark' title='Permanent Link: Deadlock Resources'>Deadlock Resources</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/12/does-your-stored-procedure-grant-itself-permissions/' rel='bookmark' title='Permanent Link: Does Your Stored Procedure Grant Itself Permissions?'>Does Your Stored Procedure Grant Itself Permissions?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jasonstrate.com/index.php/2009/12/deadlocks-on-exchangeevent-and-threadpool/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Deadlock Resources</title>
		<link>http://www.jasonstrate.com/index.php/2007/09/deadlock-resources/</link>
		<comments>http://www.jasonstrate.com/index.php/2007/09/deadlock-resources/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 17:02:00 +0000</pubDate>
		<dc:creator>jstrate</dc:creator>
				<category><![CDATA[Deadlocks]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>

		<guid isPermaLink="false">http://www.jasonstrate.com/?p=93</guid>
		<description><![CDATA[Deadlocks are a not so wonderful unnaturally occurring event that all DBAs will eventually have the pleasure to take a look at.&#160; Since deadlocks are time senisitive it is important that at the time of the deadlock the correct mechanisms are in place to capture the detail of the deadlock in the SQL Server error [...]


Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2009/12/deadlocks-on-exchangeevent-and-threadpool/' rel='bookmark' title='Permanent Link: Deadlocks on exchangeEvent and threadpool'>Deadlocks on exchangeEvent and threadpool</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2007/03/default-trace/' rel='bookmark' title='Permanent Link: Default Trace'>Default Trace</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2007/04/troubleshooting-performance-problems-in-sql-server-2005/' rel='bookmark' title='Permanent Link: Troubleshooting Performance Problems in SQL Server 2005'>Troubleshooting Performance Problems in SQL Server 2005</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2007%2F09%2Fdeadlock-resources%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2007%2F09%2Fdeadlock-resources%2F" height="61" width="51" /></a></div><p>Deadlocks are a not so wonderful unnaturally occurring event that all DBAs will eventually have the pleasure to take a look at.&#160; Since deadlocks are time senisitive it is important that at the time of the deadlock the correct mechanisms are in place to capture the detail of the deadlock in the SQL Server error log. </p>
<p>For SQL Server 2000 the trace flags to use are 1204 and 3605.&#160; And for SQL Server 2005, you can use the same flags or one up them with 1222 which produces similar results but in a much cleaner output.</p>
<p>Since there are different trace flags between 2000 and 2005 there are of course different attack plans for resolving deadlocks.&#160; A couple of the better links for SQL Server 2000 are:</p>
<ul>
<li><a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;224453">INF: Understanding and Resolving SQL Server 7.0 or 2000 Blocking Problems</a></li>
<li><a href="http://blogs.digineer.com/controlpanel/blogs/null">SQL Server technical bulletin &#8211; How to resolve a deadlock</a></li>
</ul>
<p>Some SQL Server 2005 resources:</p>
<ul>
<li><a href="http://msdn2.microsoft.com/en-us/library/ms178104.aspx">Detecting and Ending Deadlocks</a></li>
<li><a href="http://msdn2.microsoft.com/en-us/library/ms188246.aspx">Analyzing Deadlocks with SQL Server Profiler</a></li>
<li><a href="http://blogs.msdn.com/bartd/archive/2006/09/09/747119.aspx">Deadlock Troubleshooting, Part 1</a></li>
<li><a href="http://blogs.msdn.com/bartd/archive/2006/09/13/751343.aspx">Deadlock Troubleshooting, Part 2</a></li>
<li><a href="http://blogs.msdn.com/bartd/archive/2006/09/25/770928.aspx">Deadlock Troubleshooting, Part 3</a></li>
</ul>
<p>But really the key to deadlocks is really not having them in the first place:</p>
<ul>
<li><a href="http://www.sql-server-performance.com/tips/deadlocks_p1.aspx">Reducing SQL Server Deadlocks</a></li>
</ul>
<p>That&#8217;s all for now&#8230;</p>
<p> At least I figured out the deadlocks I was working on this morning&#8230;</p>


<p>Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2009/12/deadlocks-on-exchangeevent-and-threadpool/' rel='bookmark' title='Permanent Link: Deadlocks on exchangeEvent and threadpool'>Deadlocks on exchangeEvent and threadpool</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2007/03/default-trace/' rel='bookmark' title='Permanent Link: Default Trace'>Default Trace</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2007/04/troubleshooting-performance-problems-in-sql-server-2005/' rel='bookmark' title='Permanent Link: Troubleshooting Performance Problems in SQL Server 2005'>Troubleshooting Performance Problems in SQL Server 2005</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jasonstrate.com/index.php/2007/09/deadlock-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
