enterprise database administration & deployment sig ▪ 313m ▪ sept 29, 2005 ▪ 10:15 am sql...

37
Enterprise Database Administration & Deployment SIG 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 SQL Server 2005 Performance Diagnosis Performance Diagnosis and Tuning using SQL and Tuning using SQL Tools and DMVs Tools and DMVs Shawn Nesser Shawn Nesser (Borrowed from Vipul Shah) (Borrowed from Vipul Shah)

Upload: thomas-wright

Post on 17-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

SQL Server 2005 SQL Server 2005 Performance Diagnosis Performance Diagnosis and Tuning using SQL and Tuning using SQL Tools and DMVs Tools and DMVs

Shawn NesserShawn Nesser

(Borrowed from Vipul Shah)(Borrowed from Vipul Shah)

Page 2: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Session Objectives And Session Objectives And Key TakeawaysKey Takeaways

Session Objectives: Session Objectives: How Tools and DMVs can be used to How Tools and DMVs can be used to monitor and tune SQL Server 2005monitor and tune SQL Server 2005

Walk away with demo scripts you can useWalk away with demo scripts you can use

Key Takeaways:Key Takeaways:Maximize benefit from Tools and DMVs for Maximize benefit from Tools and DMVs for monitoring and tuning SQL Server 2005monitoring and tuning SQL Server 2005

Page 3: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

AgendaAgenda

New Capabilities in SQL Server 2005New Capabilities in SQL Server 2005

Management Studio ReportsManagement Studio Reports

Identify Top SQL (delta)Identify Top SQL (delta)

I/O TuningI/O Tuning

Contention TuningContention Tuning

SQL Server ProfilerSQL Server Profiler

Demo Code is at end of slides (see Demo Code is at end of slides (see Notes)Notes)

Page 4: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

New Capabilities in SQL New Capabilities in SQL 2005?2005?

Dynamic Management Views (DMVs)Dynamic Management Views (DMVs)Views on memory structures in the Views on memory structures in the EngineEngine

Monitor activity inside the EngineMonitor activity inside the Engine

Trace EventsTrace EventsNew trace events that complete the New trace events that complete the picture provided by DMVspicture provided by DMVs

Light-weight, ON-by-default trace to Light-weight, ON-by-default trace to capture schema and configuration capture schema and configuration changeschanges

Dedicated Administration ConnectionDedicated Administration Connection

Page 5: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

New Capabilities in SQL New Capabilities in SQL 2005? (continued)2005? (continued)

Database Engine Tuning AdvisorDatabase Engine Tuning AdvisorGives Partitions recommendations Gives Partitions recommendations

Indexes and Indexed Views Indexes and Indexed Views recommendationsrecommendations

Statistics recommendationsStatistics recommendations

Tunes multiple databasesTunes multiple databases

Time-bound and Storage-bound tuningTime-bound and Storage-bound tuning

XML ShowPlan XML ShowPlan MissingIndexes tagMissingIndexes tag

Indexes that query optimizer would use if Indexes that query optimizer would use if availableavailable

Page 6: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

New Capabilities in SQL New Capabilities in SQL 2005? (continued)2005? (continued)

Management Studio contains Management Studio contains performance reportsperformance reports

Reports are available at server levelReports are available at server level

Reports are available at database levelReports are available at database level

SQL Server Profiler allows for SQL Server Profiler allows for correlation with Performance correlation with Performance CountersCounters

Enhances ability to isolate problemsEnhances ability to isolate problems

Page 7: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Database Database Management ViewsManagement ViewsViews built on top of internal structuresViews built on top of internal structures

Ideal for tracking performanceIdeal for tracking performanceServer LevelServer Level Component LevelComponent Level

dm_exec_* dm_exec_* Execution of user code and Execution of user code and

associated connections associated connections

dm_os_* dm_os_* Memory, locking & scheduling Memory, locking & scheduling

dm_tran_* dm_tran_* Transactions & isolation Transactions & isolation

dm_io_* dm_io_* I/O on network and disks I/O on network and disks

dm_db_* dm_db_* Databases and database objectsDatabases and database objects

dm_repl_* dm_repl_* Replication Replication

dm_broker_* dm_broker_* SQL Service Broker SQL Service Broker

dm_fts_* dm_fts_* Full Text Search Full Text Search

dm_qn_* dm_qn_* Query Notifications Query Notifications

dm_clr_* dm_clr_* Common Language RuntimeCommon Language Runtime

Page 8: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Default TraceDefault TraceLight-weight tracing is ON by defaultLight-weight tracing is ON by default

Captures schema changes and Captures schema changes and configuration changesconfiguration changes

Trace is captured in rolling window of Trace is captured in rolling window of 5 trace files 20MB each (maximum of 5 trace files 20MB each (maximum of 100MB)100MB)

Old trace files are deletedOld trace files are deleted

100MB limit is never exceeded100MB limit is never exceeded

New trace file is created after every re-New trace file is created after every re-startstart

