[Top] [Prev] [Next]

Chapter 6

Monitoring Tools and Configuration Utilities


Overview

System 11 is equipped with a comprehensive set of tools for monitoring, configuring, and tuning a SQL Server System. These tools are essential for establishing a fully functioning system, of course; but equally important, they are at the heart of SQL Server's ability to adapt to any enterprise requirements and offer consistent, high performance as those requirements change. This chapter gives an overview of the rich set of tools and utilities System 11 provides for customizing your computing environment. This chapter covers the following topics:

Tuning Resources

No RDBMS right out of the box can perform to its maximum potential for all possible applications without some adjustments for the computing environment. That's why a good RDBMS must include a set of performance tuning utilities and monitoring tools. Sybase offers numerous tools and aids for monitoring SQL Server performance so you can achieve the highest performance possible for your distributed client/server database system.

Database design, thorough query analysis, and appropriate indexing are the fundamental influences on system performance. However, beyond these factors, you can further optimize SQL Server in your specific environment. Sybase supports performance tuning in the following ways:

Monitoring Tools

When tuning SQL Server, the fundamental measures of success appear as increases in throughput and reductions in application response time. Unfortunately, tuning SQL Server cannot be reduced to printing these two values. In most cases, your tuning efforts must take an iterative approach involving a comprehensive overview of SQL Server activity, careful tuning and analysis of queries and applications, and monitoring locking and access on an object-by-object basis.

You can run monitoring tools both before and after tuning SQL Server configuration parameters to gather data for comparison. This data gives you a basis for performance tuning and lets you observe the results of configuration changes.

You can also use monitoring tools when the system exhibits the behavior you want to investigate. For example, if you are interested in finding out how the system behaves under typically loaded conditions in an OLTP environment, run monitoring tools both during the normal OLTP load and during batch jobs.

Various monitoring tools give you many ways to see how your system is behaving: SQL Server Monitor, SQL Server Historical Monitor, and the system procedures sp_monitor and sp_sysmon.

SQL Server Monitor

SQL Server Monitor is a performance-tuning tool that greatly simplifies the task of tracking down performance bottlenecks and verifying solutions. Figure 6-1 depicts a SQL Server Monitor environment.

Figure 6-1: Using SQL Server Monitor

Through a graphical user interface, SQL Monitor displays operating statistics such as:

You can take snapshots of SQL Server performance data before and after you tune, so you can track and verify that your tuning has the affect you expect it too. It also helps you determine if opening up one bottleneck has created another, a common occurrence in performance tuning.

SQL Monitor accesses server statistics through shared memory, so it has only a slight affect on SQL Server performance. Figure 6-2 shows a display of SQL Server performance trends.

Figure 6-2: SQL Monitor performance display

Monitor Historical Server

Monitor Historical Server is an Open Server application that attaches to SQL Server shared memory to obtain statistics of SQL Server performance.

As it runs, Monitor Historical Server collects performance data that SQL Server stores in shared memory. Monitor Historical Server stores the data so you can defer inspection and analysis until it is convenient for you.

sp_monitor

SQL Server keeps track of how much work it has done in a series of global variables. You can display the current values of some of these global variables with the system procedure sp_monitor.

sp_sysmon

The system procedure sp_sysmon is a tool that provides a comprehensive overview of system performance. Once you identify the area that seems to be responsible for poor performance, you can use SQL Server Monitor to pinpoint contention on a per-object basis.

sp_sysmon is a quick way to get lots of information about the SQL Server system. The following sample shows sp_sysmon output for the "Transaction Profile" section.

Transaction Profile

-------------------



  Transaction Summary          per sec   per xact    count  % of total

  -------------------------  ---------  ---------  -------  ----------

    Committed Xacts              120.1        n/a     7261     n/a





  Transaction Detail           per sec   per xact    count  % of total

  -------------------------  ---------  ---------  -------  ----------

    Inserts

      Heap Table                 120.1        1.0     7260     100.0 %

      Clustered Table              0.0        0.0        0       0.0 %

  -------------------------  ---------  ---------  -------

    Total Rows Inserted          120.1        1.0     7260      25.0 %



    Updates

      Deferred                     0.0        0.0        0       0.0 %

      Direct In-place            360.2        3.0    21774     100.0 %

      Direct Cheap                 0.0        0.0        0       0.0 %

      Direct Expensive             0.0        0.0        0       0.0 %

  -------------------------  ---------  ---------  -------

    Total Rows Updated           360.2        3.0    21774      75.0 %



    Deletes

      Deferred                     0.0        0.0        0       0.0 %

      Direct                       0.0        0.0        0       0.0 %

  -------------------------  ---------  ---------  -------

    Total Rows Deleted             0.0        0.0        0       0.0 %



