SQL Server Debugging Made Easy using Extended Events

Slides:



Advertisements
Similar presentations
SQL Server 2012 New Performance Tuning Tools. Who am I? Menzo Steinhorst Senior Premier Field Engineer SQLRAP, WS+ SQL Server Performance Tuning, WS+
Advertisements

© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Amit Bansal CTO | Peopleware India (unit of eDominer Systems) | |
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.

customer.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
demo Demo.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Sr. Dir. – Systems Architecture Inlet Technologies.

C:\Users\> t An affair with SQL Server for nearly a decade Was part of SQL Escalation Services and Premier Field Engineering team.
SQL Advanced Monitoring Using DMV, Extended Events and Service Broker Javier Villegas – DBA | MCP | MCTS.
C:\Users\> whoami Known on Twitter t An affair with SQL Server for nearly a decade Was part of SQL Escalation Services and Premier Field.
C:\Users\> t Work as a Senior Program Manager for the SQL Server Product Group (Tiger team) An affair with SQL Server for nearly a.
MIX 09 4/17/2018 4:41 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Convergence /6/2018 © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
6/16/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
Troubleshooting Ninja using PowerBI and SQL Server Extended Events
Amit Banerjee Sr. Program Manager Microsoft Database Systems
Virtual Machine Diagnostics in Microsoft Azure
7/28/ :17 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or.
Mission-critical performance with Microsoft SQL Server 2016
Required 9s and data protection: introduction to sql server 2012 alwayson, new high availability solution Santosh Balasubramanian Senior Program Manager.
Test Upgrade Name Title Company 9/18/2018 Microsoft SharePoint
Возможности Excel 2010, о которых следует знать
Troubleshooting Ninja using PowerBI and SQL Server Extended Events
Amit Banerjee Sr. Program Manager Microsoft Data Platform Group
Troubleshooting Availability Group Failovers
Title of Presentation 11/22/2018 3:34 PM
TechEd /24/2018 8:21 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered.
SQL Server 2016 Query Data Store
Office Mac /30/2018 © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
SPC2012 – IT-Pro 11/30/2018 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Turbo-Charged Transaction Logs
Title of Presentation 12/2/2018 3:48 PM
System Admin Best Practices for NAV 2013 R2
Microsoft Office 365 ProPlus Deployment for IT Pros
Tech·Ed North America /17/2019 6:01 PM
Using Power Bi to troubleshoot SQL Server instances
Feature: Document Attachment - Flow from Master Records
Microsoft Virtual Academy
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
When Bad Things Happen to Good Applications
Andrew Fryer Microsoft UK
Windows 8 Security Internals
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
Enriching your BI Semantic Models with Data Analysis Expressions (DAX)
DevOps better together with System Center 2012 SP1 and Visual Studio
Ask the Experts: Windows 10 deployment and servicing
5/8/2019 3:20 AM bQuery-Tool 3.0 A new and elegant way to create queries and ad-hoc reports on your Baan/Infor ERP LN data. This Baan session is a query.
Title of Presentation 5/12/ :53 PM
Service Template Creation from the Ground Up
Шитманов Дархан Қаражанұлы Тарих пәнінің
Diagnostics and troubleshooting in Azure App Service Support Center
Title of Presentation 5/24/2019 1:26 PM
5/24/ :22 AM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
日本初公開!? Vista の新機能を実演 とっちゃん わんくま同盟 7/23/2019 9:09 AM
Title of Presentation 7/24/2019 8:53 PM
Microsoft Virtual Academy
Presentation transcript:

SQL Server Debugging Made Easy using Extended Events Amit Banerjee Senior Program Manager Microsoft Data Group

C:\Users\> whoami Known on Twitter as @banerjeeamit An affair with SQL Server for nearly a decade Was part of SQL Escalation Services and Premier Field Engineering team at Microsoft Now a Sr. Program Manager on the Microsoft SQL Server (TIGER) product team focusing on HADR and Replication Speaker at SQL PASS 24HOP TechEd Virtual TechDays User Groups SQL Saturdays Dabble around with supportability tools and have contributed to SQL Backup Simulator SQLDIAG/PSSDIAG Manager and SQL Nexus Co-authored “Professional SQL Server 2012: Internals and Troubleshooting” Own TroubleshootingSQL.com Also found on http://aka.ms/sqlserverteam

Please Support Our Sponsors SQL Saturday is made possible with the generous support of these sponsors. You can support them by opting-in and visiting them in the sponsor area.

Don’t Forget Silence your cell phones Online Evaluations www.sqlsaturday.com/572/sessions/sessionevaluation.aspx www.sqlsaturday.com/572/eventeval.aspx Submit for raffles by 3:30PM

