<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>SQL Canada (@SQLCAN)</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/sqlcan/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/sqlcan/feed.xml</link>
    <description>Use to be originall called SQL Learnings, but on recommendation from a friend. Going to start using SQLCAN, lets see what I can do with this. Purpose of the blog is to put lessons learned from my experinces in PFE.</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:24:59 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Help! I have -2, -3, or -4 Session ID!</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlcan/help-i-have-2-3-or-4-session-id</link>
      <pubDate>Tue, 21 Jun 2016 16:33:54 GMT</pubDate>
      <dc:creator><![CDATA[Mohit K. Gupta]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlcan/?p=106</guid>
      <description><![CDATA[We can kill a session by using KILL command. However, KILL command requires a positive number;...]]></description>
      <content:encoded><![CDATA[We can kill a session by using <a href="https://msdn.microsoft.com/en-us/library/ms173730.aspx" target="_blank">KILL</a> command. However, KILL command requires a positive number; executing KILL with negative number returns an error:
<p style="padding-left: 30px"><span style="color: #ff0000">Msg 6101, Level 16, State 1, Line 1</span>
<span style="color: #ff0000">Session ID -4 is not valid.</span></p>
In order to kill the session ID, you need to find the unit of work (UOW) guid.

[code language="sql"]
SELECT DISTINCT(request_owner_guid) AS UOW
FROM sys.dm_tran_locks
WHERE request_session_id IN (-2,-3,-4)
[/code]

Now you can kill this using UOW:

[code language="sql"]
KILL 'D5499C66-E398-45CA-BF7E-DC9C194B48CF'
[/code]

Like all normal transactions, killing a session causes any work performed by it to be rolled back to bring the database back into consistent state.

The negative session ID are orphaned or stuck sessions that SQL Server; they are rare occurrences. Most often the only one I have seen is -2; what do they mean?
<table style="width: 75%;border: 1px solid black">
<tbody>
<tr>
<th style="width: 15%">Session ID</th>
<th style="width: 85%">Description</th>
</tr>
<tr>
<td style="text-align: center">-2</td>
<td>The blocking resource is owned by an orphaned distributed transaction.</td>
</tr>
<tr>
<td style="text-align: center">-3</td>
<td>The blocking resource is owned by a deferred recovery transaction.</td>
</tr>
<tr>
<td style="text-align: center">-4</td>
<td>Session ID of the blocking latch owner could not be determined due to internal latch state transitions.</td>
</tr>
</tbody>
</table>
Reference: <a href="https://msdn.microsoft.com/en-us/library/ms179881.aspx" target="_blank">Books Online, sys.sysprocesses (Transact-SQL)</a>

This post is cross posted on my <a href="https://sqlcan.com/" target="_blank"><u>SQLCAN Blog</u></a>, <a href="https://blogs.msdn.com/b/sqlcan/" target="_blank"><u>MSDN Blog</u></a>, and <a href="https://mostafaelmasry.com/" target="_blank"><u>SQL server Consultation</u></a> blog.]]></content:encoded>
    </item>
    <item>
      <title>Dissecting SQL Server Execution Plans</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlcan/dissecting-sql-server-execution-plans</link>
      <pubDate>Tue, 31 May 2016 10:00:59 GMT</pubDate>
      <dc:creator><![CDATA[Mohit K. Gupta]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlcan/?p=105</guid>
      <description><![CDATA[I remember my days before, Microsoft SQL Server PFE.  I wanted to learn everything and know...]]></description>
      <content:encoded><![CDATA[I remember my days before, Microsoft SQL Server PFE.  I wanted to learn everything and know everything about SQL Server.  However, getting hold of good resources was tough, as I didn’t have any mentor when I started down my journey to becoming a SQL Server Database Administrator.

Along the way I did pick up lots of books and references.  One of such books is Dissecting SQL Server Execution Plans.

I read this book before becoming PFE, I read this now, and I recommend everyone read this book more then once.

Grant Fritchey (<a href="https://www.scarydba.com/">Blog</a>|<a href="https://twitter.com/GFritchey">Twitter</a>) wrote the book back in 2008; I would still recommend take ready.  This book will only help you be better DBA and Developer.

SQL Central, Jeff Moden, Dissecting SQL Server Execution Plans

<a title="https://www.sqlservercentral.com/articles/Book+Reviews/69019/" href="https://www.sqlservercentral.com/articles/Book+Reviews/69019/">https://www.sqlservercentral.com/articles/Book+Reviews/69019/</a>

Amazon, SQL Server Execution Plans

<a title="https://www.amazon.com/gp/product/1906434026?ie=UTF8&amp;tag=dkranchnet&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1906434026" href="https://www.amazon.com/gp/product/1906434026?ie=UTF8&amp;tag=dkranchnet&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1906434026">https://www.amazon.com/gp/product/1906434026?ie=UTF8&amp;tag=dkranchnet&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1906434026</a>

SQL Central, Red Gate, EBook

<a title="https://www.sqlservercentral.com/articles/books/65831/?utm_source=ssc&amp;utm_medium=weblink&amp;utm_content=Grant&amp;utm_campaign=sqltoolbelt" href="https://www.sqlservercentral.com/articles/books/65831/?utm_source=ssc&amp;utm_medium=weblink&amp;utm_content=Grant&amp;utm_campaign=sqltoolbelt">https://www.sqlservercentral.com/articles/books/65831/?utm_source=ssc&amp;utm_medium=weblink&amp;utm_content=Grant&amp;utm_campaign=sqltoolbelt</a>

This post is cross posted on my <a href="https://sqlcan.com/"><span style="text-decoration: underline">SQLCAN Blog</span></a>, <a href="https://blogs.msdn.com/b/sqlcan/"><span style="text-decoration: underline">MSDN Blog</span></a>, and <a href="https://mostafaelmasry.com/"><span style="text-decoration: underline">SQL server Consultation</span></a> blog.]]></content:encoded>
    </item>
    <item>
      <title>How to get orphaned logins for all databases?</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlcan/how-to-get-orphaned-logins-for-all-databases</link>
      <pubDate>Mon, 04 Apr 2016 19:31:50 GMT</pubDate>
      <dc:creator><![CDATA[Mohit K. Gupta]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlcan/?p=103</guid>
      <description><![CDATA[Following script gives you all user database users, that do not have a server login mapped or where...]]></description>
      <content:encoded><![CDATA[Following script gives you all user database users, that do not have a server login mapped or where database user name does not match server login name. This is follow up post to <a class="title" href="https://sqlcan.com/2016/04/02/how-get-all-users-and-their-role-mappings-from-all-databases/" rel="bookmark">How get all users and their role mappings from all databases?</a> I posted few days ago.

<code>
IF EXISTS(SELECT * FROM tempdb.sys.tables WHERE name like '#Output%')
DROP TABLE #Output
GO

CREATE TABLE #Output (DatabaseName VARCHAR(255), UserLoginSID varbinary(128), ServerLoginName VARCHAR(255), DatabaseUserName VARCHAR(255), UserType VARCHAR(50))
GO

sp_msforeachdb '
INSERT INTO #Output
SELECT ''?''
, DP.sid
, SP.name
, DP.name
, DP.type_desc
FROM sys.database_principals DP
LEFT JOIN sys.server_principals SP
ON DP.sid = SP.sid
WHERE DP.type_desc IN (''SQL_USER'',''WINDOWS_USER'')
AND DP.sid IS NOT NULL'
GO

SELECT *
FROM #Output
WHERE ServerLoginName IS NULL
OR ServerLoginName DatabaseUserName
ORDER BY DatabaseName, ServerLoginName
GO
</code>

This post is cross posted on my <a href="https://sqlcan.wordpress.com/"><span style="text-decoration: underline">SQLCAN Blog</span></a>, <a href="https://blogs.msdn.com/b/sqlcan/"><span style="text-decoration: underline">MSDN Blog</span></a>, and <a href="https://mostafaelmasry.com/"><span style="text-decoration: underline">SQL server Consultation</span></a> blog.]]></content:encoded>
    </item>
    <item>
      <title>Changing @@SERVERNAME causes SQL Server Backups to Fail for AlwaysOn Availability Group</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlcan/changing-servername-causes-sql-server-backups-to-fail-for-alwayson-availability-group</link>
      <pubDate>Wed, 13 Jan 2016 08:18:26 GMT</pubDate>
      <dc:creator><![CDATA[Mohit K. Gupta]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlcan/2016/01/13/changing-servername-causes-sql-server-backups-to-fail-for-alwayson-availability-group/</guid>
      <description><![CDATA[One of customers changed the value returned from @@SERVERNAME.&#160; SQL Server works no problem,...]]></description>
      <content:encoded><![CDATA[<p>One of customers changed the value returned from @@SERVERNAME.&#160; SQL Server works no problem, however an unexpected behavior appeared.&#160; Changing the value for @@SERVERNAME, caused the backups to fail.</p>  <p>Looking at the maintenance jobs, found all jobs completed successfully and without issues.&#160; However, upon looking at the database’s statics it states no backups completed.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/3223.image_5D74D48A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/3223.image_5F00_5D74D48A.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/4621.image_thumb_1CD2881B.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/4621.image_5F00_thumb_5F00_1CD2881B.png" width="404" height="46" /></a></p>  <p>Because the database in question is part of AlwaysOn Availability Group (AG); SQL Server executes sys.fn_hadr_backup_is_preferred_replica to determine if the backup should take place on the current node.&#160; However, it returns value of 0 for all databases, if the preferred replica is set.&#160; Because, the script makes a check that is running on the server that is preferred.&#160; It does this by comparing the value to @@SERVERNAME to value of replica_server_name in sys.availability_replicas.&#160; Because value will never match, it skips the database on both primary and secondary replica.</p>  <p>I have created a Microsoft Connect article (<a href="https://connect.microsoft.com/SQLServer/feedback/details/2238342">link</a>); asking this little bit of information to be added to Books Online article (<a href="https://msdn.microsoft.com/en-us/library/hh213235.aspx?f=255&amp;MSPPError=-2147217396">link</a>).&#160; There was a request submitted by Ola Hallengren (<a href="https://ola.hallengren.com/">Blog</a> | <a href="https://twitter.com/olahallengren">Twitter</a>), which was closed as Won’t Fix (<a href="https://connect.microsoft.com/SQLServer/Feedback/Details/798065">link</a>).&#160;&#160; Please vote!</p>  <p>This post is cross posted on my <a href="https://sqlcan.wordpress.com/"><u>SQLCAN Blog</u></a>, <a href="https://blogs.msdn.com/b/sqlcan/"><u>MSDN Blog</u></a>, and <a href="https://mostafaelmasry.com/"><u>SQL server Consultation</u></a> blog.</p>]]></content:encoded>
    </item>
    <item>
      <title>sys.foreign_keys does not have matching row in sys.indexes</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlcan/sys-foreign_keys-does-not-have-matching-row-in-sys-indexes</link>
      <pubDate>Thu, 19 Nov 2015 11:34:53 GMT</pubDate>
      <dc:creator><![CDATA[Mohit K. Gupta]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlcan/2015/11/19/sys-foreign_keys-does-not-have-matching-row-in-sys-indexes/</guid>
      <description><![CDATA[Running DBCC CHECKDB you are getting following error message:  Check Catalog Msg 3853, State 1:...]]></description>
      <content:encoded><![CDATA[<p>Running DBCC CHECKDB you are getting following error message:</p>  <p>Check Catalog Msg 3853, State 1: Attribute (referenced_object_id=194099732,key_index_id=7) of row (object_id=2040565179) in sys.foreign_keys does not have a matching row (object_id=194099732,index_id=7) in sys.indexes</p>  <p>This error means, that Unique key constraint (index_id 7) in the primary table (object_id 194099732) is missing, which was referenced by child table’s FK constraint (FK object_id 2040565179).&#160; This should not happen, SQL Server will not allow you to drop a constraint that is referenced by FK.&#160; If attempted should get following error message:</p>  <p>Msg 3723, Level 16, State 6, Line 1    <br />An explicit DROP INDEX is not allowed on index 'dbo.a.NonClusteredIndex-20151119-085219'. It is being used for FOREIGN KEY constraint enforcement.     <br />    <br />So if we are suppose to get errors? Why do we have corruption; simple answer, someone be making updates to system tables directly, which is not allowed or supported!</p>  <p>Actually we are not able to update system tables in SQL Server 2005+ (<a href="https://msdn.microsoft.com/en-us/library/ms179262(v=sql.90).aspx">ref</a>), however in SQL 2000 days, we had setting called <a href="https://technet.microsoft.com/en-us/library/aa196704(v=sql.80).aspx">allow updates</a> in sp_configure options.&#160; Also supported by the <a href="https://support.microsoft.com/en-us/kb/2787112">KB2787112</a>.</p>  <p>So question is how do you fix it?</p>  <p>First, identify the child table name from sys.foreign_keys:</p>  <p>SELECT object_name(parent_object_id) AS TableName    <br />&#160; FROM sys.foreign_keys     <br />WHERE name = 'FK_b_a'</p>  <p>Second, script our constraint definition:</p>  <ol>   <li>Find the table, we got in SQL Statement above. </li>    <li>Go to Keys. </li>    <li>Right click on FK constraint name. </li>    <li>Script Key As. </li>    <li>Create To. </li>    <li>New Query Window. </li> </ol>  <p>Third, drop the FK constraint:</p>  <p>ALTER TABLE [schema].[tablename] DROP CONSTRAINT [fk_constraint_name]</p>  <p>Fourth, Re-create the constraint, with script generated in Step 2.</p>  <p>If it was issue of someone playing around in system tables, this should resolve it.&#160; However, if you get error similar to below:</p>  <p>Msg 1776, Level 16, State 0, Line 1    <br />There are no primary or candidate keys in the referenced table 'dbo.a' that match the referencing column list in the foreign key 'FK_b_a'.</p>  <p>This means, that the key is missing in parent table and appropriate index needs be created before FK constraint can be created.&#160; Since SQL doesn’t allow the index to be dropped there most likely are other corruption issues that have gone unnoticed.&#160; If that is an issue, you will have to rely on your backups for recovery.</p>  <p>This post is cross posted on my <a href="https://sqlcan.wordpress.com/"><u>SQLCAN Blog</u></a>, <a href="https://blogs.msdn.com/b/sqlcan/"><u>MSDN Blog</u></a>, and <a href="https://mostafaelmasry.com/"><u>SQL server Consultation</u></a> blog.</p>]]></content:encoded>
    </item>
    <item>
      <title>Index Creation Date</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlcan/index-creation-date</link>
      <pubDate>Sun, 18 Oct 2015 20:14:00 GMT</pubDate>
      <dc:creator><![CDATA[Mohit K. Gupta]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlcan/2015/10/18/index-creation-date/</guid>
      <description><![CDATA[Often when troubleshooting performance related issues, it is beneficial to know when new indexes...]]></description>
      <content:encoded><![CDATA[<p>Often when troubleshooting performance related issues, it is beneficial to know when new indexes were introduced.&nbsp; However currently there is no easy way to keep track of this information or attain this information.&nbsp; That&rsquo;s why one of my colleagues and a good friend, Mohamed Sharaf (<a href="https://blogs.msdn.com/b/mosharaf/">Blog</a> | <a href="https://twitter.com/mohamsharaf">Twitter</a>), has submitted a request on Microsoft Connect, Expose index creation date in sys.indexes, <a href="https://connect.microsoft.com/SQLServer/feedback/details/1889555">Link</a>.&nbsp; Please take a few minutes to vote if you agree <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/2234.wlEmoticon-smile_1202D36F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/2234.wlEmoticon_2D00_smile_5F00_1202D36F.png" alt="Smile" />.</p>
<p>This post is cross posted on my <a href="https://sqlcan.wordpress.com/"><span style="text-decoration: underline;">SQLCAN Blog</span></a>, <a href="https://blogs.msdn.com/b/sqlcan/"><span style="text-decoration: underline;">MSDN Blog</span></a>, and <a href="https://mostafaelmasry.com/"><span style="text-decoration: underline;">SQL server Consultation</span></a> blog.</p>]]></content:encoded>
    </item>
    <item>
      <title>SQL Server 2012 NUMA Node Imbalance–Conclusion</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlcan/sql-server-2012-numa-node-imbalanceconclusion</link>
      <pubDate>Sun, 04 Oct 2015 22:21:30 GMT</pubDate>
      <dc:creator><![CDATA[Mohit K. Gupta]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlcan/2015/10/04/sql-server-2012-numa-node-imbalanceconclusion/</guid>
      <description><![CDATA[Final post in the series, I hope to summarize my findings for everyone.&#160; Thanks for all the...]]></description>
      <content:encoded><![CDATA[<p>Final post in the series, I hope to summarize my findings for everyone.&#160; Thanks for all the comments, feedback and comments I have received to-date on these posts.&#160; </p>  <p>Before providing the summary of all the testing, research and reading, I want to provide some internals for folks.</p>  <p><strong><u>NUAM Memory Allocation</u></strong></p>  <p>If a server has NUMA configuration, when we define the max memory setting.&#160; All memory gets allocated evenly from all NUMA nodes.&#160; For example, if I allocate 8GB from a server that has 4 NUMA nodes, it will allocate 2GB from each NUMA node for the instance in question. So be careful, if you are using CPU affinity.&#160; As even using CPU affinity, lets say you only want to use NUMA 1 for an instance; this can lead to foreign memory access. NUMA allocation still happens across all NUMA nodes (at least in SQL Server 2014).&#160; So even though you might only have subset of schedulers online, memory will still be accessed across all NUMA Nodes.&#160; Even though with new hardware foreign memory access does not have major impact on performance.&#160; Still recommend avoiding it.&#160; If you must use CPU affinity, then allocate sub-set of the processor from each NUMA node.</p>  <p><strong><u>Lazy Writer Responsibility</u></strong></p>  <p>Lazy Writer is back ground process and a thread is created per physical NUMA node (for Soft-NUMA, we only get one thread, you can read details <a href="https://www.sqlskills.com/blogs/jonathan/sql-server-and-soft-numa/">here</a> by Jonathan Kehayias (<a href="https://www.sqlskills.com/blogs/jonathan/">Blog</a>|<a href="https://twitter.com/SQLPoolBoy">Twitter</a>)). Lazy Writer responsibility is to make sure sufficient number of free pages, about 640 pages, are always available for new data to be loaded.&#160; If Lazy Writer thread is spinning, that is usually a clear signal of internal memory pressure.&#160; </p>  <p><em><strong>Note:</strong> <strong>Internal Memory</strong> pressure does not mean server doesn’t have enough memory.&#160; There are multiple factors that can contribute to this, one fact is low Max Server Memory, which is what has been explored in these articles.</em></p>  <p><strong><u>Original Scenario</u>: </strong>SQL Server 2012 Latest Build + Windows 2008 R2 Latest Build + Locked Pages In Memory + Low Max Server Memory + AMD Processors + NUMA Configuration</p>  <p>In this build, I can consistently reproduce the issue.&#160; If I set the Max Memory low enough, it caused the Lazy Writer on NUMA node 0 to spin non-stop, as I documented in <a href="https://sqlcan.wordpress.com/2015/10/01/sql-server-2012-numa-node-imbalance-contd/">SQL Server 2012 NUMA Node Imbalance – Cont’d</a>.&#160; To further to this I understand some additional internals around this thanks to colleague who helped here.&#160; As I was not true sure what is happening.&#160; </p>  <p>If we looked at the DBCC MEMORYSTATUS, in particular we notice following for Node 0:</p>  <p><strong>Memory node Id = 0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; KB      <br /></strong>---------------------------------------- -----------     <br />VM Reserved&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 127086340     <br />VM Committed&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 642452     <br />Locked Pages Allocated&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 55996     <br />Pages Allocated&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 54008     <br />Pages Free&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0     <br />Target Committed&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#00ff00">512000</font>     <br />Current Committed&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#ff0000">698448</font>     <br />Foreign Committed&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0     <br />Away Committed&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0     <br />Taken Away Committed&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0</p>  <p>Review the two numbers high-lighted above, Target memory is what this NUMA node is allocated and Current is what is NUMA consuming, therefore the Page Free count is 0.&#160; Thus Lazy Writer spinning to free up memory.&#160; However it is unable, thus spinning indefinitely causing CPU to pin.&#160; <strong><em>Question to answer, why can’t Lazy Writer free up memory from NUMA Node 0?</em></strong></p>  <p>Looking further into MEMORYSTATUS, we also notice, that most of the memory allocated into NUMA Node 0 is for buffer cache:</p>  <p><strong>MEMORYCLERK_SQLBUFFERPOOL (node 0)&#160;&#160;&#160;&#160;&#160;&#160; KB</strong>     <br />---------------------------------------- -----------     <br />VM Reserved&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 103971820     <br />VM Committed&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#00ff00">524288</font>     <br />Locked Pages Allocated&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 2524     <br />SM Reserved&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0     <br />SM Committed&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0     <br />Pages Allocated&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 8     <br /></p>  <p><strong>Test Scenario #1:</strong> Windows 10 + SQL Server 2012 RTM + Low Max Server Memory + Intel Processors + No-NUMA (Physical)</p>  <p>In this, I was just trying to reproduce the issue on my desktop, with no luck.&#160; Memory allocation or such were nominal.</p>  <p><strong>Test Scenario #2:</strong> Windows 2012 + SQL Server 2014 RTM + Low Max Server Memory + Intel Processors + No-NUMA (Hyper-V)</p>  <p>Again no issue, as per the title of the series, NUMA Imbalance.&#160; It was obvious and expected this two scenarios don’t show any issues.&#160; But I wanted to confirm it.</p>  <p><strong>Test Scenario #3:</strong> SQL Server 2008 R2 + Windows 2008 R2 + Low Max Server Memory + AMD Processors</p>  <p>These test was on same servers as original scenario, however we did not notice any issue.</p>  <p><font color="#00ff00"><strong>***</strong></font> During testing, we realized an interesting fact about NUMA configuration in SQL Server 2008 R2.&#160; SQL Server swaps NUMA 0 and NUMA 1 CPU mapping when creating a logical mapping for schedulers.&#160; For example, if you have 2 NUMA Nodes each with 4 cores; SQL Server binds NUMA 0 – Processor 0 – 3 to Scheduler 4 – 7 and NUMA 1 – Processor 4 – 7 to Scheduler 0 – 3.&#160; This is considered NUMA Swap, documented in this MSDN blog article <a href="https://blogs.msdn.com/b/psssql/archive/2011/11/11/sql-server-clarifying-the-numa-configuration-information.aspx">here</a> by CSS Team.&#160; However this behavior does not seem to persist in SQL Server 2012.</p>  <p><strong>Test Scenario #4:</strong> SQL Server 2014 + Windows 2012 R2 + Low Max Server Memory + Intel Processors + NUMA (Azure IaaS Virtual Machine)</p>  <p>This was interesting case, when I set the Max Server Memory to low value, the NUMA node 0’s processor time started to increase.&#160; However it was not as swear as SQL Server 2012, however these are different processors.&#160; I had same behavior as noticed above, Current Committed was higher then Target Committed, therefore NUMA thread on Node 0 was spinning.&#160; However interesting thing note, it was not as aggressive as SQL Server 2012.&#160; It was not continuously spinning, it allowed CPU to breath.&#160; However would wake up frequently as low as ever 20ms.</p>  <p><strong><font color="#ff0000">!!!</font></strong> Eliminated Locked Pages in Memory as a factor for NUMA Imbalance.</p>  <p><strong>Test Scenario #5:</strong> SQL Server 2014 + Windows 2012 R2 + Low Max Server Memory + Intel Processors + Locked Pages In Memory + NUMA (Azure IaaS Virtual Machine)</p>  <p>Exact same behavior as above was noticed, however, after restart, SQL Server no longer had Current Committed higher then Target Committed.&#160; Even after lowering the max memory even further then Scenario #4.&#160; It did not cause as dramatic shift.</p>  <p><font color="#00ff00"><strong>***</strong></font> Another <em>interesting</em> thing to note in SQL Server 2014. Up-to SQL Server 2012, Lazy Writer Thread bound to CPU 0 of each NUMA Node.&#160; In SQL Server 2014, Lazy Writer Thread is binding to last CPU of each NUMA Node.</p>  <p><strong><u>Conclusion &amp; Things to Consider</u></strong></p>  <ul>   <li>Configuring SQL Server Max Server Memory low memory will cause Lazy Writer to spin due to internal memory pressure issue. </li>    <li>There is no value at which point this behavior starts, it depends on the load of the server.&#160; For example, in Original Scenario, due to server load under 4000MB it started spinning the Lazy Writer thread; however in Test Scenario #4, I had to go down to as much as 1000MB. Therefore on your servers look at Lazy Writer thread in conjunction with CPU and DBCC MEMORYSTATUS to understand what is truly happening. </li>    <li>This behavior is consistent in whether I have Locked Pages in Memory or not. </li>    <li>In Windows 2012 R2 NUMA allocation seem to be much better then Windows 2008 R2. </li>    <li>SQL Server 2014 Lazy Writer thread does not seem to be as aggressive as SQL Server 2012. </li>    <li>Few KB articles came up during my research in SQL Server 2012 that fix NUMA related issues, <a href="https://support.microsoft.com/en-us/kb/2819662">KB2819662</a> and <a href="https://support.microsoft.com/en-us/kb/2926223">KB2926223</a>. </li>    <li>There as been some fixes released for NUMA for Windows 2008 R2 operating system also, please review <a href="https://support.microsoft.com/en-us/kb/2155311">KB2155311</a> and <a href="https://support.microsoft.com/en-us/kb/2510206">KB2510206</a>. </li>    <li>In addition, if you are running a server with more then 64-logical cores, please review K-Group Configuration, for details please reference <a href="https://blogs.msdn.com/b/saponsqlserver/archive/2011/10/08/uneven-windows-processor-groups.aspx">this article</a>. </li>    <li>Last but not least verify that memory is distributed evenly on physical server.&#160; That is the memory banks have been evenly allocated, i.e. you do not have more memory allocated in one bank versus another, as you might also see one NUMA node working extra harder if there is significant amount of foreign memory access. </li> </ul>  <ul><strong><u>Outstanding Question</u></strong></ul>  <p><strong><em>Question to answer, why can’t Lazy Writer free up memory from NUMA Node 0?</em></strong></p>  <p>SQL Server Lazy Writer is only responsible for clearing memory from Buffer Pool, it cannot remove or clear memory from any other memory clerk.&#160; Therefore, it is possible, that other internal components have memory allocated on NUMA Node 0 only, therefore NUMA Node 0 is unable to free up enough memory for buffer pool only.&#160; Looking at DBCC MEMORYSTATUS we can see which memory clerks allocate from NODE Node 0 only, there are few, for example, MEMORYCLERK_SQLCLR, MEMORYCLERK_SOSMEMMANAGER, OBJECTSTORE_LOCK_MANAGER, and MEMORYCLERK_XE_BUFFER all have allocation from NODE Node 0 only.</p>  <p>This post is cross posted on my <a href="https://sqlcan.wordpress.com/">SQLCAN Blog</a>, <a href="https://blogs.msdn.com/b/sqlcan/">MSDN Blog</a>, and <a href="https://mostafaelmasry.com/">SQL server Consultation</a> blog.</p>]]></content:encoded>
    </item>
    <item>
      <title>SQL Server 2012 NUMA Node Imbalance – Cont’d</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlcan/sql-server-2012-numa-node-imbalance-contd</link>
      <pubDate>Thu, 01 Oct 2015 14:36:49 GMT</pubDate>
      <dc:creator><![CDATA[Mohit K. Gupta]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlcan/2015/10/01/sql-server-2012-numa-node-imbalance-contd/</guid>
      <description><![CDATA[Yesterday, I had posted an issue I been troubleshooting with memory allocation.&#160; That was...]]></description>
      <content:encoded><![CDATA[<p>Yesterday, I had posted an issue I been troubleshooting with memory allocation.&#160; That was causing CPU to pin, you can read more about the issue at <a href="https://sqlcan.wordpress.com/2015/09/30/sql-sql2012/">SQL Server 2012 NUMA Node Imbalance</a>.&#160; Even though I found what was causing it, I didn’t understand the internals well enough to identify the root cause.</p>  <p>Additional testing I discovered this issue is repro on Windows 2008 R2 Server with SQL Server 2012.&#160; It does not seem to fixed that at 4000MB the issue will start; if server is busy, then it can start at a higher value.&#160; In my re-pro test, I found it starting at even 6000MB.</p>  <p>As I said the up front memory allocation and management was contributing to this, however now I am unsure if Locked Pages in Memory is to contribute to this.</p>  <p>However, further insight I learned today.&#160; If this issue exists, you might have Lazy Writer spinning continuously on the effected NUMA node.</p>  <p>Therefore if you execute following T-SQL:</p>  <p>select session_id, wait_type, wait_time, cpu_time, scheduler_id    <br />&#160; from sys.dm_exec_requests     <br />where command = 'lazy writer'     <br />order by scheduler_id</p>  <p>Look at the output generated, if your Lazy Writer thread is working as normal (aka, only wakes up sometimes) you should see something similar to following:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/1715.clip_image002_5104DBBE.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/1715.clip_5F00_image002_5F00_5104DBBE.jpg"><img title="clip_image002" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image002" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/1738.clip_image002_thumb_05A537FA.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/1738.clip_5F00_image002_5F00_thumb_5F00_05A537FA.jpg" width="244" height="115" /></a></p>  <p>However if you have this issue the Lazy Writer might look like below:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/2816.clip_image0024_13777DF5.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/2816.clip_5F00_image0024_5F00_13777DF5.jpg"><img title="clip_image002[4]" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image002[4]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/2678.clip_image0024_thumb_5341647A.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/2678.clip_5F00_image0024_5F00_thumb_5F00_5341647A.jpg" width="244" height="116" /></a></p>  <ul>   <li>Notice the wait_type has gone to NULL. </li>    <li>Notice wait_time has gone to 0 – signal it is not going to sleep like the rest. </li>    <li>Notice cpu_time keeps climbing. </li> </ul>  <p>Only work around that I know for this currently is, increase the max memory until you see lazy writer stop spinning and processor utilization starts dropping.</p>]]></content:encoded>
    </item>
    <item>
      <title>SQL Server 2012 NUMA Node Imbalance</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlcan/sql-server-2012-numa-node-imbalance</link>
      <pubDate>Wed, 30 Sep 2015 12:39:31 GMT</pubDate>
      <dc:creator><![CDATA[Mohit K. Gupta]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlcan/2015/09/30/sql-server-2012-numa-node-imbalance/</guid>
      <description><![CDATA[One of my client has been fighting a very strange problem and there is not much literature on the...]]></description>
      <content:encoded><![CDATA[<p>One of my client has been fighting a very strange problem and there is not much literature on the topic, NUMA Node Imbalance. </p>  <p><strong>Server Configuration</strong> </p>  <li>8 NUMA nodes with 6 cores each; totaling 48 cores. </li>  <li>256GB memory. </li>  <li>12 Instances of SQL Server; mix of SQL Sever 2012 Latest Build and SQL Server 2008 R2 SP2. </li>  <p><strong>Issue</strong></p> NUMA node 0 pinned to 100% when all 12 instances are set to automatic CPU affinity setting.&#160; This is recommended as default, there have been very few cases where I have had to consider changing this.&#160; Generally default is fine, the SQL Server internal engine (or SQLOS)’s scheduler handle is very efficient at distributing load.&#160; So why do we have it that NUMA node 0 was pinned?  <p><strong>Initial Troubleshooting</strong></p>  <p>Any time we have performance problem on a server that is running SQL Sever instances; my first question to ask is, is it really SQL Sever? Looking at task manager or resource governor, both show highest CPU utilization of under 5%.&#160; This is not surprising, as the CPU in both of these tools provides an average over all CPUs.&#160; Therefore there is no easy way to know which instances were causing the NUMA Node 0 on the server to pin.&#160; There is nothing obvious that is also visible if I filter through the DMV/DMFs with in each instance. </p>  <p>However due to performance issues, my client decided to manually distribute the load across the 8 NUMA nodes by using CPU affinity mask setting.&#160; And sure enough load on NUMA node 0 went down; however he only did it for subset of the instances.&#160; So load decreased from 100% to about 70%. </p>  <p><strong>Research and Investigation</strong> </p>  <p>While doing investigation, I only found two KB articles that talk about NUMA node performance issue on SQL Server 2012, KB2819662 and KB2926223. However, all the SQL Server 2012 instances are on latest build; therefore, these hot fixes did not apply.&#160; I also found KB relating to operating system and NUMA processor pressure issues, however all turned out to be not the issue here.&#160; Because even operating system was fully patched. </p>  <p>In order to troubleshoot what is causing CPU pressure issue on NUMA node 0, we decided to move all instances off NUMA node 0 by using CPU affinity mask setting.&#160; In doing so we eventually found instances that was causing the load.&#160; There were 6 instances that were contributing the load. </p>  <p>After investigating we found, locked pages in memory is enabled by default on each instance and found all affected instances had their maximum set to 4000MB.&#160; I remember reading it is no recommended to have maximum memory set to such a low value.&#160; Therefore, we increased it to 6000MB.&#160; Doing so instantly caused the CPU on NUMA node 0 to return to nominal levels. </p>  <p><strong>Details</strong> </p>  <p align="center"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/0474.MaxMemory_at_4GB_3A62E0FF.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/0474.MaxMemory_5F00_at_5F00_4GB_5F00_3A62E0FF.png"><img title="MaxMemory_at_4GB" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="MaxMemory_at_4GB" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/1256.MaxMemory_at_4GB_thumb_35EC6038.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/1256.MaxMemory_5F00_at_5F00_4GB_5F00_thumb_5F00_35EC6038.png" width="244" height="152" /></a></p>  <p align="center"><font color="#555555" size="1"><em>Memory settings on SQLInstance01</em></font> </p>  <p align="center"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/4621.CPUAffinity_At_Node5_3175DF71.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/4621.CPUAffinity_5F00_At_5F00_Node5_5F00_3175DF71.png"><img title="CPUAffinity_At_Node5" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="CPUAffinity_At_Node5" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/2148.CPUAffinity_At_Node5_thumb_713FC5F6.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/2148.CPUAffinity_5F00_At_5F00_Node5_5F00_thumb_5F00_713FC5F6.png" width="244" height="131" /></a></p>  <p align="center"><font color="#555555" size="1"><em>Processor Affinity Mask Setting – Set to NumaNode03 for SQLInstance01</em></font> </p>  <p>Above is an example of SQLInstance01, set to 4000MB with processor affinity set to NumaNode03.&#160; If I look at the CPU now, there is no issues as in screenshot below.&#160; However load is not running on NUMA node 0 right now. </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/3250.CPU_LoadBefore_Rebalance_77F2CF79.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/3250.CPU_5F00_LoadBefore_5F00_Rebalance_5F00_77F2CF79.png"><img title="CPU_LoadBefore_Rebalance" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="CPU_LoadBefore_Rebalance" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/5810.CPU_LoadBefore_Rebalance_thumb_737C4EB2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/5810.CPU_5F00_LoadBefore_5F00_Rebalance_5F00_thumb_5F00_737C4EB2.png" width="244" height="161" /></a> </p>  <p align="center"><font color="#555555" size="1"><em>CPU Load on NUMA Node 0 (highlighted in red) – Nominal</em></font> </p>  <p align="center"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/2273.CPUAffinity_At_Auto_41187B33.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/2273.CPUAffinity_5F00_At_5F00_Auto_5F00_41187B33.png"><img title="CPUAffinity_At_Auto" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="CPUAffinity_At_Auto" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/6724.CPUAffinity_At_Auto_thumb_0EB4A7B4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/6724.CPUAffinity_5F00_At_5F00_Auto_5F00_thumb_5F00_0EB4A7B4.png" width="244" height="130" /></a> </p>  <p align="center"><font color="#333333" size="1"><em>Processor Affinity Mask Setting – Set to Default for SQLInstance01 </em></font></p>  <p>Now if I change the instance to use all NUMA nodes, as per the default configuration, as in screenshot above.&#160; Processors on NUMA node 0 start to pick up again. Notice the change was almost instantaneously.&#160; Since I only did it for one instance it did not cause processor to pin to 100%; however hovered around 40% constant.&#160; Imagine that times 6 instances, no wonder NUMA node 0 was pinned to 100%. </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/1031.CPU_LoadAfter_Rebalance_1567B137.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/1031.CPU_5F00_LoadAfter_5F00_Rebalance_5F00_1567B137.png"><img title="CPU_LoadAfter_Rebalance" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="CPU_LoadAfter_Rebalance" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/3681.CPU_LoadAfter_Rebalance_thumb_35168AFF.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/3681.CPU_5F00_LoadAfter_5F00_Rebalance_5F00_thumb_5F00_35168AFF.png" width="244" height="164" /></a> </p>  <p align="center"><font color="#555555" size="1"><em>CPU Load on NUMA Node 0 (highlighted in red) – After Affinity Set to Auto in SQL Server</em></font> </p>  <p>Now if I adjust the max memory setting to 8000MB (I tested it with 6000MB); both settings, processor returned to normal performance; as per the screenshots below. </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/4760.MaxMemory_at_8GB_50BB16F5.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/4760.MaxMemory_5F00_at_5F00_8GB_5F00_50BB16F5.png"><img title="MaxMemory_at_8GB" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="MaxMemory_at_8GB" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/1121.MaxMemory_at_8GB_thumb_6297AAC2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/1121.MaxMemory_5F00_at_5F00_8GB_5F00_thumb_5F00_6297AAC2.png" width="244" height="149" /></a> </p>  <p align="center"><font color="#555555" size="1"><em>Memory setting on SQLInstance01 – Setting it to 8000MB</em></font> </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/7220.CPU_LoadAfter_Rebalance_MemoryUpdate_0965C103.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/7220.CPU_5F00_LoadAfter_5F00_Rebalance_5F00_MemoryUpdate_5F00_0965C103.png"><img title="CPU_LoadAfter_Rebalance_MemoryUpdate" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="CPU_LoadAfter_Rebalance_MemoryUpdate" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/11/metablogapi/7750.CPU_LoadAfter_Rebalance_MemoryUpdate_thumb_250A4CF9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-11-metablogapi/7750.CPU_5F00_LoadAfter_5F00_Rebalance_5F00_MemoryUpdate_5F00_thumb_5F00_250A4CF9.png" width="244" height="158" /></a></p>  <p align="center"><font color="#333333" size="1"><em>CPU Load on NUMA Node 0 (highlighted in red) – After setting the Memory to &gt; 4000MB</em></font> </p>  <p><strong>Summary</strong> </p>  <p>If you are using 64-bit of SQL Server (which is all version now) and have locked pages in memory enabled.&#160; Be careful in setting the maximum memory value to a low value.&#160; Because of locked pages in memory additional work needs to be done by SQL Server to manage the memory and from looks of it all this work is happening on NUMA node 0.&#160; I do not know if this is by design.&#160; However setting the memory to value higher then or equal to 6000MB resolved this issue. </p>  <p>I’ll follow up on this if I have any updates, as I’ll be raising the issue internally also. </p>  <p>---</p>  <p>This post is cross posted on my <a href="https://sqlcan.wordpress.com/">SQLCAN Blog</a>, <a href="https://blogs.msdn.com/b/sqlcan/">MSDN Blog</a>, and <a href="https://mostafaelmasry.com/">SQL server Consultation</a> blog.</p>]]></content:encoded>
    </item>
    <item>
      <title>Service Principal Names for SQL Server</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlcan/service-principal-names-for-sql-server</link>
      <pubDate>Tue, 17 Jun 2014 13:52:00 GMT</pubDate>
      <dc:creator><![CDATA[Mohit K. Gupta]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlcan/2014/06/17/service-principal-names-for-sql-server/</guid>
      <description><![CDATA[Service Principal Names (SPN) get used for Kerberos authentication.&nbsp; SQL Server require that...]]></description>
      <content:encoded><![CDATA[<p>Service Principal Names (SPN) get used for Kerberos authentication.&nbsp; SQL Server require that all instances have SPNs configured, if not Kerberos authentication fails.&nbsp; By default starting with Windows 2008 all communication between clients and SQL Server is first attempted on Kerberos.&nbsp; If it fails, it falls back to NTLM.&nbsp; Often if you have Kerberos issues you might also have SSPI error messages in your SQL Server errorlog.</p>
<p>So question can be asked, if it falls back to NTLM and I can get my work done.&nbsp; Why do I care?&nbsp; Simple answer is delegation.&nbsp; With incorrect configured Kerberos, delegation cannot be completed and logins fail.&nbsp; For example on delegation, read my post on <a href="https://sqlcan.wordpress.com/2013/07/08/login-failed-for-user-nt-authorityanonymous-logon-with-sql-server-reporting-services/">Login failed for user &lsquo;NT AUTHORITY\ANONYMOUS LOGON&rsquo; with SQL Server Reporting&nbsp;Services</a>.</p>
<p>So what SPNs we need? Simple answer two SPN per SQL Server instance.</p>
<ul>
<li>MSSQLSvc/SQLServerName[:Port] Domain\SQLServerServiceAccount</li>
<li>MSSQLSvc/SQLServerName.FQDN[:Port] Domain\SQLServerServiceAccount</li>
</ul>
<p>Depending on your configuration, SPNs can look different.&nbsp; We can manage SPNs two ways; 1) using <a href="https://technet.microsoft.com/en-us/library/cc773257(v=WS.10).aspx">SETSPN</a> utility 2) using Activity Tool call EDITADIS.&nbsp; Most people rely on SETSPN, as other tool is for Active Directory administrators.&nbsp; And they (AD Admins)&nbsp;don&rsquo;t like it when we mess around with their stuff; like we don&rsquo;t like it when they mess around with our stuff <span class="wp-smiley emoji emoji-wink" title=";-)">;-)</span>.&nbsp; So lets talk about various forms of SPNs you can create.</p>
<p>Example #1: Default Instance, Default Port (1433), Using Domain Service Account</p>
<ul>
<li>MSSQLSvc/SQLServerName Domain\SQLServerServiceAccount</li>
<li>MSSQLSvc/SQLServerName.FQDN Domain\SQLServerServiceAccount</li>
</ul>
<p>Example #2: Default Instance, Non-Default Port, Using Domain Service Account<br /> Example #3: Named Instance, Static Non-Default Port, Using Domain Service Account</p>
<ul>
<li>MSSQLSvc/SQLServerName:Port Domain\SQLServerServiceAccount</li>
<li>MSSQLSvc/SQLServerName.FQDN:Port Domain\SQLServerServiceAccount</li>
</ul>
<p>Example #4: Default Instance, Default Port (1433), Using Computer Account *</p>
<ul>
<li>MSSQLSvc/SQLServerName Domain\ServerName$</li>
<li>MSSQLSvc/SQLServerName.FQDN Domain\ServerName$</li>
</ul>
<p>Example #5: Default Instance, Non-Default Port, Using Computer Account *<br /> Example #6: Named Instance, Static Non-Default Port, Using Computer Account *</p>
<ul>
<li>MSSQLSvc/SQLServerName:Port Domain\ServerName$</li>
<li>MSSQLSvc/SQLServerName.FQDN:Port Domain\ServerName$</li>
</ul>
<p>Example #7: Named Instance, Dynamic Non-Default Port, Using Domain Service Account **</p>
<ul>
<li>MSSQLSvc/SQLServerName:InstanceName Domain\SQLServerServiceAccount</li>
<li>MSSQLSvc/SQLServerName.FQDN:InstanceName Domain\SQLServerServiceAccount</li>
</ul>
<p>Example #8: Named Instance, Dynamic Non-Default Port, Using Computer Account *</p>
<ul>
<li>MSSQLSvc/SQLServerName:InstanceName Domain\ServerName$</li>
<li>MSSQLSvc/SQLServerName.FQDN:InstanceName Domain\ServerName$</li>
</ul>
<p><span style="color: #999999;">* An instance is consider using computer account when it is running under built in accounts, such as Network Services.</span><br /><span style="color: #999999;">** Generally we do not recommend dynamic port as managing SPN manually can be difficult.&nbsp; Also for us to use InstanceName, the SQL Server Browser service must be running.</span></p>
<p>So after reading this you are going that&rsquo;s TOO MUCH TO REMEMBER!</p>
<p>I agree, that is why SQL Server can create and destroy this SPNs by itself without user interaction. However in order to do this, we must grant SQL Server Service Account or Computer Account permissions to Read/Write SPN Property on itself (<a href="https://support.microsoft.com/kb/319723">Reference</a>).</p>
<p>Now there is one scenario where we do not want to grant this permission and mange the SPN manually.&nbsp; Please reference <a href="https://support.microsoft.com/kb/2443457">KB2443457</a>. Copied the issue from KB for completeness.</p>
<ol>
<li>The Sqlcluster instance is active on Node A and registered the SQL SPN in domain controller A during start up..</li>
<li>The Sqlcluster instance fails over to Node B when Node A is shutdown normally.</li>
<li>The Sqlcluster instance deregistered its SPN from domain controller A during the shutdown process on Node A.</li>
<li>The SPN is removed from domain controller A but the change has not yet been replicated to domain controller B.</li>
<li>When starting up on Node B, the Sqlcluster instance tries to register the SQL SPN with domain controller B. Since, the SPN still exists Node B does not register the SPN.</li>
<li>After some time, domain controller A replicates the deletion of the SPN (from step 3) to domain controller B as part of Active Directory replication. The end result is that no valid SPN exists for the SQL instance in the domain and hence you see connection issues to the Sqlcluster instance.</li>
</ol>
<p>Blog post cross posted on ...</p>
<ul>
<li>SQLCAN (WordPress), <a href="https://sqlcan.wordpress.com/2014/06/16/service-principal-names-for-sql-server/" target="_blank">Link</a>.</li>
<li>SQLCAN (MSDN), <a href="https://blogs.msdn.com/b/sqlcan/archive/2014/06/17/service-principal-names-for-sql-server.aspx">Link</a>.</li>
</ul>]]></content:encoded>
    </item>
  </channel>
</rss>