Monitoring is important because SQL Server provides a service in a dynamic environment. The data in the application changes. The type of access that users require changes. The way that users connect changes. The types of applications accessing SQL Server may even change, but SQL Server automatically manages system-level resources, such as memory and disk space, to minimize the need for extensive system-level manual tuning. Monitoring lets administrators identify performance trends to determine if changes are necessary.
To monitor any component of SQL Server effectively:
Determine your monitoring goals.
Select the appropriate tool.
Identify components to monitor.
Select metrics for those components.
Monitor the server.
Analyze the data.
These steps are discussed in turn below.
Determine Your Monitoring Goals
To monitor SQL Server effectively you should clearly identify your reason for monitoring. Reasons can include the following:
Establish a baseline for performance.
Identify performance changes over time.
Diagnose specific performance problems.
Identify components or processes to optimize.
Compare the effect of different client applications on performance.
Audit user activity.
Test a server under different loads.
Test database architecture.
Test maintenance schedules.
Test backup and restore plans.
Determining when to modify your hardware configuration.
Select the Appropriate Tool
After determining why you are monitoring, you should select the appropriate tools for that type of monitoring. The Windows operating system and SQL Server provide a complete set of tools to monitor servers in transaction-intensive environments. These tools clearly reveal the condition of an instance of the SQL Server Database Engine or an instance of SQL Server Analysis Services.
Windows provides the following tools for monitoring applications that are running on a server:
System Monitor, which lets you collect and view real-time data about activities such as memory, disk, and processor usage
Performance logs and alerts
For more information about Windows Server or Windows tools, see the Windows documentation.
SQL Server provides the following tools for monitoring components of SQL Server:
SQL Server Profiler
Distributed Replay Utility
SQL Server Management Studio Activity Monitor
SQL Server Management Studio Graphical Showplan
Database Console Commands (DBCC)
For more information about SQL Server monitoring tools, see Performance Monitoring and Tuning Tools.
Identify the Components to Monitor
The third step to monitoring an instance of SQL Server is to identify the components that you monitor. For example, if you are using SQL Server Profiler to trace a server you can define the trace to collect data about specific events. You can also exclude events that do not apply to your situation.
Select Metrics for Monitored Components
After identifying the components to monitor, determine the metrics for components you monitor. For example, after selecting the events to include in a trace, you can choose to include only specific data about the events. Limiting the trace to data that is relevant to the trace minimizes the system resources required to perform the tracing.
Monitor the Server
To monitor the server, run the monitoring tool that you have configured to gather data. For example, after a trace is defined, you can run the trace to gather data about events raised in the server.
Analyze the Data
After the trace has finished, analyze the data to see if you have achieved your monitoring goal. If you have not, modify the components or metrics that you used to monitor the server.
The following outlines the process for capturing event data and putting it to use.
Apply filters to limit the event data collected.
Limiting the event data allows for the system to focus on the events pertinent to the monitoring scenario. For example, if you want to monitor slow queries, you can use a filter to monitor only those queries issued by the application that take more than 30 seconds to run against a particular database. For more information, see Set a Trace Filter (Transact-SQL) and Filter Events in a Trace (SQL Server Profiler).
Monitor (capture) events.
As soon as it is enabled, active monitoring captures data from the specified application, instance of SQL Server, or operating system. For example, when disk activity is monitored using System Monitor, monitoring captures event data, such as disk reads and writes, and displays it on the screen. For more information, see Monitor Resource Usage (System Monitor).
Save captured event data.
Saving captured event data lets you analyze it later or even replay it using the Distributed Replay Utility or SQL Server Profiler. Captured event data is saved to a file that can be loaded back into the tool that originally created it for analysis. SQL Server Profiler permits event data to be saved to a SQL Server table. Saving captured event data is important when you are creating a performance baseline. The performance baseline data is saved and used, when comparing recently captured event data, to determine whether performance is optimal. For more information, see SQL Server Profiler Templates and Permissions.
Create trace templates that contain the settings specified to capture the events.
Trace templates include specifications about the events themselves, event data, and filters that are used to capture data. These templates can be used to monitor a specific set of events later without redefining the events, event data, and filters. For example, if you want to frequently monitor the number of deadlocks, and the users involved in those deadlocks, you can create a template defining those events, event data, and event filters; save the template; and reapply the filter the next time that you want to monitor deadlocks. SQL Server Profiler uses trace templates for this purpose. For more information, see Set Trace Definition Defaults (SQL Server Profiler) and Create a Trace Template (SQL Server Profiler).
Analyze captured event data.
To be analyzed, the captured event data is loaded into the application that captured the data. For example, a captured trace from SQL Server Profiler can be reloaded into SQL Server Profiler for viewing and analysis. For more information, see View and Analyze Traces with SQL Server Profiler.
Analyzing event data involves determining what is occurring and why. This information lets you make changes that can improve performance, such as adding more memory, changing indexes, correcting coding problems with Transact-SQL statements or stored procedures, and so on, depending on the type of analysis performed. For example, you can use the Database Engine Tuning Advisor to analyze a captured trace from SQL Server Profiler and make index recommendations based on the results.
Replay captured event data.
Event replay lets you establish a test copy of the database environment from which the data was captured, and then repeat the captured events as they occurred originally on the real system. This capability is only available with the Distributed Replay Utility or SQL Server Profiler. You can replay the events at the same speed as they originally occurred, as fast as possible (to stress the system), or more likely, one step at a time (to analyze the system after each event has occurred). By analyzing the exact events in a test environment, you can prevent harm to the production system. For more information, see Replay Traces.