Table 6-1 summarizes the SQL Server performance categories that sp_sysmon reports on.

Table 6-1: Monitoring categories for sp_sysmon

Category Description
Kernel utilization Reports on SQL Server activities. It tells you how busy SQL Server engines were during the time that the CPU was available to SQL Server, how often the CPU yielded to the operating system, the number of times that the engines checked for network and disk I/O, and the average number of I/Os they found waiting at each check.
Task management Provides information about open connections, task context switches by engine, and task context switches by cause.
Task context switches Summarizes causes for tasks switching off engines.
Transaction profile Reports on transaction-related activities, including the number of data modification transactions, user log cache (ULC) activity, and transaction log activity.
Transaction management Reports on transaction management activities, including user log cache (ULC) flushes to transaction logs, ULC log records, ULC semaphore requests, log semaphore requests, transaction log writes, and transaction log allocations.
Index management Reports on index management activity including nonclustered maintenance, page splits, and index shrinks.
Lock management Reports on locks, deadlocks, lock promotions, and freelock contention.
Data cache Reports summary statistics for all caches, and statistics for each named cache. It reports spinlock contention, utilization, cache searches including hits and misses, pool turnover for all configured pools, buffer wash behavior including buffers passed clean, already in I/O, and washed dirty, prefetch requests performed and denied, and dirty read page requests
Procedure cache Reports on the number of times stored procedures and triggers were requested, read from disk, and removed from cache.
Memory Reports on the number of pages allocated and deallocated during the sample interval.
Recovery Indicates the number of checkpoints caused by the normal checkpoint process, the number of checkpoints initiated by the housekeeper task, and the average length of time for each type. This information is helpful for setting the recovery and housekeeper parameters correctly
Disk I/O This category is useful when checking for I/O contention. It prints an overview of disk I/O activity: maximum outstanding I/Os, I/Os delayed, total requested I/Os, and completed I/Os. A second section includes output for the master device and for other configured devices, reporting reads, writes, and semaphore contention.
Network I/O Reports on network activities for each SQL Server engine.

Automated System Administration

Sybase offers two automated database managers for SQL Server; both have a sophisticated graphical user interface that greatly simplifies system administration tasks. SQL Server Manager handles all the routine system administration tasks. Backup Server takes care of all backup and restore.

SQL Server Manager

SQL Server Manager is a system and database administration tool for SQL Server. Its powerful collection of features and graphical user interface make exacting administrative tasks easy to perform. It can take care of many of the configuration tasks that you might otherwise perform manually using the sp_configure system procedure. SQL Server Manager helps with the following typical system or database administration tasks:

Figure 6-3 shows the SQL Server Manager interface.

Figure 6-3: SQL Server Manager simplifies administration

SQL Server Manager easily performs complicated system administration. Some of the special features that support this capability are:

Performance and Maintenance Utilities

SQL Server provides a wide variety of commands and system procedures for fine-tuning performance, many of which were introduced in the last chapter.

Query Tuning Options

New query tuning options support the capabilities of named caches and provide additional control when tuning queries:

Query Processing Options

set options can customize the execution of queries and display of results, show processing statistics, and provide other diagnostic aids for debugging Transact-SQL programs. Some of the set options are listed and described later in this chapter.

Transact-SQL lets you control how queries are processed with its set command, which turns query processing options on or off for the duration of a user's work session. The many set options are generally categorized as those that:

Table 6-2 lists some of the more frequently used set options for query processing and analysis.

Table 6-2: Frequently used set options