No more than 5 trace files are availableNo more than 5 trace files are available

Page 9: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Management Studio Management Studio ReportsReports

Reports get data from DMVs and Reports get data from DMVs and Default Trace filesDefault Trace files

Use these Reports for an overviewUse these Reports for an overview

Server-level ReportsServer-level ReportsSelect SQL Server instance node in Select SQL Server instance node in Object Explorer, select ViewObject Explorer, select ViewSummary Summary menu, and Report drop-listmenu, and Report drop-list

Database-level ReportsDatabase-level ReportsSelect a database node in Object Select a database node in Object Explorer, select ViewExplorer, select ViewSummary menu, Summary menu, and Report drop-listand Report drop-list

Page 10: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Page 11: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Management Studio Management Studio ReportsReportsManagement Studio Management Studio ReportsReports

Vipul ShahVipul ShahProgram ManagerProgram ManagerSQL ServerSQL Server

Page 12: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Tracking Server Tracking Server ActivityActivityTrack activity by Wait typesTrack activity by Wait types

Waits indicate where server spends its Waits indicate where server spends its activityactivity

Focus on wait event with highest wait Focus on wait event with highest wait timetime

Track SQL statementsTrack SQL statements

How do you track Top SQL and Waits?How do you track Top SQL and Waits?““Performance – Top Queries” report in Performance – Top Queries” report in Management Studio shows you top Management Studio shows you top queries since instance start timequeries since instance start time

Use DMVs to track activity in an intervalUse DMVs to track activity in an intervalQueryStatsDelta script is an exampleQueryStatsDelta script is an example

Page 13: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Tracking Server ActivityTracking Server Activity(continued)(continued)

““QueryStatsDelta” scriptQueryStatsDelta” scriptUses dm_exec_query_statsUses dm_exec_query_stats

Takes before and after snapshots and diffs themTakes before and after snapshots and diffs them

Accounts for new statements in the intervalAccounts for new statements in the interval

Orders top SQL by elapsed timeOrders top SQL by elapsed time

Shows exact SQL statement by extracting it from Shows exact SQL statement by extracting it from batch textbatch text

Uses dm_os_wait_statsUses dm_os_wait_statsTakes before and after snapshots and diffs themTakes before and after snapshots and diffs them

Removes Idle waits and Trace waitsRemoves Idle waits and Trace waits

Orders top wait events by wait durationOrders top wait events by wait duration

Page 14: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Page 15: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Identify Top SQLIdentify Top SQLIdentify Top SQLIdentify Top SQL

Vipul ShahVipul ShahProgram ManagerProgram ManagerSQL ServerSQL Server

Page 16: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Tuning I/O Intensive Tuning I/O Intensive SQLSQL

Use “MissingIndexes” tag in XML Show Use “MissingIndexes” tag in XML Show Plan for single statement-focused Plan for single statement-focused analysisanalysis

Very useful when workload is not available or Very useful when workload is not available or workload is incompleteworkload is incomplete

Missing indexes is NOT a recommendationMissing indexes is NOT a recommendation

Optimizer would have used these indexes if Optimizer would have used these indexes if availableavailable

Remember – creating these indexes may Remember – creating these indexes may slow Inserts, Updates and Deletesslow Inserts, Updates and Deletes

Track index usage if you choose to create a missing Track index usage if you choose to create a missing indexindex

Weight the costs-benefits of the indexWeight the costs-benefits of the index

Page 17: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Tuning I/O Intensive SQL Tuning I/O Intensive SQL (continued)(continued)

Use Database Engine Tuning Advisor for Use Database Engine Tuning Advisor for comprehensive workload analysiscomprehensive workload analysis

Feed workload input to DTAFeed workload input to DTACollect workload using “Tuning” template in SQL Collect workload using “Tuning” template in SQL Server Profiler, orServer Profiler, or

Collect workload as SQL scriptCollect workload as SQL script

Select the database for workload analysisSelect the database for workload analysis

Select the databases to tuneSelect the databases to tune

Set a time-boundSet a time-bound

Review output from analysisReview output from analysis

Review reports to make educated choiceReview reports to make educated choice

Page 18: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

I/O TuningI/O TuningI/O TuningI/O Tuning

Vipul ShahVipul ShahProgram ManagerProgram ManagerSQL ServerSQL Server

Page 19: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

How do I track index How do I track index usage?usage?How do I track index usage?How do I track index usage?

Use dm_db_missing_index_group_stats, Use dm_db_missing_index_group_stats, dm_db_missing_index_groups, dm_db_missing_index_groups, dm_db_missing_indexesdm_db_missing_indexes

Identify frequently used and less Identify frequently used and less frequently used indexesfrequently used indexes

Do not drop index without careful Do not drop index without careful consideration !consideration !

Page 20: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Detecting ContentionDetecting Contention““Activity – All Blocking Transactions” Activity – All Blocking Transactions” report in Management Studio is report in Management Studio is excellent for seeing blocked excellent for seeing blocked transactions at that momenttransactions at that moment

