You are on page 1of 9

Creating Traces with SQL Server 2012

Using SQL Profiler to Track Database Performance Issues


http://databases.about.com/od/sqlserver/a/Creating-Traces-With-Sql-Server2012.htm

By Mike Chapple
Databases Expert

Share

Pin

Tweet

Submit

Stumble

Post

Share

By Mike Chapple
SQL Profiler is a diagnostic tool included with Microsoft SQL Server 2012. It allows you to
create SQL traces that track the specific actions performed against a SQL Server databases. SQL
traces provide valuable information for troubleshooting database issues and tuning database
engine performance. For example, administrators might use a trace to identify a bottleneck in a
query and develop optimizations that might improve database performance.
Creating a Trace
In this tutorial, we walk through the process of creating a SQL Server Trace with SQL
Server Profiler, step-by-step. Here's how you can create your own SQL Server
traces. Note that these instructions are for SQL Server 2012. Users of earlier
versions of SQL Server should instead read Creating Traces with SQL Profiler.
1. Open SQL Server Management Studio and connect to the SQL Server instance
of your choice. You will need to provide the server name and appropriate
logon credentials (unless you are using Windows Authentication).
1. Once you've opened SQL Server Management Studio, choose SQL Server
Profiler from the Tools menu. Note that if you do not plan to use other SQL
Server tools in this administrative session, you may choose to launch SQL
Profiler directly, rather than go through Management Studio.
2. Provide login credentials again, if you are prompted.

3. SQL Server Profiler will then assume you wish to start a new trace and open a
Trace Properties window, similar to that shown above. The window will be
blank and allow you to specify the details of your trace.
4. Create a descriptive name for your trace and type it into the "Trace Name"
text box.
5. Select a template for your trace from the "Use the Template" drop-down
menu. This allows you to start your trace using one of the predefined
templates stored SQL Server's library. See the section "Choosing a Template"
below for descriptions of three of the most commonly used SQL Server trace
templates.
6. Choose a location to save the results of your trace. You have two options
here:
o

Select Save to File to save your trace to a file on the local hard drive.
Provide a file name and location in the Save As window that pops up as
a result of clicking the checkbox. You may also set a maximum file size
(in MB) to limit the impact your trace might have on disk use.

Select Save to Table to save your trace to a table within your SQL
Server database. If you select this option, you will be prompted to
connect to the database where you wish to store your trace results.
You may also set a maximum trace size (in thousands of table rows) to
limit the impact your trace might have on your database.

7. Click on the Events Selection tab to review the events you may monitor with
your trace. Some events will automatically be selected based upon the
template you chose. You may modify those default selections at this time. You
may view additional options by clicking the Show All Events and Show All
Columns checkboxes.
8. Click the Run button to begin your trace. SQL Server will begin creating the
trace. When you are finished, select Stop Trace from the File menu.
Choosing a Template
When you begin your trace, you may choose to base it on any of the templates
found in SQL Server's trace library. Three of the most commonly used trace
templates are:

The Standard template collects a variety of information about SQL Server


connections, stored procedures and Transact-SQL statements.

The Tuning template collects information that may be used with the Database
Engine Tuning Advisor to tune your SQL Server's performance.

The TSQL_Replay template gathers enough information about each TransactSQL statement to recreate the activity in the future.

How To Create a Trace with SQL Server


Profiler

SQL Server Profiler Trace. Mike Chapple

By Mike Chapple
Databases Expert
Share
Pin

Tweet
Submit
Stumble
Post

Share
By Mike Chapple
Traces allow you to track the specific actions performed against a SQL Server databases. They
provide valuable information for troubleshooting database issues and tuning database engine
performance. In this tutorial, we walk through the process of creating a SQL Server Trace with
SQL Server Profiler, step-by-step. Note: This article is for users of SQL Server 2008 and earlier.
If you are using SQL Server 2012, read Creating Traces with SQL Server 2012.
Difficulty: Average
Time Required: 15 minutes
Here's How:
1. Open SQL Server Management Studio by selecting it from the Start menu.
2. From the Tools menu, choose SQL Server Profiler.
3. When SQL Server Profiler opens, select New Trace from the File menu.
4. SQL Server Profiler will then prompt you to connect to the SQL Server instance you wish
to profile. Provide the connection details and click the Connect button to continue.
5. Create a descriptive name for your trace and type it into the "Trace Name" textbox.
1. Select a template for your trace from the drop-down menu. (See the Tips below for
information on some commonly used trace templates)
2. Select Save to File to save your trace to a file on the local hard drive. Provide a file name
and location in the Save As window that pops up as a result of clicking the checkbox.
3. Click on the Events Selection tab to review the events you may monitor with your trace.
Some events will automatically be selected based upon the template you chose. You may
modify those default selections at this time. You may view additional options by clicking
the Show All Events and Show All Columns checkboxes.
4. Click the Run button to begin your trace. SQL Server will begin creating the trace,
providing details as shown in the image. (You may click on the image to enlarge it.)
When you are finished, select Stop Trace from the File menu.
Tips:

1. The Standard template collects a variety of information about SQL Server connections,
stored procedures and Transact-SQL statements.
2. The Tuning template collects information that may be used with the Database Engine
Tuning Advisor to tune your SQL Server's performance.
3. The TSQL_Replay template gathers enough information about each Transact-SQL
statement to recreate the activity in the future.