Option Effect
chained on | off When off, user explicitly initiates transactions with begin transaction command. When on, SQL Server begins a transaction just before the first data retrieval, data modification statement at the beginning of a session and after a transaction ends. (fetch also begins a transaction.).
close on endtran on | off When off, allows the cursor to remain open across transactions, improving performance. When on, SQL Server closes all cursors opened within a transaction at the end of that transaction.
cursor rows n Causes SQL Server to return the specified number of rows for each cursor fetch request from a client application.
nocount Turns off the display of the number of "rows affected" from a query that returns rows.
noexec Compiles each query but does not execute it.
parseonly Checks the syntax of each query and returns any error messages, without generating a sequence tree, compiling, or executing the query.
rowcount Causes SQL Server to stop processing the query after the specified number of rows is returned. To turn this option off so that all rows are returned, use set rowcount 0.
table count Sets the number of tables considered at one time while optimizing a join. This option can improve the optimization of certain join queries, but increases the compilation cost.
showplan Generates a description of the processing plan for the query. It is often used in conjunction with statistics io. showplan allows you to see whether the query uses the indexes that are in place; statistics io gives you an idea of the effectiveness of the indexes.
statistics io Displays the number of table scans, logical accesses (cache reads), and physical accesses (disk reads) for each table referenced in the statement. It also displays the number of pages written (including pages in the transaction log).
statistics time Displays the CPU time it took to parse and compile each command, and each step of the command.

The Database Options

sp_dboption controls the database options for a single database on SQL Server. Table 6-3 lists some of the most frequently used database options.

Table 6-3: Frequently used database options

Option Task
dbo use only Allows only the Database Owner to use the database.
ddl in tran Allows most Transact-SQL data definition language to be used inside a user-defined transaction.
no chkpt on recovery Used while loading database and transaction log dumps for standby servers.
read only Can be set on so that users can retrieve, but not modify, data from the database.
select into/bulkcopy Must be set on in order to perform certain operations.
single user Can be set on so that only one user at a time can access the database.
trunc log on chkpt Can be set on so that the transaction log is truncated (committed transactions are removed) every time the checkpoint checking process occurs (usually once per minute).

Global Variables

SQL Server tracks information in global variables that any user can query. Global variables are useful for decision-based processing. They are used in batches, stored procedures, triggers, and cursors. Table 6-4 lists some of the variables.

Table 6-4: Frequently referenced global variables

Variable Meaning
@@error Contains the last error number generated by the system. Often used to check the error status (succeed or fail) of the most recently executed statement. The statement: if @@error != 0 return causes an exit if an error occurs.
@@max_connections The maximum number of simultaneous connections that the operating system allows you to configure.
@@nestlevel Nesting level of current execution (initially zero). Each time a stored procedure or trigger calls another stored procedure or trigger, the nesting level is incriminated. If the maximum of 16 is exceeded, the transaction aborts.
@@procid Contains the stored procedure ID of the currently executing procedure.
@@rowcount Contains the number of rows affected by the last command. Useful for tracking cursor actions.
@@servername The name of this SQL Server.
@@textsize The maximum size in bytes of text or image data to be returned with a select statement.
@@total_read The number of disk reads by SQL Server.
@@total_write The number of disk writes by SQL Server.
@@trancount Contains the nesting level of begin transaction events for the current user.
@@version Contains information about the current version of SQL Server.
@@sqlstatus Indicates whether a cursor fetch encountered errors, succeeded, or reached the end of the result set.
@@rowcount Provides the cumulative number of rows returned to the client from the result set since the cursor was opened.
@@identity Retrieves the last value inserted into an IDENTITY column.

You can display the current values of some of these global variables with the system procedure sp_monitor.

System Procedures for Querying System Tables

