<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblogcasts.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Maciej Pilecki - SQL Server lessons from the field</title><subtitle type="html">&lt;div align="center"&gt;&lt;img src="http://sqlblogcasts.com/photos/blogimages/images/454/secondarythumb.aspx" alt="" /&gt;

&lt;/div&gt;</subtitle><id>http://sqlblogcasts.com/blogs/maciej/atom.aspx</id><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/maciej/default.aspx" /><link rel="self" type="application/atom+xml" href="http://sqlblogcasts.com/blogs/maciej/atom.aspx" /><generator uri="http://communityserver.org" version="3.1.20917.1142">Community Server</generator><updated>2008-09-21T00:06:00Z</updated><entry><title>Conference season opened</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/maciej/archive/2008/09/25/conference-season-opened.aspx" /><id>http://sqlblogcasts.com/blogs/maciej/archive/2008/09/25/conference-season-opened.aspx</id><published>2008-09-25T17:14:00Z</published><updated>2008-09-25T17:14:00Z</updated><content type="html">&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;OK, so I have opened my autumn conference season today with two presentations at &lt;/font&gt;&lt;a class="" href="http://it-republik.de/dotnet/sqlcon/" target="_blank"&gt;&lt;font face="georgia,palatino" size="2"&gt;SQLCON 2008&lt;/font&gt;&lt;/a&gt;&lt;font face="georgia,palatino" size="2"&gt; (part of &lt;/font&gt;&lt;a class="" href="http://it-republik.de/dotnet/basta/" target="_blank"&gt;&lt;font face="georgia,palatino" size="2"&gt;BASTA!&lt;/font&gt;&lt;/a&gt;&lt;font face="georgia,palatino" size="2"&gt;) in Mainz, Germany. If not for the fact that I was quite miserable due to extreme pain in my lower back (I could hardly walk and there was no position in which I would be comfortable), it was great fun! Luckily, they had a masseuse on site and she did a great job fixing me.&amp;nbsp;Many thanks to the organizers and attendees of that fine conference! I hope to be back next spring.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;So, what&amp;#39;s next? Well, quite a bit - this autumn I am doing &amp;quot;a few&amp;quot; conferences. Here is a list of the confirmed ones:&lt;/font&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div&gt;&lt;font face="georgia,palatino" size="2"&gt;September 29th - October 1st - MS Partner Conference in Riga, Latvia - I am doing both the main conference as well as 2-day post-conf SQL 2008 workshop.&lt;/font&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;font face="georgia,palatino" size="2"&gt;October 1st - 3rd - MS Partner Conference in Vilnius, Lithuania - I will miss the main conference but I will be there&amp;nbsp;in time to do the workshop on Thursday and Friday.&lt;/font&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;font face="georgia,palatino" size="2"&gt;October 13th - 14th - &lt;/font&gt;&lt;a class="" href="http://www.devreach.com/" target="_blank"&gt;&lt;font face="georgia,palatino" size="2"&gt;DevReach&lt;/font&gt;&lt;/a&gt;&lt;font face="georgia,palatino" size="2"&gt; in Sofia, Bulgaria. I will be there only on Monday (doing 2 sessions), but this conference is one of the highlights in my schedule - it&amp;#39;s one of the best in CEE.&lt;/font&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;font face="georgia,palatino" size="2"&gt;October 14th - 17th - &lt;/font&gt;&lt;a class="" href="https://www.mssinergija.net/" target="_blank"&gt;&lt;font face="georgia,palatino" size="2"&gt;Sinergija 08&lt;/font&gt;&lt;/a&gt;&lt;font face="georgia,palatino" size="2"&gt; in Novi Sad, Serbia. First time for me but I am looking forward to being part of this great conference.&lt;/font&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;font face="georgia,palatino" size="2"&gt;October 21st - 22nd - &lt;/font&gt;&lt;a class="" href="http://www.trivadis.com/training/trivadisopen-2008.html" target="_blank"&gt;&lt;font face="georgia,palatino" size="2"&gt;TrivadisOPEN 2008&lt;/font&gt;&lt;/a&gt;&lt;font face="georgia,palatino" size="2"&gt; in Zurich,&amp;nbsp;Switzerland. Dual first time: first time at this conference and first time in Switzerland. Wow, some new country for me to visit. :)&lt;/font&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;font face="georgia,palatino" size="2"&gt;November 3rd - 7th - &lt;/font&gt;&lt;a class="" href="http://www.microsoft.com/emea/teched2008/itpro/default.aspx" target="_blank"&gt;&lt;font face="georgia,palatino" size="2"&gt;TechEd ITPro EMEA&lt;/font&gt;&lt;/a&gt;&lt;font face="georgia,palatino" size="2"&gt; in Barcelona, Spain. A classic one, not to be missed.&lt;/font&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;font face="georgia,palatino" size="2"&gt;November 18th - 21st - &lt;/font&gt;&lt;a class="" href="http://summit2008.sqlpass.org/" target="_blank"&gt;&lt;font face="georgia,palatino" size="2"&gt;PASS Commuity Summit 2008&lt;/font&gt;&lt;/a&gt;&lt;font face="georgia,palatino" size="2"&gt; in Seattle, WA. First time for me at PASS Summit in US. This one is a must for any SQL Server professional!&lt;/font&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;font face="georgia,palatino" size="2"&gt;November 25th - 26th - &lt;/font&gt;&lt;a class="" href="http://www.microsoft.com/austria/server/data-and-process-management/sql-konferenz/default.mspx" target="_blank"&gt;&lt;font face="georgia,palatino" size="2"&gt;SQL Server Energy 2008&lt;/font&gt;&lt;/a&gt;&lt;font face="georgia,palatino" size="2"&gt; in Vienna, Austria. Lots of friends there - it will be a&amp;nbsp;fun conference, I am sure.&lt;/font&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;This may seem like a very busy schedule but in fact, it&amp;#39;s nothing new to me. Actually, I still have a few gaps in my calendar&amp;nbsp;so if you are organizing a conference and would like to invite me, feel free to give me a call. :)&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;I am looking forward to seeing you at one (or two) of those conferences! Make sure you join me&amp;nbsp;at one of my sessions.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;And for my Polish readers: There is a big gaping hole in this schedule that some of you may notice - it&amp;#39;s the &lt;/font&gt;&lt;a class="" href="http://www.mts2008.pl/" target="_blank"&gt;&lt;font face="georgia,palatino" size="2"&gt;Microsoft Technology Summit&lt;/font&gt;&lt;/a&gt;&lt;font face="georgia,palatino" size="2"&gt; in Warsaw in less than 2 weeks. Since many people asked me about this, I feel compelled to answer: I will not be there because I have not been invited, not because I don&amp;#39;t have time. Believe me, I wish I could join you there, but it was not for me to decide. If you want to see me there next year, make sure that you let the organizers know. I will be happy to come.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;Enjoy the conference season this year!&lt;/font&gt;&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=10843" width="1" height="1"&gt;</content><author><name>maciej</name><uri>http://sqlblogcasts.com/members/maciej.aspx</uri></author><category term="Conferences" scheme="http://sqlblogcasts.com/blogs/maciej/archive/tags/Conferences/default.aspx" /><category term="Travel" scheme="http://sqlblogcasts.com/blogs/maciej/archive/tags/Travel/default.aspx" /></entry><entry><title>Clearing your ad-hoc SQL plans while keeping your SP plans intact</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/maciej/archive/2008/09/21/clearing-your-ad-hoc-sql-plans-while-keeping-your-sp-plans-intact.aspx" /><id>http://sqlblogcasts.com/blogs/maciej/archive/2008/09/21/clearing-your-ad-hoc-sql-plans-while-keeping-your-sp-plans-intact.aspx</id><published>2008-09-20T22:40:00Z</published><updated>2008-09-20T22:40:00Z</updated><content type="html">&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;The problem of the procedure cache being inflated with ad-hoc SQL plans that are almost never reused has been discussed many times. You can find an interesting post about this by Tony Rogerson &lt;/font&gt;&lt;a class="" href="http://sqlblogcasts.com/blogs/tonyrogerson/archive/2007/07/07/procedure-cache-tuning-sizing-from-1gbyte-to-768kbytes-increase-the-size-of-usable-data-cache.aspx" target="_blank"&gt;&lt;font face="georgia,palatino" size="2"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font face="georgia,palatino" size="2"&gt;. Another post by Lara Rubbelke that touches on the same problem is &lt;/font&gt;&lt;a class="" href="http://sqlblog.com/blogs/lara_rubbelke/archive/2008/04/18/memory-pressure-on-64-bit-sql-server-2005.aspx" target="_blank"&gt;&lt;font face="georgia,palatino" size="2"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font face="georgia,palatino" size="2"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;Just to summarize: on systems that have a lot of ad-hoc SQL queries, the procedure cache can get rather large. That is especially true for some 64bit systems with a lot of memory as the procedure cache has higher thresholds for memory pressure there. The effect is usually the size of procedure cache being disproportionally large in&amp;nbsp;comparison&amp;nbsp;with the total system memory and the size of buffer pool used for data pages. I have personally seen systems with several GBs of memory used for procedure cache that was filled mostly with ad-hoc and&amp;nbsp;seldom reused plans. I have even seen this occurring on systems that were using stored procedures exclusively, as there were still a lot of ad-hoc queries coming from SQL Agent engine as well as various parts of SQL Server management tools...&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;I could go for hours explaining the reasons why this problem occurs and different ways to solve it. I cover this topic to some extent in my &amp;quot;Dude, Where Is My Memory?&amp;quot; conference session (you can see this session at many conferences throughout Europe this fall, including TechEd ITForum). I am contemplating writing an article about this, but no promises at this point... &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;OK, back to our problem... How to check if your server is experiencing this problem? The easiest way is to run this simple query:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;select objtype, &lt;br /&gt;count(*) as number_of_plans, &lt;br /&gt;sum(cast(size_in_bytes as bigint))/1024/1024 as size_in_MBs,&lt;br /&gt;avg(usecounts) as avg_use_count&lt;br /&gt;from sys.dm_exec_cached_plans&lt;br /&gt;group by objtype&lt;/p&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;If you have problems with ad-hoc plans, you are likely to see several thousand of plans with &lt;em&gt;objtype&lt;/em&gt; &amp;quot;Adhoc&amp;quot;, occupying as much as several GBs (bulk of all memory consumed by the procedure cache)&amp;nbsp;and having very low avg_use_count. The ad-hoc&amp;nbsp;plans generally&amp;nbsp;accumulate over time (up to the &lt;/font&gt;&lt;a class="" href="http://sqlug.be/blogs/wesleyb/archive/2007/01/24/486.aspx" target="_blank"&gt;&lt;font face="georgia,palatino" size="2"&gt;memory pressure limits of the procedure cache&lt;/font&gt;&lt;/a&gt;&lt;font face="georgia,palatino" size="2"&gt;) so you may not see this right after a server restart or proc cache flush - but you will see the number constantly growing until it reaches the limit.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;If you want to get rid of the ad-hoc plans, one simple and effective yet somewhat dangerous way is to clear the procedure cache completely with DBCC FREEPROCCACHE. I have seen many people do it, even having&amp;nbsp;it scheduled as a regular job.&amp;nbsp;It works great&amp;nbsp;to get rid of all the clutter in procedure cache but the problem&amp;nbsp;is that&amp;nbsp;since you are clearing&amp;nbsp;the cache&amp;nbsp;completely, you are also getting rid of your valuable SP plans. This can cause a noticeable system slowdown right after, due to the cost of compiling any incoming SP call and possible contention in case of many compilations occurring at the same time (compilations in SQL Server are throttled). And of course you will have to do it again in a few hours/minutes as the ad-hoc plans will start building up again... &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;So, I recently started wondering how to be a little more selective in what we throw out of the procedure cache. The revelation came to me about a week ago and I already had a chance to test it on a few systems. The idea is so simple that I am actually very surprised that I have never seen it described anywhere before. The key&amp;nbsp;to understanding how this works (and how I arrived at my solution) is to realize that there is no single procedure cache. The procedure cache actually consists of 4 distinct cache stores that hold different types of plans. Those cache stores are:&lt;/font&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div&gt;&lt;font face="georgia,palatino" size="2"&gt;CACHESTORE_OBJCP - these are &amp;quot;Object Plans&amp;quot; - stored procedures, functions and triggers. Generally, the good stuff.&lt;/font&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;font face="georgia,palatino" size="2"&gt;CACHESTORE_SQLCP - these are &amp;quot;SQL Plans&amp;quot; - ad-hoc SQL statements (including parameterized ones) and prepared statements. This is the stuff that we are after.&lt;/font&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;font face="georgia,palatino" size="2"&gt;CACHESTORE_PHDR - so-called &amp;quot;Bound Trees&amp;quot; for views, constraints and defaults. Irrelevant for the problem discussed.&lt;/font&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;font face="georgia,palatino" size="2"&gt;CACHESTORE_XPROC - not really execution plans but rather pointers to the entry points of your extended SPs.&lt;/font&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;With all this information, I am sure you can guess where I am going: Can we clear just one part of the procedure cache? Just the cache store holding the ad-hoc plans? &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;And the answer is: YES! &lt;img src="http://sqlblogcasts.com/emoticons/emotion-1.gif" alt="Smile" /&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;All you have to do is run:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;DBCC FREESYSTEMCACHE(&amp;#39;SQL Plans&amp;#39;)&lt;/p&gt;
&lt;p&gt;&lt;/font&gt;&lt;font face="georgia,palatino" size="2"&gt;and you will see all&amp;nbsp;your ad-hoc&amp;nbsp;and prepared plans vaporize, while your SP plans will remain intact. This is much nicer than the overkill of DBCC FREEPROCCACHE and will have much lower performance impact on the system. And, in case you wonder, the&amp;nbsp;parameter in the statement above&amp;nbsp;is the name&amp;nbsp;of the cache store of type CACHESTORE_SQLCP.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="georgia,palatino" size="2"&gt;I am curious to hear your comments and whether this solution works for your scenario...&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=10827" width="1" height="1"&gt;</content><author><name>maciej</name><uri>http://sqlblogcasts.com/members/maciej.aspx</uri></author><category term="Memory" scheme="http://sqlblogcasts.com/blogs/maciej/archive/tags/Memory/default.aspx" /><category term="SQLOS" scheme="http://sqlblogcasts.com/blogs/maciej/archive/tags/SQLOS/default.aspx" /><category term="Procedure Cache" scheme="http://sqlblogcasts.com/blogs/maciej/archive/tags/Procedure+Cache/default.aspx" /></entry><entry><title>Time to get started?</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/maciej/archive/2008/09/21/time-to-get-started.aspx" /><id>http://sqlblogcasts.com/blogs/maciej/archive/2008/09/21/time-to-get-started.aspx</id><published>2008-09-20T21:06:00Z</published><updated>2008-09-20T21:06:00Z</updated><content type="html">&lt;p&gt;&lt;span style="FONT-SIZE:10pt;"&gt;&lt;font face="georgia,palatino"&gt;Well, I have created this blog some time ago but somehow never got around to write anything here. While this is hardly surprising given my very busy schedule (and the fact that I have 3 small kids), I think this is also a major failure on my part. Seems like&amp;nbsp;anyone who can write has a&amp;nbsp;blog (or two)&amp;nbsp;these days so not having&amp;nbsp;one seems like a major oversight. I guess I should start blogging before my kids do (or blogging goes out of fashion, in favor of something else)... :)&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10pt;"&gt;&lt;font face="georgia,palatino"&gt;So, I decided that it is time to get started. Mostly because I have a bunch of technical stuff that I would like to share with the community, but I would also like to use this blog to connect with people out there - customers, friends, fellow MVPs and people who attend my conference sessions and training. I would like to use it to answer some of the questions I am receiving after my presentations, share the lessons learned while consulting my customers (hence the name of the blog) or just share some thoughts and observations I may have about SQL Server and its surroundings. And I promise that I will try not to insult or annoy anyone while I am doing that... :)&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10pt;"&gt;&lt;font face="georgia,palatino"&gt;Stay tuned!&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=10823" width="1" height="1"&gt;</content><author><name>maciej</name><uri>http://sqlblogcasts.com/members/maciej.aspx</uri></author></entry></feed>