Presentation is loading. Please wait.

Presentation is loading. Please wait.

Extend Your Knowledge with Extended Events!

Similar presentations


Presentation on theme: "Extend Your Knowledge with Extended Events!"— Presentation transcript:

1 Extend Your Knowledge with Extended Events!
Janis Griffin Senior DBA Hello my name is Janis Griffin and my presentation on Extended Events.

2 Who Am I Senior DBA for Confio Software Current – 24+ Years DBA
@DoBoutAnything Current – 24+ Years DBA Primarily SQL Server, Sybase, Oracle Former – Database Design & Implementation Specialize in Performance Tuning Review Database Performance for Customers and Prospects Common Thread – How do I tune it? Before we get started, I want to introduce myself. I’ve been a DBA over almost 25 years now. I started out in Oracle, picked up sybase and sql server along the way among many other database types. Most of my career has been spend in the Telecom / Networking companies. I’ve been working at Confio for almost 5 years now. Confio makes database performance monitoring tools and my main responsibility is working with our customer and prospective customers helping them find the biggest problems in their database and then give them some idea on how to go about fixing them. So naturally, I wanted to looking into Extended events because they give more information about problems and help you troubleshoot issue.

3 Agenda Extended Events Introduction Terms & Useful DMVs
How to Create in 2012 Viewing & Reporting Event Info Examples Deadlock Monitoring Query Performance Aggregate Like SQLs Here is the agenda for today. We look at the history of extended events, what are they, why would you use them. Then we’ll go through some terms and I’ll show you some DMVs and tables to view them in actions as well as get metadata information about them. We’ll also look at how to view report the information gathered. Finally, I’ll go through several live examples of Deadlock Monitoring, Query performance and if we have time parameter capture for stored procedures.

4 Extended Events Intro (EE)
Lightweight event-handling mechanism Captures event information like SQL Profiler / SQL Trace More information plus you can now configure When events are triggered, they can be sent to a target for further analysis Introduced in SQL Server 2008 Very complex to code and read (parse xml) Much Improved in 2012 with many more Events SSMS has Extended Event Interface Deprecation Announcement SQL Profiler and SQL Trace won’t be in Versions > 2012 So what are extended events? Well, they are a lightweight event handling mechanism that captures information when an event occurs. They are similar to sql profiler or sql trace. However, extended events gives you much more information. Plus, you can now configure which ones you want to see and get exactly the information you want. When events are triggered, they can be sent to a target for further analysis. They were introduced in Sql Server 2008, however, not too many used them because there was no UI and they were complex to code. Also, the output was in XML so you either had to write a parsing routine to get the information out of XML or become a very good XML reader. In 2012, Extended events were greatly improved and expanded upon ???? Need number of events for 2008 versus 2012. Now Management Studio has an interface for extended events so you don’t have to write complex code. Also, there are some reporting features within SSMS so you don’t have to parse XML. I’ll show some examples of that later. Finally, Microsoft has announced that Sql Profile and SQL Trace won’t be available after 2012. ???? In fact, in 2012, Sql Profile has been replaced by extended events.

5 Extended Events Intro (EE)
DDL statements that create / modify Extended Events sessions CREATE EVENT SESSION Creates an extended event session object Identifies Source of the events, Targets, and Parameters ALTER EVENT SESSION Starts/stops an event session or changes an event session configuration DROP EVENT SESSION Drops an event session DMVs / Catalog views show session data & metadata Use TSQL statements to get information on every extended events session that is created Just a little bit about 2008 extended events. But first, can I see a show of hands. How many people are running 2012? How many people are using extended events in 2008 today? Well, in 2008, you had to create and modify extended events with DDL commands. There was no UI to manage them … so I don’t think they were widely adopted because of that very reason. I’ve listed the 3 ddl statements, Microsoft gives you to manage them. The Create Event Session is use to set up an event session. A session identifies the source of the events captured, the targets and the parameters used. The Alert Event Session basically is how you stop or start and event session or you can use the alter command to change the sessions configuration. Finally the Drop Event Session will remove it from the sql server instance. There are several DMVs and catalog views that show the session data as it’s being collect and metadata about the event sessions. I’ll show you these in the next few slides.

6 Catalog Views for EE Metadata Views for event session creation
sys.server_event_sessions Lists all event session definitions sys.server_event_session_actions Returns a row for each action on each event of an event session sys.server_event_session_events Returns a row for each event in an event session sys.server_event_session_fields Returns a row for each customizable column explicitly set on events and targets sys.server_event_session_targets Returns a row for each event target for an event session I’ve listed here all the catalog views for Extended Events. As you can see, you can use these views to get information on the sessions currently set up in an instance, their events , actions and targets. Also, you can get specific values for the customizable fields that are explicitly set for events and targes. We won’t be going through these views in any real detail , but I wanted my slides to be complete so you can use them as a reference.