The master database (SQL Server's controlling database) contains all of the SQL Server-supplied tables. Each user database is created with its own additional subset of system tables as well. System tables are alternatively referred to as the data dictionary or the system catalogs.

System tables are a rich source of information. You can query system tables just like any other tables. For example, the following statement returns the names of all the triggers in the database:

select name 

from sysobjects 

where type = "TR" 

Here is a list of SQL Server system procedures that make it easy to gather information from system tables.

Usage Information

Two system procedures report on CPU and I/O usage by SQL Server login name to provide information for chargeback accounting. The sp_reportstats system procedure prints information for an individual login name, or for all users if no login name is provided:

sp_reportstats

Name      Since       CPU    Percent CPU I/O    Percent I/O

--------  ----------- -----  ----------- -----  -----------

bea       Sep 15 1993    16  13.7931%       65  23.8970%

karenp    Sep 24 1993    37  31.8965%       53  19.4852%

fred      Sep 23 1993     6  5.1724%         4  1.4705%

wanda     Sep 17 1993    13  11.2069%       12  4.4117%

ruth      Sep 19 1993    27  23.2758%       96 35.2941%

robbie    Sep 20 1993    11  9.4827%         7  2.5735%

The system procedure sp_clearstats first runs sp_reportstats, and then clears the data from the system tables to initiate a new accounting period. The CPU and I/O data is stored in the syslogins system table.

Index Statistics

The update statistics command regenerates and stores information about the distribution of the key values in indexes. Using this command helps SQL Server make decisions about which indexes are best to use to process a specific query.

SQL Server's ability to optimize queries depends on the accuracy of distribution steps. When you create or re-create an index on a table that already contains data, SQL Server generates statistics about the density and distribution of keys in the index. If the data changes over time and affects the distribution of keys, you can run the update statistics on that index to re-generate the statistics and maintain good performance.

Configuration Parameters

The system procedure sp_configure gives you control over many aspects of SQL Server behavior, performance, and physical resource management.

System 11 lets you associate a display level to limit the amount of output SQL Server gives you. The three levels of display are: basic, intermediate, and comprehensive.

A user with a basic display level will see only a very small set of parameters. It is suitable for users who intend to adjust the following SQL Server parameters: recovery interval, number of devices, number of locks, number of open databases, number of open database objects, number of user connections, and stack size.

A user with an intermediate display level has the same capabilities as the user with a basic display level, but will see an additional 40 percent of the configuration parameters.

A user with a comprehensive display level will see all of the configuration parameters.

sp_configure's configuration parameters are preset to reasonable default values upon installation. Table 6-5 lists the sp_configure parameters and their effect.

Table 6-5: Configuration parameters

Category Parameter Name Effect
Backup and recovery print recovery information Sets a toggle that determines what information SQL Server sends to the error log during recovery.
recovery interval in minutes Sets the maximum number of minutes that SQL Server should use to recover each database in case of a system failure.
tape retention in days Sets the number of days to retain each tape used for a database or transaction log dump.
Cache manager memory alignment boundary Determines the boundary on which a cache is aligned.
number of index trips The number of times an aged index page traverses the MRU/LRU chain before it is swapped out.
number of oam trips The number of times an OAM page traverses the MRU/LRU chain before it is swapped out.
procedure cache percent Gives the percentage of memory allocated to the procedure cache after SQL Server's memory needs are met.
Disk I/O allow SQL Server async io A toggle that enables SQL Server to run with asynchronous disk I/O.
disk i/o structures Specifies the initial number of disk I/O control blocks SQL Server allocates on start-up.
number of devices Controls the number of database devices that SQL Server can use.
page utilization percent Used during page allocations to control whether SQL Server scans a table's OAM to find unused pages, or allocates a new extent to the table.
General information configuration file Specifies the location of the configuration file currently in use.
Languages default character set id Stores the number of the default character set used by the server.
default language id Reports the number of the language that is used to display system messages unless a user has chosen another language from those available on the server.
default sortorder id Reports the number of the sort order that is in use on this SQL Server.
number of languages in cache The maximum number of languages that can simultaneously be held in the language cache.
Lock manager address lock spinlock ratio Sets the ratio of spinlocks protecting the address locks hash table for SQL Servers running multiple engines.
deadlock checking period Specifies the minimum amount of time before SQL Server initiates a deadlock check for a process waiting for a lock to be released.
deadlock retries Applies to a situation in which SQL Server is trying to acquire a lock on an index page for a page split. Specifies the number of times that SQL Server retires to get the lock before giving up and going to sleep.
freelock transfer block size Specifies the number of locks moved between the engine freelock lists and the global freelock list.
max engine freelocks Maximum number of locks available to the engine freelock lists as a percentage of the total number of locks.
number of locks Sets the number of available locks.
page lock spinlock ratio Sets the ratio of spinlocks protecting the internal page locks hash table.
table lock spinlock ratio Sets the ratio of spinlocks protecting the internal table locks hash table.
Network communication allow remote access Determines whether users from remote servers can access this SQL Server.
default network packet size Sets the default size of network packets for all users on SQL Server.
max network packet size Sets the maximum network packet size that a client program can request.
max number network listeners Specifies the maximum number of network listeners allowed by SQL Server at one time.
number of remote connections Controls the limit on active connections initiated to and from this SQL Server.
number of remote logins Controls the number of active user connections from this SQL Server to remote servers.
number of remote sites Controls the number of simultaneous remote sites that can access this SQL Server.
remote server pre-read packets Controls the number of packets pre-read in connections with remote servers.
tcp no delay Toggles TCP packet batching.
Operating system resources max async i/os per engine Specifies the maximum number of asynchronous disk I/O requests that can be outstanding for a single engine at one time.
max async i/os per server Specifies the maximum number of asynchronous disk I/O requests that can be outstanding at any one time.
o/s async i/o enabled Indicates whether or not asynchronous disk I/O has been enabled at the operating system level.
o/s file descriptors Indicates the maximum per-process number of file descriptors configured for your operating system.
shared memory starting address Determines the virtual address at which SQL Server starts its shared memory region.
Physical memory additional network memory Allocates additional memory for clients that request packet sizes that are larger than the default packet size for the server.
lock shared memory Disallows swapping of SQL Server pages to disk and allows the operating system kernel to avoid the server's internal page locking code.
total memory Sets the size of memory, in pages, that SQL Server allocates from the operating system. The default varies according to platform.
Processors max online engines Controls the number of engines in a symmetric multiprocessor environment.
min online engines Not currently used.
SQL Server administration allow nested triggers Determines whether triggers can call other triggers (that is, be "nested") or not.
allow updates to system tables Allows system tables to be updated directly.
audit queue size Determines the number of audit records that the audit queue can hold.
cpu accounting flush interval Specifies how many machine clock ticks to accumulate before adding CPU usage data to syslogins for use in chargeback accounting statistics.
cpu grace time Specifies the maximum amount of time that a user process can run without yielding the CPU before SQL Server preempts and terminates it with a time slice error.
default database size Sets the default number of megabytes allocated to each new user database.
default fill factor percent Determines how full SQL Server makes each page when it creates an index on existing data (unless the user specifies some other value in the create index statement).
event buffers per engine Specifies the number of events per SQL Server engine that can be simultaneously monitored.
housekeeper free write percent Specifies the maximum percentage by which the housekeeper task can increase database writes.
identity burning factor Determines the percentage of potential IDENTITY column values made available in each block.
identity grab size Allows each SQL Server process to reserve a block of IDENTITY column values for inserts into tables that have an IDENTITY column.
i/o accounting flush interval Specifies how many disk I/Os to accumulate before flushing the data to syslogins for use in chargeback accounting.
i/o polling process count Specifies the maximum number of SQL Server processes run by SQL Server before the scheduler checks for disk and/or network I/O completions.
lock promotion HWM Sets the number of page locks permitted by a Transact-SQL command below which SQL Server never attempts to issue a table lock on the object. Use with lock promotion LWM.
lock promotion LWM Sets the number of page locks permitted by a Transact-SQL command below which SQL Server never attempts to issue a table lock on the object. Use with lock promotion HWM.
lock promotion PCT Sets the percentage of page locks permitted by a Transact-SQL command before SQL Server attempts to issue a table lock on the table.
number of alarms Specifies the number of alarm structures allocated by SQL Server.
number of extent I/O buffers Allocates the specified number of extents (eight data pages) for I/O use by create index.
number of mailboxes Specifies the number of mailbox structures allocated by SQL Server.
number of messages Specifies the number of message structures allocated by SQL Server.
number of open databases Sets the maximum number of databases that can be open at one time on SQL Server.
number of open objects Sets the maximum number of database objects that can be open at one time on SQL Server.
number of pre-allocated extents Specifies the number of extents (eight pages) allocated in a single trip to the page manager.
number of sort buffers Specifies the number of buffers used to hold pages read from input tables for create index.
print deadlock information Enables printing of deadlock information to the error log.
runnable process search count Specifies the number of times an engine loops looking for a runnable task before relinquishing to the CPU.
partition groups Specifies how many partition groups to allocate for SQL Server.
partition spinlock ratio Specifies the ratio of spinlocks to internal partition caches.
size of auto identity column Sets the precision of IDENTITY columns automatically created with the sp_dboption "auto identity" option.
sort page count Specifies the maximum amount of memory a create index operation can use.
SQL Server clock tick length Specifies the duration of the server's clock tick.
time slice Sets the number of milliseconds that a user process is allowed to run by SQL Server's scheduler.
User environment number of user connections Sets the maximum number of user connections that can be connected to SQL Server at the same time. The global variable @@max_connections stores the maximum values for your system; it varies according to platform and operating system.
permission cache entries Determines the number of cache protectors per task.
stack guard size Sets the size of the stack guard area.
stack size Sets the size of SQL Server's stack.
systemwide password expiration Is the number of days that passwords remain in effect after they are changed.
user log cache size Specifies the size for each user's log cache.
user log cache spinlock ratio Specifies the ratio of user log caches per user log cache spinlock.



[Top] [Prev] [Next] [Bottom]