Professional Documents
Culture Documents
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 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.
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.
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.
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.
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.