{"id":1576,"date":"2013-02-04T00:00:00","date_gmt":"2013-02-04T00:00:00","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/getting-started-with-extended-events-in-sql-server-2012\/"},"modified":"2021-08-24T13:39:58","modified_gmt":"2021-08-24T13:39:58","slug":"getting-started-with-extended-events-in-sql-server-2012","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/database-administration-sql-server\/getting-started-with-extended-events-in-sql-server-2012\/","title":{"rendered":"Getting Started with Extended Events in SQL Server 2012"},"content":{"rendered":"<div class=\"article-content\">\n<p class=\"start\">With the release of SQL Server 2008, Microsoft introduced Extended Events, a system for collecting event-driven data about a SQL Server instance and its databases. The Extended Events feature required a smaller footprint than trace events and supported a robust programmatic interface that let you write customized tools to work with event information. However, SQL Server 2008 included no GUI that interfaced with the events directly. Instead, DBAs had to write complex T-SQL statements to gather the information they needed. And when they did, that information was returned as XML, not always the first choice for DBAs needing quick access to event data. Consequently, the Extended Events feature in SQL Server 2008 saw little adoption throughout the industry.<\/p>\n<p>But SQL Server 2012 has proven to be a game changer. SQL Server Management Studio (SSMS) now includes a GUI component that makes working with Extended Events and viewing event-related data a series of intuitive and simple operations.<\/p>\n<p>You manage extended events in SQL Server 2012 through the <code><strong>Extended Events<\/strong><\/code> node in the <code><strong>Object Explorer<\/strong><\/code> window, under the <code><strong>Management<\/strong><\/code> folder. If you expand the <code><strong>Extended Events<\/strong><\/code> node, you&#8217;ll find a <code><strong>Sessions<\/strong><\/code> folder. To collect event data in Extended Events, you must create and configure a session that specifies exactly what data to collect.<\/p>\n<p>In this article, we&#8217;ll create a session that collects event information about T-SQL <code><strong>SELECT<\/strong><\/code> statements. The examples are based on querying data in the <code><strong>AdventureWorks2012<\/strong><\/code> sample database-on a local instance of SQL Server 2012-but you can use any database to generate queries whose events you want to capture.<\/p>\n<h2>Creating an Extended\u00a0Events Session<\/h2>\n<p>In the <code><strong>Sessions<\/strong><\/code> folder in <code><strong>Object Explorer<\/strong><\/code>, you&#8217;ll find one or two preconfigured sessions. By default, SQL Server 2012 includes the <code><strong>system_health<\/strong><\/code> session and, depending on which version of SQL Server 2012 you&#8217;re running, the <code><strong>AlwaysOn_health<\/strong><\/code> session. You can examine these sessions at your leisure, but for now, we&#8217;ll focus on creating a new session so you better understand how Extended Events works. Each session contains the same fundamental components.<\/p>\n<p>To create a session, you can use the <code><strong>New Session Wizard<\/strong><\/code> or create the session manually. (You can also use T-SQL to create the session, but that&#8217;s what we&#8217;re trying to avoid.) For this article, we&#8217;ll create the session manually. The wizard makes it easier, but does not permit the granular control that a manual creation does. True, you can always access the session properties later to configure the session as you want, but by creating the session manually, you can configure the properties upfront if desired, and you gain a better understanding of how sessions work. Besides, once you&#8217;ve created a session manually, the wizard will be a breeze. So let&#8217;s get started with our session.<\/p>\n<p>In <code><strong>Object Explorer<\/strong><\/code>, right-click the <code><strong>Sessions<\/strong><\/code> folder and then click <code><strong>New Session<\/strong><\/code>. When the <code><strong>New Session<\/strong><\/code> dialog box appears, the <code><strong>General<\/strong><\/code> page will be active, as shown in Figure 1. Type a name for your session in the <code><strong>Session name<\/strong><\/code> text box. I used <code><strong>Check Queries<\/strong><\/code>.<\/p>\n<p class=\"illustration center\"><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure1.png\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure1small.png\" alt=\"1736-figure1small.png\" \/><\/a><\/p>\n<p class=\"caption\">Figure 1: Creating an Extended Events session in SQL Server 2012<\/p>\n<p>At this point, you don&#8217;t need to configure any of the other options on this page, but they&#8217;re worth noting. The first is the <code><strong>Template<\/strong><\/code> drop-down list. You can choose from a list of templates that preconfigure your session with event-related settings. For instance, you can use the <code><strong>Query Detail Sampling<\/strong><\/code> template to retrieve event data about T-SQL statements, stored procedures, and batches, along with other information. You can either modify the preconfigured settings-such as adding or deleting events-or use the settings as configured in the template. Once you save the session, you can&#8217;t change the template being used, but you can modify the properties as necessary.<\/p>\n<p>For the most part, the other options on the <code><strong>General<\/strong><\/code> page should be self-evident. The only one that might not be clear is in the <code><strong>Casualty tracking<\/strong><\/code> section. The <code><strong>Track how events are related to one another<\/strong><\/code> option lets you track events across related tasks, when one task causes work to be done by another.<\/p>\n<p>Once you&#8217;ve provided a name for your session, go to the <code><strong>Events<\/strong><\/code> page (shown in Figure 2) to select the events you want to monitor.<\/p>\n<p class=\"illustration center\"><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure2.png\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure2small.png\" alt=\"1736-figure2small.png\" \/><\/a><\/p>\n<p class=\"caption\">Figure 2: Adding events to an Extended Events session<\/p>\n<p>If you select an event in the <code><strong>Event library<\/strong><\/code> grid, a description is listed below, along with a list of fields associated with the event. Each event is made up of a set of fields that provide specific information about the event. For example, in Figure 2, the <code><strong>query_post_execution_showplan<\/strong><\/code> event is selected. The event returns an XML representation of the query plan, along with details such as the database name and the query&#8217;s duration, as reflected in the list of fields.<\/p>\n<p>To add an event to your session, select the event in the <code><strong>Event library<\/strong><\/code> grid, and then click the right arrow to add it to the <code><strong>Selected events<\/strong><\/code> grid at the right of the page. For this exercise, we&#8217;ll add the <code><strong>query_post_execution_showplan<\/strong><\/code> and <code><strong>sql_statement_completed<\/strong><\/code> events. Figure 3 shows what the <code><strong>Events<\/strong><\/code> page looks like after you&#8217;ve added the two events.<\/p>\n<p class=\"illustration center\"><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure3.png\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure3small.png\" alt=\"1736-figure3small.png\" \/><\/a><\/p>\n<p class=\"caption\">Figure 3: Viewing selected events in the New Session dialog box<\/p>\n<p>When adding events to your session, remember that the process of tracking events comes at a cost, particularly an event such as <code><strong>query_post_execution_showplan<\/strong><\/code>. So select your events carefully and keep the tracking costs in mind when you run your sessions. Events that are particularly costly, like <code><strong>query_post_execution_showplan<\/strong><\/code>, usually come with a warning in their descriptions, so be sure to take note of those.<\/p>\n<p>Otherwise, that&#8217;s all you need to do to set up a basic session. There are certainly more granular ways we can configure our session, which we&#8217;ll do later in the article, but first, let&#8217;s try out what we&#8217;ve done so far so you can see the session in action. Click <code><strong>OK<\/strong><\/code> to save the session and close the <code><strong>New Session<\/strong><\/code> dialog box. Your event should now be listed beneath the <code><strong>Sessions<\/strong><\/code> folder in <code><strong>Object Explorer<\/strong><\/code>.<\/p>\n<p>The next step will be to test the session. To do so, you&#8217;ll need to run a few queries, unless you created your session on a SQL Server instance that&#8217;s actively being queried. On my system, I created the following queries to run against the <code><strong>AdventureWorks2012<\/strong><\/code> database:<\/p>\n<pre class=\"lang:tsql theme:ssms2012\">SELECT * FROM Production.TransactionHistory\r\nORDER BY TransactionDate DESC, ReferenceOrderID, ReferenceOrderLineID;\r\n\r\nSELECT * FROM Person.Person\r\nWHERE BusinessEntityID &lt;&gt; 100\r\n  OR BusinessEntityID &lt;&gt; 200\r\nORDER BY PersonType, Lastname, FirstName;\r\n\r\nSELECT * FROM Sales.Currency\r\nORDER BY Name;<\/pre>\n<p>Once you&#8217;ve gotten your queries ready to go, right-click the new event and click <code><strong>Start Session<\/strong><\/code>. Then right-click the event again and click <code><strong>Watch Live Data<\/strong><\/code>. This opens a tab in SSMS that displays the events in the upper pane and details about each event in the lower pane. Now run your queries. Your results should look similar to those shown in Figure 4.<\/p>\n<p class=\"illustration center\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure4.png\" alt=\"1736-figure4.png\" \/><\/p>\n<p class=\"caption\">Figure 4: Viewing a query_post_execution_showplan event<\/p>\n<p>On my system, the session recorded one <code><strong>sql_statement_completed<\/strong><\/code> event for each statement I ran, one <code><strong>query_post_execution_showplan<\/strong><\/code> event for each of those statements, and numerous other <code><strong>query_post_execution_showplan<\/strong><\/code> events related to SQL Server management.<\/p>\n<p>Along with the list of events, you can view details about an event by selecting the event in the top pane. For example, the first <code><strong>query_post_execution_showplan<\/strong><\/code> event shown in Figure 4 is selected. Below you can find details about the event, broken down by field, such as <code><strong>duration<\/strong><\/code>, <code><strong>estimated_rows<\/strong><\/code>, and <code><strong>showplan_xml<\/strong><\/code>. If you double-click the <code><strong>showplan_xml<\/strong><\/code> value, the XML will open in its own tab, rendered in a more readable format.<\/p>\n<p class=\"caption\">Figure 5, on the other hand, shows the details of the first <code><strong>sql_statement_completed<\/strong><\/code> event to be recorded in my session. The event includes some of the same fields as the previous one, but additional fields as well, such as <code><strong>physical_reads<\/strong><\/code> and <code><strong>row_count<\/strong><\/code>.<\/p>\n<p class=\"illustration center\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure5.png\" alt=\"1736-figure5.png\" \/><\/p>\n<p class=\"caption\">Figure 5: Viewing a sql_statement_completed event<\/p>\n<p>If you double-click the value of a non-XML field, the field&#8217;s value will be displayed in its own window. For example, Figure 6 shows the value of the <code><strong>statement<\/strong><\/code> field. The value in this case is the <code><strong>SELECT<\/strong><\/code> statement that generated the event.<\/p>\n<p class=\"illustration center\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure6.png\" alt=\"1736-figure6.png\" \/><\/p>\n<p class=\"caption\">Figure 6: Viewing the T-SQL statement in a sql_statement_completed event<\/p>\n<p>Although we added only two events to our session, we still receive plenty of information about our query executions. However, if we keep the session running, we&#8217;ll end up with a lot more events than we want or need. To prevent this from happening, we can add filters to our session to limit the returned events to those that most interest us.<\/p>\n<h2>Adding Filters to a Session<\/h2>\n<p>Filters let you limit the number of events you return based on specified criteria. Before adding any filters to your session, first close the <code><strong>Live Data<\/strong><\/code> tab and then, in <code><strong>Object Explorer<\/strong><\/code>, right-click the session and click <code><strong>Properties<\/strong><\/code>. In the <code><strong>Session Properties<\/strong><\/code> dialog box, go to the <code><strong>Events<\/strong><\/code> page and click the <code><strong>Configure<\/strong><\/code> button in the top-right corner. You should be presented with a screen that lets you select fields and configure filters. Go to the <code><strong>Filter (Predicate)<\/strong><\/code> tab and select the <code><strong>query_post_execution_showplan<\/strong><\/code> event in the <code><strong>Selected events<\/strong><\/code> grid, as shown in Figure 7.<\/p>\n<p class=\"illustration center\"><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure7.png\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure7small.png\" alt=\"1736-figure7small.png\" \/><\/a><\/p>\n<p class=\"caption\">Figure 7: Adding filters to the query_post_execution_showplan event<\/p>\n<p>You create filters based on the selected event. To create a filter, you specify a field, operator, and value. The events returned must match these criteria. For example, notice in Figure 7 that I&#8217;ve added two filters for the <code><strong>query_post_execution_showplan<\/strong><\/code> event. The first filter specifies the <code><strong>duration<\/strong><\/code> field, the greater-than (<code><strong>&gt;<\/strong><\/code>) operator, and the value <code><strong>500000<\/strong><\/code>. As a result, for a <code><strong>query_post_execution_showplan<\/strong><\/code> event to be returned by the session, it must have a <code><strong>duration<\/strong><\/code> value greater than 500,000 microseconds. This way, only longer running <code><strong>query_post_execution_showplan<\/strong><\/code> events are returned.<\/p>\n<p>The second filter works in a similar fashion. It specifies that the <code><strong>source_database_id<\/strong><\/code> value must equal <code><strong>7<\/strong><\/code>, which, on my system, is the ID assigned to the <code><strong>AdventureWorks2012<\/strong><\/code> database. I added this filter so my session includes only <code><strong>query_post_execution_showplan<\/strong><\/code> events related to that database.<\/p>\n<p>I next added a filter on the <code><strong>sql_statement_completed<\/strong><\/code> event, as shown in Figure 8. This is the same filter I added on the duration field for the <code><strong>query_post_execution_showplan<\/strong><\/code> event. As a result, only <code><strong>sql_statement_completed<\/strong><\/code> events whose duration is greater than 500,000 microseconds will be included in the session results.<\/p>\n<p class=\"illustration center\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure8small.png\" alt=\"1736-figure8small.png\" \/><\/p>\n<p class=\"caption\">Figure 8: Adding a filter to the sql_statement_completed event<\/p>\n<p>Once you&#8217;ve configured your filters, click <code><strong>OK<\/strong><\/code> to close the <code><strong>Session Properties<\/strong><\/code> dialog box, right-click the session in <code><strong>Object Explorer<\/strong><\/code>, and then click <code><strong>Watch Live Data<\/strong><\/code>. If necessary, run your T-SQL statements again, or wait for other statements to run. On my system, I ran the three queries, but only two of the statements returned events that were not filtered out, as indicated by the <code><strong>Live Data<\/strong><\/code> tab shown in Figure 9.<\/p>\n<p class=\"illustration center\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure9.png\" alt=\"1736-figure9.png\" \/><\/p>\n<p class=\"caption\">Figure 9: Viewing the filtered events in SQL Server Management Studio<\/p>\n<p>Because only two of my <code><strong>SELECT<\/strong><\/code> statements ran over 500,000 microseconds, my session included only events generated by those statements. And because I limited <code><strong>query_post_execution_showplan<\/strong><\/code> events to the <code><strong>AdventureWorks2012<\/strong><\/code> database, my session no longer includes all those extra <code><strong>query_post_execution_showplan<\/strong><\/code> events. As a result, my session now includes only two <code><strong>sql_statement_completed<\/strong><\/code> events and two <code><strong>query_post_execution_showplan<\/strong><\/code> events.<\/p>\n<p>Your session results might be different from mine, but you can still see how useful filters can be to help ensure you&#8217;re returning only the data you want to return.<\/p>\n<h2>Adding Fields to a Session<\/h2>\n<p>Now let&#8217;s look at another way you can configure your session to include the information you need. Close the <code><strong>Live Data<\/strong><\/code> tab and again open your session&#8217;s properties. Once more, go to the <code><strong>Events<\/strong><\/code> page and click the <code><strong>Configure<\/strong><\/code> button. This time, however, go to the <code><strong>Global Fields (Actions)<\/strong><\/code> tab. Global fields, such as <code><strong>database_id<\/strong><\/code> or <code><strong>database_name<\/strong><\/code>, are fields available to multiple events. At times, it can be useful to add one or more of these fields to provide necessary information in an event. For example, it can be sometimes be difficult to know which <code><strong>query_post_execution_showplan<\/strong><\/code> event is associated with which <code><strong>sql_statement_completed<\/strong><\/code> event in our results. If we add the <code><strong>transaction_id<\/strong><\/code> field to each event we have a better idea how to associate the events.<\/p>\n<p>To add a global field, select the event in the <code><strong>Selected events<\/strong><\/code> grid and then select the global fields you want to include. Figure 10 shows the <code><strong>transaction_id<\/strong><\/code> field selected for the <code><strong>query_post_execution_showplan<\/strong><\/code> event.<\/p>\n<p class=\"illustration center\"><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure10.png\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure10small.png\" alt=\"1736-figure10small.png\" \/><\/a><\/p>\n<p class=\"caption\">Figure 10: Adding a global field to the query_post_execution_showplan event<\/p>\n<p>In some cases, you can also decide which event-specific fields to include. If you go to the <code><strong>Event Fields<\/strong><\/code> tab (with the <code><strong>query_post_execution_showplan<\/strong><\/code> event still selected), you can see that the <code><strong>database_name<\/strong><\/code> field is optional, as shown in Figure 11. You can choose to include the field or not. For this exercise, we&#8217;ll include it. Note, however, some fields are listed as global, but are also included in the event fields, as is the case with the <code><strong>database_name<\/strong><\/code> field.<\/p>\n<p class=\"illustration center\"><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure11.png\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure11small.png\" alt=\"1736-figure11small.png\" \/><\/a><\/p>\n<p class=\"caption\">Figure 11: Adding an event field to the query_post_execution_showplan event<\/p>\n<p>Regardless of where the field is listed, keep in mind that you should add fields only when necessary because any components you add contribute to the overhead, even if only slightly. You could argue, of course, that we do not need to include the <code><strong>database_name<\/strong><\/code> field on this event because our filter returns events only for one database. However, including the database name in this case is meant only to demonstrate how optional event fields work.<\/p>\n<p>Now let&#8217;s repeat the process for the <code><strong>sql_statement_completed<\/strong><\/code> event. Select the event in the <code><strong>Selected events<\/strong><\/code> grid, go to the <code><strong>Global Fields (Actions)<\/strong><\/code> tab, and select the <code><strong>database_name<\/strong><\/code> and <code><strong>transactio n _id<\/strong><\/code> fields, as shown in Figure 12. (Note that, in this case, <code><strong>database_name<\/strong><\/code> is not included in the event fields.)<\/p>\n<p class=\"illustration center\"><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure12.png\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure12small.png\" alt=\"1736-figure12small.png\" \/><\/a><\/p>\n<p class=\"caption\">Figure 12: Adding global fields to the sql_statement_completed event<\/p>\n<p>Now let&#8217;s look at the <code><strong>Event Fields<\/strong><\/code> tab associated with the <code><strong>sql_statement_completed<\/strong><\/code> event (shown in Figure 13). Notice that you can choose to include the <code><strong>parameterized_plan_handle<\/strong><\/code> field and <code><strong>statement<\/strong><\/code> field. By default, the first is not selected and the second is. For this exercise, we&#8217;ll stick with the default settings. Click <code><strong>OK<\/strong><\/code> to save your session and close the <code><strong>Session Properties<\/strong><\/code> dialog box.<\/p>\n<p class=\"illustration center\"><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure12.png\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure12small.png\" alt=\"1736-figure12small.png\" \/><\/a><\/p>\n<p class=\"caption\">Figure 13: Viewing event fields for the sql_statement_completed event<\/p>\n<p>Next, launch the <code><strong>Live Data<\/strong><\/code> tab and run your test queries. Your session should include the same events as before; however, it&#8217;s when you view the individual events that you&#8217;ll see the difference. For example, Figure 14 shows the details for the first <code><strong>query_post_execution_showplan<\/strong><\/code> event. Notice that the information now includes the database name and a transaction ID, in this case, <code><strong>309748<\/strong><\/code>.<\/p>\n<p class=\"illustration center\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure14.png\" alt=\"1736-figure14.png\" \/><\/p>\n<p class=\"caption\">Figure 14: Viewing the transaction_id and database_name fields<\/p>\n<p>My next event, <code><strong>sql_statement_completed<\/strong><\/code>, also shows a transaction ID of <code><strong>309748<\/strong><\/code>, as well as the database name, both of which are shown in Figure 15.<\/p>\n<p class=\"illustration center\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure15.png\" alt=\"1736-figure15.png\" \/><\/p>\n<p class=\"caption\">Figure 15: Viewing the transaction_id and database_name fields<\/p>\n<p>As you can see, including the additional information can help to better understand what you&#8217;re looking at, where the data comes from, and how the pieces fit together. But so far, we&#8217;ve only looked at events as they&#8217;ve occurred. It&#8217;s time to learn how to capture and save that data.<\/p>\n<h2>Saving Session Data<\/h2>\n<p>Once again, close the <code><strong>Live Data<\/strong><\/code> tab and open the session&#8217;s properties, but this time go to the <code><strong>Data Storage<\/strong><\/code> page, as shown in Figure 16. Here you specify how you want to capture event data so you can save it for later viewing.<\/p>\n<p class=\"illustration center\"><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure16.png\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure16small.png\" alt=\"1736-figure16small.png\" \/><\/a><\/p>\n<p class=\"caption\">Figure 16: Adding data storage to an Extended Events session<\/p>\n<p>SQL Server lets you save your session events in a number of formats:<\/p>\n<ul>\n<li><code><strong>etw_classic_sync_target:<\/strong><\/code> Outputs events in an Event Tracing for Windows (ETW) format.<\/li>\n<li><code><strong>event_counter :<\/strong><\/code> Outputs events to memory in order to track the number of times an event has occurred during a session.<\/li>\n<li><code><strong>event_file :<\/strong><\/code> Outputs events to a file saved to a folder on a disk.<\/li>\n<li><code><strong>histogram :<\/strong><\/code> Outputs events to memory in order to group and count events based on fields or actions.<\/li>\n<li><code><strong>pair_matching :<\/strong><\/code> Outputs events to memory in order to track events that don&#8217;t have a corresponding event based on the target configuration.<\/li>\n<li><code><strong>ring_buffer :<\/strong><\/code> Outputs events to memory in order to track a limited amount of event data based on the target configuration.<\/li>\n<\/ul>\n<p>When you select one of these data storage types, you&#8217;re presented with a set of options at the bottom of the page that let you further configure how to save the data. For this exercise, we&#8217;ll go with the <code><strong>event_file<\/strong><\/code> type. Select the type in the first row of the <code><strong>Targets<\/strong><\/code> grid and then specify a file path and name. On my system, I targeted the events to <code><strong>C:\\DataFiles\\CheckQueries.xel<\/strong><\/code>. (By default, Extended Events files use the .xel extension.) Then click <code><strong>OK<\/strong><\/code> to save the session and close the <code><strong>Session Properties<\/strong><\/code> dialog box.<\/p>\n<p>Run your queries to ensure you&#8217;ve generated the necessary events. Next, in <code><strong>Object Explorer<\/strong><\/code>, expand your session&#8217;s node. Beneath your session, you should find a reference to the event file. On my system, the reference reads <code><strong>package0.event_fil e<\/strong><\/code>. Double-click the file node. This will open a new tab in SSMS and display the captured data similar to how it appeared on the <code><strong>Live Data<\/strong><\/code> tab, as shown in Figure 17. (You can also open the file by navigating to it through the SSMS <code><strong>File<\/strong><\/code> menu.)<\/p>\n<p class=\"illustration center\"><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/1736-figure17.png\" alt=\"1736-figure17.png\" \/><\/p>\n<p class=\"caption\">Figure 17: Viewing an event file for an Extended Events session<\/p>\n<p>When you&#8217;re finished viewing the contents of the file, close the tab. Also, unless you specifically want to continue to capture data, you should stop your session. To do so, right-click the session and then click <code><strong>Stop Session<\/strong><\/code>. You can start it again whenever you want to capture more event data.<\/p>\n<p>That&#8217;s all you need to do to create a session and capture event data. The Extended Events interface in SSMS makes this a fairly straightforward process. And as you can see from the number of events available-and other features we did not try out-we&#8217;ve only skimmed the surface. But you should now have seen enough to understand how easy it is to get started with Extended Events. And get started you should. With the release of SQL Server 2012, Microsoft announced the deprecation of SQL Server Profiler and SQL Trace, the event-capturing systems that Extended Events will slowly replace. You still have a while to make the transition, but now is a good time to get started.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Extended Events provide a way of unintrusively monitoring what&#8217;s going on in a SQL Server instance. Unlike SQL Server Profiler and SQL Trace, it has little performance impact. Now, in SQL Server 2012 SSMS, it is relatively easy to use, as Robert Sheldon shows.&hellip;<\/p>\n","protected":false},"author":221841,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143527],"tags":[4170,5966,4364,4150,4151],"coauthors":[6779],"class_list":["post-1576","post","type-post","status-publish","format-standard","hentry","category-database-administration-sql-server","tag-database-administration","tag-monitor","tag-monitoring","tag-sql","tag-sql-server"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/1576","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/221841"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=1576"}],"version-history":[{"count":5,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/1576\/revisions"}],"predecessor-version":[{"id":74742,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/1576\/revisions\/74742"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=1576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=1576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=1576"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=1576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}