<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://powershell.com/cs/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results for 'app:weblogs' matching tags 'SQL Server' and 'operating system'</title><link>http://powershell.com/cs/search/SearchResults.aspx?q=app:weblogs&amp;tag=SQL+Server,operating+system&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tags 'SQL Server' and 'operating system'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 (Build: 30929.2835)</generator><item><title>Capture Performance Counter Data and Write to SQL Server</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/07/27/capture-performance-counter-data-and-write-to-sql-server.aspx</link><pubDate>Wed, 27 Jul 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:11592</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;strong&gt;Summary:&lt;/strong&gt; Learn how to use Windows PowerShell to capture performance counter information and write the saved data to a SQL Server database.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img title="Hey, Scripting Guy! Question" border="0" alt="Hey, Scripting Guy! Question" align="left" src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/q-sm.jpg" width="34" height="34" /&gt;Hey, Scripting Guy! I have been enjoying your PoshMon articles this week, but I have found them to be of limited value. I would love to see how I could store this performance data in a SQL database. I could then use SQL Reporting Services to parse the data and create reports.&lt;/p&gt;
&lt;p&gt;&amp;mdash;RS&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img title="Hey, Scripting Guy! Answer" border="0" alt="Hey, Scripting Guy! Answer" align="left" src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/a-sm.jpg" width="34" height="34" /&gt;Hello RS,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy Ed Wilson here. I am in the middle of a two-week road trip. The engagement with the Central Ohio Windows PowerShell Users group was great, and so was SQLSaturday in Wheeling, West Virginia. I had never been to Wheeling&amp;mdash;it is actually a pretty cool place and is relatively near both Columbus, Ohio, and Pittsburgh, Pennsylvania. Now I am in Seattle, Washington, for the internal-to-Microsoft TechReady conference, and it has been a great experience. I have gotten to see many of my friends from other locations, so it has been like a reunion in one respect. I have also learned a lot both in terms of perceived customer needs and technical aspects.&lt;/p&gt;
&lt;p&gt;RS, I am going to use the technique from &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/07/26/import-counters-from-a-perfmon-chart-into-powershell.aspx"&gt;yesterday&amp;rsquo;s blog post&lt;/a&gt; wherein I automatically glean the performance counters from a binary performance trace file. The reason for doing this is that it greatly simplifies the task of specifying the performance counters. For that post, I carefully selected a nice collection of counters by using the graphical selector tool in the Performance Monitor tool, and I do not want to repeat that task. The original code is shown here:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$counters = Import-Counter -Path &amp;quot;C:\Users\edwils\Desktop\HSG-New\System Monitor Log.blg&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$paths = $counters[0].countersamples | % {$_.path}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-Counter -Counter $paths&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For a more permanent solution, it would be trivial to export the counter paths to a text file. You could then use the &lt;b&gt;Get-Content&lt;/b&gt; cmdlet to read the text file and populate the &lt;i&gt;$counterPath&lt;/i&gt; variable when needed. This would save needing to parse the .blg file on a repetitive basis. The code to do this is shown here:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$paths | Out-File -FilePath c:\fso\ExportPaths.txt -Encoding ascii -Append&lt;/p&gt;
&lt;p&gt;In fact, I like the idea of writing the counters to a data file. I decided to modify the original code to use the &lt;b&gt;Tee-Object&lt;/b&gt; to send the output to both a variable and a text file at the same time. This is not something that &lt;b&gt;Tee-Object&lt;/b&gt; is normally used for, but because &lt;b&gt;Tee-Object&lt;/b&gt; will output to the screen if it is the last command in the pipeline, I save the output to a variable. This gives me both a file and a variable at the same time. The code to write to both a variable and a file is shown here (the &lt;b&gt;%&lt;/b&gt; symbol is an alias for the &lt;b&gt;ForEach-Object&lt;/b&gt; cmdlet):&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$paths = $counters[0].countersamples | % {$_.path} | Tee-Object -FilePath c:\fso\testpaths.txt&lt;/p&gt;
&lt;p&gt;The advantage of using &lt;b&gt;Tee-Object&lt;/b&gt; is the code is still three lines long, but I now get both the variable populated and the text file created all at once. The modified code is shown here:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$counters = Import-Counter -Path &amp;quot;C:\Users\edwils\Desktop\HSG-New\System Monitor Log.blg&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$paths = $counters[0].countersamples | % {$_.path} | Tee-Object -FilePath c:\fso\counterpaths.txt&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-Counter -Counter $paths&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The text file that contains the counter paths is shown here.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8358.HSG_2D00_7_2D00_27_2D00_11_2D00_01.png"&gt;&lt;img style="border:0px;" title="Image of text file with counter paths" alt="Image of text file with counter paths" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8358.HSG_2D00_7_2D00_27_2D00_11_2D00_01.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After I have my counters in a text file, I can use the &lt;b&gt;Get-Content&lt;/b&gt; cmdlet to read the counter text file for the counter paths. I specify 20 samples and a sample interval of 6 seconds. This will give me 20 readings over a two-minute period. When I have completed gathering my data, I use the &lt;b&gt;Export-Counter&lt;/b&gt; cmdlet to export my performance data to a CSV file. It is much better to use this cmdlet than to attempt manually creating the CSV data.&lt;/p&gt;
&lt;p&gt;These four lines of code are really two logical lines of code. I use the line continuation character at the end of the first and third lines to break the code to the next lines to make the code easier to read on the blog. The code to read counter paths from a text file, pass the paths to the &lt;b&gt;Get-Counter&lt;/b&gt; cmdlet to retrieve 20 samples at 6-second intervals, store the results in a variable, and export the data to a CSV file is shown here:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$counterData = Get-Counter -Counter (Get-Content C:\fso\counterPaths.txt) `&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; -MaxSamples 20 -SampleInterval 6&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Export-Counter -Path c:\fso\counterData.csv -FileFormat csv `&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;-InputObject&amp;nbsp; $counterData&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The script and associated output (there is no output) are shown here in a screen shot of the Windows PowerShell ISE.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8053.HSG_2D00_7_2D00_27_2D00_11_2D00_02.png"&gt;&lt;img style="border:0px;" title="Image of script and associated (empty) output" alt="Image of script and associated (empty) output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8053.HSG_2D00_7_2D00_27_2D00_11_2D00_02.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The data that is collected outputs to a CSV file. By default, CSV files associate with Microsoft Excel (if installed), and the CSV file created by running the script and exporting the counter information are shown in the following figure.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1524.HSG_2D00_7_2D00_27_2D00_11_2D00_03.png"&gt;&lt;img style="border:0px;" title="Image of CSV file created by running script and exporting counter information" alt="Image of CSV file created by running script and exporting counter information" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1524.HSG_2D00_7_2D00_27_2D00_11_2D00_03.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After I have verified that I have captured the data and have it in an acceptable format, I am ready to import it into a database. One note: if anything changes from the .blg file to the counter path file to the time when you run your script to capture data, you might receive an error while running the script. The error might be associated with an &amp;ldquo;invalid&amp;rdquo; counter path. This might happen, for example, if you were running this on a laptop and the counter is supposed to use a wired network connection, and later you were on a wireless network connection and disabled the wired network adapter. All the other data would be captured; only the invalid Perfmon counters would be mentioned in the error message and no data would be captured for those instances. A sampling of such errors is shown in the following figure.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8311.HSG_2D00_7_2D00_27_2D00_11_2D00_04.png"&gt;&lt;img style="border:0px;" alt="Image of sampling of errors" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8311.HSG_2D00_7_2D00_27_2D00_11_2D00_04.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To import my newly created CSV file into my database, I am going to use the SQL Server Import and Export Wizard. I created my database earlier by using Microsoft SQL Server Management Studio, but I could have used the &lt;a href="http://sqlpsx.codeplex.com/"&gt;SQLPSX&lt;/a&gt; cmdlets from CodePlex. I am using SQL Server 2008 R2 Express Edition, which is a free download. One disadvantage of using the Express Edition is that I cannot save my import package.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5164.HSG_2D00_7_2D00_27_2D00_11_2D00_05.png"&gt;&lt;img style="border:0px;" title="Image of using flat file source for CSV file in SQL Server Import and Export Wizard" alt="Image of using flat file source for CSV file in SQL Server Import and Export Wizard" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5164.HSG_2D00_7_2D00_27_2D00_11_2D00_05.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After I have chosen my data source, selected the file, and specified that the column names are in the first data row, I go to the next page where I can view the way the data will be&amp;nbsp;imported. If it does not look acceptable, I can go back and make advanced changes. In this case, however, everything looks fine, as is shown in the following figure.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0724.HSG_2D00_7_2D00_27_2D00_11_2D00_06.png"&gt;&lt;img style="border:0px;" title="Image of how data will be imported" alt="Image of how data will be imported" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0724.HSG_2D00_7_2D00_27_2D00_11_2D00_06.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now I need to choose which database I am going to use. I am going to use my PoshMon database on my SQL Server Express Edition, and connect via Windows Authentication. This is shown in the following figure.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8306.HSG_2D00_7_2D00_27_2D00_11_2D00_07.png"&gt;&lt;img style="border:0px;" title="Image of choosing the database to use" alt="Image of choosing the database to use" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8306.HSG_2D00_7_2D00_27_2D00_11_2D00_07.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now I need to map the data to a particular table. I am going to wimp out and allow the wizard to automatically create a new table for me. The table will be called counterData, which was the name from the spreadsheet. The table mapping is shown in the following figure.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3513.HSG_2D00_7_2D00_27_2D00_11_2D00_08.png"&gt;&lt;img style="border:0px;" title="Image of table mapping" alt="Image of table mapping" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3513.HSG_2D00_7_2D00_27_2D00_11_2D00_08.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It is time to click a few more times and allow the import to run. The results appear on the final screen. If a problem occurs, a report will be available under the Message column. The successful conclusion page is shown here.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3021.HSG_2D00_7_2D00_27_2D00_11_2D00_09.png"&gt;&lt;img style="border:0px;" title="Image of successful conclusion page in wizard" alt="Image of successful conclusion page in wizard" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3021.HSG_2D00_7_2D00_27_2D00_11_2D00_09.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After the import has completed, I like to run a query from inside the SQL Server Management Studio. I can right-click the newly created table and choose &lt;b&gt;Select Top 1000 Rows&lt;/b&gt;&lt;i&gt; &lt;/i&gt;from the shortcut menu. The generated query and associated data are shown in the following figure.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8836.HSG_2D00_7_2D00_27_2D00_11_2D00_10.png"&gt;&lt;img style="border:0px;" title="Imag of generated query and associated data" alt="Imag of generated query and associated data" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8836.HSG_2D00_7_2D00_27_2D00_11_2D00_10.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;That is it for querying performance counters and writing them to a SQL database. It can be lots of fun. Download SQL Express today, and give it a whirl.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3443542" width="1" height="1" alt="" /&gt;</description></item><item><title>Use PowerShell to Monitor Your SQL Server Performance</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/07/25/use-powershell-to-monitor-your-sql-server-performance.aspx</link><pubDate>Mon, 25 Jul 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:11539</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;: Guest Blogger Kevin Kline talks about using Windows PowerShell to monitor SQL Server performance.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img title="Hey, Scripting Guy! Question" border="0" alt="Hey, Scripting Guy! Question" align="left" src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/q-sm.jpg" width="34" height="34" /&gt;Hey, Scripting Guy! I am wondering about using Windows PowerShell to work with SQL performance counters. Is this something that can be done?&lt;/p&gt;
&lt;p&gt;&amp;mdash;SH&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img title="Hey, Scripting Guy! Answer" border="0" alt="Hey, Scripting Guy! Answer" align="left" src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/a-sm.jpg" width="34" height="34" /&gt;Hello SH,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy Ed Wilson here. We have a new guest blogger today. Kevin Kline is the technical strategy manager for SQL Server Solutions at &lt;a title="Quest Software&amp;#39;s SQL Server Solutions" href="http://sqlserver.quest.com/" target="_blank"&gt;Quest Software&lt;/a&gt;, a leading provider of award-winning tools for database management and application monitoring.&lt;/p&gt;
&lt;p&gt;Kevin is a founding board member and former president of the international &lt;a href="http://www.sqlpass.org/" target="_blank"&gt;Professional Association for SQL Server (PASS)&lt;/a&gt; and frequently contributes to database technology magazines, websites, and discussion forums. Kevin was the recipient of the &lt;a href="http://kevinekline.com/2010/02/03/pass-2009-lifetime-passion-award/"&gt;PASS 2009 Lifetime Achievement Award&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Kevin&amp;rsquo;s most popular book is &lt;a href="http://www.oreilly.com/catalog/sqlnut3/" target="_blank"&gt;SQL in a Nutshell&lt;/a&gt; (now in its third edition) published by &lt;a title="O&amp;#39;Reilly Media" href="http://www.oreilly.com/" target="_blank"&gt;O&amp;rsquo;Reilly Media&lt;/a&gt;. Kevin is also author or co-author of seven other IT books, including &lt;a href="http://www.oreilly.com/catalog/wintrnssql/" target="_blank"&gt;Transact-SQL Programming&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;span style="font-size:medium;"&gt;Tuning SQL Server: Windows PowerShell + PerfMon &amp;lt;&amp;gt; 2P. It&amp;rsquo;s = P&lt;sup&gt;2&lt;/sup&gt;!&lt;/span&gt;&lt;sup&gt;&lt;/sup&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Performance tuning is one of the most rewarding and interesting parts of the IT pro&amp;rsquo;s job. Don&amp;rsquo;t like performance tuning? Then you&amp;rsquo;re missing out on an activity that provides endless variety, opportunity for innovation, and a chance to show the boss that you rock.&lt;/p&gt;
&lt;p&gt;So what&amp;rsquo;s keeping you from jumping into performance tuning? Whenever I talk to customers&amp;mdash;in every environment from small four-person IT shops to huge Fortune 50 enterprises&amp;mdash;about why they don&amp;rsquo;t spend more time doing performance tuning, it usually comes down to two obstacles:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The tyranny of the urgent: Boiled down to its essence, IT pros have too many fires to put out to actually get on top of performance. The analogy I like to use is, &amp;ldquo;When you barely have enough time to bail the water out of your sail boat to keep it from sinking, you certainly won&amp;rsquo;t have time to adjust the sails for better speed.&amp;rdquo;&lt;/li&gt;
&lt;li&gt;Skills: Or as my buddy Jermaine says &amp;ldquo;mad skilz.&amp;rdquo; Simply put, IT pros have so much to do and so little time to do it that they don&amp;rsquo;t have time to learn how to do &lt;i&gt;one more thing&lt;/i&gt;. Our brains are full and learning something new not only requires a big investment in brain power, it will very likely lead to more responsibility without removing any of our other responsibilities. So not only do we not have the time to learn performance tuning, we don&amp;rsquo;t have the time for all of the follow-up responsibilities we will have to commit to in the future. The analogy I like to use is, &amp;ldquo;Ignorance is bliss, or at least less painful than not being ignorant.&amp;rdquo;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;But there&amp;rsquo;s a tradeoff that PowerShell plus Performance Monitor (PerfMon, also known as System Monitor and, most recently, Windows Reliability and Performance Monitor) offers you to mitigate the obstacles mentioned above.&lt;/p&gt;
&lt;p&gt;First, and in answer to the tyranny of the urgent, when you get a handle on performance tuning, urgent issues crop up less often&amp;mdash;a &lt;i&gt;lot&lt;/i&gt; less often&lt;i&gt;.&lt;/i&gt; When you don&amp;rsquo;t know how to collect and interpret performance issues, every snag seems like an emergency. But many times, those red flags turn out to be red herrings instead. Instead of going into emergency firefighter mode every now and then, you&amp;rsquo;re forced to put on your fire hat every time the phone rings. Too much stress! Second, and in response to acquiring mad skilz, Scripting Guy Ed Wilson and I have teamed up to make performance tuning a &amp;ldquo;no-skilz required&amp;rdquo; activity. Why learn a whole new set of skills when you can learn just 20 percent of the content but get 80 percent of the productivity boost of being an expert? Invoke the power of the 80/20 rule by reusing these lessons freely.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:medium;"&gt;&lt;b&gt;What&amp;rsquo;s our objective? &lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;re going to teach you how to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Perform a quick health check of SQL Server.&lt;/li&gt;
&lt;li&gt;Find the best performance counters for SQL Server performance tuning.&lt;/li&gt;
&lt;li&gt;Develop robust monitoring solutions.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Once you&amp;rsquo;ve followed our guidance here, performance tuning on SQL Server is no longer a black art. That&amp;rsquo;s because you&amp;rsquo;ll be able to shine the bright light of good instrumentation on your Windows and SQL Server instances.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:medium;"&gt;&lt;b&gt;Step 1: Perform a quick health check of SQL Server&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Knowing which PerfMon counters to keep an eye on is half the battle. Maybe even more than half the battle. I&amp;rsquo;m going to start off by teaching you the handful of PerfMon counters, as well as their usage and values, that enable you to perform a quick health check of Windows and SQL Server.&lt;/p&gt;
&lt;p&gt;A little later in the article, I&amp;rsquo;ll also show you where you can get a &lt;i&gt;huge&lt;/i&gt; best practices collection for SQL Server PerfMon counters if you&amp;rsquo;re interested in looking at more than a handful of counters or are ready to go to the next step of hardcore performance tuning.&lt;/p&gt;
&lt;p&gt;As a practical recommendation from a long-time SQL Server expert, SQL Server usually encounters problems in IO, memory, and then CPU (in order of commonality). The reason that SQL Server consumes an inordinate amount of IO, memory, and CPU is usually because of poor-quality SQL code, poor database design, or inadequate hardware (in order of commonality). Notice that poor code and poor design are usually the problem. So that means that if you usually fix performance issues by throwing more hardware at the problem, you&amp;rsquo;ll eventually end where you started&amp;mdash;with an underperforming application. This is because poor code and poor design will always use more resources than they have available.&lt;/p&gt;
&lt;p&gt;So here&amp;rsquo;s your quick list of PerfMon counters to determine SQL Server health relating to IO, memory, and CPU. These three sections are analogous to every visit to the medical clinic that starts with pulse, blood pressure, and temperature checks. If one of these is out of whack, something is definitely wrong. We haven&amp;rsquo;t necessarily diagnosed an illness, but we know there&amp;rsquo;s definitely a problem.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:small;"&gt;&lt;b&gt;IO&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;When assessing the top level of IO health, latency is your best quick health check. Latency means the amount of time measured between the initiation of an IO operation and its completion. Though these numbers can vary widely due to all sorts of variations in the underlying storage systems, here&amp;rsquo;s a good place to start:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Physical Disk: Average Disk/sec Reads&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Physical Disk: Average Disk/sec Write&lt;/p&gt;
&lt;p&gt;The lower these values, the better. &lt;a href="http://msdn.microsoft.com/library/cc966412#ECAA"&gt;Microsoft recommends&lt;/a&gt; that a well-tuned IO subsystem should deliver IOs at 5 milliseconds or below on the disks holding the transaction log files and at 20 milliseconds or less on the disks holding the data files. (The transaction logs and database files are on separate disks, right?) In real world systems, I&amp;rsquo;ve seen applications perform well when reads and writes average a bit higher than their white paper recommended values, but these are great rules of thumb. Numbers a lot higher than the recommendations means that the IO subsystem is under stress.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:small;"&gt;&lt;b&gt;Memory&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;A lot of IT pros new to SQL Server get quite alarmed when they see that SQL Server is gobbling up all of a server&amp;rsquo;s available memory. Not to worry&amp;mdash;that&amp;rsquo;s by design. By default, SQL Server is configured to grab all of a server&amp;rsquo;s available physical memory (even if it doesn&amp;rsquo;t immediately use it all), and then give it back to other Windows processes whenever they ask for it. That way, SQL Server can optimize large blocks of memory for queries and major processes, such as big reporting jobs and backup processes.&lt;/p&gt;
&lt;p&gt;When doing a quick check of SQL Server memory, I like to corroborate the findings by checking more than one indicator. In this case, these two counters provide an excellent quick indicator of memory pressure inside SQL Server:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;SQL Server: Memory Manager &amp;gt;&amp;gt; Free List Stalls/sec&lt;/p&gt;
&lt;p&gt;This counter monitors the number of requests per second where data requests stall because no buffers are available. Any value greater than 2 indicates that SQL Server needs more memory:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;SQL Server: Memory Manager &amp;gt;&amp;gt; Memory Grants Pending&lt;/p&gt;
&lt;p&gt;This counter shows the total number of processes per second waiting for a workspace memory grant. Numbers greater than 0 indicate a lack of memory.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:small;"&gt;&lt;b&gt;CPU&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s not very common for SQL Server, when running OLTP workloads, to use up major amounts of CPU. Even a busy SQL Server will usually use between 25-45 percent of CPU when responding to a transaction heavy workload. SQL Server will use more CPU for BI applications, but even then it usually consumes an added 20-30 percent of CPU. To find out the total amount of CPU being used and the proportion of that being used by SQL Server, check these counters:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Processor(_total): % Processor Time&lt;/p&gt;
&lt;p&gt;This is the percentage of elapsed time the processor spends executing work (in other words, nonidle threads). On a box dedicated to SQL Server, I raise a red flag if this is frequently above 80 percent:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Process (sqlservr): % Processor Time&lt;/p&gt;
&lt;p&gt;This shows the percentage of processor time spent exclusively on SQL Server process threads. Combining this value with the &lt;b&gt;Processor:% Processor Time&lt;/b&gt; value will show you conclusively the overall CPU utilization of the server overall compared to how much SQL Server is using.&lt;/p&gt;
&lt;p&gt;As I pointed out earlier in the memory section, it&amp;rsquo;s sometimes very useful to corroborate a finding with overmeasures to ensure you have a clear picture of the issue. Any quick and easy check of CPU pressure to add to the mix follows:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;System: Processor Queue Length&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s sometimes a bit of hassle trying to figure out CPU utilization based on percentages when you factor in multiple cores, hyperthreading, and virtualization. So it&amp;rsquo;s often valuable not to check a metric based on percentages, but on the raw number of threads waiting for access to that resource. In this case, the processor queue length is a great resource because it represents the number of threads waiting for CPU: anything about 12 is a red flag; values between 9 to 12 per CPU are good or fair; 5&amp;ndash;8 is better; and 4 or less is best.&lt;b&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:medium;"&gt;&lt;b&gt;Step 2: Find the best performance counters for SQL Server performance tuning&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In the previous section, I&amp;rsquo;ve pointed out a couple PerfMon counters that quickly assess the health of your SQL Server&amp;rsquo;s IO, memory, and CPU. These quick checks basically show whether your SQL Server is overextended or not. But they don&amp;rsquo;t reveal the root cause that is contributing to overconsumption of IO, memory, or CPU. For example, you might have memory issues on a SQL Server because stored procedures running on the server are constantly recompiling and are never able to stay in the cache for long. Similarly, a SQL Server might by showing high IO consumption when, at the root of the problem, the transactions running on the server are constantly blocking each other and preventing each other from completing quickly. There are PerfMon counters for that, too.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve spent a lot of time building the ultimate list of SQL Server PerfMon counters and the troubleshooting scenarios when they&amp;rsquo;re most useful. Rather than run through all of them here, please take a look at &lt;a href="http://kevinekline.com/?s=perfmon"&gt;my website&lt;/a&gt;&amp;nbsp;to take a deeper dive.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:medium;"&gt;&lt;b&gt;Step 3: Develop robust monitoring solutions&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Now that you know what to look for, it&amp;rsquo;s time to use Windows PowerShell to regularly poll your SQL Servers for these PerfMon values. I strongly encourage you to use Windows PowerShell not just for an occasional spot check of these values but to build a regular monitoring solution that runs at a rather frequent polling interval&amp;mdash;say, 5 or 15 minutes, saving the data as you go along. That way you can save long-term performance information and look for trends and problem areas in your system.&lt;/p&gt;
&lt;p&gt;To get PerfMon information about using Windows PowerShell, we&amp;rsquo;ll use the &lt;b&gt;Get-Counter&lt;/b&gt; cmdlet. Without parameters, this cmdlet retrieves a handy set of summary information about the server. However, we want to retrieve performance information from specific computers. We do that by providing the name of the server along with the path of the counter, as I&amp;rsquo;ve shown earlier, using the &lt;i&gt;&amp;ndash;Computer&lt;/i&gt; parameter:&lt;b&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; $computer = $ENV:Computername&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; Get-Counter &amp;quot;\\$computer\processor(_total)\% processor time&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Timestamp CounterSamples&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;--------- --------------&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;6/11/2011 11:16:44 AM \\...\processor(_total)\% processor time :&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;25.4520932356424&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Don&amp;rsquo;t know the path to the performance counter you want? Then use the &lt;i&gt;-ListSet&lt;/i&gt; parameter to search for just the right counter or set of counters. To see all counter sets, use an asterisk as the parameter value.&lt;/p&gt;
&lt;p&gt;When building your database of monitored values, export the retrieved counter information using the &lt;b&gt;Export-Counter&lt;/b&gt; cmdlet to save your data in a format that other tools can read, such as the .blg format used by Windows Performance Monitor. That way you can use the nice graphic tools in Windows Performance Monitor for easy graphic analysis of performance and problems.&lt;/p&gt;
&lt;p&gt;I hope you find this quick introduction to SQL Server performance monitor counters and Windows PowerShell to be useful. Please look me up on &lt;a href="http://twitter.com/kekline"&gt;Twitter&lt;/a&gt; and on my blog at &lt;a href="http://kevinekline.com/"&gt;http://KevinEKline.com&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks, Kevin, that was exactly what I was looking for.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:small;"&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3443143" width="1" height="1" alt="" /&gt;</description></item></channel></rss>