44
This document is provided for informational purposes only and Microsoft makes no warranties, either express or implied, in this document. Information in this document, including URL and other Internet Web site references, is subject to change without notice. The entire risk of the use or the results from the use of this document remains with the user. Unless otherwise noted, the companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted in examples herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. © 2013 Microsoft Corporation. All rights reserved. Microsoft and other Microsoft products referenced herein are trademarks of the Microsoft group of companies. All other trademarks are property of their respective owners. Disclaimer

Troubleshooting SQL Server Performance SQL Saturday

Embed Size (px)

Citation preview

Page 1: Troubleshooting SQL Server Performance SQL Saturday

This document is provided for informational purposes only and Microsoft makes no warranties, either express or implied, in this document. Information in this document, including URL and other Internet Web site references, is subject to change without notice. The entire risk of the use or the results from the use of this document remains with the user. Unless otherwise noted, the companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted in examples herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.

© 2013 Microsoft Corporation. All rights reserved.

Microsoft and other Microsoft products referenced herein are trademarks of the Microsoft group of companies.

All other trademarks are property of their respective owners.

Disclaimer

Page 2: Troubleshooting SQL Server Performance SQL Saturday
Page 4: Troubleshooting SQL Server Performance SQL Saturday

What does it collect?

Server

Configuration

PerfStats

Script

Event Logs Performance Monitor

Profiler Trace Error Logs

Page 5: Troubleshooting SQL Server Performance SQL Saturday
Page 6: Troubleshooting SQL Server Performance SQL Saturday
Page 7: Troubleshooting SQL Server Performance SQL Saturday

http://www.microsoft.com/en-us/download/details.aspx?id=4511

http://sqlnexus.codeplex.com/

http://diagmanager.codeplex.com/

Page 8: Troubleshooting SQL Server Performance SQL Saturday
Page 9: Troubleshooting SQL Server Performance SQL Saturday
Page 10: Troubleshooting SQL Server Performance SQL Saturday
Page 11: Troubleshooting SQL Server Performance SQL Saturday
Page 12: Troubleshooting SQL Server Performance SQL Saturday
Page 13: Troubleshooting SQL Server Performance SQL Saturday
Page 14: Troubleshooting SQL Server Performance SQL Saturday
Page 15: Troubleshooting SQL Server Performance SQL Saturday
Page 16: Troubleshooting SQL Server Performance SQL Saturday
Page 17: Troubleshooting SQL Server Performance SQL Saturday

It’s all about

the bottleneck

Page 18: Troubleshooting SQL Server Performance SQL Saturday
Page 19: Troubleshooting SQL Server Performance SQL Saturday

• Look for high number of logical reads

• Could be heavy compiles

• Could be stale statistics

Find the most expensive

query

Page 20: Troubleshooting SQL Server Performance SQL Saturday
Page 21: Troubleshooting SQL Server Performance SQL Saturday
Page 22: Troubleshooting SQL Server Performance SQL Saturday

Start Time: 8/28/2015 3:39:27 AM

End Time: 8/28/2015 3:41:35 AM

Top N: 5

Trace Event ID

58

33

55

79

69

166SQL:StmtRecompile 134

Sort Warnings 121

Missing Column Statistics 39

Hash Warning 8

Exception 33

Event Name Number of Events

Auto Stats 12

Interesting Events Parameters Value

sqlnexus

What can I do?

Enable Optimize

for Adhoc

Workloads

Parameterization:

Forced

Page 23: Troubleshooting SQL Server Performance SQL Saturday
Page 24: Troubleshooting SQL Server Performance SQL Saturday
Page 25: Troubleshooting SQL Server Performance SQL Saturday

• Look for scans, hashes, sorts or expensive operators

in plan

• Look for high number of logical reads

• Could be heavy compiles

Find the most

expensive

query

• Incorrect cardinality estimation a top issue

• Missing indexes or out of date stats

• May be a query design issue

• Parallel queries may take over the machine

Common

issues

• Tune indexes, stats, and/or query

• Limiting MAXDOP for parallel queries is temporary

• Apply a hotfix build

• Parameterize the query to reduce compiles

Common

Solutions

What if I don’t have high

CPU?

Page 26: Troubleshooting SQL Server Performance SQL Saturday
Page 27: Troubleshooting SQL Server Performance SQL Saturday
Page 28: Troubleshooting SQL Server Performance SQL Saturday

Server test

Version (SP) 10.50.4033.0 (SP2)

Database Io Stall Write

MS

9728

1668117

21634

1981

31151

3527

16197332

4998212

15620

2677

8914

1322

16105301

4129583

1354

929

26806

12355

40130

13914

4922013

8981765

281077

731547

117129995

70134865

57652

3885142

22398

17956

481720

381234

5787266017

5786113560

5785960247

5787337436

5785950704

5789762688

5786332154

5787772010

5786279150

5787097163

5789463367

5788817205

188508903%drive%\folder\name 69 503259 189012162

%drive%\folder\name 3540 5333884 5794797251

%drive%\folder\name 3540 5367121 5794184326

%drive%\folder\name 3541 5160621 5791439771

%drive%\folder\name 3540 5533804 5792630967

%drive%\folder\name 3541 5148116 5791480270

%drive%\folder\name 3541 5121586 5792893596

%drive%\folder\name 3542 5393845 5791344549

