+ All Categories
Home > Documents > DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q...

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

Date post: 24-Dec-2015
Category:
Upload: pamela-sparks
View: 214 times
Download: 0 times
Share this document with a friend
39
DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero Solid Quality Learning [email protected]
Transcript
Page 1: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Fernando G. Guerrero

Solid Quality [email protected]

Page 2: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@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?

Page 3: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 4: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 5: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

Agenda

SQL Profiler as Management Tool

Looking under the hood of database tools

Defining effective Traces

Scripting SQL Server Traces

Page 6: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 7: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 8: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 9: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

Key components of SQL Profiler/Trace

General Trace Properties

Events

Data Columns

Filters

Page 10: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

General Trace Properties

Page 11: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

Events

Page 12: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

Data Columns

Page 13: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

Filters

Page 14: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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!

Page 15: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

Profiler lowers CPU utilization in the server?

0

20

40

60

80

100

120

8AM

10AM

12PM

2PM

4PM

Standard

Profilerrunning

Page 16: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 17: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 18: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 19: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

Scripting SQL Server Enterprise Manager actions

demodemo

Page 20: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

What the SqlDataAdapter Update method does to SQL Server

demodemo

Page 21: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

DTC Transactions with COM+ components

demodemo

Page 22: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

Defining effective Traces

Finding the worst-performing queries

Detecting the use of cursors

Detecting deadlocks

Prioritizing objects’ optimization

Identifying table and index scans

Page 23: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 24: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

Detecting the use of cursors

Cursors are EVIL… in principle

Capture the following events:CursorOpen

CursorClose

CursorExecute

CursorImplicitConversion

Page 25: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 26: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

Detecting Deadlocks

demodemo

Page 27: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 28: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

Prioritizing objects’ optimization

demodemo

Page 29: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

Identifying table and index scans

You should monitor:Scan: Started

Transaction IDObject IDIndex IDMode

Scan: StoppedObject IDIndex IDDurationReads

Page 30: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 31: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

Scripting a Trace from SQL Server Profiler

demodemo

Page 32: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 33: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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? ♥

Page 34: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 35: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 36: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

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

Page 37: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

Thank you! Questions?

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

You can contact me at:[email protected]

Page 38: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

evaluationsevaluations

Page 39: DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com.

© 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