You are on page 1of 23

Monitoring Your Server

Topics
• Tools
• Performance Issue
SQL Server Performance Tuning and
Monitoring
• SQL Server is a great platform to get your database application up and running fast.
• The graphical interface of SQL Server Management Studio allows you to create tables, insert data, develop stored procedures,
etc... in no time at all.
• Initially your application runs great in your production, test and development environments, but as use of the application increases
and the size of your database increases you may start to notice some performance degradation or worse yet, user complaints.
• This is where performance monitoring and tuning come into play.
• Usually the first signs of performance issues surface from user complaints.
• A screen that used to load immediately now takes several seconds.
In this class we will cover some of the common issues with performance such as:
• deadlocks
• blocking
• missing and unused indexes
• I/O bottlenecks
• poor query plans
• statistics
• wait stats
• fragmentation
• We will look at basic techniques all DBAs and Developers should be aware of to make sure their database applications are
performing at peak performance.
Performance Related Tools
• In order to monitor and improve performance for your SQL Server
environment you need to know what tools are available and how to use
each of these tools.
• In this section we will look at the following tools to give you an
introduction as to what they are used for an how you can use them to
collect performance related data.
• Dynamic Management Views (DMVs) and System Catalog Views
• Profiler and Server Side Traces
• Windows Performance Monitor
• Built in performance reports in SSMS
• Query Plans
• Database Tuning Advisor
Dynamic Management Views
DMVs are a great tool to help troubleshoot performance related issues and
once you understand their power they will become a staple for your
Database Administration.
Here are some of the more useful DMVs that you should familiarize yourself
with:
• sys.dm_exec_cached_plans - Cached query plans available to SQL Server
• sys.dm_exec_sessions - Sessions in SQL Server
• sys.dm_exec_connections - Connections to SQL Server
• sys.dm_db_index_usage_stats - Seeks, scans, lookups per index
• sys.dm_io_virtual_file_stats - IO statistics for databases and log files
• sys.dm_tran_active_transactions - Transaction state for an instance of SQL Server
• sys.dm_exec_sql_text - Returns TSQL code
• sys.dm_exec_query_plan - Returns query plan
• sys.dm_os_wait_stats - Returns information what resources SQL is waiting on
• sys.dm_os_performance_counters - Returns performance monitor counters related
to SQL Server
Profiler and Server Side Traces
Profiler is a GUI based tool that runs a SQL Server trace to capture the
metrics listed above as well additional data. This data can then be used
to determine where your SQL Server performance issues are related to
your TSQL code. Running a trace without using Profiler is known as a
Server Side Trace. You can create and start the trace using TSQL
commands instead of having to use the GUI.
Profiler
A Trace Properties window will open and you can click
Run to start the trace with the default settings
Selecting Events, Columns and Filters
• Events
A good starting place is to capture just these two events. These will show you all completed batches and metrics
related to the batch. A batch is basically a set of work, like a stored procedure, that contains multiple
statements.
Stored Procedures - RPC:Completed
TSQL - SQL:BatchCompleted
• Columns
As far as columns go just select all columns and once you see the data that is captured you can reduce the
amount of columns you are capturing.
• Filters
Filters allow you to further define what is captured. To set filters click on Column Filters. So if you only want to
capture data for a specific process.
• Reading the Output
After you have collected the output you can see which statements are returned based on the events and filters
that you have set. If you start with the two events above you can begin to take a look at the statements that
have the longest duration and these are the statements that you should begin trying to tune to improve
performance.
Performance Monitor
• Windows Performance Monitor or PerfMon is another great tool to
capture metrics for your entire server.
• The Performance Monitor tool allows you to capture and graph many
aspects for the Windows server. There are counters for .NET, Disks,
Memory, Processors, Network, etc... as well several counters related
to each instance of SQL Server on the box. If you have multiple
instances running on one server, the counters are available for each
instance so you can see what is occurring at the instance level.
Launching Performance Monitor
Start > Control Panel >
Administrative Tools >
Performance Monitor or you can
launch PerfMon.exe.
Once this is running you will get
an interface like the following:
Adding Counters and Changing Settings
To add a counter, right click on the
big green plus button above the
graph and a new window will
open like the following:
From this window we can select
additional counters such as
Memory, Physical Disk and SQL
Server specific counters. To add a
counter select the counter and
click the Add button. The below
screen shot shows multiple
counters that have been
selected. Click OK when you are
done to start capturing this data.
Useful Counters
• Memory
• Available MBytes
• Physical Disk
• Avg. Disk sec/Read
• Avg. Disk sec/Write
• Processor
• % Processor Time
• SQL Server: Buffer Manager
• Page Life Expectancy
• Buffer cache hit ratio
• SQL Server: SQL Statistics
• Batch Requests/sec
• Compilations/sec
Built in Performance Reports in SSMS
There are several reports related to performance that
can be used to see current activity as well as
historical activity. Here is a list of some of the
available reports.
• Server Dashboard
• Scheduler Health
• Memory Consumption
• Activity - All Blocking Transactions
• Activity - Top Sessions
• Activity - top Connections
• Top Connections by Block Transactions Count
• Top Transaction by Locks Count
• Performance - Batch Execution Statistics
• Performance - Object Execution Statistics
• Performance - Top Queries by Average CPU Time
• Performance - Top Queries by Average IO
• Performance - Top Queries by Total CPU Time
• Performance - Top Queries by Total IO
Query Execution Plans
Another useful tool that SQL Server offers is the ability to see query execution
plans. An execution plan shows you how SQL Server breaks down a query and also
identifies where issues might exist within the execution plan. Once you have
identified statements that take a long time to complete, you can then look at the
execution plan to determine tuning needs.
SQL Server can create execution plans in two ways:
• Actual Execution Plan - (CTRL + M) - is created after execution of the query and contains the
steps that were performed
• Estimated Execution Plan - (CTRL + L) - is created without executing the query and contains
an approximate execution plan
Execution plans can be presented in these three ways and each option offers
benefits over the other.
• Text Plans
• Graphical Plans
• XML Plans
Database Engine Tuning Advisor
• SQL Server also includes another performance tool called the Database
Engine Tuning Advisor or DTA. This tool allows you to have SQL Server
analyze one statement or a batch of statements that you captured by
running a Profiler or server side trace. The tool will then go through each
statement to determine where improvements can be made and then
presents you with options for improvement.
The Database Engine Tuning Advisor is basically a tool that helps you figure
out if additional indexes are helpful as well as partitioning. Here is a
summary of the options:
• Adding indexes (clustered, non-clustered, and indexed views)
• Adding partitioning
• Adding statistics including multi-column statistics which are not created
automatically even when you have the AUTO_CREATE_STATISTICS database option
set to ON
Assignments
• Simply ENJOY 
Thank You

You might also like