7 DMVs for EE Session data created when event session is started
Note:  Views don’t have session data until a session starts sys.dm_os_dispatcher_pools - Returns information about session dispatcher pools sys.dm_xe_objects - Returns a row for each object exposed by an event package sys.dm_xe_object_columns - Returns the schema information for all the objects sys.dm_xe_packages - Lists all the packages registered with extended events engine sys.dm_xe_sessions - Returns information about an active extended events session sys.dm_xe_session_targets - Returns information about session targets sys.dm_xe_session_events - Returns information about session events sys.dm_xe_session_event_actions - Returns information about event session actions sys.dm_xe_session_object_columns - Shows the configuration values for objects bound to a session sys.dm_xe_map_values - Provides a mapping of internal keys to human-readable text Here are the list of DMVs that you can use to report on the session data. This data is created when an event session is started. Please not that these views won’t have any data in them if a session is not running. I have some examples of using these in the next few slides.

8 DMVs for EE Objects SELECT p.name AS package_name, o.name AS event_name, o.description FROM sys.dm_xe_packages AS p JOIN sys.dm_xe_objects AS o ON p.guid = o.package_guid WHERE (p.capabilities IS NULL OR p.capabilities & 1 = 0) AND (o.capabilities IS NULL OR o.capabilities & 1 = 0) AND o.object_type = 'event' ORDER by o.name Here is an example of looking at the package and events in the package that is currently running. As you can see I’m selecting from the DMVs, dm_xe_packages and objects joining on package_guid. I’m checking to see if capabilities is null or not equal to 1 (with the bitwise check) and looking for object_type of event.

9 DMVs for EE Targets SELECT p.name AS package_name, o.name AS target_name, o.description FROM sys.dm_xe_packages AS p JOIN sys.dm_xe_objects AS o ON p.guid = o.package_guid WHERE (p.capabilities IS NULL OR p.capabilities & 1 = 0) AND (o.capabilities IS NULL OR o.capabilities & 1 = 0) AND o.object_type = ‘target' ORDER by o.name Here is the same query looking for the object_type of targets for package0. This shows where I can send the events from the session. I’ll have some examples of these in later slides but notice you can send the events to a file for later analysis

10 DMVs for EE Actions SELECT p.name AS package_name, o.name AS action_name, o.description FROM sys.dm_xe_packages AS p JOIN sys.dm_xe_objects AS o ON p.guid = o.package_guid WHERE (p.capabilities IS NULL OR p.capabilities & 1 = 0) AND (o.capabilities IS NULL OR o.capabilities & 1 = 0) AND o.object_type = ‘action' ORDER by o.name Finally, you can view the actions that are taken or captured when an event occurs in a session. You can select different actions for each event. In the sqlserver package, I’m capturing the session_id and sql_text information.

11 2012 Extended Events In 2012, Extended Events got much easier… because now Management studio has an interface to show us all of the information without querying the dmvs. We can get out of the weeds so to speak. You access them under the Management Object there is now an Extended Events folder which you can expand and see the sessions. In 2012, Microsoft gives 2 default sessions. The AlwaysOn_health session is not started by default. However, the system_health on is started by default. You can see the one underneath that one is called Wait Events and that is one session I create which we will go through in more detail during the live demo.

