Performance Monitoring Using Extended Events, DMVs & Query Store

Slides:



Advertisements
Similar presentations
Yukon – What is New Rajesh Gala. Yukon – What is new.NET Framework Programming Data Types Exception Handling Batches Databases Database Engine Administration.
Advertisements

Module 17 Tracing Access to SQL Server 2008 R2. Module Overview Capturing Activity using SQL Server Profiler Improving Performance with the Database Engine.
The Essentials: DMV’s and T-SQL for the DBA Rocky Mountain Tech Tri-Fecta.
Backup, Integrity Check and Index and Statistics Maintenance
Key Concepts About Performance Factors Affecting SQL Performance SQL Performance Tuning Methodologies SQL Performance Tuning Tools 1.
1099 Why Use InterBase? Bill Todd The Database Group, Inc.
Learningcomputer.com SQL Server 2008 – Profiling and Monitoring Tools.
SQLRX – SQL Server Administration – Tips From the Trenches SQL Server Administration – Tips From the Trenches Troubleshooting Reports of Sudden Slowdowns.
Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools.
Troubleshooting SQL Server Performance: Tips &Tools Amit Khandelwal.
1 11g NEW FEATURES ByVIJAY. 2 AGENDA  RESULT CACHE  INVISIBLE INDEXES  READ ONLY TABLES  DDL WAIT OPTION  ADDING COLUMN TO A TABLE WITH DEFAULT VALUE.
Why Should I Care About … The Plan Cache? Tuning When Stakeholders Won’t Say Where It Hurts.
SQL Server 2016 – New Features Tilahun Endihnew March 12, 2016.
SQL Advanced Monitoring Using DMV, Extended Events and Service Broker Javier Villegas – DBA | MCP | MCTS.
Improve query performance with the new SQL Server 2016 query store!! Michelle Gutzait Principal Consultant at
You Inherited a Database Now What? What you should immediately check and start monitoring for. Tim Radney, Senior DBA for a top 40 US Bank President of.
No more waiting. Sponsors About me  Database Technology Specialist  MVP  Blogger  Author 3
Session Name Pelin ATICI SQL Premier Field Engineer.
MANAGEMENT DATA WAREHOUSE AND DATA COLLECTOR Ian Lanham.
SQL Saturday #509 | Brisbane 2016 #509 | Brisbane 2016 Martin Catherall Moving from Profiler to Extended Events.
3 Methods to End the Madness
An introduction to Wait Statistics
You Inherited a Database Now What?
Automated Restore Script Output for Ola Hallengren’s Maintenance Solution 1) Start SQL Services on Local 2) Connect to Azure AlwaysOn 3) Delete all maintenance.
A big party is being held to honor relational database systems and their impact on modern society. Outside the venue, the host awaits the guests. The.
Troubleshooting SQL Server high CPU usage
Building a Performance Monitoring System using XEvents and DMVs
Things You Can Find in the Plan Cache.
Building a Performance Monitoring System using XEvents and DMVs
Query Store What’s it all About? Andrew J. Kelly
Using Extended Events to Diagnose Application Issues
Isolation Levels Understanding Transaction Temper Tantrums
Root Cause Analysis with DMVs
SSAS Tabular Toolbelt Sergiy Lunyakin.
Auditing in SQL Server 2008 DBA-364-M
Solving ETL Bottlenecks with SSIS Scale Out
Parallel Database Maintenance with 24/7 Systems and Huge DBs
Query Execution Expectation-Reality Denis Reznik
Introducing the SQL Server 2016 Query Store
Introducing the SQL Server 2016 Query Store
Building a Performance Monitoring System using XEvents and DMVs
What Power BI users need to know about R
Lock, Block, and Two Smoking CPUs
The Ultimate Maintenance Plan By Ed Roepe Perimeter DBA, LLC
Introduction to partitioning
Introducing the SQL Server 2016 Query Store
SQL Server 2016 Query Data Store
TEMPDB – INTERNALS AND USAGE
Enterprise Auditing with SQL Server Audit
SQL Server Performance Tuning Nowadays
මොඩියුල විශ්ලේෂණය SQL Server Waits. Tables රැසක් එකට එකතු කිරීම.
Targeting Wait Statistics with Extended Events
Dynamic Management Views a practical overview!
You Inherited a Database Now What?
Kris Hokanson That’s bad mmmkay! …Or, how to know when your SQL Server isn’t working as well as it could.
Go, go Query Store! Gail Shaw.
Dynamic Management Views a practical overview!
Top 5 TIPS TO KEEP Always on AGs humming and users happy
Analyzing Performance Problems Using XEvents, DMVs & Query Store
Building a Performance Monitoring System using XEvents and DMVs
Change Tracking Live Data Warehouse
Server-Side Programming
Denis Reznik SQL Server 2017 Hidden Gems.
Isolation Levels Understanding Transaction Temper Tantrums
Using wait stats to determine why my server is slow
Go, Go, QueryStore!.
Analyzing Performance Problems Using XEvents, DMVs & Query Store
Inside the Database Engine
Inside the Database Engine
The DBA Quit and now you’re it:
Presentation transcript:

Performance Monitoring Using Extended Events, DMVs & Query Store Ola Hallengren, Principal Database Architect, Saxo Bank

Principal Database Architect, Saxo Bank Microsoft MVP – Data Platform Author of the popular maintenance scripts at https://ola.hallengren.com Database Consultant Ola Hallengren Principal Database Architect, Saxo Bank E-mail: ola@hallengren.com

Agenda Extended Events, DMVs and Query Store How are they working in different scenarios? How can you use them together? Comparing performance data Experiences from the bank and when working with customers Troubleshooting performance problems Collecting data into a monitoring database

Extended Events – What data do we have? Level Reads Writes CPU time Dura-tion Result sql_batch_completed Outer Yes OK/Abort/Error rpc_completed module_end Module * - sp_statement_completed Statement Only fires if completed successfully sql_statement_completed * A module could be a stored procedure or a function

A stored procedure was timing out – What statement was executing? A stored procedure was timing out. You are looking at a rpc_completed event with result = Abort, and a module_end event. What statement was in process executing when the timeout happened? module_end tsql_frame Successful execution: <frame … line="0" offsetStart="-1" offsetEnd="-1“ /> Aborted execution: <frame … line="6" offsetStart="74" offsetEnd="202“/> You can pass the sql_handle to sys.dm_exec_sql_text to retrieve the sql text, and then use the offsets to calculate the statement Demo

Query Store Intro Added in SQL Server 2016 The typical use case for Query Store is to look at changes to query plans Automatically stores queries, query plans, run_time statistics and wait statistics Run_time statistics and wait statistics aggregated for one hour intervals Stored by execution type: Regular, Aborted, and Exception Query Store data stored in the user database Here is how to enable Query Store: ALTER DATABASE WideWorldImporters SET QUERY_STORE = ON

Query Store – How to find the query_id? Real-world case: A critical report timed out last night. You have the application name, the host name, and the timestamp. Unfortunately the error message in the application was not very clear, and you are not sure what the query was. Limitation: Query Store does not have any information about application name, host name or login name. How can I find the query in Query Store? You need some additional data to find the query: sys.dm_exec_requests: statement_sql_handle and statement_context_id Extended Events: sql_handle, start_offset, and end_offset in tsql_frame Demo

Query Store - The important context_setting_id Real-world case: Some days later another critical report times out. This time you know the name of the stored procedure. You are thinking that it should be easy to find the query in Query Store and maybe force a good plan. To your surprise there are several query_id’s for the same object_id and offsets in sys.query_store_query. Only the context_setting_id is different. It turns out that some developers have been executing the stored procedure in SSMS to try o find out about the problem. SSMS has different set_options than the application. Again you need statement_context_id in sys.dm_exec_requests. Demo

How Query Store works with killed sessions Real-world case: A query has been running for a long time. There is no command timeout in the application, so eventually you have to kill it. You look in the Query Store to compare the plans, but you can’t find any Aborted executions. Limitation: Executions are not captured in the Query Store sys.query_store_runtime_stats and sys.query_store_wait_stats, if a session is killed or if the client application or host is restarted or crash. The plan is still captured in sys.query_store_plan. Demo

Query Store vs sys. dm_exec_query_stats vs sys Query Store vs sys.dm_exec_query_stats vs sys.dm_exec_procedure_stats - Part 1 What happens with the statistics in Query Store, sys.dm_exec_query_stats, and sys.dm_exec_procedure_stats in different situations? A recompile triggered by a statistics update? sp_recompile? WITH RECOMPILE? OPTION (RECOMPILE)? DBCC FREEPROCCACHE?

