DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S...

Preview:

Citation preview

DAT308SQL Server 2000 Profiler: The Database Programmer's Best Friend

Fernando G. Guerrero

Solid Quality Learningfernando@solidqualitylearning.com

Hi Profiler! What is happening in my Server?

What really happen in my database server?

What all these GUI tools are doing to my server?

This “black box” application is behaving badly, what is it sending to SQL Server?

I know I have some deadlocks, but how can I fix them?

Quick info about Fernando(2 milliseconds)

MCSD, MCSE+Internet (W2K), MCDBA, MCT, SQL Server MVP

CEO and principal mentor at Solid Quality Learning

Writing for SQL Sever Magazine and SQL Server Professional

Co-author of Microsoft SQL Server 2000 Programming by Example (ISBN : 0789724499)

Author of the .NET Operations Guide and the .NET Deployment Guide for Microsoft TechNet

Solid Quality Learning (3 ms) An association of SQL Server experts from around the world

Principal Mentors:Itzik Ben-Gan

Kalen Delaney

Fernando G. Guerrero

Michael Hotek

Brian Moran

Ron Talmage

Kimberly L. Tripp

Helping you get the best out of your SQL Server:

Training

Consulting

Mentoring

Stay tuned to

http://www.SolidQualityLearning.com

Agenda

SQL Profiler as Management Tool

Looking under the hood of database tools

Defining effective Traces

Scripting SQL Server Traces

SQL Profiler as Management tool

Performance/Network Monitorcounts events

Event logheap where events are logged

Query Analyzertool to analyze queriesTool to run administrative scripts

SQL TraceServer side component of the auditing engine

SQL ProfilerGUI tool for SQL Trace

SQL Trace / SQL Profiler

SQL Trace was an external tool in SQL Server 6.5SQL Profiler was the audit tool in SQL Server 7.0SQL Trace is the internal server side audit component in SQL Server 2000SQL Profiler is the GUI tool for SQL Trace in SQL Server 2000C2 auditing is a special case of comprehensive trace to meet C2 requirements

SQL Trace / SQL Profiler (2)

You can use SQL Trace without SQL Profiler… as long as you know how to script it in Transact-SQL

SQL Trace writes events into an external file

SQL Profiler can write traces directly into a SQL Server table (SQL Trace can’t)

SQL Trace provides an open audit framework where you can even define your own events

Key components of SQL Profiler/Trace

General Trace Properties

Events

Data Columns

Filters

General Trace Properties

Events

Data Columns

Filters

Performance implications

SQL Trace runs in the serverSQL Profiler shouldn’t run in the serverThe SQL Trace file shouldn’t be stored in the serverThe SQL table used by Profiler to store the trace shouldn’t be in the main serverUnder these conditions, running a trace shouldn’t be a big problemCommunication bottlenecks might make Profiler losing some events!

Profiler lowers CPU utilization in the server?

0

20

40

60

80

100

120

8AM

10AM

12PM

2PM

4PM

Standard

Profilerrunning

Profiler lowers CPU utilization in the server? (2)

If that happens… you have PROBLEMS:

The CPU utilization was too high originally

You start a trace and SQL Server can’t cope with the extra workload

SQL Server limits the throughput so it can run the trace

So, SQL Server executes fewer transactions

Profiler lowers CPU utilization in the server? (3)

It looks like you find a way to lower CPU utilization after all:

Then, your CPU utilization looks better

But your clients complain because they can’t get through

STOP that b#$%#$ Trace!!!FIX what caused the CPU to be high in the first place

Looking under the hood of Database Tools

Let’s look at some demos:Scripting SQL Server Enterprise Manager actions

Optimistic concurrency in ADO 2.8

How the SqlDataAdapter sends updates to SQL Server by default

DTC Transactions with COM+ components

Scripting SQL Server Enterprise Manager actions

demodemo

What the SqlDataAdapter Update method does to SQL Server

demodemo

DTC Transactions with COM+ components

demodemo

Defining effective Traces

Finding the worst-performing queries

Detecting the use of cursors

Detecting deadlocks

Prioritizing objects’ optimization

Identifying table and index scans

Finding the worst-performing queries

You want to capture the duration of your queries:

Capture at least the Duration and TextData columns for:

SQL:BatchCompleted

SQL:StmtCompleted

RPC:Completed

SP:Completed

DCTTransaction

SQLTransaction

Detecting the use of cursors

Cursors are EVIL… in principle

Capture the following events:CursorOpen

CursorClose

CursorExecute

CursorImplicitConversion

Detecting deadlocks

This could be the most complex and comprehensive trace you can create

Errors and warnings

Deadlocks

SQL statements

Transactions

I prefer to show it with a demo

Detecting Deadlocks

demodemo

Prioritizing objects’ optimization

You want to know:How many times every Procedure/UDF is executed

What are the procedures/UDFs using more execution time in SQL Server

How long it takes to execute each Procedure/UDF in average

You want to focus your optimization work on the most “popular” objects

You want to get the highest performance boost from your tuning work

Prioritizing objects’ optimization

demodemo

Identifying table and index scans

You should monitor:Scan: Started

Transaction IDObject IDIndex IDMode

Scan: StoppedObject IDIndex IDDurationReads

Scripting SQL Server Traces

You can create a trace by using the following procedures:

Sp_trace_create

Sp_trace_setevent

Sp_trace_setfilter

Sp_trace_setstatus

Get information from a trace:Fn_trace_getinfo

Fn_trace_gettable

Fn_trace_geteventinfo

Fn_tarce_getfilterinfo

Scripting a Trace from SQL Server Profiler

demodemo

User-defined events

EXEC @ret = sp_trace_generateevent [ @eventid = ] event_id

[ , [ @userinfo = ] 'user_info' ]

[ , [ @userdata = ] user_data ]

Event_id should be between 82 and 91

User_info is nvarchar(128) (sysname)

User_data is varbinary(8000)

These events are traced as any other system events

Summary

SQL Profiler as Management Tool

Looking under the hood of database tools

Defining effective Traces

Scripting SQL Server Traces

Do you love Profiler a bit more? ♥

Ask The ExpertsGet Your Questions Answered

I’ll be at the Ask the Experts area:2 July 2003: 12:00-14:00

3 July 2003: 11:00-13:00

4 July 2003: 12:00-14:00

You’ll see me around some more times

Community Resources

Community Resourceshttp://www.microsoft.com/communities/default.mspx

Most Valuable Professional (MVP)http://www.mvp.support.microsoft.com/

NewsgroupsConverse online with Microsoft Newsgroups, including Worldwidehttp://www.microsoft.com/communities/newsgroups/default.mspx

User GroupsMeet and learn with your peershttp://www.microsoft.com/communities/usergroups/default.mspx

Suggested Reading And Resources

The tools you need to put technology to work!The tools you need to put technology to work!

TITLETITLE AvailableAvailable

Microsoft® SQL Server 2000™ Microsoft® SQL Server 2000™ Performance Tuning Technical Performance Tuning Technical Reference: 0-7356-1270-6Reference: 0-7356-1270-6 TodayToday

Microsoft Press books are 20% off at the TechEd Bookstore

Also buy any TWO Microsoft Press books and get a FREE T-Shirt

Thank you! Questions?

Download the source code of this session from:http://www.solidqualitylearning.com/conferences

You can contact me at:fernando@solidqualitylearning.com

evaluationsevaluations

© 2003 Microsoft Corporation. All rights reserved.© 2003 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.

Recommended