12 2012 Extended Events If you right click on the sessions folder, you can either use the ‘new session wizard’ or just use the new session properties pages to set up your sessions that you want. For the first time, I chose the wizard but you will quickly see that it’s easy enough to set up without using the wizard. When I chose the wizard, it has a banner page that tells you why you might use extended events – application tuning, troubleshooting performance and / or looking at T-SQL performance. You can turn of this initial page, but I chose to display it because on the left hand side it shows all the steps you need to do in order to create a session. We are going to give the session a name, and set properties, we can decide to choose a specific template, select the events we want to capture and the ‘global fields’ or actions we want to take when an event happen. We will set up filters or parameters specific to the event (for example, I may not want to capture any information about background processes. Then we will define the target or session data storage to house the event session data. Finally after we are done configuring the session, we will review it and create the session.

13 Creating Deadlock EE Here are the session properties that I can set up. I can give it a name and choose a template or leave the template blank. In this example, I’ve named my session Deadlocks and chose the Count Query Locks template. Notice also, that I can decide whether this session automatically startes at server startup or not.

14 Deadlock Event Then I choose the events that I want to capture. Notice that I can filter by event name – which I’ve done here on the keyword of ‘deadlock. Also notice that description underneath the event library. It also listed the event fields that this event will produce. I’ve highlighte the xml_deadlock_report so the description is about that event. You can pick and choose the events and move them to the selected box with the errors.

15 Deadlock EE Actions Next, you’ll want to choose the global fields or actions to collect once an event has fired. In 2008, these were called actions and I like that term better because it means that sql server has to do something in order to get this information. So becareful when selecting actions because the more things you ask sql server to do when the event happens, the more impact collecting events will have on performance. I know when I first started playing with this, I just selected all actions and I quickly saw that not only did performance dwindle down but I also filled up my targets very quickly. More about targets, later. In this example, I’m choosing nt_username, process_id, query_hash, query_plan_hash, and session_id.

16 Deadlock EE Filters I can also set filters or parameters to tell when I want the event to fire. Here I’m only looking at sessions with a session id greater than 50 because I’m assuming most of the background processing happens below that and I only want to look at deadlocks in user sessions.

17 Deadlock EE Target This screen sets up different targets to store the session data. In this example, I’ve chosen to save the data in a file. I can name the file and decide how large it should grow before it rolls over. I’ve left it at the default of 1gb in size and only 5 files before it starts reusing the files. Notice, I can also set a ring_buffer target where you can view it immediately. This is useful for smaller data sets or continuous data collection. Again, I’ve left that a the default. Once I’ve defined the targets, the wizard will show a summary page of my settings and then create the event session.

18 Managing/ Viewing Sessions
Once I refresh my object view, I’ll see the new session under the sessions folder. If I right-click on the new session, I can start the session. Also, notice the other things that I can do. I can stop the session, I can watch live data (the session would have to first be started) . I can export the session, this is good if I want to put this on other sql server instances and of course I can review/change it’s properties. Once I start the session, the targets will start populating and you can expand the session to see them. The example on the right shows that I’ve expanded the system_health session and I’m going to ‘view target data’ out of it’s ring_buffer

19 Viewing Targets Once you either view target data or watch live data, you will see the data in the query screen. By default, the session data will only show 2 fields, the event name and a timestamp in the top screen and all the other fields for a particular record below that. You can configure this view and either show them as columns in the top or add or remove them as needed. Also, notice the circled options at the top. I have a new menu item of ‘Extended events’ that I can use as a dropdown. Or, I can show all options on the menu bar. You can change your view, group, sort and further filter the data. You can also aggregate the data as well. I have examples of that in the next slides. Here I’ve highlited a wait_info event and I can see that session id 59 is waiting on a shared lock. Notice the sql text….

20 Viewing Targets Here is another view of the session data where I have grouped the data by wait events. Notice that different ring_buffer activity… due to the system health and probably my ‘wait events’ event sessions

21 Demonstration Examples Deadlock Monitoring Query Performance
Aggregate Like SQLs Okay, hopefully that is enough background before we jump into the demo. I have 3 event session examples that I’d like to show you. Hopefully, we can get through them all. I’m going to walk through a deadlock example, look at query performance and then try to capture some parameter values.

22 Demo Steps Deadlocking Walk through the Session properties
General Events, Actions, Filters Targets Start Monitor Run dlock1 / dlock2 to get deadlock Show different target examples For the first example, I’m going to set up a deadlock situation and then show you the session I set up – start the session then try to create a deadlock so we can view it in action.

23 Demo Steps Query Performance Show How To Script Start Monitor
Run load – AdventureWorks Show Extended Event Options Save Viewing properties for reuse File / Open Group Session / Duration - Filter Waits Ok, in this example, I’m going to use some example queries from the AdventureWorks2012 and just create a load. Again, we’ll walk through the session properties, show the ddl behind the session creation and starting. We will also show you how you can save of the viewing of data.

24 Demo Steps Aggregate Like SQLs Group By Query Plan Hash
Sum by Duration Sort Descending Select * from

25 Summary Extended Events are light weight
Quickly / continuously gather Performance Data Easy to capture, store and view data Via Sessions, Events, Actions, Filters, & Targets Can be used to troubleshoot issues Replaces Sql Server Profile for Trace Capture Deprecated in next release Still need to use for Trace Capture of Analysis Services Replaces Sql Trace Stored procedures, functions and catalog views

26 About Confio Wait-Based Performance Tools Ignite8 / IgniteVM
Ignite for SQL Server, Oracle, DB2, Sybase Helps show which SQL to tune Based in Colorado, worldwide customers Free trial at – Free Current View


Download ppt "Extend Your Knowledge with Extended Events!"

Similar presentations


Ads by Google