|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. Or a report that used to take a few minutes to run now takes an hour. As I mentioned these issues usually arise from user complaints, but with a few steps and techniques you can monitor these issues and tune accordingly, so that your database applications are always running at peak performance.
In this tutorial we will cover some of the common issues with performance such as:
- missing and unused indexes
- I/O bottlenecks
- poor query plans
- wait stats
We will look at basic techinques 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
With the introduction of SQL Server 2005, Microsoft introduced Dynamic Management Views (DMVs) which allow you to get better insight into what is happening in SQL Server. Without these new tools a lot of the information was unavailable or very difficult to obtain.
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.
The DMVs were introduced in SQL 2005 and with each new release, Microsoft has been adding additional DMVs to help troubleshoot issues. DMVs actually come in two flavors DMVs (dynamic management views) and DMFs (dynamic management functions) and are sometimes classified as DMOs (dynamic management objects). The DMVs act just like any other view where you can select data from them and the DMFs require values to be passed to the function just like any other function.
The DMVs are broken down into the following categories:
- Change Data Capture Related Dynamic Management Views
- Change Tracking Related Dynamic Management Views
- Common Language Runtime Related Dynamic Management Views
- Database Mirroring Related Dynamic Management Views
- Database Related Dynamic Management Views
- Execution Related Dynamic Management Views and Functions
- Extended Events Dynamic Management Views
- Full-Text Search Related Dynamic Management Views
- Filestream-Related Dynamic Management Views (Transact-SQL)
- I/O Related Dynamic Management Views and Functions
- Index Related Dynamic Management Views and Functions
- Object Related Dynamic Management Views and Functions
- Query Notifications Related Dynamic Management Views
- Replication Related Dynamic Management Views
- Resource Governor Dynamic Management Views
- Service Broker Related Dynamic Management Views
- SQL Server Operating System Related Dynamic Management Views
- Transaction Related Dynamic Management Views and Functions
- Security Related Dynamic Management Views
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
Here are some additional articles about DMVs.
- Dynamic Management Views and Functions in SQL Server 2005
- Understanding Catalog Views in SQL Server 2005 and 2008
- Additional DMV tips
There are several factors that can degrade SQL Server performance and in this section we will investigate some of the common areas that can effect performance. We will look at some of the tools that you can use to identify issues as well as review some possible remedies to fix these performance issues.
We will cover the following topics:
- Role of statistics
- Query Tuning Bookmark Lookups
- Query Tuning Index Scans