<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Facility9 &#187; SQL University</title>
	<atom:link href="http://facility9.com/category/sql-university/feed/" rel="self" type="application/rss+xml" />
	<link>http://facility9.com</link>
	<description>Jeremiah Peschka - professional something or other</description>
	<lastBuildDate>Fri, 24 Feb 2012 16:00:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>SQL University &#8211; Snow Day</title>
		<link>http://facility9.com/2009/10/sql-university-snow-day/</link>
		<comments>http://facility9.com/2009/10/sql-university-snow-day/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 13:00:58 +0000</pubDate>
		<dc:creator>Jeremiah Peschka</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL University]]></category>

		<guid isPermaLink="false">http://facility9.com/?p=1070</guid>
		<description><![CDATA[I was supposed to have a second blog post up this week for SQL University, however I haven&#8217;t been feeling well and have been focusing my energy on my day job. Unfortunately, I&#8217;ve had to drop the ball on a few other things. My second SQL University post for the internals week is what got&#8230;]]></description>
			<content:encoded><![CDATA[<p>I was supposed to have a second blog post up this week for SQL University, however I haven&#8217;t been feeling well and have been focusing my energy on my day job. Unfortunately, I&#8217;ve had to drop the ball on a few other things. My second SQL University post for the internals week is what got dropped (as well as a few other things that don&#8217;t directly involve anyone else).</p>
<p>However, I did come across this little gem that I&#8217;d like to share. <a href='http://www.solidq.com/insidetsql/books/insidetsql2008/Logical%20Query%20Processing%20Poster.pdf' target='_blank'>Logical Query Processing Poster (PDF alert)</a></p>
<p>This is the logical query processing diagram that is in Itzik Ben-Gan&#8217;s fantastic book <a href="http://www.amazon.com/gp/product/0735626030?ie=UTF8&amp;tag=facility9-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0735626030">Inside Microsoft® SQL Server® 2008: T-SQL Querying</a><img src="http://www.assoc-amazon.com/e/ir?t=facility9-20&amp;l=as2&amp;o=1&amp;a=0735626030" width="1" height="1" border="0" alt="" style="border:none !important;margin:0px !important" />. This explains how SQL Server builds a query from the ground up and includes all phases of query processing.</p>
]]></content:encoded>
			<wfw:commentRss>http://facility9.com/2009/10/sql-university-snow-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Introduction to SQL Server System Databases</title>
		<link>http://facility9.com/2009/10/an-introduction-to-sql-server-system-databases/</link>
		<comments>http://facility9.com/2009/10/an-introduction-to-sql-server-system-databases/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 13:30:13 +0000</pubDate>
		<dc:creator>Jeremiah Peschka</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL University]]></category>
		<category><![CDATA[syndication]]></category>
		<category><![CDATA[books online]]></category>

		<guid isPermaLink="false">http://facility9.com/?p=1044</guid>
		<description><![CDATA[SQL Server 2008 (and 2005) contain five special databases: master, model, tempdb, msdb, and mssqlsystemresource (aka Resource). These databases are used by SQL Server for its own maintenance and management. master The master database contains all of the system level information for SQL Server &#8211; all of the logins, linked servers, endpoints, and other system-wide&#8230;]]></description>
			<content:encoded><![CDATA[<p>SQL Server 2008 (and 2005) contain five special databases: master, model, tempdb, msdb, and mssqlsystemresource (aka Resource). These databases are used by SQL Server for its own maintenance and management. </p>
<h3 id="master">master</h3>
<p>The master database contains all of the system level information for SQL Server &#8211; all of the logins, linked servers, endpoints, and other system-wide configuration settings. The master database is also where SQL Server stores information about the other databases on this instance and the location of their files. If the master database is not present, SQL Server cannot start.</p>
<blockquote>
<p><strong>Always</strong> take regular backups of the master database.</p>
</blockquote>
<p>Since the master database hold all of the information related to logins, endpoints, linked servers, and user databases, it&#8217;s important that you take a backup of the master database after configuring any of these server level changes. Otherwise, if your SQL Server suffers a catastrophic failure, those changes will be lost to the sands of time.</p>
<p>Books Online contains a great deal of helpful information about the master database that you can find in the appropriately named <a href="http://msdn.microsoft.com/en-us/library/ms187837.aspx">master Database</a> article.</p>
<p>Speaking from personal experience, one of the most important points from that article is this: &#8220;Do not create user objects in master. Otherwise, master must be backed up more frequently.&#8221; I cannot tell you the number of times I have connected to a development server, opened up a file, and run the DDL contents of the file only to realize that I have created new tables on the master database because I did not have a <code>USE AdventureWorks</code> at the top of my DDL script. </p>
<h3 id="model">model</h3>
<p>The model database is used as a template whenever a new user database is created. You can change most database properties, create users, stored procedures, tables, views, etc &#8211; whatever you do will be applied to any <strong>new</strong> databases. </p>
<p>The nice thing is that you can create a guaranteed set of users, stored procedures, and options (including collation options) by making changes to the model database. Once those changes are in place, they are applied to every new database.</p>
<p>Outside of its role as a template, model doesn&#8217;t do anything else. You can find more information in the <a href="http://msdn.microsoft.com/en-us/library/ms186388.aspx">model Database</a> article of Books Online.</p>
<h3 id="msdb">msdb</h3>
<p>msdb is used by the SQL Server Agent, database mail, Service Broker, and other services. If you aren&#8217;t actively working with things like jobs, alerts, log shipping, etc you can pretty safely ignore msdb&#8230; sort of.</p>
<p>One important item is that msdb holds backup history. Using the msdb tables (you can start by taking a look at <code>msdb.dbo.backupset</code>), it&#8217;s possible to determine when each database and filegroup was last backed up. This is very useful, especially when you&#8217;ve just started working at a new company or taken over the maintenance of new servers. </p>
<p>A <strong>word of warning:</strong> you need to make sure that you are pruning old backup history from msdb. Leaving old backup data can slow down the performance of backup and restore operations. Brent Ozar documented this during his Backup Tricks Week article <a href="http://www.brentozar.com/archive/2009/09/checking-your-msdb-cleanup-jobs/">Checking MSDB Cleanups</a>. In this article, the <a href="http://technet.microsoft.com/en-us/library/ms188328.aspx">sp_delete_backuphistory</a> system stored procedure is mentioned. This stored procedure will delete information older than the <code>@oldest_date</code> parameter. It is important that you are incredibly careful when using this store procedure and don&#8217;t attempt to delete all of the backup history data in your msdb at once. Attempting to clear out a large number of database backup history records in one fell swoop can have an adverse effect on performance. I suggest removing the data one to two days at a time. It&#8217;s tedious, I know, but your users will thank you.</p>
<h3 id="resource_database">Resource database</h3>
<p>The resource database is a hidden system database. This is where system objects are stored. It isn&#8217;t possible to see the resource database by normal means. However you can see the data file by navigating to <code>C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Binn</code>. The exact size and modification data of this file will be different from version to version, but the modified date should be the same date that you see when you run <code>SELECT @@version</code>.</p>
<p>It is best to think of the resource database as if it were another system DLL. The resource database is designed to make it easy for quick database upgrades. If new system objects are being put in place, it is only necessary to swap out the resource database MDF file.</p>
<p>Typically, the only way to view the contents of the resource database is using the <code>OBJECT_DEFINITION</code> system function. </p>
<pre lang="tsql">SELECT OBJECT_DEFINITION(OBJECT_ID('sys.objects'))

-- on my test system this yields the following:
CREATE VIEW sys.objects AS
    SELECT name, object_id, principal_id, schema_id, parent_object_id,
        type, type_desc, create_date, modify_date,
        is_ms_shipped, is_published, is_schema_published
    FROM sys.objects$
</pre>
<h3 id="tempdb">tempdb</h3>
<p>We come, at last, to tempdb. Tempdb is the workhorse of the system databases. It is the workspace that SQL Server uses to store the intermediate results of query processing and sorting. You know how you see those spools in your execution plans? When you see one of those, SQL Server is probably spooling the data to a temporary table in the tempdb. Outside of storing temporary results, tempdb is also used during snapshot isolation and for user created temporary tables (<a href='http://scarydba.wordpress.com/2009/10/13/table-variables-are-only-in-memory-fact-or-myth/' target='_blank'>this includes table variables</a>).</p>
<p>One thing that is interesting to note about tempdb is that it is re-created every time the SQL Server service is started. Any objects that you have created in tempdb will be gone once the server restarts. If you want specific tables or stored procedures to always be available in tempdb, you will need to add them to the model database or else use a stored procedure to create them in tempdb when the SQL Server is started.</p>
<p>A properly sized and configured tempdb is vital for effective SQL Server performance. By default tempdb starts at 8MB in size and will continue to grow by ten percent until the drive is full. If the tempdb is sized too small, system resources will be used growing the tempdb file. This overhead can be avoided by increasing the default size of tempdb.</p>
<h3 id="related_reading">Related Reading</h3>
<p><a href="http://www.mssqltips.com/tip.asp?tip=1420">SQL Server System Databases</a><br />
<a href="http://msdn.microsoft.com/en-us/library/ms178028.aspx">System Databases</a><br />
<a href="http://technet.microsoft.com/en-us/library/cc966545.aspx">Working with tempdb in SQL Server 2005</a><br />
<a href="http://www.amazon.com/gp/product/0735626243?ie=UTF8&amp;tag=facility9-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0735626243">Microsoft SQL Server 2008 Internals pp 126 &#8211; 128</a></p>
]]></content:encoded>
			<wfw:commentRss>http://facility9.com/2009/10/an-introduction-to-sql-server-system-databases/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>SQL Server Error Logs</title>
		<link>http://facility9.com/2009/10/sql-server-error-logs/</link>
		<comments>http://facility9.com/2009/10/sql-server-error-logs/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 12:30:08 +0000</pubDate>
		<dc:creator>Jeremiah Peschka</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL University]]></category>
		<category><![CDATA[syndication]]></category>
		<category><![CDATA[Database Administration]]></category>

		<guid isPermaLink="false">http://facility9.com/?p=1007</guid>
		<description><![CDATA[What is the Error Log? SQL Server maintains its own error logs that contain messages describing informational and error events. These are simple text files stored on disk, but it&#8217;s best to view them using the facilities provided by SQL Server to prevent any SQL operations from being blocked by opening one of these files&#8230;]]></description>
			<content:encoded><![CDATA[<h3 id="what_is_the_error_log">What is the Error Log?</h3>
<p>SQL Server maintains its own error logs that contain messages describing informational and error events. </p>
<p>These are simple text files stored on disk, but it&#8217;s best to view them using the facilities provided by SQL Server to prevent any SQL operations from being blocked by opening one of these files in a text editor. Also, the error log files can become quite large &#8211; SQL Server will stream the files into the Log File Viewer whereas notepad will open the file into a single buffer and consume a great deal more memory.</p>
<p>A new error log file will be created when one of two things happens:</p>
<ol>
<li>The SQL Server service is started</li>
<li><code>sp_cycle_errorlog</code> is called</li>
</ol>
<p>Once this happens, any pending writes to the current log file will complete and a new log file will be created. The actual error log files can be found at <code>Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\LOG\ERRORLOG</code> and <code>ERRORLOG.n</code>. </p>
<h3 id="viewing_the_error_log">Viewing the Error Log</h3>
<h4 id="the_basics">The Basics</h4>
<table class="alignright">
<tr>
<td>
<div id="attachment_1011" class="wp-caption alignnone" style="width: 160px"><a href="http://d1kpgdt94igfig.cloudfront.net/wp-content/uploads/2009/10/Error-Logs-01.jpg"><img src="http://d1kpgdt94igfig.cloudfront.net/wp-content/uploads/2009/10/Error-Logs-01-150x150.jpg" alt="Locating the error log" width="150" height="150" class="size-thumbnail wp-image-1011" /></a><p class="wp-caption-text">Locating the error log</p></div>
</td>
<td>
<div id="attachment_1012" class="wp-caption alignnone" style="width: 160px"><a href="http://d1kpgdt94igfig.cloudfront.net/wp-content/uploads/2009/10/Error-Logs-02.jpg"><img src="http://d1kpgdt94igfig.cloudfront.net/wp-content/uploads/2009/10/Error-Logs-02-150x150.jpg" alt="Viewing the Error Logs" width="150" height="150" class="size-thumbnail wp-image-1012" /></a><p class="wp-caption-text">Viewing the Error Logs</p></div>
</td>
</tr>
</table>
<p>Viewing the error log is a simple operation:</p>
<ol>
<li>Connect to the SQL Server using SQL Server Management Studio</li>
<li>Expand the Server &gt; Management &gt; SQL Server Logs</li>
<li>Double click on a log file</li>
</ol>
<p>This will open up the log file. One thing to keep in mind is that by default this log file will only cycle when the SQL Server service has started. If this is a production server and you haven&#8217;t made any configuration changes, then this file could be quite large and take a long time to open.</p>
<h4 id="refining_your_view" style='clear: both'>Refining Your View</h4>
<table class="alignright">
<tr>
<td>
<div id="attachment_1009" class="wp-caption alignnone" style="width: 160px"><a href="http://d1kpgdt94igfig.cloudfront.net/wp-content/uploads/2009/10/Error-Log-Filter-01.jpg"><img src="http://d1kpgdt94igfig.cloudfront.net/wp-content/uploads/2009/10/Error-Log-Filter-01-150x150.jpg" alt="The Error Log Filter Box" width="150" height="150" class="size-thumbnail wp-image-1009" /></a><p class="wp-caption-text">The Error Log Filter Box</p></div></td>
<td>
<div id="attachment_1010" class="wp-caption alignnone" style="width: 160px"><a href="http://d1kpgdt94igfig.cloudfront.net/wp-content/uploads/2009/10/Error-Log-Filter-02.jpg"><img src="http://d1kpgdt94igfig.cloudfront.net/wp-content/uploads/2009/10/Error-Log-Filter-02-150x150.jpg" alt="Filtered Error Log Results" width="150" height="150" class="size-thumbnail wp-image-1010" /></a><p class="wp-caption-text">Filtered Error Log Results</p></div>
</td>
</tr>
</table>
<p>By default, you will end up with a view of the entire contents of one or more log files. This probably isn&#8217;t very useful to you unless you want to scan the contents for something very recent. On a busy server, though, there could be hundreds of thousands of lines in a single error log file. </p>
<p>Clicking the filter button opens up the Filter Settings window. This gives you the opportunity to filter by User, Computer, Start and End Date, the message text, and the message source. Given that there are so many different sources for the messages in the error log, the ability to filter the error log is a huge boon. Once you&#8217;ve entered your filter criteria, check &#8216;Apply filter&#8217; and then click OK. Just make sure you check &#8216;Apply filter&#8217; otherwise SQL Server Management Studio will happily discard all of your filter criteria and not filter any of the data.</p>
<h3 id="care_feeding_of_the_log_file" style='clear: both'>Care &amp; Feeding of the Log File</h3>
<h4 id="automated_log_file_rotation">Automated Log File Rotation</h4>
<p>To prevent the log files from growing too large it&#8217;s necessary to rotate them on a regular basis. Restarting the SQL Server service every week at 3:34 AM on a Sunday isn&#8217;t advisable, so there must be some other option. Thankfully, there is. The log file can be automatically rotated using the <code>sp_cycle_errorlog</code> system stored procedure. </p>
<p>Depending on who you talk to, different people will tell you to cycle the error log on a daily, weekly, or monthly schedule. The frequency really depends on your particular system and how much data accumulates in the logs during the course of regular operations. The more writes to the error log, the more often you should cycle the log. To cycle the logs, create a new Agent Job with a single T-SQL task (or combine it with regular daily or weekly maintenance).</p>
<h4 id="number_of_log_files_to_maintain">Number of Log Files to Maintain</h4>
<p>Depending on the amount of storage space you have available and the amount of activity on your SQL Server, you will want to change how often you rotate your log files and also the number of log files that you want to retain. Why would you want to do this? To keep as much historical information available as you possibly can.</p>
<table class="alignright">
<tr>
<td>
<div id="attachment_1013" class="wp-caption alignnone" style="width: 160px"><a href="http://d1kpgdt94igfig.cloudfront.net/wp-content/uploads/2009/10/Error-Logs-Change-Number-01.jpg"><img src="http://d1kpgdt94igfig.cloudfront.net/wp-content/uploads/2009/10/Error-Logs-Change-Number-01-150x150.jpg" alt="Configuring the Error Log" width="150" height="150" class="size-thumbnail wp-image-1013" /></a><p class="wp-caption-text">Configuring the Error Log</p></div>
</td>
<td>
<div id="attachment_1014" class="wp-caption alignnone" style="width: 160px"><a href="http://d1kpgdt94igfig.cloudfront.net/wp-content/uploads/2009/10/Error-Logs-Change-Number-02.jpg"><img src="http://d1kpgdt94igfig.cloudfront.net/wp-content/uploads/2009/10/Error-Logs-Change-Number-02-150x150.jpg" alt="Changing the Number of Error Log Files" width="150" height="150" class="size-thumbnail wp-image-1014" /></a><p class="wp-caption-text">Changing the Number of Error Log Files</p></div>
</td>
</tr>
</table>
<p>More importantly, how do you do this?</p>
<ol>
<li>Right click on the SQL Server Logs folder in the Object Explorer</li>
<li>Select &#8216;Configure&#8217;</li>
<li>Check the box to &#8216;Limit the number of error log files before they are recycled&#8217;. This seems silly, but by default SQL Server will only keep 6 error log files before trashing them.</li>
<li>Put in a new value and click &#8216;OK&#8217;.</li>
</ol>
<p>I typically keep 99 error logs before they are recycled. Why? Because I can.</p>
<h3 id="wrap_up" style='clear: both'>Wrap Up</h3>
<p>I hope that this has helped you understand more about the SQL Server Error Log and how you can can automate the successful maintenance of your servers&#8217; log file information.</p>
]]></content:encoded>
			<wfw:commentRss>http://facility9.com/2009/10/sql-server-error-logs/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: basic
Object Caching 462/473 objects using disk: basic
Content Delivery Network via Amazon Web Services: CloudFront: d1kpgdt94igfig.cloudfront.net

Served from: facility9.com @ 2012-05-24 12:07:47 -->
