<?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 Server Blogs</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/batala/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/batala/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:39:42 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>SqlServerWriter missing when VSSadmin list writers command is run</title>
      <link>https://docs.microsoft.com/archive/blogs/batala/sqlserverwriter-missing-when-vssadmin-list-writers-command-is-run</link>
      <pubDate>Mon, 01 Aug 2011 11:54:00 GMT</pubDate>
      <dc:creator><![CDATA[Harsh Chawla]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/batala/2011/08/01/sqlserverwriter-missing-when-vssadmin-list-writers-command-is-run/</guid>
      <description><![CDATA[In this blog, I will discuss about what to do when :
1. we run Vssadmin list writers command and...]]></description>
      <content:encoded><![CDATA[<p>In this blog, I will discuss about what to do when :</p>
<p>1. we run Vssadmin list writers command and sqlserverwriter is missing and&nbsp;</p>
<p>2. Also, there is no error message in Application event logs and</p>
<p>3. Also, SQLserver VSS writer service is running</p>
<p>Here are the steps you need to follow to resolve such issues.</p>
<p></p>
<p>1. First of all we need to check if there are any spaces in the databases names. please run the query :</p>
<p><span style="background-color: #ffff00;">select '#' + name +'#'&nbsp; from sys.databases&nbsp;</span></p>
<p>if you notice any space in database names e.g. #test &nbsp;# , we need to make sure we remove the space from the database name.&nbsp;</p>
<p>Please follow this article to rename the database name : -&nbsp;<a href="https://msdn.microsoft.com/en-us/library/ms345378.aspx">https://msdn.microsoft.com/en-us/library/ms345378.aspx</a></p>
<p></p>
<p>once you remove the space in the database name, then issue vssadmin list writers command and check if the SQLwriter is there or not</p>
<p>2. If still SQLwriter is not there then:&nbsp;</p>
<p>please check the service logon which is mostly Nt authority/system or any user which you have mentioned as service logon, is added in SQL server as sysadmin privileges or not. If it's not there then please make it as syadmin. Run the VSSadmin list writers command.&nbsp;</p>
<p>Please feel free to post a question if the issue still persists.</p>]]></content:encoded>
    </item>
    <item>
      <title>Troubleshoot high CPU issue without using profile traces</title>
      <link>https://docs.microsoft.com/archive/blogs/batala/troubleshoot-high-cpu-issue-without-using-profile-traces</link>
      <pubDate>Sat, 23 Jul 2011 11:05:00 GMT</pubDate>
      <dc:creator><![CDATA[Harsh Chawla]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/batala/2011/07/23/troubleshoot-high-cpu-issue-without-using-profile-traces/</guid>
      <description><![CDATA[&nbsp;
The scope of these issues is very wide but I would discuss about the approach which I follow...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p>
<p>The scope of these issues is very wide but I would discuss about the approach which I follow to resolve these issues. I have resolved more than 50% of the cases by using this approach without even looking at profiler traces. I hope this will help you troubleshooting issues in your environment.</p>
<p>It&rsquo;s specific to SQL server 2008 &ndash; 64 bit environments but could be tried on 32 bit environments too.</p>
<p>Let&rsquo;s discuss about how to start it step by step.</p>
<p><b><span style="text-decoration: underline;">Step 1</span></b><b>: -</b> When you see high CPU utilization on the server check in task manager, which process is consuming high CPU. If it&rsquo;s SQL server then open perfmon and add the counter for Processor: % Privileged time, % Processor time and %user time</p>
<p>If you see the %privileged time to be high like hovering around 40% and above then it could be some driver issue. To troubleshoot these kinds of issues you could try:</p>
<p>Using Xperf: - <a href="https://blogs.msdn.com/b/ntdebugging/archive/2010/03/22/using-xperf-to-root-cause-cpu-consumption.aspx"><b>https://blogs.msdn.com/b/ntdebugging/archive/2010/03/22/using-xperf-to-root-cause-cpu-consumption.aspx</b></a> -- Video; <a href="https://msdn.microsoft.com/en-us/performance/cc709422"><b>https://msdn.microsoft.com/en-us/performance/cc709422</b></a></p>
<p>If it&rsquo;s user time which is high then the below steps will be applicable for troubleshooting:</p>
<p><b><span style="text-decoration: underline;">Step 2</span></b>: - First and very important one is to know what&rsquo;s the architecture i.e. 64 bit (X64 or IA 64) or 32 bit(x86):</p>
<p>Check the configuration using command: - Xp_msver</p>
<p>In this blog I will talk specifically about SQL server 2008 64-bit.</p>
<p><b><span style="text-decoration: underline;">Step 3</span></b>: - Check if there are any trace flags enabled:</p>
<p>dbcc tracestatus (-1); It&rsquo;s always good to check the reason of enabling the trace flags, if enabled.</p>
<p>Step 4: - Check the below mentioned SQL parameters</p>
<p>sp_configure 'advanced',1</p>
<p>go</p>
<p>reconfigure with override</p>
<p>go</p>
<p>sp_configure</p>
<p>go</p>
<ol>
<li><b>Priority Boost</b>: - it&rsquo;s not recommended to be enabled as it can cause high CPU utilization. If it&rsquo;s enabled (value =1) please disable(set value to 0) it - it&rsquo;s a static parameter which needs SQL restart</li>
<li><b>Max degree of parallelism</b>: - Although this parameter doesn&rsquo;t make much of a difference but sometimes I have seen SPID stuck in ACCESS_METHODS_SCAN_RANGE_GENERATOR, cxpacket or other parallel waittypes. If you see any such waits when you run this query :</li>
</ol>
<p>Select a.session_id, a.wait_type, a.wait_time, a.* from sys.dm_exec_requests a, sys.dm_exec_sessions b</p>
<p>where a.session_id=b.session_id and b.is_user_process=1</p>
<p>If in your case waittypes to be any of related to parallelism and the waittime is more than 20 ms reduce the parallelism to e.g. if 8 then to 4 and so on unless the waits go away.</p>
<p>Note: - If you have more than 8 processors, please make sure the max degree of parallelism parameter is 8 or below 8.</p>
<ol>
<li>Ensure that you have set max server memory by leaving minimum 3-4 GB for the OS</li>
</ol>
<p><b><span style="text-decoration: underline;">Step 4</span></b>: - Run dbcc memorystatus and check for the USERSTORE_TOKENPERM memory clerk. If the value is high say above 400 MB then follow the article: - <a href="https://support.microsoft.com/kb/927396"><b>https://support.microsoft.com/kb/927396</b></a></p>
<p><b><span style="text-decoration: underline;">Step 5</span></b>: - If everything mentioned above is alright then next thing we have to check is compilations and recompilations :</p>
<ol>
<li>Open perfmon and add the counters: -</li>
</ol>
<p>MSSQL: SQL statistics &agrave; Batch requests/s, compilations/s and recompilations/s.</p>
<p>If you notice compilations/sec are greater than 20% then there is definitely fair amount of chances for Procedure cache pollution. To confirm that please run the query:</p>
<p>WITH cached_plans (cacheobjtype, objtype, usecounts, size_in_bytes, dbid, objectid, short_qry_text) AS(</p>
<p>SELECT p.cacheobjtype, p.objtype, p.usecounts, size_in_bytes, s.dbid, s.objectid,</p>
<p>CONVERT (nvarchar(100), REPLACE (REPLACE (</p>
<p>CASE</p>
<p>-- Special cases: handle NULL s.[text] and 'SET NOEXEC'</p>
<p>WHEN s.[text] IS NULL THEN NULL</p>
<p>WHEN CHARINDEX ('noexec', SUBSTRING (s.[text], 1, 200)) &gt; 0 THEN SUBSTRING (s.[text], 1, 40)</p>
<p>-- CASE #1: sp_executesql (query text passed in as 1st parameter)</p>
<p>WHEN (CHARINDEX ('sp_executesql', SUBSTRING (s.[text], 1, 200)) &gt; 0)</p>
<p>THEN SUBSTRING (s.[text], CHARINDEX ('exec', SUBSTRING (s.[text], 1, 200)), 60)</p>
<p>-- CASE #3: any other stored proc -- strip off any parameters</p>
<p>WHEN CHARINDEX ('exec ', SUBSTRING (s.[text], 1, 200)) &gt; 0</p>
<p>THEN SUBSTRING (s.[text], CHARINDEX ('exec', SUBSTRING (s.[text], 1, 4000)),</p>
<p>CHARINDEX (' ', SUBSTRING (SUBSTRING (s.[text], 1, 200) + ' ', CHARINDEX ('exec', SUBSTRING (s.[text], 1, 500)), 200), 9) )</p>
<p>-- CASE #4: stored proc that starts with common prefix 'sp%' instead of 'exec'</p>
<p>WHEN SUBSTRING (s.[text], 1, 2) IN ('sp', 'xp', 'usp')</p>
<p>THEN SUBSTRING (s.[text], 1, CHARINDEX (' ', SUBSTRING (s.[text], 1, 200) + ' '))</p>
<p>-- CASE #5: ad hoc UPD/INS/DEL query (on average, updates/inserts/deletes usually</p>
<p>-- need a shorter substring to avoid hitting parameters)</p>
<p>WHEN SUBSTRING (s.[text], 1, 30) LIKE '%UPDATE %' OR SUBSTRING (s.[text], 1, 30) LIKE '%INSERT %'</p>
<p>OR SUBSTRING (s.[text], 1, 30) LIKE '%DELETE %'</p>
<p>THEN SUBSTRING (s.[text], 1, 30)</p>
<p>-- CASE #6: other ad hoc query</p>
<p>ELSE SUBSTRING (s.[text], 1, 45)</p>
<p>END</p>
<p>, CHAR (10), ' '), CHAR (13), ' ')) AS short_qry_text</p>
<p>FROM sys.dm_exec_cached_plans p</p>
<p>CROSS APPLY sys.dm_exec_sql_text (p.plan_handle) s</p>
<p>)</p>
<p>SELECT COUNT(*) AS plan_count, SUM (size_in_bytes) AS total_size_in_bytes,</p>
<p>cacheobjtype, objtype, usecounts, dbid, objectid, short_qry_text</p>
<p>FROM cached_plans</p>
<p>GROUP BY cacheobjtype, objtype, usecounts, dbid, objectid, short_qry_text</p>
<p>HAVING COUNT(*) &gt; 100</p>
<p>ORDER BY COUNT(*) DESC</p>
<p>RAISERROR ('', 0, 1) WITH NOWAIT</p>
<p>In the output you will need check:</p>
<p><b>Plan_count</b> : - number of times the similar plan was found in the procedure cache</p>
<p><b>use count</b> : - How many times the plan was reused and in the output of this query you will see the use_count = 1 most of the times which will tell that the query was not being reused.</p>
<p><b>Total_size_in_bytes</b>: - It&rsquo;s the memory consumed by the execution plans of the similar kinds.</p>
<p>For the description of the counters please check: - <a href="https://msdn.microsoft.com/en-us/library/aa173933(v=sql.80).aspx"><b>https://msdn.microsoft.com/en-us/library/aa173933(v=sql.80).aspx</b></a></p>
<p>In many cases you will find this to be the problem.</p>
<p>If you see the procedure cache pollution then you need to check the memory clerk: CACHESTORE_SQLCP in &ldquo;dbcc memorystatus&rdquo; command output (run in query analyzer).</p>
<p>In 64 bit system I have seen this memory to grow up to 8GB or more which is sign of excessive compilation. After you confirm this, there can be two possibilities</p>
<ol>
<li>Memory pressure which can cause cleanup of the execution plans and make SQL to compile the plan and in this case there will be no procedure cache pollution.</li>
<li>There are excessive Ad-hoc queries which are causing this compilation and you will see high pollution in the queries.</li>
</ol>
<p>For point number 2, there are steps which could be followed:</p>
<ol>
<li>Identify the text and database of the query which is being compiled in the output of the above mentioned query and set parameterization to forced</li>
<li>Parameterize the ad-hoc query :- <a href="https://msdn.microsoft.com/en-us/library/ee343986(v=sql.100).aspx"><b>https://msdn.microsoft.com/en-us/library/ee343986(v=sql.100).aspx</b></a></li>
</ol>
<p>If you see high re-compilations then check the article : - <a href="https://msdn.microsoft.com/en-us/library/ee343986(v=sql.100).aspx"><b>https://msdn.microsoft.com/en-us/library/ee343986(v=sql.100).aspx</b></a> .</p>
<p>Also, make sure statistics of the tables are updated with fullscan. To check the statistics updated date, run the query:</p>
<p>EXEC sp_msforeachtable 'select object_name(object_id) tablename,name as index_name,stats_date(object_id,index_id) as statistics_update_date from sys.indexes where Object_id=object_id("?")'</p>
<p>If after implementing the above action plans issue doesn&rsquo;t resolve then:</p>
<p>Check for the hashing and sorting in SQL server:</p>
<p>Open perfmon and add the counters: - MSSQL: memory manager (Granted workspace area) or check the output of the query:</p>
<p>select * from sys.dm_os_memory_clerks where type='MEMORYCLERK_SQLQERESERVATIONS'</p>
<p>If the value is very high e.g. more than like 3-4 GB and I have seen this value to go till 10 GB in high memory machines. It&rsquo;s a clear sign of big hash tables /huge sorting being done.</p>
<p>Then run the query (only for sql server 2008) : -</p>
<ol>
<li>Run the query :</li>
</ol>
<p>print '-- query and plan hash capture --'</p>
<p>print '-- query and plan hash capture --'</p>
<p>print '-- top 10 CPU by query_hash --'</p>
<p>select getdate() as runtime, *&nbsp; --into tbl_QueryHashByCPU</p>
<p>from</p>
<p>(</p>
<p>SELECT TOP 10 query_hash, COUNT (distinct query_plan_hash) as 'distinctquery_plan_hash count',</p>
<p>sum(execution_count) as 'execution_count',</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;sum(total_worker_time) as 'total_worker_time',</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;SUM(total_elapsed_time) as 'total_elapsed_time',</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;SUM (total_logical_reads) as 'total_logical_reads',</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</p>
<p>&nbsp;&nbsp;&nbsp; max(REPLACE (REPLACE (SUBSTRING (st.[text], qs.statement_start_offset/2 + 1,</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CASE WHEN qs.statement_end_offset = -1 THEN LEN (CONVERT(nvarchar(max), st.[text]))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ELSE qs.statement_end_offset/2 - qs.statement_start_offset/2 + 1</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END), CHAR(13), ' '), CHAR(10), ' '))&nbsp; AS sample_statement_text</p>
<p>FROM sys.dm_exec_query_stats AS qs</p>
<p>CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st</p>
<p>group by query_hash</p>
<p>ORDER BY sum(total_worker_time) DESC</p>
<p>) t</p>
<p>go</p>
<p>Find out which one is on the TOP and then run the below query to find the missing indexes:</p>
<p>DECLARE @runtime datetime</p>
<p>DECLARE @cpu_time_start bigint, @cpu_time bigint, @elapsed_time_start bigint, @rowcount bigint</p>
<p>DECLARE @queryduration int, @qrydurationwarnthreshold int</p>
<p>DECLARE @querystarttime datetime</p>
<p>SET @runtime = GETDATE()</p>
<p>SET @qrydurationwarnthreshold = 5000</p>
<p>PRINT ''</p>
<p>PRINT '==============================================================================================='</p>
<p>PRINT 'Missing Indexes: '</p>
<p>PRINT 'The "improvement_measure" column is an indicator of the (estimated) improvement that might '</p>
<p>PRINT 'be seen if the index was created. This is a unitless number, and has meaning only relative '</p>
<p>PRINT 'the same number for other indexes. The measure is a combination of the avg_total_user_cost, '</p>
<p>PRINT 'avg_user_impact, user_seeks, and user_scans columns in sys.dm_db_missing_index_group_stats.'</p>
<p>PRINT ''</p>
<p>PRINT '-- Missing Indexes --'</p>
<p>SELECT CONVERT (varchar, @runtime, 126) AS runtime,</p>
<p>mig.index_group_handle, mid.index_handle,</p>
<p>CONVERT (decimal (28,1), migs.avg_total_user_cost * migs.avg_user_impact * (migs.user_seeks + migs.user_scans)) AS improvement_measure,</p>
<p>'CREATE INDEX missing_index_' + CONVERT (varchar, mig.index_group_handle) + '_' + CONVERT (varchar, mid.index_handle)</p>
<p>+ ' ON ' + mid.statement</p>
<p>+ ' (' + ISNULL (mid.equality_columns,'')</p>
<p>+ CASE WHEN mid.equality_columns IS NOT NULL AND mid.inequality_columns IS NOT NULL THEN ',' ELSE '' END + ISNULL (mid.inequality_columns, '')</p>
<p>+ ')'</p>
<p>+ ISNULL (' INCLUDE (' + mid.included_columns + ')', '') AS create_index_statement,</p>
<p>migs.*, mid.database_id, mid.[object_id]</p>
<p>FROM sys.dm_db_missing_index_groups mig</p>
<p>INNER JOIN sys.dm_db_missing_index_group_stats migs ON migs.group_handle = mig.index_group_handle</p>
<p>INNER JOIN sys.dm_db_missing_index_details mid ON mig.index_handle = mid.index_handle</p>
<p>WHERE CONVERT (decimal (28,1), migs.avg_total_user_cost * migs.avg_user_impact * (migs.user_seeks + migs.user_scans)) &gt; 10</p>
<p>ORDER BY migs.avg_total_user_cost * migs.avg_user_impact * (migs.user_seeks + migs.user_scans) DESC</p>
<p>PRINT ''</p>
<p>GO</p>
<p><br />For information on the DMV&rsquo;s used in the query, please check <a href="https://msdn.microsoft.com/en-us/library/ms345421.aspx"><b>https://msdn.microsoft.com/en-us/library/ms345421.aspx</b></a></p>
<p>You will definitely find some index recommendations for the TOP queries. Create the indexes and see if that makes the difference.</p>
<p>If creating the indexes doesn&rsquo;t help then you will have to find the execution plan of the Top in the Top CPU query and try to tune it.</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>In SQL server, How to see the standby file path when we restore the database in standby mode:</title>
      <link>https://docs.microsoft.com/archive/blogs/batala/in-sql-server-how-to-see-the-standby-file-path-when-we-restore-the-database-in-standby-mode</link>
      <pubDate>Wed, 20 Jul 2011 21:35:00 GMT</pubDate>
      <dc:creator><![CDATA[Harsh Chawla]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/batala/2011/07/20/in-sql-server-how-to-see-the-standby-file-path-when-we-restore-the-database-in-standby-mode/</guid>
      <description><![CDATA[&nbsp;
I was answering to the questions on Social.msdn.microsoft.com forum site, Someone posted the...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p>
<p>I was answering to the questions on Social.msdn.microsoft.com forum site, Someone posted the question :</p>
<p>&nbsp;How to see the standby file path when we restore the database in standby mode:</p>
<p>&nbsp;I checked lots of DMVs e.g. msdb..restorefile, msdb..restorehistory etc. but couldn't find any place to get the standby file name.&nbsp;I Spent around 1-2 hours to find out the path. The answer, really awesome, was provided by someone else on the forums. I decided to blog this&nbsp;so that in future if someone wants to know about it, it's easier to find the answer.</p>
<p>&nbsp;</p>
<p>Just a little background for what happens when we restore the database in standby mode:</p>
<p>When we restore the database with recovery, it rolls back all the uncommitted transactions and bring the database online. And, when we restore the database with standby it leaves the database in read-only mode. Undo uncommitted transactions, but save the undo actions in a standby file so that recovery effects can be reverted.</p>
<p>&nbsp;</p>
<p>&nbsp;Here is how we can find the name of the .tuf,.Bak file which is created when we restore database in standby mode.</p>
<p>&nbsp;</p>
<p>** Please create a folder temp in C drive.</p>
<p>&nbsp;</p>
<p>** Below script<span style="background-color: #ffff00; font-size: medium;"> create the database,stop and read the log file to find the tuf filepath</span>.</p>
<p>&nbsp;</p>
<p>/* create test database */</p>
<p>CREATE DATABASE [DELETEME] ON</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRIMARY (NAME = N'DELETEME_data', FILENAME = N'C:\Temp\DELETEME_data.mdf')</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LOG ON (NAME = N'DELETEME_log', FILENAME = N'C:\Temp\DELETEME_log.ldf');</p>
<p>GO</p>
<p>BACKUP DATABASE [DELETEME] TO DISK = N'C:\Temp\deleteme.bak';</p>
<p>GO</p>
<p>BACKUP LOG [DELETEME] TO DISK = N'C:\Temp\deleteme.trn' WITH NORECOVERY;</p>
<p>GO</p>
<p>RESTORE DATABASE [DELETEME] FROM DISK = N'C:\Temp\deleteme.bak' WITH STANDBY = N'C:\Temp\DELETEME.TUF';</p>
<p>GO</p>
<p>/* run script to find undo file location</p>
<p>/* then run this cleanup */</p>
<p>DROP DATABASE [DELETEME];</p>
<p>EXEC xp_cmdshell 'DEL C:\Temp\deleteme.*', no_output</p>
<p>*/</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>/* ******************************** */</p>
<p>/* retrieve undo filepath from tlog */</p>
<p>/* ******************************** */</p>
<p>DECLARE @DATABASE SYSNAME;</p>
<p>SET @DATABASE = 'DELETEME';</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>declare @tlog varchar(260);</p>
<p>declare @undo varchar(520);</p>
<p>declare @cmd varchar(1000);</p>
<p>&nbsp;</p>
<p>set @tlog =</p>
<p>(</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.sysaltfiles.filename</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; from</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.sysaltfiles</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; left join</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.sysdatabases</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; on sys.sysdatabases.dbid = sys.sysaltfiles.dbid</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and sys.sysdatabases.filename = sys.sysaltfiles.filename</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.sysaltfiles.dbid = db_id(@DATABASE)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.sysdatabases.filename is null</p>
<p>);</p>
<p>&nbsp;</p>
<p>create table #file (id int identity(1,1) primary key clustered, line varchar(255) null, wrap varchar(510) null);</p>
<p>&nbsp;</p>
<p>set @cmd = 'sqlcmd -S' + @@servername + ' -Q"alter database ' + @DATABASE + ' set offline with rollback immediate"';</p>
<p>exec xp_cmdshell @cmd, no_output;</p>
<p>&nbsp;</p>
<p>set @cmd = 'type "' + @tlog + '"';</p>
<p>&nbsp;</p>
<p>insert into #file (line)</p>
<p>exec xp_cmdshell @cmd;</p>
<p>&nbsp;</p>
<p>set @cmd = 'sqlcmd -S' + @@servername + ' -Q"alter database ' + @DATABASE + ' set online with rollback immediate"';</p>
<p>exec xp_cmdshell @cmd, no_output;</p>
<p>&nbsp;</p>
<p>update here</p>
<p>set wrap = here.line + isnull(there.line, '')</p>
<p>from #file as here</p>
<p>left join #file there on there.id = here.id + 1;</p>
<p>&nbsp;</p>
<p>set @undo = (</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select distinct substring(wrap, patindex('%_[a-z]_:_\_%_._[a-z]_[a-z]_[a-z]_%', wrap), charindex('.', wrap, patindex('%_[a-z]_:_\_%_._[a-z]_[a-z]_[a-z]_%', wrap)) - patindex('%_[a-z]_:_\_%_._[a-z]_[a-z]_[a-z]_%', wrap) + 8)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; from #file</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where wrap like '%_[a-z]_:_\_%_._[a-z]_[a-z]_[a-z]_%'</p>
<p>);</p>
<p>&nbsp;</p>
<p>drop table #file;</p>
<p>&nbsp;</p>
<p>select @undo = replace(@undo, LEFT(@undo, 1), '');</p>
<p>select convert(varchar(260), @undo) as undo_filename</p>
<p>&nbsp;</p>
<p>&nbsp;You will get the output as the .tuf filename along with path.</p>
<p>&nbsp;</p>
<p>Kind regards</p>
<p>Harsh Chawla</p>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Perfmon counters missing for newly added database in sql server 2005</title>
      <link>https://docs.microsoft.com/archive/blogs/batala/perfmon-counters-missing-for-newly-added-database-in-sql-server-2005</link>
      <pubDate>Tue, 15 Mar 2011 11:03:00 GMT</pubDate>
      <dc:creator><![CDATA[Harsh Chawla]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/batala/2011/03/15/perfmon-counters-missing-for-newly-added-database-in-sql-server-2005/</guid>
      <description><![CDATA[Hello Everyone!
Recently I was working on a scenario in which&nbsp;we were not able to see any...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">Hello Everyone!<o:p></o:p></span></p>
<p><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">Recently I was working on a scenario in which&nbsp;we were not able to see any perfmon counters for newly added database. Evertytime we had to rebuild all the perfmon counters for sql server to get the perfmon counters of new database. It was just a workaround but&nbsp;we wanted to have a permanent resolution. <o:p></o:p></span></p>
<p><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">To find the cause of the problem, i checked the application logs and found the error:<o:p></o:p></span></p>
<p><span><span style="font-family: 'Arial','sans-serif'; background: yellow; color: black; font-size: 9pt;">The configuration information of the performance library ""C:\WINDOWS\system32\sqlctr90.dll"" for the ""MSSQLSERVER"" service does not match the<strong><span style="font-family: 'Arial','sans-serif';"> </span></strong></span><strong><span><span style="font-family: 'Arial','sans-serif'; background: lime; color: black; font-size: 9pt;">trusted performance</span></span></strong><span><span style="font-family: 'Arial','sans-serif'; background: lime; color: black; font-size: 9pt;"> </span><span style="font-family: 'Arial','sans-serif'; background: yellow; color: black; font-size: 9pt;"></span><span style="font-family: Times New Roman; font-size: small;">library information stored in the registry. The functions in this library will not be treated as trusted.</span></span></span><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;"><o:p></o:p></span></p>
<p><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">&nbsp;<o:p></o:p></span></p>
<p><strong><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">Then I checked the method which was being followed to rebuild the counters and found:</span></strong><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;"><o:p></o:p></span></p>
<p><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">1. Change the path to the BINN directory of the SQL Server instance you desire to correct.&nbsp;&nbsp; (Ex: C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\Binn) <br />&nbsp;&nbsp;&nbsp; <br />2. Unload the counters:<o:p></o:p></span></p>
<p><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">For a default instance of SQL Server run this command:<br />unlodctr MSSQLSERVER<o:p></o:p></span></p>
<p><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">3.&nbsp; Check the .ini files by running a command on command prompt: - dir *.ini<o:p></o:p></span></p>
<p><span><span style="font-family: 'Arial','sans-serif'; background: yellow; color: black; font-size: 9pt;">&nbsp;4. Execute lodctr /R:sqlctr.ini &nbsp;</span></span><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;"><o:p></o:p></span></p>
<p><span><span style="font-family: 'Arial','sans-serif'; background: yellow; color: black; font-size: 9pt;">**&nbsp;&nbsp;&nbsp; LODCTR /R&nbsp; rebuild the perf registry strings and info from scratch based on the current</span></span><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;"><o:p></o:p></span></p>
<p><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">5. Restart the remote registry and then open perfmon and check if the missing counters are back otherwise restart the machine.<o:p></o:p></span></p>
<p><strong><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">&nbsp;To resolve the error :</span></strong><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;"><o:p></o:p></span></p>
<p><span><span style="font-family: 'Arial','sans-serif'; background: yellow; color: black; font-size: 9pt;">The configuration information of the performance library ""C:\WINDOWS\system32\sqlctr90.dll"" for the ""MSSQLSERVER"" service does not match the<span></span><span style="font-family: 'Arial','sans-serif'; background: lime; color: black; font-size: 9pt;"> <strong><span style="font-family: 'Arial','sans-serif';">trusted performance</span></strong></span></span><span style="font-family: 'Arial','sans-serif'; background: yellow; color: black; font-size: 9pt;"> library information stored in the registry. The functions in this library will not be treated as trusted.</span></span><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;"><o:p></o:p></span></p>
<p><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">I had to just change the switch to /T <o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: Calibri;"><span><span style="color: black; font-size: 8pt;">1. Change the path to the BINN directory of the SQL Server instance you desire to correct</span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span><span><span lang="EN" style="color: black; font-size: 10pt; mso-ansi-language: EN; mso-bidi-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri;">.&nbsp;&nbsp; (Ex: C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\Binn) </span></span><span><span style="font-family: 'Times New Roman','serif'; color: black; font-size: 12pt;"><u1:p></u1:p></span><o:p></o:p></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: Calibri;"><b><span><span lang="EN" style="color: black; font-size: 7pt; mso-ansi-language: EN;">&nbsp;&nbsp;&nbsp; </span></span></b><span><u1:p></u1:p></span><span style="color: black;"><o:p></o:p></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: Calibri;"><span><span><span lang="EN" style="color: black; font-size: 10pt; mso-ansi-language: EN; mso-bidi-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri;">2. Unload the counters:<u1:p></u1:p></span></span></span><span style="color: black;"><o:p></o:p></span></span></p>
<p class="MsoListParagraph" style="line-height: 9.5pt; margin: 0in 0in 0pt 0.5in; background: white;"><span><u1:p><span><span style="font-family: 'Verdana','sans-serif'; color: black; font-size: 8pt; mso-bidi-font-family: Arial;">&nbsp;</span></span></u1:p></span><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;"><o:p></o:p></span></p>
<p class="MsoListParagraph" style="line-height: 9.5pt; margin: 0in 0in 0pt 0.5in; background: white;"><span><span><span style="font-family: 'Verdana','sans-serif'; color: black; font-size: 8pt; mso-bidi-font-family: Arial;">For a default instance of SQL Server run this command:<u1:p></u1:p></span></span></span><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;"><o:p></o:p></span></p>
<p class="MsoListParagraph" style="line-height: 9.5pt; margin: 0in 0in 0pt 0.5in; background: white;"><span style="font-family: Times New Roman;"><span><span style="color: black; font-size: 8pt;">unlodctr MSSQLSERVER<u1:p></u1:p></span></span><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;"><o:p></o:p></span></span></p>
<p class="MsoListParagraph" style="line-height: 9.5pt; margin: 0in 0in 0pt 0.5in; background: white;"><span><u1:p><span style="font-family: 'Segoe UI','sans-serif'; color: black; font-size: 8pt;">&nbsp;</span></u1:p></span><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: Calibri;"><span><span><span lang="EN" style="color: black; font-size: 10pt; mso-ansi-language: EN; mso-bidi-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri;">3. &nbsp;Check the .ini files by running a command on command prompt: - dir *.ini<u1:p></u1:p></span></span></span><span style="font-family: 'Times New Roman','serif'; color: black; font-size: 12pt;"><o:p></o:p></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span><u1:p><span><strong><span style="font-family: 'Verdana','sans-serif'; background: yellow; color: black; font-size: 8pt; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi;"></span><span><u1:p></u1:p></span><span><u1:p></u1:p></span><span><u1:p></u1:p></span><span><span style="font-family: Calibri; font-size: small;">4. Execute lodctr /T:sqlctr.ini&nbsp; </span></span></strong></span></u1:p></span><span style="color: black;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Verdana','sans-serif'; background: yellow; color: black; font-size: 8pt;"></span><span style="font-size: small;"><span style="font-family: Calibri;"><span><span><span>** LODCTR /T:&lt;Service-Name&gt;&nbsp; set the performance counter service as trusted.</span></span></span><span style="color: black;"><o:p></o:p></span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Verdana','sans-serif'; color: black; font-size: 8pt;"></span><span style="font-size: small;"><span style="font-family: Calibri;"><span><span>5. Restart the remote registry and then open perfmon and check if the missing counters are back otherwise restart the machine.<u1:p></u1:p></span></span><span style="color: black;"><o:p></o:p></span></span></span></p>
<p><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">After the above action plan the issue was resolved permanently<o:p></o:p></span></p>
<p><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">A very good blog on related issues : -</span><span style="font-size: small;"><span style="font-family: 'Calibri','sans-serif'; color: #1f497d;"> </span><span style="font-family: 'Arial','sans-serif'; color: #1f497d; font-size: 9pt;"><a href="https://blogs.msdn.com/b/psssql/archive/2009/03/03/troubleshooting-sql-server-2005-2008-performance-counter-collection-problems.aspx"><span style="font-family: 'Calibri','sans-serif'; font-size: 12pt;">https://blogs.msdn.com/b/psssql/archive/2009/03/03/troubleshooting-sql-server-2005-2008-performance-counter-collection-problems.aspx</span></a></span></span><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;"><u1:p><o:p></o:p></u1:p></span></p>
<p><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">Kind regards<o:p></o:p></span></p>
<p><span style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt;">Harsh Chawla<o:p></o:p></span></p>]]></content:encoded>
    </item>
    <item>
      <title>Data Capturing and Analysis using SQL Server 2008 Activity Monitor and SQL DMV’s</title>
      <link>https://docs.microsoft.com/archive/blogs/batala/data-capturing-and-analysis-using-sql-server-2008-activity-monitor-and-sql-dmvs</link>
      <pubDate>Tue, 23 Nov 2010 01:14:02 GMT</pubDate>
      <dc:creator><![CDATA[Harsh Chawla]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/batala/2010/11/23/data-capturing-and-analysis-using-sql-server-2008-activity-monitor-and-sql-dmvs/</guid>
      <description><![CDATA[In this blog, I will be sharing a unique instance of data capturing and analysis using SQL Activity...]]></description>
      <content:encoded><![CDATA[<p>In this blog, I will be sharing a unique instance of data capturing and analysis using SQL Activity monitor ,SQL DMV&rsquo;s and also their correlation. </p>
<p>We usually tend to see Activity monitor for a quick understanding of SQL health and resource consumption. Here is a scenario very close to Network IO in Activity monitor. </p>
<p>Below is the screen shot depicting Network IO operation in one of my SQL Server troubleshooting cases. </p>
<p>&nbsp;<img height="318" width="576" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/sqlserverfaq/WindowsLiveWriter/DataCapturingandAnalysisusingSQLServer20_EEB4/image_5.png" original-url="https://blogs.msdn.com/blogfiles/sqlserverfaq/WindowsLiveWriter/DataCapturingandAnalysisusingSQLServer20_EEB4/image_5.png" alt="image" border="0" title="image" style="display: inline; border-width: 0px;" /> </p>
<p>Here we observe that there are some waits happening on NetworkIO and this data is collected internally using sys.dm_os_wait_stats DMV&rsquo;s view. </p>
<p>Let me take you further into this, how we can establish the correlation between SQL Activity monitor and DMV which we can use in our normal administration work with SQL Server Network IO troubleshooting. </p>
<p>Looking at the above Activity monitor, SQL Administrator have a general perception that network IO mean something to do only with Network Lines, however its more than that. Activity monitor represents Network I/O as waits on OLEDB, MSQL_DQ, DTC_STATE, DBMIRROR_SEND and ASYNC_NETWORK_IO. </p>
<p>In this scenario customer was running SQL Server profiler trace on the SQL server capturing data and we could observe Network I/O in activity monitor. </p>
<p>Checked sys.dm_os_waiting_tasks and found that there was a task waiting on oledb and Found that session was executing stored procedure to gather the profiler data (dbcc inputbuffer(&lt;session_id&gt;)): </p>
<p><b>(@P1 int) exec sp_trace_getdata @P1, 0</b></p>
<p>Checked sys.dm_os_wait_stats view and found some waits on oledb also checked sys.dm_exec_requests view and found that the session was waiting on oledb. </p>
<p>In the above scenario it was clear that the issue was oledb waits which are quite normal when we capture profiler traces. </p>
<p>We can reproduce the same scenario on our box using below steps. </p>
<p>1. Start a normal profiler trace. </p>
<p>2. Run the activity monitor and see the waits. </p>
<p>3. Query the view: sys.dm_os_waiting_tasks and check the Session id waiting on oledb. </p>
<p>4. Run dbcc inputbuffer(&lt;session_id&gt;), you will see the query text: -&ldquo;exec&nbsp; sp_trace_getdata&rdquo; </p>
<p>5. Stop the trace and the waits will not be there </p>
<p>In the above scenario we had visibility of waits in the <b>sys.dm_exec_requests </b>view and <b>sys.dm_os_wait_stats </b>DMV as well as in activity monitor. </p>
<p>But what if, there are no waits observed in <b>sys.dm_exec_requests</b> DMV for any resource but in activity monitor and <b>sys.dm_os_wait_stats</b> view. </p>
<p>Here is another case study where we see waits in activity monitor and <b>sys.dm_os_wait_stats</b> but no wait in <b>sys.dm_exec_requests</b>. </p>
<p>Step 1: open activity monitor and check resource waits. </p>
<p>Step 2: Run a select statement which returns more than 1000 rows </p>
<blockquote>
<p>&nbsp;&nbsp;&nbsp; e.g.&nbsp;&nbsp; select * from &lt;Table Name&gt; </p>
</blockquote>
<p>Step 3: Now you will see the network waits in activity monitor. </p>
<p>Step 4: Query the sys.dm_exec_requests view and there will be no waits by that session. </p>
<p>Step 5: select * from sys.dm_os_wait_stats where wait_type='async_network_io' </p>
<p>Step 6: Run the query in step 2 and then repeat step 5 </p>
<p>You will see the increase in <b>async_network_io</b> waits. </p>
<p>Hence we need to look at the DMV&rsquo;s&nbsp; before we draw any conclusion on the basis of activity monitor. It&rsquo;s also a best approach to correlate the data with Perfmon counters to reach a conclusion. </p>]]></content:encoded>
    </item>
    <item>
      <title>SQL Server encounters memory pressure and generate 701 Error due to incorrect configuration of Service Broker</title>
      <link>https://docs.microsoft.com/archive/blogs/batala/sql-server-encounters-memory-pressure-and-generate-701-error-due-to-incorrect-configuration-of-service-broker</link>
      <pubDate>Tue, 23 Nov 2010 00:57:00 GMT</pubDate>
      <dc:creator><![CDATA[Harsh Chawla]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/batala/2010/11/23/sql-server-encounters-memory-pressure-and-generate-701-error-due-to-incorrect-configuration-of-service-broker/</guid>
      <description><![CDATA[Here is one of the rare scenario on SQL Server memory issue (701 error) caused due service broker...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family: Segoe UI; font-size: x-small;">Here is one of the rare scenario on SQL Server memory issue (701 error) caused due service broker misconfiguration or incorrectly used, causing memory object <b>OBJECTSTORE_SERVICE_BROKER</b> to grow and not releasing memory back.</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">Below is the memory error, we observed in SQL Server error log followed by DBCC MEMORYSTATUS output. </span></p>
<p><b><span style="font-family: Segoe UI; font-size: x-small;">You will see below error messages in SQL Server error log:</span></b></p>
<p><b><span style="font-family: Segoe UI; font-size: x-small;"></span></b></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">2010-02-17 07:28:43.06 Server&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Failed allocate pages: FAIL_PAGE_ALLOCATION 1</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">2010-02-17 07:28:43.06 spid14s&nbsp;&nbsp;&nbsp;&nbsp; Error: 701, Severity: 17, State: 123.</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">2010-02-17 07:28:43.06 spid14s&nbsp;&nbsp;&nbsp;&nbsp; There is insufficient system memory to run this query.</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">2010-02-17 07:28:43.06 spid12s&nbsp;&nbsp;&nbsp;&nbsp; Error: 802, Severity: 17, State: 11.</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">2010-02-17 07:28:43.06 spid12s&nbsp;&nbsp;&nbsp;&nbsp; There is insufficient memory available in the buffer pool.</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">In DBCC <b>MEMORYSTATUS</b> we find:</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">Memory Manager </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">VM Reserved = 1650436 KB</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">VM Committed = 1649556 KB </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">AWE Allocated = 0 KB </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">Reserved Memory = 1024 KB </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">Reserved Memory In Use = 0 KB </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">MEMORYCLERK_SQLBUFFERPOOL (Total) </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">VM Reserved = 1632340 KB </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">VM Committed = 1632340 KB </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">AWE Allocated = 0 KB </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">SM Reserved = 0 KB </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">SM Committed = 0 KB</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">SinglePage Allocator = 0 KB</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">MultiPage Allocator = 400 KB</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">OBJECTSTORE_SERVICE_BROKER&nbsp; (Total) </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">VM Reserved = 0 KB </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">VM Committed = 0 KB </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">AWE Allocated = 0 KB </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">SM Reserved = 0 KB </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">SM Committed = 0 KB</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">SinglePage Allocator = 1523880 KB&nbsp; --&gt;Consuming most of the memory</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">MultiPage Allocator = 0 KB</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">The Single Page allocator value for OBJECTSTORE_SERVICE_BROKER object looks interesting and uncommon causing BPOOL exhaustion consuming almost 1.5 GB.</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">This hints problem towards service broker. Further to go indepth in troubleshooting service broker gathered the information from the view:</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">select state,COUNT(*) from sys.conversation_endpoints group by state</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">There were millions of conversations in the view:</span></p>
<p><b><span style="font-family: Segoe UI; font-size: x-small;">count&nbsp;&nbsp;&nbsp;&nbsp; </span></b></p>
<p><b><span style="font-family: Segoe UI; font-size: x-small;">--------</span></b></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">20930578</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">&ldquo;90% of the conversation was in conversing state&rdquo;</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">Was checking the service broker configurations and observed that initiator and target was configured on the same database. The service broker was configured to temporarily save the application messages to improve application performance.</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">The queue was set in auto mode i.e. the procedure at the target would be called automatically to pick up the message from the target queue.&nbsp; Checked the profiler traces and found that there was no call to the target procedure and that seemed to be the cause of the problem.</span></p>
<p><b><span style="font-family: Segoe UI; font-size: x-small;">Further dived deeper into this issue and was successful in reproducing the issue using the steps below:</span></b></p>
<p><b><span style="font-family: Segoe UI; font-size: x-small;">Repro steps</span></b></p>
<p><b><span style="font-family: Segoe UI; font-size: x-small;">===========</span></b></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">Note: Intent of the below mentioned repro is just to show that when the stored procedure at the target gets invalidated then the messages get stuck in the queue causing OBJECTSTORE_SERVICE_BROKER object to keep growing.</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">ALTER DATABASE DBName SET ENABLE_BROKER </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">create message type req1 AUTHORIZATION dbo validation= None </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">create message type req2 AUTHORIZATION dbo validation= None </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">create queue senderqueue </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">create queue receiverqueue </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">create contract testcontract (req1 sent by initiator, req2 sent by target) </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">create service sendreqservice on queue senderqueue(testcontract) </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">create service receivereqservice on queue receiverqueue(testcontract) </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">select name,service_broker_GUID from sys.databases where is_broker_enabled=1 </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">create route testroute with service_Name='sendreqservice', broker_instance='CB496106-EC67-41A9-8F01-3EDFE58FB01B', address='TCP://localhost:1433' </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">create table temp_table (message char(10)) </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">create procedure sp_processqueue </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">as </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">begin </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">Declare @message char(20) </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">declare @message_type_name varchar(20) </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">declare @conversationhandle uniqueidentifier </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">begin </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">receive top(1) </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">@conversationhandle =conversation_handle, </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">@message_type_name=message_type_name, </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">@message=message_body </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">from dbo.receiverqueue </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">if @message_type_name='req1' </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">begin </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">insert into temp_table values(@message); </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">end </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">--end conversation @conversationhandle with cleanup; </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">end </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">end </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">Alter queue receiverqueue&nbsp; with activation(status=ON,procedure_name = SP_processqueue,execute as owner) </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">Declare @message char(10); </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">declare @conversationhandle uniqueidentifier </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">set @message='hi' </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">begin dialog conversation @conversationhandle </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">from service sendreqservice </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">to service 'receivereqservice' </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">on contract testcontract </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">with encryption =off; </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">send on conversation @conversationhandle </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">message type req1 </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">(@message); </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">--end conversation @conversationhandle </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">Now let&rsquo;s invalidate the procedure to create the problem:</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">1. Change the procedure code somewhere and make it invalid:</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">alter procedure sp_processqueue</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">as</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">begin</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">Declare @message char(20)</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">declare @message_type_name varchar(20)</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">declare @conversationhandle uniqueidentifier</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">begin</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">receive top(1)</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">@conversationhandle =conversation_handle,</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">@message_type_name=message_type_name,</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">@message=message_body</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">from dbo.receiverqu --&gt; changed the name to invalid table_name</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">if @message_type_name='req1'</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">begin</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">insert into temp_table values(@message);</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">end</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">--end conversation @conversationhandle with cleanup;</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">end</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">end</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">2. Now again run the code to queue a message.</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">Declare @message char(10);</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">declare @conversationhandle uniqueidentifier</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">set @message='hi'</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">begin dialog conversation @conversationhandle</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">from service sendreqservice</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">to service 'receivereqservice'</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">on contract testcontract</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">with encryption =off;</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">send on conversation @conversationhandle</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">message type req1</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">(@message);</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">--end conversation @conversationhandle</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">select * from temp_table&nbsp; </span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">select * from sys.conversation_endpoints</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">You will see that the status in the sys.conversation_endpoints is again "CONVERSING". Which is same as the successful execution but the difference is that the message is not processed, you can also check in the profiler trace that we called the stored procedure to process the message but it failed to execute as it was invalid.</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">1. Now correct the stored procedure:</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">alter procedure sp_processqueue</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">as</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">begin</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">Declare @message char(20)</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">declare @message_type_name varchar(20)</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">declare @conversationhandle uniqueidentifier</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">begin</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">receive top(1)</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">@conversationhandle =conversation_handle,</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">@message_type_name=message_type_name,</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">@message=message_body</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">from dbo.receiverqueue --&gt;changed the name to valid table_name</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">if @message_type_name='req1'</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">begin</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">insert into temp_table values(@message);</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">end</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">--end conversation @conversationhandle with cleanup;</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">end</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">end</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">2. Again run the below code to enqueue the message:</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">Declare @message char(10);</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">declare @conversationhandle uniqueidentifier</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">set @message='hi'</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">begin dialog conversation @conversationhandle</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">from service sendreqservice</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">to service 'receivereqservice'</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">on contract testcontract</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">with encryption =off;</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">send on conversation @conversationhandle</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">message type req1</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">(@message);</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">If you see in the profiler trace, there will be no call to the stored procedure at target. Hence the message don&rsquo;t get processed as its still considered as invalid until we run manually at least once.</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">To sort out the problem, run the stored procedure manually:</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">exec sp_processqueue</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">After this you will find the messages being processed, run the below query to confirm the same.</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">select * from temp_table&nbsp; </span></p>
<p><b><span style="font-family: Segoe UI; font-size: x-small;">Resolution</span></b></p>
<p><b><span style="font-family: Segoe UI; font-size: x-small;">==========</span></b></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">1. You will need to run the target procedure manually.</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">It will deliver the messages to the target and release the space from the&nbsp; <b>OBJECTSTORE_SERVICE_BROKER</b>&nbsp; objectstore.</span></p>
<p><span style="font-family: Segoe UI; font-size: x-small;">2. But to clear the messages from the service_endpoints view you will have to&nbsp; change the procedure code to end the conversations (with cleanup). </span></p>
<p><strong></strong></p>]]></content:encoded>
    </item>
  </channel>
</rss>