sql server extended events what, why, how, who?. stuart moore started with sql server 7 in 1998, 15...
TRANSCRIPT
![Page 1: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/1.jpg)
SQL Server Extended Events
What, Why, How, Who?
![Page 2: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/2.jpg)
Stuart Moore• Started with SQL Server 7 in 1998, 15 years later still working
with it, but newer versions as well.• Worked as DBA and Developer in that period.• Also work with Oracle, MySQL and Linux
• In spare time I’m most likely to be found studying a Mathematics degree with the OU, or sat on a bike saddle somewhere remote.
• Email: [email protected]• Twitter: @napalmgram
![Page 3: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/3.jpg)
What we’ve had
• SQL Trace – Server side tracing mechanism• SQL Profiler – Client side tool to use SQL Trace
![Page 4: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/4.jpg)
What was wrong with that?
• Performance hit– All event data captured, and then filtered– Especially bad if run through Profiler
![Page 5: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/5.jpg)
• Not the most user friendly of syntax:
![Page 6: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/6.jpg)
So, Extended Events
• Introduced in SQL Server 2008.• ‘Extended’ in SQL Server 2008R2 – Unofficial GUI from Codeplex
• And again in SQL Server 2012– Now includes all SQL Trace functionality– Official GUI tool in SSMS
![Page 7: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/7.jpg)
SQL Server 2008 SQL Server 2008R2 SQL Server 2012
action 35 35 48
Event 253 257 616
Map 57 60 240
Pred_compare 111 111 77
Pred_source 29 29 44
Target 7 7 6
Type 29 29 28
Changes across SQL Server versions
![Page 8: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/8.jpg)
• Extendable– New packages can be loaded, for instance for
Microsoft Support calls• Better performance– Filtering done as early as possible to avoid
overheads– You already have a session running and probably
not noticed: • System_health
![Page 9: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/9.jpg)
• Sessions can be told to ‘lose’ events if performance degraded:– Allow_single_event_loss (Default)– Allow_multiple_event_loss– No_event_loss
• Can persist server restarts
![Page 10: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/10.jpg)
Basic Example
• Demo
![Page 11: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/11.jpg)
Packages
• All events, actions, types, etc belong to a Package.
• Registered packages can be seen in– sys.dm_xe_packages
• SQL 2012 ships with 8 packages. Others can be installed, usually by MS support for debugging faults
![Page 12: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/12.jpg)
• Packages loaded by corresponding module during startup.
• All events, objects, targets, etc are owned by a package
• But, all can be used interchangably– Ie; a sqlos event can capture sqlserver actions and
record in a package0 target• Anything marked ‘private’ is system access only:– SecAudit being the prime example
![Page 13: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/13.jpg)
Sessions
• All defined event sessions recorded in– sys.server_event_sessions
• If session is running, it’s recorded in– Sys.dm_xe_sessions
![Page 14: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/14.jpg)
Events• The events which can be monitored.– 616 in SQL Server 2012• Select * from sys.dm_xe_objects where
object_type=‘event’ and isnull(capability,’’)<>’private’
– Each event is ‘owned’ by a package:select b.name, a.* from sys.dm_xe_objects a inner join sys.dm_xe_packages b
on a.package_guid=b.guid where a.object_type='event' and isnull(a.capabilities_desc,'')<>'private'
![Page 15: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/15.jpg)
• A session can capture more than one event:
Create event session ex1 on serveradd event sqlserver.sql_statement_startingadd event sqlserver.sql_statement_completedadd target ring_buffer
![Page 16: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/16.jpg)
‘Payload’
• Each event ‘drops’ a payload to the ‘target’:
select b.name, a.name, a.type_name, a.description, a.column_type, a.column_value From sys.dm_xe_object_columns a join sys.dm_xe_objects b on a.object_package_guid=b.package_guid and a.object_name=b.nameand isnull(b.capability,’’)<>’private’
![Page 17: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/17.jpg)
• 3 column_type values:– readonly – internal value– data – values returned by default– Customizable – these can be changed, options
described in the description field, and default value in the column_value field.
![Page 18: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/18.jpg)
Actions
• Actions are extra data/payload that can be collected when an event fires:
select b.name, b.description, a.* from sys.dm_xe_objects a join sys.dm_xe_packages b on a.package_guid=b.guid where a.object_type='action' and isnull(a.capabilities_desc,'')<>'private';
![Page 19: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/19.jpg)
Predicates
• Used to filter the events captured:select b.name, a.* From sys.dm_xe_objects a join sys.dm_xe_packages b on a.package_guid=b.guid where a.object_type='pred_source' and isnull(a.capabilities_desc,'')<>'private';
![Page 20: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/20.jpg)
Maps
• Means of mapping names to values for predicates– For example Wait types to an ID
select b.name, a.name, a.map_key, a.map_value, b.description from sys.dm_xe_map_values ainner join sys.dm_xe_objects b on a.object_package_guid=b.package_guid and a.name=b.nameorder by b.name, a.map_key
![Page 21: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/21.jpg)
Targets
• Where the data ends up.– A number of different types, main differences:• Synchronous• Asynchronous• Memory resident• Persisted storage (disk)
![Page 22: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/22.jpg)
• Etw_classic_sync_target– Used for ETW, useful for devs for tracing through large
systems but out of scope here• Histogram & event_counter– Memory resident tally targets. Histogram used to group
data asynchronosyly, counter is a synchronous counter• Pair_matching– Memory resident and asynchronous. Used to pair up
events, eg; beginning and end of transaction• Event_file– Disk based asynchronous target, for bulk or long term
retention• Ring_Buffer– Memory based asynchronous FIFO target.
![Page 23: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/23.jpg)
Examples
• 1 – Deadlocks• 2 – Possible parameter sniffing• 3 – Capture Data file growth• 4 – Statement counting• 5 – Perfmon stats via GUI
![Page 24: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/24.jpg)
All Good?
• Not quite:– Can still drag performance down,– Viewing results in GUI still a resource hog
• But it’s the way forward
![Page 25: SQL Server Extended Events What, Why, How, Who?. Stuart Moore Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions](https://reader030.vdocument.in/reader030/viewer/2022032722/56649cf45503460f949c19bf/html5/thumbnails/25.jpg)
References
• Jonathan Kehayias:– on the load impact of Extended Event sessions:
• http://bit.ly/XLeMWF
– 31 days of Xevents:• http://bit.ly/153GfZU
• MSDN– Overview
• http://bit.ly/13eCnCx
– Dynamic Management View• http://bit.ly/WWg4T1