Tải bản đầy đủ (.pdf) (99 trang)

Microsoft Press microsoft sql server 2005 PHẦN 7 docx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (3.32 MB, 99 trang )

508 Chapter 14 Working with SQL Server Agent Jobs
NOTE Can’t execute multiple tasks on same schedule
Remember that when creating a maintenance plan, you are in essence creating an SSIS package,
so you are defining the flow control definition within the SSIS package. However, you will not
be executing multiple maintenance tasks on the same schedule, so this step in the wizard is
superfluous.
Depending on the maintenance task you select, the options that you can specify at
this point in the wizard vary. If you select a maintenance plan for a database
backup, you’ll see the option to select the databases to apply the task to, as shown
in Figure 14-12.
Figure 14-12 Specifying databases to back up
After you select the check box for the databases you want to back up, click OK.
You can then specify the folder in which you want to store the backups, along
with whether you want to verify the backup integrity, as Figure 14-13 shows. Click
Next.
When you have specified all the appropriate task options, you can define a schedule,
as shown in Figure 14-14. To access scheduling options, click Change.
C1462271X.fm Page 508 Friday, April 29, 2005 7:57 PM
Lesson 2: Creating a Maintenance Plan 509
Figure 14-13 Specifying backup options
Figure 14-14 Defining one schedule for the entire maintenance plan
C1462271X.fm Page 509 Friday, April 29, 2005 7:57 PM
510 Chapter 14 Working with SQL Server Agent Jobs
The scheduling options available are the same as when you are scheduling a
SQL Server Agent job (see Figure 14-15). The difference is that for a regular SQL
Server Agent job, you can define multiple schedules for a regular job and reuse previ-
ously created job schedules, but you can define only one schedule for a maintenance
plan.
Figure 14-15 Specifying scheduling options
Click OK to close the New Job Schedule dialog box. After defining the schedule, you
see a summary of the scheduling options displayed within the Maintenance Plan Wiz-


ard, as Figure 14-16 shows. Click Next.
For reporting purposes, you can configure each maintenance plan to write an out-
put file or to e-mail the report about the actions it performs, as shown in Figure 14-17.
You will usually specify writing to an output file that you can scan for errors. Click
Next.
C1462271X.fm Page 510 Friday, April 29, 2005 7:57 PM
Lesson 2: Creating a Maintenance Plan 511
Figure 14-16 Single schedule definition for the maintenance plan
Figure 14-17 Specifying reporting options
At this point, you have completed the creation of a maintenance plan, and the wizard
asks you to verify your choices, as Figure 14-18 shows. When you click Finish, the wiz-
ard performs the following steps:
1. Generates an SSIS package.
2. Stores that SSIS package within the msdb database.
C1462271X.fm Page 511 Friday, April 29, 2005 7:57 PM
512 Chapter 14 Working with SQL Server Agent Jobs
3. Creates a job in SQL Server Agent to execute the maintenance plan.
4. Creates entries in the sys.dbmaintplan* tables within the msdb database.
Figure 14-18 Finishing maintenance plan creation
Quick Check
1. What operations can a maintenance plan perform?
2. How many schedules can you apply to a maintenance plan?
Quick Check Answers
1. A maintenance plan can back up databases, delete old backup files from
the operating system, maintain indexes, execute another job, and shrink a
database.
2. You can apply only one schedule to a maintenance plan.
PRACTICE Create a Maintenance Job
In this exercise, you will practice the creation of a maintenance plan to back up the
AdventureWorks database. Instead of using the Maintenance Plan Wizard to create the

maintenance plan, you will define it from a generic maintenance plan.
1. In SSMS, right-click the Maintenance Plans node in Object Explorer and choose
New Maintenance Plan.
C1462271X.fm Page 512 Friday, April 29, 2005 7:57 PM
Lesson 2: Creating a Maintenance Plan 513
2. Specify a name for the maintenance plan and click OK.
3. Click the browser button (…) to the right of the Schedule text box.
4. Configure the maintenance plan to run once per day at 23:00, or 11:00 PM.
When you’re done, click OK to close the Job Schedule Properties dialog box.
5. Click Connections to open the Manage Connections dialog box. Click Add and
specify the server connection options. Click OK to save your changes and then
click OK again to close the Manage Connections dialog box.
6. Click Logging and configure the logging options you want to use for this plan.
7. In the Maintenance Plan Tasks toolbox, drag and drop the Back Up Database
Task onto the surface of the maintenance plan.
8. Double-click the Back Up Database Task and specify the AdventureWorks data-
base to perform a full backup. Click OK to close the Back Up Database Task
dialog box.
9. Drag and drop a Maintenance Cleanup Task onto the surface of the maintenance
plan.
10. Select the Back Up Database Task.
11. Drag the green arrow from the Back Up Database Task to the Maintenance
Cleanup Task, which creates a dependency between the two tasks so that the
backup task runs first and the cleanup task runs second.
12. Double-click the Maintenance Cleanup Task and specify saving the backups for
one day. When you’re done, click OK to close the Maintenance Cleanup Task
dialog box.
13. Click Save on the toolbar to save your maintenance plan.
Lesson Summary
■ A maintenance plan enables you to graphically configure SQL Server to perform