““Blocked Process Report” trace eventBlocked Process Report” trace eventTo set 5 second blocked process reportTo set 5 second blocked process report

sp_configure 'blocked process threshold', sp_configure 'blocked process threshold', 55

““Deadlock Graph” trace eventDeadlock Graph” trace event

DMV dm_os_wait_stats shows DMV dm_os_wait_stats shows aggregate duration spent on lock aggregate duration spent on lock waitswaits

Page 21: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Tuning ContentionTuning ContentionSQL Server 2000 – tradeoff between SQL Server 2000 – tradeoff between consistency and concurrencyconsistency and concurrency

SQL Server 2005 - use Row-SQL Server 2005 - use Row-Versioning based isolation levelsVersioning based isolation levels

Eliminates lockingEliminates locking

Uses version store to keep old row Uses version store to keep old row versionsversions

No tradeoff between consistency and No tradeoff between consistency and concurrencyconcurrency

Read Committed Snapshot isolation levelRead Committed Snapshot isolation levelProvides statement level consistencyProvides statement level consistency

Snapshot isolation levelSnapshot isolation levelProvides transaction level consistencyProvides transaction level consistency

Page 22: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Tuning Contention Tuning Contention (continued)(continued)

Use Read Committed Snapshot Use Read Committed Snapshot isolation levelisolation level

Most existing applications require no Most existing applications require no changechange

OFF by defaultOFF by defaultTurn it ON per databaseTurn it ON per database

Works with distributed transactionsWorks with distributed transactions

Page 23: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Detecting Contention Detecting Contention and Deadlocksand DeadlocksDetecting Contention Detecting Contention and Deadlocksand Deadlocks

Vipul ShahVipul ShahProgram ManagerProgram ManagerSQL ServerSQL Server

Page 24: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Performance Correlation in Performance Correlation in ProfilerProfiler

SQL Server ProfilerSQL Server ProfilerUse to Trace eventsUse to Trace events

Use to Replay eventsUse to Replay events

Correlate Performance Counters to Correlate Performance Counters to isolate problems quicklyisolate problems quickly

Page 25: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Performance Counter Performance Counter Correlation in ProfilerCorrelation in ProfilerPerformance Counter Performance Counter Correlation in ProfilerCorrelation in Profiler

Vipul ShahVipul ShahProgram ManagerProgram ManagerSQL ServerSQL Server

Page 26: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

Thank you!Thank you for attending this session and the 2005 PASS

Community Summit in Grapevine! Please help us improve the quality of our conference by completing your

session evaluation form. Completed evaluation forms may be given to the room monitor as you exit or to staff at the

registration desk.

Page 27: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Create TablesCreate TablesCreate TablesCreate Tables

Requires AdventureWorks databaseRequires AdventureWorks database Script is in Notes sectionScript is in Notes section

Scripts

Page 28: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Create Scheduled JobCreate Scheduled JobCreate Scheduled JobCreate Scheduled Job

Scripts

Requires AdventureWorks databaseRequires AdventureWorks database Script is in Notes sectionScript is in Notes section

Page 29: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Create Stored Create Stored ProceduresProceduresCreate Stored Create Stored ProceduresProcedures

Scripts

Requires AdventureWorks databaseRequires AdventureWorks database Creates SPs and Functions for TopSQL and TopWaitsCreates SPs and Functions for TopSQL and TopWaits Script is in Notes sectionScript is in Notes section

Page 30: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Workload Without DMLWorkload Without DMLWorkload Without DMLWorkload Without DML

Scripts

Requires AdventureWorks databaseRequires AdventureWorks database Script is in Notes sectionScript is in Notes section

Page 31: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Workload With DMLWorkload With DMLWorkload With DMLWorkload With DML

Scripts

Requires AdventureWorks databaseRequires AdventureWorks database Script is in Notes sectionScript is in Notes section

Page 32: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Demo QueriesDemo QueriesDemo QueriesDemo Queries

Scripts

Requires AdventureWorks databaseRequires AdventureWorks database Script is in Notes sectionScript is in Notes section

Page 33: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

ReaderReaderReaderReader

Scripts

Requires Snapshots databaseRequires Snapshots database Script is in Notes sectionScript is in Notes section

Page 34: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

WriterWriterWriterWriter

Scripts

Requires Snapshots databaseRequires Snapshots database Script is in Notes sectionScript is in Notes section

Page 35: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

First Part of DeadlockFirst Part of DeadlockFirst Part of DeadlockFirst Part of Deadlock

Scripts

Requires AdventureWorks databaseRequires AdventureWorks database Script is in Notes sectionScript is in Notes section

Page 36: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Second Part of Second Part of DeadlockDeadlockSecond Part of Second Part of DeadlockDeadlock

Scripts

Requires AdventureWorks databaseRequires AdventureWorks database Script is in Notes sectionScript is in Notes section

Page 37: Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools

Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.