Database Engine Tuning Advisor in SQL


Server 2012
SQL Server 2012s Database Engine Tuning Advisor (DETA) provides database administrators
with a powerful way to tune your database for your specific environment. DETA allows you to
design a customized workload that mimics your operational environment and then analyze that
workload to determine the optimal configuration settings for your SQL Server instance. DETAs
recommendations include adding normal and clustered indexes to your database, partitioning
tables and creating indexed views, where appropriate.
Getting Started with DETA
To run DETA for the first time, you must be a member of the sysadmin fixed server
role, as DETA must create several system-wide tables in the msdb database. Once
this first-time initialization is complete, any user who is a member of the db_owner
database role for a particular database may use DETA to tune that database.
You can run DETA several different ways, depending upon your current location in
the server environment:

From the Start menu choose Microsoft SQL Server 2012, then select
Performance Tools, and finally click on Database Engine Tuning Advisor.

If you are within SQL Server Management Studio, select Database Engine
Tuning Advisor from the SSMS Tools menu.

If you are in the SQL Server Management Studio Query Editor, open a
Transact-SQL script and select the text that you wish to analyze. Right-click
on that text and choose Analyze Query in Database Engine Tuning Advisor to
get started in DETA with the selected workload.

If you are running SQL Server Profiler, choose Database Engine Tuning
Advisor from the Tools menu.

Choosing a Tuning Workload


DETA provides environment-specific recommendations for tuning SQL Server
performance based upon an administrator-specified workload. It is critically
important to select a workload that is representative of the environment you are
seeking to tune, as DETA will make design recommendations that optimize
performance for the provided workload. Database administrators have several
choices for providing a DETA workload:

SQL Server Profiler Traces -- One of the best ways to design a SQL Server
workload is to create a database trace using SQL Server Profiler. With this
approach, you use the Profiler tool to capture database activity during a time
where you can either capture a representative workload or simulate the
expected workload. SQL Profiler will capture this activity in a trace file that
may be used as an input to DETA.

Custom-designed workload -- Alternatively, you may write your own


Transact-SQL script that contains the queries you want to optimize your
database to perform. You can create this script using Query Editor or the text
editor of your choice.

Use the SQL Server plan cache -- SQL Server maintains a cache of query
execution plans to improve the operational efficiency of the database server.
This cache contains information on recently executed SQL queries and may
be used to create a DETA workload. This is the easiest way to get started with
DETA, as it does not require any special administrator configuration.
However, it should only be used if you are relatively certain that recent
database activity reflects the conditions you wish to optimize your database
against.

Running DETA
Once youve selected your workload and started DETA using one of the methods
described earlier, follow this process to run DETA:
1. Provide the connection details for your database server in the Connect to
Server window. Click Connect to open the database connection.
2. Select the appropriate radio button in the Workload section of the window
and, if applicable, browse to the file you wish to use for your workload. This
file may be either a SQL Trace, XML file or SQL file. It's essential to choose a
workload representative of normal activity for your database, as DETA will
optimize the database's performance based upon this information.
3. Confirm the database that DETA should use for workload analysis using the
drop-down box.
4. Using the checkboxes in the grid at the bottom section of the screen, select
the database(s) and/or table(s) that you wish to tune.

5. Click the Start Analysis button and wait for the database tuning analysis to
complete.
6. Review the recommendations presented by DETA and implement those that
you deem appropriate.

SQL Server Index Tuning


Most database administrators are familiar with the potential performance benefits they can gain
through the judicious use of indexes on database tables. Indexes allow you to speed query
performance on commonly used columns and improve the overall processing speed of your
database.
Microsoft SQL Server supports two types of indexes: clustered indexes and non-clustered
indexes.
Clustered indexes define the physical sorting of a database tables rows in the storage media.
For this reason, each database table may have only one clustered index. If a PRIMARY KEY
constraint is created for a database table and no clustered index currently exists for that table,
SQL Server automatically creates a clustered index on the primary key.
Non-clustered indexes are created outside of the database table and contain a sorted list of
references to the table itself. SQL Server supports a maximum of 249 non-clustered indexes per
table. However, its important to keep in mind that non-clustered indexes slow down the data
modification and insertion process, so indexes should be kept to a minimum
One of the hardest tasks facing database administrators is the selection of
appropriate columns for non-clustered indexes. You should consider creating nonclustered indexes on any columns that are frequently referenced in the WHERE
clauses of SQL statements. Other good candidates are columns referenced by JOIN
and GROUP BY operations.
You may wish to also consider creating non-clustered indexes that cover all of the
columns used by certain frequently issued queries. These queries are referred to as
covered queries and experience excellent performance gains.
SQL Server provides a wonderful facility known as the Database Engine Tuning
Advisor which greatly enhances the index selection process. To use this tool, first
use SQL Profiler to capture a trace of the activity for which you wish to optimize
performance. You may wish to run the trace for an extended period of time to
capture a wide range of activity. Then, using Enterprise Manager, start the Index
Tuning Wizard and instruct it to recommend indexes based upon the captured trace.
It will not only suggest appropriate columns for queries but also provide you with an
estimate of the performance increase youll experience after making those changes!

You might also like