Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

26
© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential. CSI FOR SQL Learn to be an SQL Sleuth

Transcript of Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

Page 1: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

© 2015 IDERA, Inc. All rights reserved.Proprietary and confidential.

CSI FOR SQLLearn to be an SQL Sleuth

Page 2: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

2© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

AGENDA

Objectives Methodology Performance Monitor Extended Events Bonus Diagnostic Queries Questions

Page 3: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

3© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

OBJECTIVES

Meet Service Level Agreements Get the most out of existing hardware Prevent unnecessary hardware purchases /

upgrades Spend $$ where it will make a difference Create a Baseline Be a Hero (or stay out of the Dog House)

Page 4: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

4© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

AGENDA

Objectives Methodology Performance Monitor Extended Events Bonus Diagnostic Queries Questions

Page 5: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

5© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

QueriesDatabase

Other Software

Operating System

Hardware

METHODOLOGY

Bottom Up Top Down Entire Ecosystem

Triage Approachto determinewhere to focusfirst• Emergency Room Medical Approach• Questions & Answers determine

entry point of your investigation

TopDown

BottomUp

Page 6: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

6© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

METHODOLOGY – IMMEDIATE ISSUE

Medical Approach• Chief Complaint• History of Present

Illness• Past Medical History• Past Family Social• Physical Exam

Page 7: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

7© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

METHODOLOGY – IMMEDIATE ISSUE

Chief Complaint• Clarification

• “The System is Down!!!!”− Nobody can work?− Some people can’t work?− One person can’t work?− Some “thing” isn’t working?

• Verification• Make sure what is being reported is actual

factual information.• Does the claim agree with what you see

happening on the server?• Emotional versus Rational

Page 8: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

8© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

METHODOLOGY – IMMEDIATE ISSUE

History of Present Illness• Who, Context, Timing, Location, Duration?• AKA: Who, What, When, Where, How Long?

We’re after the WHY. Example

• A complaint comes in that saving a reference number for an order (what) takes more than 1 minute (how long).

• This began about 3 hours ago (when).• It appears it is only happening in the order entry

application (where).• Both users on local workstations and remote

users are reporting problems in this area (who).

Page 9: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

9© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

METHODOLOGY – IMMEDIATE ISSUE

Past Medical History• Is the problem new?• When did the problem start?• Has the server had issues before or

recently?• Any interesting history about the server

you’d like to share?• “We had a drive failure about 3 weeks ago”• “We had a consulting company remotely

taking care of this server until recently”• “We applied SP2 for SQL 2012 last week”

Page 10: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

10© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

METHODOLOGY – IMMEDIATE ISSUE

Past Family Social• What other applications are on this

server?• Antivirus, Windows Indexing?, Windows

Update? Reporting Services? (on and on)• How many instances of SQL are on the

server?• How many databases? What are they?

Page 11: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

11© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

METHODOLOGY – IMMEDIATE ISSUE Physical Exam

• If Problem is Actively Happening • Any Blocking?

− Head of Chain?− What are they running?

• What’s Running Now and what do the Waits say?

• Extended Event Capture− Long Running Queries− Wide Open with Focused Filtering and Short

Duration• If Problem is Intermittent or Not

Obvious• Perfmon Capture - PAL• Diagnostic DMVs• Extended Event Capture Job• Long Running Queries• Set Traps

TOP

DOWN

BOTTOM

UP

Page 12: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

12© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

AGENDA

Objectives Methodology Performance Monitor Extended Events Bonus Diagnostic Queries Questions

BOTTOM

UP

Page 13: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

13© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

PERFORMANCE MONITOR A few quick counters to spot check

• All counters accessible through start/run/perfmonCounters to Quickly Spot Check When Eyebrows should

raiseMeaning

SQLServer:Buffer Manager:Page Life Expectancy

< 300 Memory Pressure

SQLServer:Memory Manager: Target Server Memory

Way less than you think SQL should be getting

Incorrect Memory Config

Memory: AvailableMB > 30 OS may be starving

Physical Disk: Avg Disk/Sec Read & Avg Disk Sec/Write

> .100 Disk is insufficient and/or Memory insufficient.

Physical Disk: % Idle Time Low is bad. 0 means disk is saturated

Disk is insufficient and/or Memory insufficient.

Processor: % Processor Time > 80% consistently / usage is not balanced

Processors insufficient and/or Memory or Disk insufficient.

Processor: % Interrupt Time Usually on Proc 0 only. Should be < 5% consistently.

Hardware Driver issue (out of date, incorrect version, corruption)

Page 14: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

14© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

PERFORMANCE MONITOR Longer Term Counters to Collect and Review