one or more predefined maintenance tasks on a scheduled basis against one or
more databases.
■ The most common type of maintenance plan that you will create is to back up a
database on a regular basis.
■ Each maintenance plan is a monolithic SSIS package that can have only one
schedule defined for it.
C1462271X.fm Page 513 Friday, April 29, 2005 7:57 PM
514 Chapter 14 Working with SQL Server Agent Jobs
Lesson Review
The following questions are intended to reinforce key information presented in this
lesson. The questions are also available on the companion CD if you prefer to review
them in electronic form.
NOTE Answers
Answers to these questions and explanations of why each answer choice is right or wrong are
located in the “Answers” section at the end of the book.
1. What types of tasks can you define with the Maintenance Plan Wizard? (Choose
all that apply.)
A. Database creation
B. Database backup
C. Index rebuilding
D. SSIS package execution
C1462271X.fm Page 514 Friday, April 29, 2005 7:57 PM
Lesson 3: Configuring Operators 515
Lesson 3: Configuring Operators
The SQL Server Agent subsystem enables you to define operators to receive notifica-
tions about jobs. You can use this mechanism to enable SQL Server Agent to send a
notice when a job has failed, for example, alerting DBAs so that they can quickly eval-
uate and repair problems.
After this lesson, you will be able to:
■ Configure operators.

Estimated lesson time: 10 minutes
How to Configure an Operator
You configure an operator by naming it and specifying various notification methods
for the operator and other parameters, such as an e-mail address to send the notifica-
tion to. To begin the configuration, in SSMS, right-click the Operators node below
SQL Server Agent, and choose New Operator to define properties for an operator, as
Figure 14-19 shows.
Figure 14-19 Defining operator parameters
C1462271X.fm Page 515 Friday, April 29, 2005 7:57 PM
516 Chapter 14 Working with SQL Server Agent Jobs
Each operator needs a name. You then specify which notification methods—e-mail, net
send, and pager—are valid for that operator.
NOTE Enable the Messenger Service
In order to use a net send, the Messenger Service must be enabled.
You specify addresses or numbers for each valid notification method. In addition, you
can configure an operator to receive notifications only during specific on-duty hours.
NOTE Specifying a work week
Unfortunately, the graphical user interface (GUI) assumes that the work week is Monday through
Friday for everyone in the world.
Selecting the Notifications page displays all jobs and alerts for which a particular oper-
ator is configured to receive notifications. Click OK to create the operator.
Quick Check
■ Which notification methods are valid for an operator?
Quick Check Answer
■ You can notify an operator using net send, e-mail, or text messaging.
Managing and Troubleshooting Jobs
You can manage SQL Server Agent jobs within SSMS. To access the list of jobs
that are configured on an instance, expand the SQL Server Agent node within
SSMS, right-click the Job Activity Monitor item, and choose View Job Activity.
The Job Activity Monitor displays a list of the jobs for the instance, along

with the date and time the job was last run and the next date and time the job
will run.
The Job Activity Monitor also displays whether the job is enabled and whether
the last run was successful. You can enable, disable, start, and stop a job by right-
clicking it within the job activity grid. The shortcut menu also enables you to
access the detailed history for a particular job, including any error messages that
might have occurred during job execution.
C1462271X.fm Page 516 Friday, April 29, 2005 7:57 PM
Lesson 3: Configuring Operators 517
PRACTICE Configuring Operators
In this practice, you will configure an operator to receive e-mail notifications.
1. Expand the SQL Server Agent node.
2. Right-click Operators and choose New Operator.
3. Specify a name for the operator.
4. Specify an e-mail address for the operator.
5. Click OK.
NOTE Sending e-mail
To send e-mail to this operator, you must enable and configure Database Mail. Because text mes-
saging also relies on the mail subsystem, it also requires you to configure Database Mail. For infor-
mation about configuring Database Mail, see Lesson 2, “Configuring Database Mail,” in Chapter 2,
“Configuring SQL Server 2005.”
Lesson Summary
■ SQL Server Agent enables you to define operators to receive notifications from
jobs via e-mail, net send, or pager.
■ Operators provide a convenient way to refer to one or more messaging addresses
by a single name.
■ To send e-mail or text messages, you need to have SQL Server Database Mail con-
figured and enabled.
Lesson Review
The following questions are intended to reinforce key information presented in this