Session Objectives And Takeaways Tech Ready 15 7/31/2018 Session Objectives And Takeaways Understand capabilities of Extended Events to troubleshoot and mitigate issues quickly in mission-critical environments Set up session templates proactively to reduce mitigation time during reactive situations Use Extended Events to troubleshoot and resolve complex issues in a timely manner and improve CPE © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Agenda TechReady 18 7/31/2018 Best Practices Common Troubleshooting Scenarios System Health Query Performance Always On Backup, Restore and Recovery Demos © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Best Practices Premise: “drop events, not performance” Event Buffers Avoid EVENT_RETENTION_MODE = NO_EVENT_LOSS Best Practices Event Buffers None: 3 buffers (fixed) x 1.3 MB ~4.0 MB (Default MAX_MEMORY=4.0 MB) Node: 3 * number_of_nodes CPU: 2.5 * number_of_cpus For high end machines MEMORY_PARTITION_MODE=PER_NODE | PER_CPU Increase MAX_MEMORY, use multiple XE file targets to increase write throughput Example: 4 node, 16 logical cores/node Event session options http://blogs.msdn.com/b/extended_events/archive/2010/03/31/optio n-trading-getting-the-most-out-of-the-event-session-options.aspx Memory partitioning http://blogs.msdn.com/b/extended_events/archive/2010/12/07/sessio n-memory-who-s-this-guy-named-max-and-what-s-he-doing-with-my- memory.aspx Buffer memory http://blogs.msdn.com/b/extended_events/archive/2010/06/28/take- it-to-the-max-and-beyond.aspx Avoid expensive Events e.g. showplan Actions e.g. callstack Filters on text columns

Configure Extended Events Session Why am I showing this?

Common Scenarios