• Can use sys.dm_os_performance_counters DMV to query/collect these directly from SQL Server

SQL Server Specific Counterssql server: sql statistics: batch requests/sec sql server: locks: avg wait time(ms)sql server: sql statistics: sql compilations/sec

sql server: general statistics: processes blocked

sql server: sql statistics: sql re-compilations/sec

sql server: buffer manager: page life expectancy

sql server: sql statistics: user connections sql server: buffer manager: free pagessql server: access methods: full scans/sec

sql server: buffer manager: lazy writes/sec

sql server: access methods: index searches/sec

sql server: memory manager: total server memory (kb)

sql server: access methods: page splits/sec

sql server: memory manager: target server memory (kb)

sql server: locks: number of deadlocks/sec

sql server: memory manager: memory grants pending

sql server: locks: table lock escalations/sec

Page 15: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

15© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

PERFORMANCE MONITOR Longer Term Counters to Collect and Review

SQL Server Specific Counters

process(sqlserver): % processor time physical disk: avg disk sec/readprocessor: % processor time physical disk: avg disk sec/writeProcessor: % interrupt time physical disk: disk reads/secmemory: available mbytes physical disk: disk writes/secmemory: page splits/sec physical disk: disk read bytes/sec

physical disk: disk write bytes/sec

Page 16: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

16© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

PERFORMANCE MONITOR Use Counters Together not in Isolation

Bytes per Second

Disk Response Time

Server AIOs Per Second

Page 17: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

17© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

PERFORMANCE MONITOR

PAL Tool for SQL• Create an XML Template of important

SQL Counters• Generates an HTML Report

• Graphs• Explanations• Links

Page 18: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

18© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

AGENDA

Objectives Methodology Performance Monitor Extended Events Bonus Diagnostic Queries Questions

TOP

DOWN

Page 19: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

19© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

EXTENDED EVENTS

Completed Events Capture• SQL_Batch_Completed• RPC_Completed

• SP_Statement_Completed

Page 20: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

20© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

EXTENDED EVENT FIELDSSP_Statement_Completed SQL_Batch_Completed RPC_Completed

statement batch_text statementsource_database_id database_id database_idtransaction_id transaction_id transaction_idline_number    nt_username nt_username nt_usernameclient_hostname client_hostname client_hostnameclient_app_name client_app_name client_app_nameserver_principal_name server_principal_name server_principal_namesession_id session_id session_idduration duration durationtimestamp timestamp timestamplogical_reads logical_reads logical_readsphysical_reads physical_reads physical_readswrites writes writescpu_time cpu_time cpu_timeobject_id    server_instance_name server_instance_name server_instance_namename name nameobject_name   object_namedatabase_name database_name database_namerow_count row_count row_count

Page 21: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

21© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

EXTENDED EVENTS APPROACHES

Long Running Query• Duration Filter > X Seconds

Thousand Paper Cuts• Wide Open Trace

• Very Short Duration• Strong Filter

− Spid− Hostname− ApplicationName

Gaps Between SQL Calls• Wide Open Trace

• Very Short Duration• Strong Filter

− Spid− Hostname− ApplicationName

• Look for silence between Completion of Stmt 1 and Start of Stmt 2

Page 22: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

22© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

AGENDA

Objectives Methodology Performance Monitor Extended Events Bonus Diagnostic Queries Questions

TOP

DOWN

Page 23: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

23© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

BONUS DIAGNOSTIC QUERIES

Blocking• Find head of the blocking chain (spid)

• Sp_who2 − Eyeball it− Copy/Paste to excel, sort and filter− Write/Borrow something custom that does recursive SQL

• Google Sp_whoisactive by Adam Machanic• Select * from master.dbo.sysprocesses

• Look to see what blocking spid is doing• Dbcc inputbuffer(spid)

• Phonecall / Kill• Post Mortem

Page 24: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

24© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

BONUS DIAGNOSTIC QUERIES

Useful Queries

Desired_Indexes_last10mins.sql

Get_Proc_CPU_Qty_Last10secs.sql

Longest_Running_Queries_Right_Now.sql

Dmv_most_expensive_queries.sql

Dmv_top_100_sps_by_exec_qty.sql

Dmv_top_20_sps_by_cpu_pressure.sql

Dmv_top_20_sps_by_memory_pressure.sql

Dmv_top_20_sps_by_physical_io_pressure.sql

Dmv_top_20_sps_by_logical_writes.sql

Page 25: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

25© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

AGENDA

Objectives Methodology Performance Monitor Extended Events Bonus Diagnostic Queries Questions

Page 26: Geek Sync I CSI for SQL: Learn to be a SQL Sleuth

26© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.

THANKS!Any questions?You can find me at:@[email protected]