Extend Your Knowledge with Extended Events! Janis Griffin Senior DBA
Who Am I Senior DBA for Confio Software Current – 24+ Years DBA JanisGriffin@confio.com @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?
Agenda Extended Events Introduction Terms & Useful DMVs How to Create in 2012 Viewing & Reporting Event Info Examples Deadlock Monitoring Query Performance Aggregate Like SQLs
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 Trace No More won’t be in Versions > 2012 select instance_name, cntr_value from sys.dm_os_performance_counters where object_name like '%deprecate%' and instance_name like '%trace%'
Extended Events Intro (EE) 2008 - 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
Catalog Views for EE Metadata Views for event session creation sys.server_event_sessions Lists all event session definitions sys.server_event_session_events Returns a row for each event in an event session sys.server_event_session_actions Returns a row for each action on each event of 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
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
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
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
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
Session Creation Example CREATE EVENT SESSION [Deadlocks] ON SERVER ADD EVENT sqlserver.xml_deadlock_report (ACTION(sqlserver.client_connection_id,sqlserver.database_name,sqlserver.query_hash,sqlserver.session_id,sqlserver.sql_text,sqlserver.tsql_stack)) ADD TARGET package0.event_file(SET filename=N'c:\Program Files\Microsoft SQL Server\MSSQL11.SPEEDTY\MSSQL\Log\Deadlocks_xml.xel'), ADD TARGET package0.histogram(SET filtering_event_name=N'sqlserver.xml_deadlock_report',source=N'xml_report',source_type=(0)), ADD TARGET package0.ring_buffer WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=ON,STARTUP_STATE=OFF) GO
Session Creation Example 2012 Script used in 2008 CREATE EVENT SESSION [Deadlocks] ON SERVER ADD EVENT sqlserver.xml_deadlock_report (ACTION(sqlserver.session_id,sqlserver.sql_text,sqlserver.tsql_stack)) ADD TARGET package0.ring_buffer WITH (MAX_MEMORY=4096 KB, EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS, MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB, MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=ON, STARTUP_STATE=OFF) GO
2012 Extended Events
2012 Extended Events
Creating Deadlock EE
Deadlock Event
Deadlock EE Actions
Deadlock EE Filters
Deadlock EE Target
Managing/ Viewing Sessions
Viewing Targets
Viewing Targets
Demonstration Examples Deadlock Monitoring Query Performance Aggregate Like SQLs
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
Demo Steps Query Performance Show How To Script Start Monitor Run load – AdventureWorks Show Extended Event Options (Menu) Save Viewing properties for reuse File / Open Group Session / Sum Duration / View Waits
Demo Steps Aggregate Like SQLs Group By Query Plan Hash Sum by Duration Sort Descending Select * from sys.dm_exec_query_plan(@handle);
Summary Extended Events are light weight Quickly / continuously gather Performance Data 2012 - 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
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 www.confio.com http://www.ignitefree.com – Free Current View