Backup and Restore tracing 7/31/2018 9:26 PM Backup and Restore tracing Long running tasks Not enough insight into progress Trace flag (3004) output is cryptic and unformatted Errorlog TF 3014 = TF 3014 + TF 3004 + TF 3212 (buffer config details) Formatted messages - Backup(dbname) and Restore(dbname) All errors (currently sent to the client, which can be lost) Extended Event backup_restore_progress_trace SQL Server 2016 Options - checksum, compression, encryption, and buffer configs Size estimation before starting actual copy operation Elapsed time - checkpointing, zeroing files (restore), history table updates Percentage progress during file processing Waits for locks - only high-level/database-level locks Major steps for filestream filegroups First/last LSNs in consistent format Backup and restore are long running tasks in SQL Server with limited insights into progress. Often a question asked is “How much longer will it take for this operation to complete?”. Though there are trace flags and DMVs that provide some information, they are either unstructured (ex: trace flags send output to error logs and can be hard to parse) or hard to interpret. In SQL Server 2016 (starting with CTP 2), we have introduced a new extended event that can be used to easily gain insight into progress of any of these long running activities. In addition, you can leverage the rich collection and diagnostic capabilities of extended events for advanced analysis. We hope that this extended event will simply your troubleshooting experience with backup and restore activities. Single Extended Event You can turn on the backup_restore_progress_trace extended event to trace both Backup and Restore progress. CREATE EVENT SESSION [Backup trace] ON SERVER ADD EVENT sqlserver.backup_restore_progress_trace ADD TARGET package0.event_file(SET filename=N’Backup trace’) WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS, MAX_DISPATCH_LATENCY=5 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE, TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF) GO The event has the following data that is part of the payload. name type_name description operation_type database_operation_type Type of operation – Indicates whether the database is being backed up or restored trace_level backup_restore_trace_level Backup/Restore trace level database_name unicode_string Logical name of the database trace_message unicode_string Progress trace messages for key steps in backup or restore   name map_key map_value database_operation_type 0 Backup database_operation_type 1 Restore backup_restore_trace_level 0 Information of major steps in the operation backup_restore_trace_level 1 Verbose I/O related information © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Database Recovery tracing 7/31/2018 9:26 PM Database Recovery tracing Limited information available during database recovery activities such as Analysis, Redo and Undo Errorlog Does not output during Analysis phase “Recovery of database ‘%’ is xx% complete (approximately yy seconds remaining) Three new Extended Events: database_recovery_progress_report database_recovery_times database_recovery_trace SQL Server 2016 As most of you can attest, there is limited information available during database recovery activities such as Analysis, Redo and Undo phases. I am happy to share that in SQL Server 2016, we have introduced three new extended events to help you gain insight into database recovery. database_recovery_progress_report This event can be used to gather high level progress information such as phase, percent_complete and estimated time during database recovery. The following data is available as part of the event: name phase percent_complete total_elapsed_time_sec estimated_remaining_time_sec database_name   Recovery phase in the extended event payload can be one of the following: PreRecovery Analysis Redo Undo Complete PostRecovery database_recovery_times With this extended event, you can also get the recovery time for specific steps during database startup.   database_recovery_trace If the two extended events listed above are not sufficient and you wanted detailed insight, you can also turn on database_recovery_trace extended event. Note that this can generate lot of data and use with caution. Off course, you can leverage the filtering capabilities of the extended event framework to limit the collection to a specific database or a specific phase. Some of the useful information that you can instantly get are: Number of VLFs Estimated log size Number of transactions Time spent in each phase © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Database Recovery progress 7/31/2018 9:26 PM Database Recovery progress Progress and time estimates for various phases Recovery time for specific steps during database startup SQL Server 2016 Extended Event Session Script The following session definition was used to collect the events above. Though the session can be launched any time during the middle of a long running recovery to gather insight, you can turn on the startup state for the session to automatically launch at startup in case you want to collect data during server startup when database recovery usually happens.   CREATE EVENT SESSION [recovery_trace] ON SERVER ADD EVENT sqlserver.database_recovery_progress_report(SET collect_database_name=(1)), ADD EVENT sqlserver.database_recovery_times, ADD EVENT sqlserver.database_recovery_trace ADD TARGET package0.event_file(SET filename=N’recovery_trace’) WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=3 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=ON) GO © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Powershell Extensions 7/31/2018 9:26 PM Powershell Extensions PS SQLSERVER:\XEvent\TR23DEMO\SQL2016\Sessions\system_health> dir Events Name Package Name Predicate Description ---- ------------ --------- ----------- sqlclr.clr_allocation_failure sqlclr A memory allocation failed. sqlclr.clr_virtual_alloc_fa... sqlclr A virtual memory allocation failed sqlos.memory_broker_ring_bu... sqlos Memory broker ring buffer recorded sqlos.memory_node_oom_ring_... sqlos Memory node OOM ring buffer recorded sqlos.process_killed sqlos Process killed sqlos.scheduler_monitor_dea... sqlos Deadlock ring buffer recorded for sch... sqlos.scheduler_monitor_non... sqlos Nonyielding IOCP ring buffer recorded... sqlos.scheduler_monitor_non... sqlos Nonyielding ring buffer recorded for ... sqlos.scheduler_monitor_non... sqlos Non-yielding resource manager ring bu... sqlos.scheduler_monitor_sta... sqlos Stalled dispatcher event recorded for... sqlos.scheduler_monitor_sys... sqlos System health ring buffer recorded fo... sqlos.wait_info sqlos ([duration]>(1500... Occurs when there is a wait on a SQLO... sqlos.wait_info_external sqlos ([duration]>(5000... Occurs when a SQLOS task switches to ... sqlserver.connectivity_ring... sqlserver Occurs when there is a server-initiat... sqlserver.error_reported sqlserver ([severity]>=(20)... Occurs when an error is reported. sqlserver.security_error_ri... sqlserver Security error ring buffer recorded sqlserver.sp_server_diagnos... sqlserver ([sqlserver].[is_... Occurs when a component state is dete... sqlserver.sql_exit_invoked sqlserver Occurs when SQLExit() routine is invoked sqlserver.xml_deadlock_report sqlserver Produces a deadlock report in XML for... https://msdn.microsoft.com/en-us/library/ff877887(v=sql.130).aspx © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Somebody got hurt real bad!!!  Lease Timeout Somebody got hurt real bad!!! 

Availability Group: Lease Timeout 7/31/2018 9:26 PM Availability Group: Lease Timeout hadr_ag_lease_renewal - Renews every 5 seconds availability_group_lease_expired – Raised when the lease expires SQL Server 2012 Service Pack 3 and above More information about this improvement can be found in the following articles: https://blogs.msdn.microsoft.com/alwaysonpro/2016/02/23/improved-alwayson-availability-group-lease-timeout-diagnostics/ https://support.microsoft.com/en-us/kb/3112363 Refer the following for Lease Timeouts: https://blogs.msdn.microsoft.com/psssql/2012/09/07/how-it-works-sql-server-alwayson-lease-timeout/ © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES EXPRESS IMPLIED OR STATUTORY AS TO THE INFORMATION IN THIS PRESENTATION.

Availability Group: Latency 7/31/2018 9:26 PM Availability Group: Latency hadr_apply_log_block hadr_capture_log_block hadr_capture_vlfheader hadr_database_flow_control_action hadr_db_commit_mgr_harden hadr_log_block_compression hadr_log_block_decompression hadr_log_block_group_commit hadr_log_block_send_complete hadr_lsn_send_complete hadr_receive_harden_lsn_message hadr_send_harden_lsn_message hadr_transport_flow_control_action hadr_transport_receive_log_block_message log_block_pushed_to_logpool log_flush_complete log_flush_start recovery_unit_harden_log_timestamps SQL Server 2012 Service Pack 3 and above © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES EXPRESS IMPLIED OR STATUTORY AS TO THE INFORMATION IN THIS PRESENTATION.

Let’s look at something COOL! DEMO Let’s look at something COOL!

Questions Resources Twitter: https://github.com/Microsoft/tigertoolbox Blog: Aka.ms/sqlserverteam www.troubleshootingsql.com Twitter: @banerjeeamit @mssqltiger Github: https://github.com/Microsoft/tigertoolbox https://github.com/Microsoft/sql-server-samples

Thank You This FREE SQL Saturday is brought to you courtesy of these sponsors, speakers and volunteers who staff this event