lesson. The questions are also available on the companion CD if you prefer to review
them in electronic form.
NOTE Answers
Answers to these questions and explanations of why each answer choice is right or wrong are
located in the “Answers” section at the end of the book.
C1462271X.fm Page 517 Friday, April 29, 2005 7:57 PM
518 Chapter 14 Working with SQL Server Agent Jobs
1. Which notification methods are available for an operator? (Choose all that
apply.)
A. cell phone
B. pager
C. e-mail
D. instant messaging
C1462271X.fm Page 518 Friday, April 29, 2005 7:57 PM
Lesson 4: Configuring Alerts 519
Lesson 4: Configuring Alerts
The alert subsystem within SQL Server Agent enables you to notify administrators
when specific conditions within an environment are met. SQL Server Agent polls the
system on a periodic basis to check for any alert conditions.
After this lesson, you will be able to:
■ Configure alerts.
Estimated lesson time: 10 minutes
How to Configure Alerts
The high-level steps for configuring alerts are the following:
1. Create a new alert.
2. Select a type of alert.
3. Configure conditions to monitor.
4. Define an action to be taken when a condition is met.
5. Define additional messaging options.
You find SQL Server alerts in a node under SQL Server Agent. To configure a new

alert, right-click the Alerts node and choose New Alert. All alerts should have a name
associated with them that describes the purpose of the alert. You also define an alert
as based on one of three types of events: performance condition, SQL Server event, or
Windows Management Instrumentation (WMI) event.
You base a performance-condition alert on a performance counter. You can specify
only one performance counter for an alert, so if you need something more sophisti-
cated that uses multiple counters, you cannot use a SQL Server alert. The example
that Figure 14-20 shows specifies an alert condition when the percentage of the
transaction log space used in the AdventureWorks database exceeds 80 percent.
You base a SQL Server event alert on either an error code or a severity level, as shown
in Figure 14-21. You can further refine the particular alert by restricting it to errors
that contain a specific string within the error text.
C1462271X.fm Page 519 Friday, April 29, 2005 7:57 PM
520 Chapter 14 Working with SQL Server Agent Jobs
Figure 14-20 Specifying alert parameters for a SQL Server performance condition
Figure 14-21 Specifying alert parameters for a SQL Server event
Figure 14-22 shows the final type of alert you can create: a WMI event. For this type
of alert, you specify a predefined notification query for SQL Server Agent to use or
enter your own custom notification query.
C1462271X.fm Page 520 Friday, April 29, 2005 7:57 PM
Lesson 4: Configuring Alerts 521
Figure 14-22 Specifying alert parameters for a WMI event
When SQL Server detects that a condition specified by the alert is met, it raises the alert
and executes a response based on the response configuration you define. The response
to an alert can be as simple as notifying an operator by e-mail, pager, or the net send
command. In some scenarios, you can configure SQL Server to respond by executing a
job that contains a set of steps designed to address the particular alert event.
If the response to an alert is to notify an operator, you can specify additional options
for the notification, as Figure 14-23 shows.
C1462271X.fm Page 521 Friday, April 29, 2005 7:57 PM

522 Chapter 14 Working with SQL Server Agent Jobs
Figure 14-23 Specifying alert options
Quick Check
■ What types of alerts can you define?
Quick Check Answer
■ You can define alerts for a single SQL Server performance counter, SQL
Server error code, error severity level, or WMI event.
PRACTICE Configure Alerts
In this exercise, you will practice the creation of an alert to notify an operator when
the AdventureWorks database has a fatal integrity error.
1. Open the SQL Server Agent node in SSMS.
2. Right-click Alerts and choose New Alert.
3. Enter a name for the alert.
4. In the Type drop-down list, verify that a SQL Server Event Alert is selected.
5. From the Database Name drop-down list, select the AdventureWorks database.
6. From the Severity drop-down list, select 023–Fatal Error: Database Integrity
Suspect.
C1462271X.fm Page 522 Friday, April 29, 2005 7:57 PM
Lesson 4: Configuring Alerts 523
7. Select the Response page.
8. Select the Notify Operators check box.
9. In the Operator List, select an operator to notify by selecting the operator’s E-Mail,
Pager, or Net Send check boxes.
10. Select the Options page.
11. Select the E-Mail check box to configure the alert to include the error informa-
tion in the e-mail it sends to operators.
12. Click OK to save the alert.
Lesson Summary
■ Alerts provide a basic monitoring capability within SQL Server.
■ You can monitor SQL Server for alert conditions related to performance