Query Store vs sys. dm_exec_query_stats vs sys Query Store vs sys.dm_exec_query_stats vs sys.dm_exec_procedure_stats - Part 2 Level Includes Stored Interval Query Store Statement All executions, except killed In memory  User database 1 hour (default) sys.dm_exec_query_stats Successful executions only In memory No interval sys.dm_exec_procedure_stats Stored procedure All executions

Stats reset plan_generation_num updated Query Store vs sys.dm_exec_query_stats vs sys.dm_exec_procedure_stats - Part 3 Recompile triggered by statistics update or index rebuild sp_recompile DBCC FREEPROC CACHE Query Store Not affected sys.dm_exec_query_stats Stats reset plan_generation_num updated Entry removed All entries removed sys.dm_exec_procedure_stats

Only last execution included Query Store vs sys.dm_exec_query_stats vs sys.dm_exec_procedure_stats - Part 4 WITH RECOMPILE OPTION (RECOMPILE) Query Store Included sys.dm_exec_query_stats Not included Only last execution included sys.dm_exec_procedure_stats

Log writes and Always On synchronizations Real-world case: You are troubleshooting an issue with slow transactions. You are collecting data from Extended Events, DMVs, and also looking in Query Store. The durations just does not add up. Limitation: Query Store, sys.dm_exec_query_stats, and the statement - level Extended Events do not include hardening of the log write to disk, or synchronization with the secondary replica in Always On. Demo

When is Log writes and Always On included? Includes transaction log write to disk Includes Always On synchronization * sql_batch_completed Yes rpc_completed module_end sp_statement_completed No sql_statement_completed Only if outside a module_end Query Store sys.dm_exec_query_stats sys.dm_exec_procedure_stats * Always On with synchronous-commit

Looking at problems back in time How do you answer questions like “Why did this stored procedure time out for the last few days.” When you are investigating problems back in time, the key thing is to have the data. For Query Store the data collection happens automatically in the user database. We have seen that in many cases the data collected in Query Store is not enough. Often you also need data from Extended Events and DMVs. For Extended Events and DMVs, you need to do the collection of data.

Collecting data into a monitoring database Collecting data from execution related DMVs and Extended Events into a monitoring database for easy querying The raw data in the tables Views to transform and combine the data Collection Server (PowerShell scripts) Monitoring Database (PerformanceStore) Production Servers

Quick overview of the monitoring database Table Views Extended Events ExtendedEvents.Events ExtendedEvents.AbortedExecutions ExtendedEvents.SlowExecutions ExtendedEvents.BlockedProcesses DMVs dbo.dm_exec_sessions_extended dbo.Sessions SQL Texts dbo. dm_exec_sql_text

A query timeout from different angles Real-world case : An important stored procedure was timing out early in the morning. The business wants to know what happened and you start investigating it. Troubleshooting using data in your monitoring database and in Query Store Demo

Putting it all together If you have a completed/end event in Extended Events, you have the timestamp, and the duration. The timestamp is the end time. Using the duration you can calculate the start time. Then you can find session/request snapshots for the same session_id and in this interval. You can use statement_sql_handle and statement_context_id in sys.dm_exec_requests to find the query_id in Query Store You can use transaction_id to find blocked_process_report events, and then change the filter to monitor_loop_id to look at a snapshot of the blocking

blocked_process_report – What is the monitor_loop_id? The blocked_process_report event is very useful when investigating blocking problems Handled by the same thread in SQL Server that is searching for deadlocks Every time the monitor thread wakes up and is looking for blocking it has a new monitor_loop_id <blocked-process-report monitorLoop="1369"> If you want to get a “snapshot” of all blocking that was going on at a time, filter on monitor_loop_id Demo

Questions? The presentation and demo code will be available at http://www.sqlbits.com The code for the monitoring database is available at https://ola.hallengren.com/scripts/PerformanceStore.zip You can contact me at ola@hallengren.com Thank You Please complete the session feedback forms

SQLBits - It's all about the community... Please visit Community Corner, we are trying this year to get more people to learn about the SQL Community, equally if you would be happy to visit the community corner we’d really appreciate it.