Download presentation
Presentation is loading. Please wait.
Published byPamela Sparks Modified over 9 years ago
1
DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning fernando@solidqualitylearning.com
2
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?
3
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
4
S olid Q uality L earning (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
5
Agenda SQL Profiler as Management Tool Looking under the hood of database tools Defining effective Traces Scripting SQL Server Traces
6
SQL Profiler as Management tool Performance/Network Monitor counts events Event log heap where events are logged Query Analyzer tool to analyze queries Tool to run administrative scripts SQL Trace Server side component of the auditing engine SQL Profiler GUI tool for SQL Trace
7
SQL Trace / SQL Profiler SQL Trace was an external tool in SQL Server 6.5 SQL Profiler was the audit tool in SQL Server 7.0 SQL Trace is the internal server side audit component in SQL Server 2000 SQL Profiler is the GUI tool for SQL Trace in SQL Server 2000 C2 auditing is a special case of comprehensive trace to meet C2 requirements
8
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
9
Key components of SQL Profiler/Trace General Trace Properties Events Data Columns Filters
10
General Trace Properties
11
Events
12
Data Columns
13
Filters
14
Performance implications SQL Trace runs in the server SQL Profiler shouldn’t run in the server The SQL Trace file shouldn’t be stored in the server The SQL table used by Profiler to store the trace shouldn’t be in the main server Under these conditions, running a trace shouldn’t be a big problem Communication bottlenecks might make Profiler losing some events!events
15
Profiler lowers CPU utilization in the server?
16
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
17
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
18
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
19
Scripting SQL Server Enterprise Manager actions demo demo
20
What the SqlDataAdapter Update method does to SQL Server demo demo
21
DTC Transactions with COM+ components demo demo
22
Defining effective Traces Finding the worst-performing queries Detecting the use of cursors Detecting deadlocks Prioritizing objects’ optimization Identifying table and index scans
23
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
24
Detecting the use of cursors Cursors are EVIL… in principle Capture the following events: CursorOpen CursorClose CursorExecute CursorImplicitConversion
25
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
26
Detecting Deadlocks demo demo
27
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
28
Prioritizing objects’ optimization demo demo
29
Identifying table and index scans You should monitor: Scan: Started Transaction ID Object ID Index ID Mode Scan: Stopped Object ID Index ID Duration Reads
30
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
31
Scripting a Trace from SQL Server Profiler demo demo
32
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
33
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? ♥
34
Ask The Experts Get 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
35
Community Resources http://www.microsoft.com/communities/default.mspx Most Valuable Professional (MVP) http://www.mvp.support.microsoft.com/ Newsgroups Converse online with Microsoft Newsgroups, including Worldwide http://www.microsoft.com/communities/newsgroups/default.mspx User Groups Meet and learn with your peers http://www.microsoft.com/communities/usergroups/default.mspx
36
Suggested Reading And Resources The tools you need to put technology to work! TITLEAvailable Microsoft® SQL Server 2000™ Performance Tuning Technical Reference: 0-7356-1270-6 Today Microsoft Press books are 20% off at the TechEd Bookstore Also buy any TWO Microsoft Press books and get a FREE T-Shirt
37
Thank you! Questions? Download the source code of this session from: http://www.solidqualitylearning.com/conferences You can contact me at: fernando@solidqualitylearning.com
38
evaluations evaluations
39
© 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.