counters, error codes, error severity levels, or WMI events.
■ When an alert is triggered, you can send a notification or configure the alert to
execute a SQL Server Agent job that will resolve the situation.
Lesson Review
The following questions are intended to reinforce key information presented in this
lesson. The questions are also available on the companion CD if you prefer to review
them in electronic form.
NOTE Answers
Answers to these questions and explanations of why each answer choice is right or wrong are
located in the “Answers” section at the end of the book.
1. What types of alerts can you define? (Choose all that apply.)
A. Performance conditions for CPU utilization
B. Performance conditions for SQL Server
C. Security permissions being changed for a login
D. Errors generated by an application
C1462271X.fm Page 523 Friday, April 29, 2005 7:57 PM
524 Chapter 14 Review
Chapter Review
To further practice and reinforce the skills you learned in this chapter, you can
■ Review the chapter summary.
■ Review the list of key terms introduced in this chapter.
■ Complete the case scenario. This scenario sets up a real-world situation involv-
ing the topics of this chapter and asks you to create solutions.
■ Complete the suggested practices.
■ Take a practice test.
Chapter Summary
■ SQL Server Agent provides a powerful and flexible scheduling engine within
SQL Server.
■ By using the capabilities exposed in SQL Server Agent, you can configure oper-
ations to automatically execute on a scheduled basis without requiring user

intervention.
■ You can use the Database Maintenance Plan Wizard to define maintenance
tasks, such as database backups or reindexing tasks, to perform against one or
more databases.
■ You can configure operators to receive notifications such as job failure via e-mail,
net send, or pager.
■ By combining alerts with the job subsystem, you can use SQL Server Agent to
monitor the system for conditions that you specify and then to execute jobs to
proactively address potential issues.
Key Terms
Do you know what these key terms mean? You can check your answers by looking up
the terms in the glossary at the end of the book.
■ alert
■ job
■ job schedule
■ job step
C1462271X.fm Page 524 Friday, April 29, 2005 7:57 PM
Chapter 14 Review 525
■ maintenance job
■ maintenance plan
■ operator
■ SQL Server Agent proxy
Case Scenario: Scheduling Administrative Actions
In the following case scenario, you will apply what you’ve learned in this chapter. You
can find answers to these questions in the “Answers” section at the end of this book.
Contoso Limited, a health care company located in Bothell, WA, has a volatile data-
base containing patient claims data. Contoso is under strict regulation and is required
to protect all customer data within a database.
Government regulations allow for minimal data loss in the event of a natural disaster.
In the case of Contoso, minimal data loss is defined as no more than 10 minutes of

data loss.
In addition, Contoso needs to ensure that performance within its patient claims data-
base is optimal.
Each evening, Contoso receives data feeds from several external vendors that process
payments to patients. Frequently, data in the feeds needs to be edited and reimported
based on validation scripts that reconcile the data within the patient claims database
with the data feeds submitted by the external vendors. While the import processes
execute, no other transactions are issued against the patient claims database. The cur-
rent process creates a full backup of the patient claims database at 23:00 before the
import routines are executed.
Contoso also executes a full database backup at 06:00. The exact time that this
backup executes is not important as long as it executes before business operations
begin for the day.
At 04:00 each day, the system administrators at Contoso shut down the SQL Servers
to perform routine maintenance such as applying service packs and hotfixes to the
operating system and other software on the server.
Contoso wants to improve its backup strategy to ensure that government regulations
are met, as well as requiring a maximum of eight restore operations to recover a
database.
C1462271X.fm Page 525 Friday, April 29, 2005 7:57 PM
526 Chapter 14 Review
1. How does Contoso guarantee that a full backup is created before the patient
claims import routines are executed?
2. How do the Contoso DBAs guarantee that a full backup is performed before
business operations start in the morning?
3. What backup strategy should be implemented to ensure that a database can be
recovered with a maximum of eight restore operations?
Suggested Practices
To help you successfully master the exam objectives presented in this chapter, com-
plete the following tasks.

