Troubleshooting SQL Server Basics
Luan Moreno M. Maciel Sr. Database Consultant at Pythian [BI Team] MCT | MCSE Data Platform & BI Microsoft MVP - SQL Server
Luan Moreno M. Maciel
Agenda Patterns Waits Concepts Analysis Step by Step
Analysis Step by Step Types? Where? Interpretation? Methodology?
Where? DMV’s (Dynamic Management Views) Performance Counters Execution Plan Analysis Custom-TSQL MDW Where? Tools
Types? Historical Live
Methodology? Symptom Root Cause Solution
Interpretation? Colect Correct Data Daily Snapshots of the Data Verify and Validate Data Understanding of the Data Collected Find Patterns Internet Tips Daily Snapshots of the Data Interpretation?
Process and Thread Process Contains Thread Thread – Unit of Execution
Worker Threads SQL Server use O.S Threads Threads = SO Thread of Pools - Requests
Parallelism Guarantee Parallelism? Multi-Processor Available Resource? Utilization of Multiple Threads Split to Win! Query Optimizer – Serial Plan or Parallel Plan Parallel Plan <> Execution in Parallel Guarantee Parallelism? Multi-Processor Available Resource? MaxDop Cost Threshold of Parallelism
Cost Threshold for Parallelism Parallelism Options MaxDop Cost Threshold for Parallelism MaxDop = 4 Thread 1 Thread 2 Thread 0 Thread 3 Thread 4
Thread Scheduling SQL Server Controls Threads Non-Preemptive Scheduling Processor = Scheduler
Components of the Scheduler Processor Waiter List Runnable Queue One Thread per Time Wait Statistics Resource Wait Waiting
SQL Server Schedulers 4 Physical Cores + Hyper-Threading Processor Waiter List Runnable Queue Processor Waiter List Runnable Queue Processor Waiter List Runnable Queue Processor Waiter List Runnable Queue Processor Waiter List Runnable Queue Processor Waiter List Runnable Queue Processor Waiter List Runnable Queue Processor Waiter List Runnable Queue
Demo 1 Schedulers
Thread States Processor Waiter List Runnable Queue SPID 88 - Running
SPID 88 – CX_PACKET (Suspended) Thread States Processor Waiter List Runnable Queue SPID 88 – CX_PACKET (Suspended)
Thread States Processor Waiter List Runnable Queue SPID 88 (Runnable),
Example Processor SPID 88 - Running Runnable Queue Waiter List SPID 97 – IO_COMPLETION SPID 13 – Runnable SPID 56 – PAGEIOLATCH_SH SPID 27 – Runnable SPID 43 – CX_PACKET
Example Processor SPID 88 - Running Runnable Queue Waiter List SPID 97 – IO_COMPLETION SPID 13 – Runnable SPID 56 – PAGEIOLATCH_SH SPID 27 – Runnable SPID 43 – Runnable
Example Processor Runnable Queue Waiter List SPID 88 - LATCH_EX SPID 13 – Runnable SPID 97 – IO_COMPLETION SPID 27 – Runnable SPID 56 – PAGEIOLATCH_SH SPID 43 – Runnable
Example Processor Runnable Queue Waiter List SPID 88 - LATCH_EX SPID 13 – Running SPID 88 - LATCH_EX SPID 27 – Runnable SPID 97 – IO_COMPLETION SPID 43 – Runnable SPID 56 – PAGEIOLATCH_SH
Demo 2 Thread States
Waits Waiting Unavailable Resource Tracked by SQL Server
Waits & Queues Methodology Waits and Queues Tom Davidson [2005] - SQLCAT Tracked on SQL Server Right Direction to Find Issue ! 2005 – Performance Dashboards 2008/2012 – MDW & EX
sys.dm_os_wait_stats sys.dm_os_waiting_tasks sys.dm_exec_requests Demo 3 sys.dm_os_wait_stats sys.dm_os_waiting_tasks sys.dm_exec_requests
Troubleshooting Patterns (Most Common) Paul S. Randal – Worldwide Survey bit.ly/fSWeO5 1.800 SQL Server Instances Top 3 – Detailed Anaylisis CX_PACKET ASSYNC_NETWORK_IO WRITELOG
CX_Packet Wait Type Parallel Plans Executing Adjust MaxDop = 1[Knee-Jerk] Verify Plans with Large Scan Operation Check Requests with CX_PACKET Wait Statistics Set MaxDop and Cost Threshold
PAGEIOLATCH_Wait Type Waiting Data Page to go to Buffer Pool SH – Read or EX - Changed I/O Issue = 1[Knee-Jerk] Check Disk Latency Examine Plans with CONVERT_IMPLICT NonClustered Index Creation Statistics Memory
ASSYNC_NETWORK_IO_Wait Type SQL Server Waits Ack Network Issue = 1[Knee-Jerk] Analyze Application Code Analyze Network RBAR Problem – Row By Agonizing Row – Row By Row Huge Table Scans
Hands On...... [DBA Curaçao Team] Production Server Hands On...... [DBA Curaçao Team]
Thank You....