More Related Content Similar to Geek Sync I CSI for SQL: Learn to be a SQL Sleuth (20) More from IDERA Software (20) Geek Sync I CSI for SQL: Learn to be a SQL Sleuth1. © 2015 IDERA, Inc. All rights reserved.
Proprietary and confidential.
CSI FOR SQL
Learn to be an SQL Sleuth
2. 2© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.
AGENDA
Objectives
Methodology
Performance Monitor
Extended Events
Bonus Diagnostic Queries
Questions
3. 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)
4. 4© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.
AGENDA
Objectives
Methodology
Performance Monitor
Extended Events
Bonus Diagnostic Queries
Questions
5. 5© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.
Queries
Database
Other Software
Operating System
Hardware
METHODOLOGY
Bottom Up
Top Down
Entire Ecosystem
Triage Approach
to determine
where to focus
first
• Emergency Room Medical Approach
• Questions & Answers determine
entry point of your investigation
Top
Down
Bottom
Up
6. 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
7. 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
8. 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).
9. 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”
10. 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?
11. 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
12. 12© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.
AGENDA
Objectives
Methodology
Performance Monitor
Extended Events
Bonus Diagnostic Queries
Questions
13. 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
raise
Meaning
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)
14. 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 Counters
sql 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 pages
sql 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
15. 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/read
processor: % processor time physical disk: avg disk sec/write
Processor: % interrupt time physical disk: disk reads/sec
memory: available mbytes physical disk: disk writes/sec
memory: page splits/sec physical disk: disk read bytes/sec
physical disk: disk write bytes/sec
16. 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 A
IOs Per Second
17. 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
18. 18© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.
AGENDA
Objectives
Methodology
Performance Monitor
Extended Events
Bonus Diagnostic Queries
Questions
19. 19© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.
EXTENDED EVENTS
Completed Events Capture
• SQL_Batch_Completed
• RPC_Completed
• SP_Statement_Completed
20. 20© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.
EXTENDED EVENT FIELDS
SP_Statement_Completed SQL_Batch_Completed RPC_Completed
statement batch_text statement
source_database_id database_id database_id
transaction_id transaction_id transaction_id
line_number
nt_username nt_username nt_username
client_hostname client_hostname client_hostname
client_app_name client_app_name client_app_name
server_principal_name server_principal_name server_principal_name
session_id session_id session_id
duration duration duration
timestamp timestamp timestamp
logical_reads logical_reads logical_reads
physical_reads physical_reads physical_reads
writes writes writes
cpu_time cpu_time cpu_time
object_id
server_instance_name server_instance_name server_instance_name
name name name
object_name object_name
database_name database_name database_name
row_count row_count row_count
21. 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
22. 22© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.
AGENDA
Objectives
Methodology
Performance Monitor
Extended Events
Bonus Diagnostic Queries
Questions
23. 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
24. 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
25. 25© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.
AGENDA
Objectives
Methodology
Performance Monitor
Extended Events
Bonus Diagnostic Queries
Questions
26. 26© 2015 IDERA, Inc. All rights reserved. Proprietary and confidential.
THANKS!
Any questions?
You can find me at:
@sqlgirl
mindycurnutt@hotmail.com