<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlserver.ro/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>How-To Articles</title><link>http://sqlserver.ro/forums/19/ShowForum.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>SQL Server 2005 - The Default Trace</title><link>http://sqlserver.ro/forums/thread/2888.aspx</link><pubDate>Mon, 08 Oct 2007 16:33:36 GMT</pubDate><guid isPermaLink="false">963f3a18-65dd-4aad-905c-b785cfe1d7c7:2888</guid><dc:creator>xmldeveloper</dc:creator><slash:comments>0</slash:comments><comments>http://sqlserver.ro/forums/thread/2888.aspx</comments><wfw:commentRss>http://sqlserver.ro/forums/commentrss.aspx?SectionID=19&amp;PostID=2888</wfw:commentRss><description>&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;What's in a name? That which we call this trace by any other word would mean it’s stopped? But nay, it’s running quietly on your server and I will tell you why.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;The Default Trace is a light-weight trace that is running by the default on your SQL Server. Its primary role is to help you in troubleshooting various problems. Light-weight means that you shouldn't be too concerned about its impact on your server’s performance.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;Let’s get some more information about it. Using the &lt;B&gt;fn_trace_getinfo&lt;/B&gt; function, you can get some of its properties. The Default Trace has the id value 1 so I will call the function &lt;B&gt;fn_trace_getinfo&lt;/B&gt; using 1 as argument.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;Example:&lt;BR&gt;SELECT * &lt;BR&gt;FROM fn_trace_getinfo(1) &lt;BR&gt;GO&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;--Results&lt;BR&gt;traceid property value&lt;BR&gt;------- -------- ----------------------------------------&lt;BR&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;BR&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\log_156.trc&lt;BR&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20&lt;BR&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL&lt;BR&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;I will explain the results, don’t worry! The property column has the following meaning: 1= Trace options, 2 = File name, 3 = Max size, 4 = Stop time, 5 = Current trace status. In our case, we see a rollover trace having a maximum size of 20MB. Rollover means that when the maximum size of the file is reached a new file will be created. The number appended to the name of the trace &lt;/SPAN&gt;&lt;FONT face=Arial size=2&gt;(156 in this case) &lt;/FONT&gt;&lt;SPAN class=bodytext&gt;is used to indicate its sequence.&amp;nbsp; There are only 5 trace files just in case you wonder if it will fill-up your disk drive’s space. The trace file location can be different on your server (and you can see the exact location using the above query).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;The next step is to see the events recorded by this trace:&lt;B&gt;&amp;nbsp;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;Example:&lt;BR&gt;SELECT T.eventid AS [id], E.name&lt;BR&gt;FROM fn_trace_geteventinfo(1) T&lt;BR&gt;&amp;nbsp; JOIN sys.trace_events E&lt;BR&gt;&amp;nbsp; ON T.eventid = E.trace_event_id&lt;BR&gt;GROUP BY T.eventid, E.name&lt;BR&gt;GO&lt;BR&gt;&lt;BR&gt;-- Results&lt;BR&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp; name&lt;BR&gt;----- -----------------------------&lt;BR&gt;18&amp;nbsp;&amp;nbsp;&amp;nbsp; Audit Server Starts And Stops&lt;BR&gt;20&amp;nbsp;&amp;nbsp;&amp;nbsp; Audit Login Failed&lt;BR&gt;22&amp;nbsp;&amp;nbsp;&amp;nbsp; ErrorLog&lt;BR&gt;46&amp;nbsp;&amp;nbsp;&amp;nbsp; Object:Created&lt;BR&gt;47&amp;nbsp;&amp;nbsp;&amp;nbsp; Object:Deleted&lt;BR&gt;55&amp;nbsp;&amp;nbsp;&amp;nbsp; Hash Warning&lt;BR&gt;69&amp;nbsp;&amp;nbsp;&amp;nbsp; Sort Warnings&lt;BR&gt;79&amp;nbsp;&amp;nbsp;&amp;nbsp; Missing Column Statistics&lt;BR&gt;80&amp;nbsp;&amp;nbsp;&amp;nbsp; Missing Join Predicate&lt;BR&gt;81&amp;nbsp;&amp;nbsp;&amp;nbsp; Server Memory Change&lt;BR&gt;92&amp;nbsp;&amp;nbsp;&amp;nbsp; Data File Auto Grow&lt;BR&gt;93&amp;nbsp;&amp;nbsp;&amp;nbsp; Log File Auto Grow&lt;BR&gt;94&amp;nbsp;&amp;nbsp;&amp;nbsp; Data File Auto Shrink&lt;BR&gt;95&amp;nbsp;&amp;nbsp;&amp;nbsp; Log File Auto Shrink&lt;BR&gt;102&amp;nbsp;&amp;nbsp; Audit Database Scope GDR Event&lt;BR&gt;103&amp;nbsp;&amp;nbsp; Audit Schema Object GDR Event&lt;BR&gt;104&amp;nbsp;&amp;nbsp; Audit Addlogin Event&lt;BR&gt;105&amp;nbsp;&amp;nbsp; Audit Login GDR Event&lt;BR&gt;106&amp;nbsp;&amp;nbsp; Audit Login Change Property Event&lt;BR&gt;108&amp;nbsp;&amp;nbsp; Audit Add Login to Server Role Event&lt;BR&gt;109&amp;nbsp;&amp;nbsp; Audit Add DB User Event&lt;BR&gt;110&amp;nbsp;&amp;nbsp; Audit Add Member to DB Role Event&lt;BR&gt;111&amp;nbsp;&amp;nbsp; Audit Add Role Event&lt;BR&gt;115&amp;nbsp;&amp;nbsp; Audit Backup/Restore Event&lt;BR&gt;116&amp;nbsp;&amp;nbsp; Audit DBCC Event&lt;BR&gt;152&amp;nbsp;&amp;nbsp; Audit Change Database Owner&lt;BR&gt;153&amp;nbsp;&amp;nbsp; Audit Schema Object Take Ownership Event&lt;BR&gt;155&amp;nbsp;&amp;nbsp; FT:Crawl Started&lt;BR&gt;156&amp;nbsp;&amp;nbsp; FT:Crawl Stopped&lt;BR&gt;157&amp;nbsp;&amp;nbsp; FT:Crawl Aborted&lt;BR&gt;164&amp;nbsp;&amp;nbsp; Object:Altered&lt;BR&gt;167&amp;nbsp;&amp;nbsp; Database Mirroring State Change&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;The names of the events are self-explanatory. You can see that memory changes will be recorded as well as DBCC commands execution, DDL events (creating or dropping objects, schema modifications) etc. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;But where you can see the recorded information? You will find the answer to this question looking at the Summary Reports in SQL Server Management Studio. &lt;/SPAN&gt;&lt;FONT face=Arial size=2&gt;To view these reports, start SQL Server Management Studio, press F7 (or click Summary in the View menu), and finally use the Reports dropdown list to select a report&lt;/FONT&gt;&lt;SPAN class=bodytext&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial size=2&gt;As you may expect, you can get the same data by running a SQL query:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;Example:&lt;BR&gt;SELECT * &lt;BR&gt;FROM fn_trace_gettable&lt;BR&gt;('C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\log.trc', default)&lt;BR&gt;GO&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial size=2&gt;I won’t include the results because they are pretty large and they don't look as nice as the graphical reports in Management Studio&lt;/FONT&gt;&lt;SPAN class=bodytext&gt;. I will recommend you to try the scripts above and to test-drive the new Summary Reports, I can tell you that it’s worth it. They can give you a good idea of what happens or happened on your server from object creation to configuration changes. In the end, the Default Trace along with the Summary Reports and the new Dynamic Management Views will make your life easier (provided you work with SQL Server of course). &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;[published in Culminis Compass &lt;A href="http://emea.culminis.com/Newsletters/200603_march/0306defaulttrace.htm"&gt;http://emea.culminis.com/Newsletters/200603_march/0306defaulttrace.htm&lt;/A&gt;]&lt;/SPAN&gt;&lt;/P&gt;</description></item></channel></rss>