Danette Dineen Riviello Magellan Health March 17, 2015 1.

Slides:



Advertisements
Similar presentations
DAT 342 Advanced SQL Server Performance and Tuning Bren Newman Program Manager SQL Server Development Microsoft Corporation.
Advertisements

SQL Server performance tuning basics
SQL Performance 2011/12 Joe Chang, SolidQ
TDPS Wireless v Enhancements E1 - Multi load E2 - Driver time scheduler.
© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 10 Slide 1 IT390 Business Database Administration Unit 10:
Virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft.
Microsoft SQL Server Administration for SAP Performance Monitoring and Tuning.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Anil Desai Austin CodeCamp  Anil Desai ◦ Independent consultant (Austin, TX) ◦ Author of several SQL Server books ◦ Instructor, “Implementing and.
Chapter 9 Overview  Reasons to monitor SQL Server  Performance Monitoring and Tuning  Tools for Monitoring SQL Server  Common Monitoring and Tuning.
Module 18 Monitoring SQL Server 2008 R2. Module Overview Monitoring Activity Capturing and Managing Performance Data Analyzing Collected Performance Data.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
Key Concepts About Performance Factors Affecting SQL Performance SQL Performance Tuning Methodologies SQL Performance Tuning Tools 1.
Store Procedures Lesson 9. Skills Matrix Stored Procedures Stored procedures in SQL Server are similar to the procedures you write in other programming.
Dexterity | CONFIDENTIAL 2009 MRO | Analytics | Insights 1 Stored Procedures.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
How to solve a SQL performance problem Paul Zgondea.
DMV Performance Monitoring & Tuning Presented by Franklin Yamamoto.
1 Definition of a subquery Nested subqueries Correlated subqueries The ISNULL function Derived tables The EXISTS operator Mixing data types: CAST & CONVERT.
Administration and Monitoring the Database Oracle 10g.
Agenda for Today Do Chapter 14 Final Project Review for Final.
Applications hitting a wall today with SQL Server Locking/Latching Scale-up Throughput or latency SLA Applications which do not use SQL Server.
Learningcomputer.com SQL Server 2008 – Profiling and Monitoring Tools.
It Depends Database administration for developers.
Module 8: Implementing Stored Procedures. Overview Implementing Stored Procedures Creating Parameterized Stored Procedures Working With Execution Plans.
Creating a dynamic search form with database paging Tony Rogerson SQL Server MVP Torver Computer Consultants.
Troubleshooting 11i issues Adam Janbolat
Gail Shaw XpertEase DAT 305 Topics Background Information Query Hints Plan Cache Metadata Plan Guides Plan Freezing Monitoring Plan Guide Use.
Advanced Database & Client Server Introduction to MS SQL Server 2000 and Transact SQL -
Advanced Performance Tuning Tips with Database Performance Analyzer Jon Shaulis Senior DBA © 2014 SOLARWINDS WORLDWIDE, LLC. ALL RIGHTS RESERVED.
Execution Plans Detail From Zero to Hero İsmail Adar.
Why Should I Care About … The Plan Cache? Tuning When Stakeholders Won’t Say Where It Hurts.
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
This document is provided for informational purposes only and Microsoft makes no warranties, either express or implied, in this document. Information.
מימוש מערכות מסדי נתונים (236510)
3 Methods to End the Madness
SQL Server Performance Tuning and Optimization Plamen Ratchev
Parameter Sniffing in SQL Server Stored Procedures
Tuning Transact-SQL Queries
Query Optimization Techniques
Building a Performance Monitoring System using XEvents and DMVs
Become a SQL Server Performance Detective
Building a Performance Monitoring System using XEvents and DMVs
Using Extended Events to Diagnose Application Issues
Become a SQL Server Performance Detective
Parameter Sniffing in SQL Server Stored Procedures
SQL Server Monitoring Overview
Building Modern Transaction Systems on SQL Server
Root Cause Analysis with DMVs
Parameter Sniffing, Sp_Recompile
Performance Monitoring Using Extended Events, DMVs & Query Store
Building a Performance Monitoring System using XEvents and DMVs
Twitter Sr. SQL Premier Field Engineer Twitter LinkedIn: sam mesel Query Store.
Query Optimization Techniques
Top Tips for Better TSQL Stored Procedures
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
Transactions, Locking and Query Optimisation
මොඩියුල විශ්ලේෂණය SQL Server Waits. Tables රැසක් එකට එකතු කිරීම.
Dynamic Management Views a practical overview!
Introduction to Execution Plans
Dynamic Management Views a practical overview!
Query Tuning Fundamentals
Analyzing Performance Problems Using XEvents, DMVs & Query Store
Jean Joseph DBA/Developer
Building a Performance Monitoring System using XEvents and DMVs
Introduction to Execution Plans
Query Optimization Techniques
Introduction to Execution Plans
Analyzing Performance Problems Using XEvents, DMVs & Query Store
Presentation transcript:

Danette Dineen Riviello Magellan Health March 17,

 What triggers an Investigation?  Emergent Performance Issues  Chronic Performance Problems  Solving the Case 2

 Increase in User Complaints  Application Timeouts  Long-running queries  Open Transactions  Chain of blocking 3

 Look at all running processes sp_who2 active  Look for one login or one database: 4 SELECT spid, [status], loginame [Login],hostname, blocked BlkBy, Db_name(dbid) DBName, cmd Command, cpu CPUTime, physical_io DiskIO, last_batch LastBatch, [program_name] ProgramName FROM master.dbo.sysprocesses where [status] not in ('sleeping') and loginame like '%login%' And Db_name(dbid) = 'DBName' ORDER BY dbname

Look for the lead of a blocking chain SELECT spid,sp.STATUS,loginame = SUBSTRING(loginame, 1, 12),hostname = SUBSTRING(hostname, 1, 12),blk = CONVERT(CHAR(3), blocked),open_tran,dbname = SUBSTRING(DB_NAME(sp.dbid),1,10),cmd,waittype,program_name,waittime,last_batch,SQLStatement = SUBSTRING ( qt.text, er.statement_start_offset/2, (CASE WHEN er.statement_end_offset = -1 THEN LEN(CONVERT(nvarchar(MAX), qt.text)) * 2 ELSE er.statement_end_offset END - er.statement_start_offset)/2 ) FROM master.dbo.sysprocesses sp LEFT JOIN sys.dm_exec_requests er ON er.session_id = sp.spid OUTER APPLY sys.dm_exec_sql_text(er.sql_handle) AS qt WHERE spid IN (SELECT blocked FROM master.dbo.sysprocesses) AND blocked = 0 5

 Look at object locks 6 SELECT resource_type, object_name(resource_associated_entity_id), request_status, request_mode,request_session_id, resource_description FROM sys.dm_tran_locks WHERE resource_type = 'OBJECT'

 Look for open transactions 7 SELECT spid, [status], loginame [Login],hostname, blocked BlkBy, Db_name(dbid) DBName, cmd Command, cpu CPUTime, physical_io DiskIO, last_batch LastBatch, [program_name] ProgramName FROM master.dbo.sysprocesses WHERE open_tran>0 ORDER BY spid

 Find the line of code that is running: SELECT [Spid] = session_Id, ecid, [Database] = DB_NAME(sp.dbid), [User] = nt_username, [Status] = er.status, [Wait] = wait_type, [Individual Query] = SUBSTRING (qt.text, er.statement_start_offset/2, (CASE WHEN er.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2 ELSE er.statement_end_offset END - er.statement_start_offset)/2),[Parent Query] = qt.text, Program = program_name, Hostname, nt_domain, start_time FROM sys.dm_exec_requests er INNER JOIN sys.sysprocesses sp ON er.session_id = sp.spid CROSS APPLY sys.dm_exec_sql_text(er.sql_handle) as qt WHERE session_Id -- is the one in Question ORDER BY 1, 2 8

 What has changed?  Look at default system trace: 9

 Look for recent changes  Look at the Log directory for prior files 10

 To find most expensive stored procedures: SELECT TOP 100 d.object_id, d.database_id, OBJECT_NAME(object_id, database_id) 'proc name', d.cached_time, d.last_execution_time, d.total_elapsed_time, d.total_elapsed_time/d.execution_count AS [avg_elapsed_time], d.last_elapsed_time, d.execution_count FROM sys.dm_exec_procedure_stats AS d ORDER BY [total_worker_time] DESC; 11

 Most expensive Stored procedure runs 12

 Less impact than an interactive trace  Can load trace data on an alternate server  Can load trace data at a different time of day  Capture specific parameters passed  Compare same time of day on different days 13