Create a SQL Server Agent job
For this task, practice creating the following jobs:
■ Practice 1 Create a job to perform a differential backup of the AdventureWorks
database twice per day—at 23:00 and 16:00.
■ Practice 2 Create a job to perform a transaction log backup of the Adventure-
Works database every 10 minutes.
Create a Maintenance Plan
For this task, practice creating the following maintenance plans:
■ Practice 1 Using the Maintenance Plan Wizard, create a maintenance plan to
perform a differential backup of the AdventureWorks database twice per day—at
11:00 and 16:00.
■ Practice 2 Using the Maintenance Plan Wizard, create a maintenance plan to per-
form a transaction log backup of the AdventureWorks database every 10 minutes.
Create an Alert
For this task, practice creating the following alert:
■ Practice 1 Create an alert to notify an operator when there is a table-integrity
error.
C1462271X.fm Page 526 Friday, April 29, 2005 7:57 PM
Chapter 14 Review 527
Take a Practice Test
The practice tests on this book’s companion CD offer many options. For example, you
can test yourself on just the content covered in this chapter, or you can test yourself on
all the 70-431 certification exam content. You can set up the test so that it closely sim-
ulates the experience of taking a certification exam, or you can set it up in study mode
so that you can look at the correct answers and explanations after you answer each
question.
MORE INFO Practice tests
For details about all the practice test options available, see the “How to Use the Practice Tests” sec-
tion in this book’s Introduction.
C1462271X.fm Page 527 Friday, April 29, 2005 7:57 PM

C1462271X.fm Page 528 Friday, April 29, 2005 7:57 PM
529
Chapter 15
Monitoring and Troubleshooting
SQL Server Performance
Monitoring and troubleshooting Microsoft SQL Server is a broad topic that spans a
variety of tools and processes. All database administrators (DBAs) eventually face per-
formance issues or errors they have to resolve. In addition, effective monitoring can
help DBAs proactively address many issues before they affect applications, users, or
customers. This chapter covers the various tools that you can use to monitor the
health of your databases, including SQL Server Profiler, Windows System Monitor,
the Database Engine Tuning Advisor (DTA), and SQL Server 2005 Dynamic Manage-
ment Views (DMVs) and Dynamic Management Functions (DMFs). You will also
explore the processes for correlating various pieces of data from these tools together
to proactively manage databases. A key element in troubleshooting performance
problems is understanding SQL Server locking and blocking mechanisms and how to
resolve deadlocks, which this chapter also covers. And you will see how to connect to
SQL Server via the new dedicated administrator connection (DAC), which guarantees
that you will never be locked out of a SQL Server that you need to troubleshoot.
MORE INFO SQL Server performance monitoring and troubleshooting
Many books have been devoted to the topic of SQL Server performance monitoring and troubleshoot-
ing. This chapter gives you an overview of essential tools and processes and gets you started with the
basic and most tried-and-true techniques for finding and resolving performance problems. For com-
plete information about each topic in this chapter, see SQL Server 2005 Books Online. SQL Server 2005
Books Online is installed as part of SQL Server 2005. Updates for SQL Server 2005 Books Online are
available for download at www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx.
MORE INFO Top performance Web sites
You can also obtain a wealth of performance information from the following valuable Web
resources:
■ Microsoft SQL Server Customer Advisory Team blog at />■ Gert Draper’s SQLDEV.Net Web site at www.sqldev.net, which contains useful utilities and

background information
Both these Web sites should be in your Favorites list.
C1562271X.fm Page 529 Friday, April 29, 2005 7:59 PM
530 Chapter 15 Monitoring and Troubleshooting SQL Server Performance
Exam objectives in this chapter:
■ Gather performance and optimization data by using the SQL Server Profiler.
❑ Start a new trace.
❑ Save the trace logs.
❑ Configure SQL Server Profiler trace properties.
❑ Configure a System Monitor counter log.
❑ Correlate a SQL Server Profiler trace with System Monitor log data.
■ Gather performance and optimization data by using the Database Engine Tun-
ing Advisor.
❑ Build a workload file by using SQL Server Profiler.
❑ Tune a workload file by using the Database Engine Tuning Advisor.
❑ Save recommended indexes.
■ Monitor and resolve blocks and deadlocks.
❑ Identify the cause of a block by using the sys.dm_exec_requests system view.
❑ Terminate an errant process.
❑ Configure SQL Server Profiler trace properties.
❑ Identify transaction blocks.
■ Diagnose and resolve database server errors.
❑ Connect to a nonresponsive server by using the dedicated administrator
connection (DAC).
❑ Review SQL Server startup logs.
❑ Review error messages in event logs.
■ Gather performance and optimization data by using DMVs.
Lessons in this chapter:
■ Lesson 1: Working with SQL Server Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
■ Lesson 2: Working with System Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548