%drive%\folder\name 3542 5422169 5795184857

3543 5266074 5791226321

%drive%\folder\name 3543 5153100 5792490536

tempdb %drive%\folder\name 3544 5235544 5792501561

%drive%\folder\name 3544 5464094 5791577654

%drive%\folder\name

msdb %drive%\folder\name 84 541860 1023580

%drive%\folder\name 45 725 381959

model %drive%\folder\name 46 23110 45508

%drive%\folder\name 38 2764 20720

master %drive%\folder\name 93 127712 185364

%drive%\folder\name 65 3121 3888263

db9 %drive%\folder\name 155 2327209010 2444339005

%drive%\folder\name 8 2291590 72426455

db8 %drive%\folder\name 70 7502681 7783758

%drive%\folder\name 7 58688 790235

db7 %drive%\folder\name 74 347820645 352742658

%drive%\folder\name 1 266082 9247847

db6 %drive%\folder\name 44 254850721 254890851

%drive%\folder\name 0 10243 24157

db5 %drive%\folder\name 47 273913948 273940754

%drive%\folder\name 0 1707 14062

db17 %drive%\folder\name 17 974720 976074

%drive%\folder\name 3 318 1247

db16 %drive%\folder\name 50 81051902 97157203

%drive%\folder\name 11 189206 4318789

db15 %drive%\folder\name 40 81011 89925

%drive%\folder\name 3 391 1713

db14 %drive%\folder\name 38 14309 29929

%drive%\folder\name 6 458 3135

4233

db13 %drive%\folder\name 66 29135356 45332688

%drive%\folder\name 4 1494983 6493195

164 2145

db12 %drive%\folder\name 117 747305 778456

%drive%\folder\name 2 706

0 25899 1694016

db11 %drive%\folder\name 206 29862211 29883845

%drive%\folder\name 1

file Avg IOTime MS Io Stall Read MS Io Stall MS

db10 %drive%\folder\name 10 13355 23083

%drive%\folder\name

SQL Server Virtual Fle StatsStart Time 7/9/2015 6:00:35 AM

End Time 7/9/2015 7:18:08 AM

This report displays Virtual File Stats snapshots. By default, it displays last snapshot. But you can display other snapshots by changing Snapshot Time parameter.

Page 29: Troubleshooting SQL Server Performance SQL Saturday

• Is it waiting on another resource?

• Is it idle?

• Is it running?

Find the lead blocker

• Transaction not committed or long running transaction

• Waiting on another resource

• Poor query plan

• Basic concurrency is “working”

Common issues

• Tune index, stats, and/or query

• Application design (Ex. Fix commit tran problem)

• Consider READ_COMMITTED_SNAPSHOT db option

Typical Solutions

What if I don’t have

blocking?

Deadlocks start as

blocking . Almost

always app

problem.

A large blocking

chain can lead

to a “hang” as

seen in

ERRORLOG

Page 30: Troubleshooting SQL Server Performance SQL Saturday

Turtle

Page 31: Troubleshooting SQL Server Performance SQL Saturday

High Sec/T + High Bytes/Sec =

SQL Flood High Sec/T + Low Bytes/Sec =

Disk Subsystem

Page 32: Troubleshooting SQL Server Performance SQL Saturday

This is starting to sound familiar…

Page 33: Troubleshooting SQL Server Performance SQL Saturday

Not enough

cache for data

Physical read counters

Buffer Cache Hit Ratio is

misleading

Check ‘max server

memory’

Not enough

cache for

queries

Check compilations/sec

Too many ad-hoc queries

Engine has forced limits

Forced Parameterization

and optimize for ad hoc

workloads

Memory

throttles lead

to blocking

Compile memory

Query memory (sorts and

hash joins)

Page 34: Troubleshooting SQL Server Performance SQL Saturday
Page 35: Troubleshooting SQL Server Performance SQL Saturday
Page 36: Troubleshooting SQL Server Performance SQL Saturday

• DMVs, sp_updatestats, UPDATE STATS, and

“auto stats”Update Stats

• DMVs, SHOWPLAN, and DTACreate missing

indexes

• Change T-SQL, Query Hints, Plan GuidesChange query

Tune index,

stats, query

Change application

Often required for

blocking/deadlocks

Tune hardware

CPU, Memory, I/O

Don’t just jump

to any of

these!

Page 37: Troubleshooting SQL Server Performance SQL Saturday
Page 38: Troubleshooting SQL Server Performance SQL Saturday

• Prompts for password

• Must be able to login into target instances

• Must be a member of the sysadmin role

• Must be a member of Administrators

Page 39: Troubleshooting SQL Server Performance SQL Saturday
Page 40: Troubleshooting SQL Server Performance SQL Saturday

Test

5GBNo

kitchen sink

Page 41: Troubleshooting SQL Server Performance SQL Saturday

PSSdiag /B 14:00:00

PSSdiag /E +02:00:00

PSSdiag /B 08:00:00 /E +09:00:00

PSSdiag /E 02:00:00 /L /Q

All command line parameters:

http://msdn.microsoft.com/en-us/library/ms162833.aspx

Page 42: Troubleshooting SQL Server Performance SQL Saturday
Page 43: Troubleshooting SQL Server Performance SQL Saturday
Page 44: Troubleshooting SQL Server Performance SQL Saturday