14

15

 Load the trace file to another server select * into dbo.tmp_loadtraceFile_ServerA_ _8 FROM ::fn_trace_gettable('d:\trace_ _8.trc', 1)  Query trace file to find commands that are calling the suspected stored procedure select top 25 textdata, loginname, spid, duration, starttime, endtime, reads, cpu From dbo.tmp_loadtraceFile_ServerA_ _8 Where textdata like '%offendingproc%' Order by duration desc 16

17

 Use “Display Estimated Execution Plan”  Use “Include Actual Execution plan”  Query to get query plans from DMV: 18 select top 25 st.text, qp.query_plan, qs.plan_handle from sys.dm_exec_query_stats qs cross apply sys.dm_exec_sql_text(qs.sql_handle) st cross apply sys.dm_exec_query_plan(qs.plan_handle) qp

 Look at the query plan  Missing index or wrong index chosen?  Look at the parameters sent in  Check for other runs that perform better  Could it be a parameter sniffing issue? 19

 Query plan developed based on the first values passed to the procedure  Pros:  Saves time: only one compile needed  Cons:  Wrong query plan chosen 20

 Look at Query plans  If one procedure performs well in one case and not others  Do the index choices make sense? 21

22

 Do Nothing  Force Recompile each run (expensive!)  Query Hints (OPTIMIZE FOR)  Break down stored procedures to handle specific cases  Education users on best parameter choices 23

 Check for table scans caused by:  Missing index  Broad “where” clause  Check for improper join (many-to-many)  Check for too many tables in one join  Use of a function in a large query result set 24

SELECT migs.avg_total_user_cost * (migs.avg_user_impact / 100.0) * (migs.user_seeks + migs.user_scans) AS improvement_measure, 'CREATE INDEX [missing_index_' + CONVERT (varchar, mig.index_group_handle) + '_' + CONVERT (varchar, mid.index_handle) + '_' + LEFT (PARSENAME(mid.statement, 1), 32) + ']' + ' ON ' + mid.statement + ' (' + ISNULL (mid.equality_columns,'') + CASE WHEN mid.equality_columns IS NOT NULL AND mid.inequality_columns IS NOT NULL THEN ',' ELSE '' END + ISNULL (mid.inequality_columns, '') + ')' + ISNULL (' INCLUDE (' + mid.included_columns + ')', '') AS create_index_statement, migs.*, mid.database_id, mid.[object_id] FROM sys.dm_db_missing_index_groups mig INNER JOIN sys.dm_db_missing_index_group_stats migs ON migs.group_handle = mig.index_group_handle INNER JOIN sys.dm_db_missing_index_details mid ON mig.index_handle = mid.index_handle WHERE migs.avg_total_user_cost * (migs.avg_user_impact / 100.0) * (migs.user_seeks + migs.user_scans) > 10 ORDER BY migs.avg_total_user_cost * migs.avg_user_impact * (migs.user_seeks + migs.user_scans) DESC 25

 Solution may change over time  Tables grow  Statistics out of date  Parameter Sniffing  Some problems result from multiple issues  Do least disruptive changes first:  Add an index  Close open connections 26

 Thank you for attending!  Further questions: 27