■ Lesson 3: Using the Database Engine Tuning Advisor . . . . . . . . . . . . . . . . . . . 554
■ Lesson 4: Using Dynamic Management Views and Functions . . . . . . . . . . . . 566
■ Lesson 5: Correlating Performance and Monitoring Data . . . . . . . . . . . . . . . . 575
■ Lesson 6: Resolving Blocking and Deadlocking Issues. . . . . . . . . . . . . . . . . . . 582
■ Lesson 7: Resolving Database Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
C1562271X.fm Page 530 Friday, April 29, 2005 7:59 PM
Before You Begin 531
Before You Begin
To complete the lessons in this chapter, you must have
■ SQL Server 2005 installed.
■ A copy of the AdventureWorks sample database installed in the instance.
Real World
Michael Hotek
The phone rang at 12:30, just as I was heading out for a lunch meeting with a
customer. We were going to discuss a possible week-long project to analyze the
customer’s application for performance issues. It was the customer on the other
end of the line.
His ordering system couldn’t accept orders. The servers were running, and SQL
Server was online. Queries were coming in, but they were taking so long to exe-
cute that applications were timing out or customers were going elsewhere. So,
30 minutes later, I was in the company’s office instead of at lunch.
While I was driving to the office, I asked the DBAs to launch a SQL Server Pro-
filer trace to begin gathering data. After I reached the office, we saved the current
trace data and began the analysis process. We immediately found two stored pro-
cedures that were creating most of the issues—but not all of them.
We also found that someone in the marketing department had connected
Microsoft Office Access to the company’s production database and was running
several queries. Unfortunately, the marketing staffer had neglected to join tables
together and was executing cross joins instead. Of course, no one in the com-
pany would admit to running any queries against production data. After remov-

ing the marketing department user’s access, customers could suddenly
complete orders, but performance was still an issue.
Based on our Profiler traces, we tuned the two procedures that were degrading
performance the most. Although these quick fixes didn’t solve all of the com-
pany’s performance issues, which we resolved over the next three weeks, they
did patch the performance problems enough that customers could complete
orders on the company’s Web site instead of taking their business to the
competitors.
C1562271X.fm Page 531 Friday, April 29, 2005 7:59 PM
532 Chapter 15 Monitoring and Troubleshooting SQL Server Performance
Lesson 1: Working with SQL Server Profiler
SQL Server Profiler is a powerful but rarely used tool for analyzing database perfor-
mance issues. By using Profiler to capture traces of database activity, you can analyze
query patterns to detect performance problems even before applications are affected.
This lesson describes Profiler’s role and how to use it to configure traces that capture
the information you need to resolve performance issues. You will see how to save a
trace in a format that enables you to perform advanced analysis and how various trace
options affect the data that Profiler gathers. Note that Profiler captures only SQL
Server events, not operating system or networking conditions that might be affecting
database performance.
After this lesson, you will be able to:
■ Define a trace.
■ Start, pause, and stop a trace.
■ Save a trace log.
■ Gather showplan data.
■ Create a replay trace.
Estimated lesson time: 45 minutes
Defining a Trace
Inside the database engine, SQL Server provides an event subsystem called SQL Trace
that is based on an external application programming interface (API). This external

API enables you to call SQL Trace by using a variety of parameters that define events
and columns of data to capture. The SQL Trace subsystem also enables you to specify
optional filters on the data being captured so that you can focus your analysis.
Although you can write the call to SQL Trace by using Transact-SQL code or SQL
Server Management Object (SMO), the most common way to work with the SQL Trace
API is through the SQL Server Profiler graphical user interface (GUI). Let’s look at
how to define a trace within Profiler.
You launch SQL Server Profiler from the SQL Server 2005 Performance Tools menu.
After it opens, choose File, New Trace. A connection dialog box appears. Connect to
the SQL Server instance in which the sample AdventureWorks database is installed.
You then see the Trace Definition dialog box shown in Figure 15-1.
C1562271X.fm Page 532 Friday, April 29, 2005 7:59 PM

×