Επεξεργασία

Κοινή χρήση μέσω


Monitor SQL Server Components

Applies to: SQL Server

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:

  1. Determine your monitoring goals.
  2. Select the appropriate tool.
  3. Identify components to monitor.
  4. Select metrics for those components.
  5. Monitor the server.
  6. 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're 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:

  • Start Performance Monitor (Windows), which lets you collect and view real-time data about activities such as memory, disk, and processor usage.
  • Performance logs and alerts
  • Task Manager

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:

Important

SQL Trace and SQL Server Profiler are deprecated. The Microsoft.SqlServer.Management.Trace namespace that contains the Microsoft SQL Server Trace and Replay objects are also deprecated.

This feature will be removed in a future version of SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

Use Extended Events instead. For more information on Extended Events overview, see Quickstart: Extended Events and Use the SSMS XEvent Profiler.

Note

SQL Server Profiler for Analysis Services workloads is NOT deprecated, and will continue to be supported.

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're 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 don't 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 haven't, 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.

  1. 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 on filtering Extended Event traces, see Quickstart: Extended Events.

    For more information on filtering SQL Trace, see Set a Trace Filter (Transact-SQL) and Filter Events in a Trace (SQL Server Profiler).

  2. Monitor (capture) events.

    As soon as it's 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 (Performance Monitor).

  3. Save captured event data.

    Saving captured event data lets you analyze it later. Captured event data that is saved to a file that can be loaded back into the tool that originally created it for analysis. Saving captured event data is important when you're creating a performance baseline. The performance baseline data is saved and used, when comparing recently captured event data, to determine whether performance is optimal.

    Extended Events permits event data to be saved to an event file, event counter, histogram, and ring buffer. For more information, see Targets for Extended Events.

    SQL Trace event data can even be replayed using the Distributed Replay Utility or SQL Server Profiler. SQL Server Profiler permits event data to be saved to a file or SQL Server table. For more information, see SQL Server Profiler Templates and Permissions.

  4. 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.

    An Extended Event session definition is a template that can be scripted and re-used. To create and manage sessions, see Manage Event Sessions in the Object Explorer. The Management Studio XEvent Profiler already provides templates that are ready to use. For more information, see Use the SSMS XEvent Profiler.

    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).

    Tip

    A SQL Trace definition can be converted to an Extended Event session. For more information, see Convert an Existing SQL Trace Script to an Extended Events Session.

  5. Analyze captured event data.

    To be analyzed, the captured event data is loaded into the application that captured the data.

    For example, a captured Extended Event trace can be reloaded into SQL Server Management Studio for viewing and analysis. For more information, see View event data in SQL Server Management Studio.

    SQL Trace data 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 Extended Events or SQL Server Profiler and make index recommendations based on the results.

  6. Replay captured event data (optional).

    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.