1. Trang chủ
  2. » Công Nghệ Thông Tin

Microsoft SQL Server 2008 R2 Unleashed- P236 ppsx

10 110 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 546,53 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

CHAPTER 55 Configuring, Tuning, and Optimizing SQL Server Options are limited to that maximum number of user connections until you specify a larger value.. CHAPTER 55 Configuring, Tuning

Trang 1

CHAPTER 55 Configuring, Tuning, and Optimizing SQL Server Options

are limited to that maximum number of user connections until you specify a larger value

If you specify a value other than0, the memory allocation for user connections is allocated

at SQL Server startup time, and it burns up portions of the memory pool Each connection

takes up 40KB of memory space For instance, if you configure SQL Server for 100

connec-tions, SQL Server pre-allocates 4MB (40KB× 100) for user connections You can see that

setting this value too high might eventually impact performance because the extra

memory could instead be used to cache data In general, user connections are best left to be

self-configuring

The following is an example of this option:

exec sp_configure ‘user connections’, 300

go

RECONFIGURE

go

In Figure 55.6, you can see the current setting of 0(unlimited) for the user connections

value within SSMS If you plan to set this option, the value must be between 5and

32,767

FIGURE 55.6 The Connections page of the Server Properties dialog in SSMS

Trang 2

user options

Type: Basic

Default value: 0

Theuser optionsparameter allows you to specify certain defaults for all the options

allowed with the SETT-SQL command Individual users can override these values by using

theSETcommand You are essentially able to establish these options for all users unless

the users override them for their own needs User optionsis a bitmask field, and each bit

represents a user option Table 55.1 outlines the values you can set with this parameter

TABLE 55.1 SpecifyingUser Options Values

Bitmask

Value

Description

1 DISABLE_DEF_CNST_CHKcontrols interim/deferred constraint checking

2 IMPLICIT_TRANSACTIONScontrols whether a transaction is started implicitly when

a statement is executed

4 CURSOR_CLOSE_ON_COMMITcontrols the behavior of cursors after a commit has

been performed

8 ANSI_WARNINGScontrols truncation and nulls in aggregate warnings

16 ANSI_PADDINGcontrols padding of fixed-length variables

32 ANSI_NULLScontrols null handling when using equality operators

64 ARITHABORTterminates a query when an overflow or divide-by-zero error occurs

during query execution

128 ARITHIGNOREreturns NULLwhen an overflow or divide-by-zero error occurs during a

query

256 QUOTED_IDENTIFIERdifferentiates between single and double quotation marks

when evaluating an expression

512 NOCOUNTturns off the message returned at the end of each statement that states

how many rows were affected by the statement

1024 ANSI_NULL_DFLT_ONalters the session’s behavior to use ANSI compatibility for

nullability New columns that are defined without explicit nullability are defined to

allowNULLvalues

2048 ANSI_NULL_DFLT_OFFalters the session’s behavior to not use ANSI compatibility

for nullability New columns defined without explicit nullability are defined not to

allowNULLvalues

Trang 3

CHAPTER 55 Configuring, Tuning, and Optimizing SQL Server Options

For a given user connection, you can use the @@optionsglobal variable to see the values

that have been set

The following is an example of this option:

exec sp_configure ‘user options’, 256

go

RECONFIGURE

Go

Again, a user can override these values with the SETcommand during a session

XP-Related Configuration Options

Type: Advanced

Default: 0

A handful of advanced options are available with SQL Server 2008 to more granularly

address the execution of extended stored procedures within different SQL server

components:

Agent XPs

Database Mail XPs

Replication XPs Option

SMO and DMO XPs

SQL Mail XPs

xp_cmdshell

Each of these options defaults to 0, which means external stored procedures for these areas

are not available in the instance If you enable these options, you should fully understand

that doing so opens these extended stored procedures to all on the instance

As SQL Server 2008 expands in use, some of these options will probably be highlighted in

more detail as more real-world examples support their use and attention

TABLE 55.1 SpecifyingUser Options Values

Bitmask

Value

Description

4096 CONCAT_NULL_YIELDS_NULLhas SQL Server return a NULLwhen concatenating a

NULLvalue with a string

8192 NUMERIC_ROUNDABORThas SQL Server generate an error if loss of precision ever

occurs in an expression

16344 XACT_ABORThas SQL Server roll back a transaction if a T-SQL statement raises a

runtime error

Trang 4

Database Engine Tuning Advisor

Database Engine Tuning Advisor is a decent supplement for the SQL Server performance

options It is not the hottest offering from Microsoft, but it can be valuable in enforcing

some basic design options in regard to partitioning, indexing, and basic table structures

You can use either the GUI version of the DTA or the batch command-line version to

achieve the same results With DTA, you can run an analysis against an entire database or

just focus on as little as one table within a database Say that you have one problem child

table that is at the heart of all your misery In this case, you would probably just want to

tune that one table for optimal database access

To tune and analyze anything, DTA must base its analysis on something That something

is usually a set of SQL queries that represent the “workload” of data accesses you want the

database to support well These data accesses (that is, the workload) can be attained in

many ways One way is to create a SQL script that contains any or all of the data accesses

you want considered in the tuning effort; another is to simply capture real SQL

transac-tions by using SQL Profiler traces You can easily retain these traces in .trcfile form or

keep the captured SQL traces in a SQL table In the example you are about to run, a SQL

trace was done against the AdventureWorksdatabase and stored in table form (in SQL

Server) You will see how to use this captured workload representation in the next section

Let’s first look at the GUI version

The Database Engine Tuning Advisor GUI

From the Tools menu in SSMS, you can select the Database Engine Tuning Advisor option

to invoke the GUI for DTA (You can also invoke this GUI by selecting Start, All Programs,

Microsoft SQL Server 2008, Performance Tools, Database Engine Tuning Adviser Program

from your desktop.) You are asked to initiate a new session for doing database tuning

analysis

NOTE

It’s best not to run the DTA against a live production database You should make a

copy of the database in a safe place for this type of detailed analysis You should use

a copy of the production database, though, because you want all decisions to be based

on reality, and your workload should also reflect true production data accesses

When you are connected to the target SQL Server platform, a default for a session name

appears; it is the user’s name and the date on which the analysis is being done Figure 55.7

shows this new session start and the specification of what workload to use for the analysis

As you can also see in Figure 55.7, you specify a workload location where you have stored

the SQL traces that are to be used for the analysis This can be to a file or table location;

DTA Example trace ASDB.trc in this example You then specify AdventureWorksas the

database for workload analysis to start in Any USEdatabase commands in the trace (or

script) would be executed, but you want this analysis to start in a certain place Then you

select the database to tune from the bottom list of databases (again, the AdventureWorks

Trang 5

ptg CHAPTER 55 Configuring, Tuning, and Optimizing SQL Server Options

FIGURE 55.7 Database Engine Tuning Advisor new session setup

database in this example) If you click the Selected Tables drop-down for the

AdventureWorksdatabase, as shown in Figure 55.8, you could further limit what you want

to tune down to an individual table level In this example, you tune the entire database

You then click the Tuning Options tab to select exactly what you want to tune for Figure

55.9 shows the various tuning options

For this example, you tune all indexes, use no partitioning, and keep all existing physical

data structures as the first tuning analysis you want the DTA to do Someday, Microsoft

FIGURE 55.8 Database Engine Tuning Advisor selected tables for tuning

Trang 6

FIGURE 55.9 Database Engine Tuning Advisor tuning options to use for this session

will triple the tuning types here, but for now, the offerings are limited The Advanced

Options button allows you to specify the maximum number of columns that could be

contained in a new index recommendation (1,023 columns), whether DTA should

gener-ate only SQL DDL that can be executed online, and the maximum space that DTA can

utilize for physical structure changes The defaults for these settings are typically

suffi-cient Now, you simply click the Start Analysis menu item (the one with a little green right

arrow next to it) or choose Actions, Start Analysis option Figure 55.10 shows the

execu-tion progress of this analysis session

FIGURE 55.10 Database Engine Tuning Advisor tuning execution progress and tuning log

Trang 7

CHAPTER 55 Configuring, Tuning, and Optimizing SQL Server Options

The tuning log shows the SQL events, actual statements, and frequency of these

state-ments (that is, the number of times the same SQL was processed) This information sheds

some light on the mix of SQL hitting this database When the progress is complete, a

Recommendations tab and a Reports tab appear for this session (see Figure 55.11) Here,

the DTA says that an estimated improvement of 24% can be gained if the

recommenda-tions it is advising are followed Because you wanted only index recommendarecommenda-tions, you

don’t see any partitioning recommendations However, there are a few index

recommen-dations for several tables based on the workload provided by the SQL Profiler trace file

The Reports tab shows the summary of the tuning session and all the tuning reports

generated In the Tuning Reports section at the bottom of Figure 55.12, you can see the

index usage report (recommended) There are several reports, ranging from detailed index

recommendations to workload analysis reports

At any time, you can choose to preview the workload of the file or table you specified for

the analysis You simply choose View, Preview Workload Table or View, Preview Workload

File, and SQL Profiler is invoked with your SQL trace

If you are satisfied with the recommendations of any one of your tuning sessions, you can

choose to have them saved to a .sqlfile and scheduled to be applied at some later time,

or you can apply them immediately by selecting Actions, Apply Recommendations or

Actions, Save Recommendations

It’s that simple

TIP

If you regularly run the DTA with a good sampling of your typical transaction workload,

you can proactively identify potential changes that will keep your application humming

FIGURE 55.11 The Database Engine Tuning Advisor Recommendations tab following analysis

Trang 8

FIGURE 55.12 Index Usage report (recommended)

The Database Engine Tuning Advisor Command Line

DTA is also available in a batch mode so that you don’t have to be around to run it online

(because doing so can often take hours if you have a large workload to analyze) In

addi-tion, this mode allows you to run the same tests over and over, with varying options You

can easily view DTA command-line options by using the help option of the command

itself (that is, the -?option) You simply run this option at the command line and have its

output piped into a file for viewing in Notepad (or another editor):

C:> DTA -? > dta.out

Microsoft (R) SQL Server Microsoft SQL Server Database Engine

Tuning Advisor command line utility

Version 10.50.1352.12 ((KJ_PreRelease).091030-1758 )

Copyright(c) Microsoft Corporation All rights reserved.

Usage:

DTA.EXE [-S ServerName[\Instance]]

[-U LoginId]

[-P Password]

[-E]

[-d DatabaseName]

[-D DatabaseName[, DatabaseName]]

[-Tl TableName[, TableName]]

[-Tf TableListFileName]

[-if WorkloadFileName]

[-it WorkloadTableName]

[-s SessionName]

[-of [ScriptFileName]]

[-or [ReportFileName]]

Trang 9

CHAPTER 55 Configuring, Tuning, and Optimizing SQL Server Options

[-rl Report[, Report]]

[-ox [OutputXmlFileName]]

[-F]

[-ID SessionID]

[-ix InputXmlFileName]

[-A TuningTime]

[-n NumberOfEvents]

[-m MinimumImprovement]

[-fa PhysicalDesignStructure]

[-fp PartitionStrategy]

[-fk PhysicalDesignStructure]

[-fx]

[-B StorageSize]

[-c MaxKeyColumnsInIndex]

[-C MaxColumnsInIndex]

[-e TuningLogTable]

[-N OnlineOption]

[-q]

[-u]

[-x]

[-a]

[-?]

This output has the following components:

-S ServerName[\Instance]—Indicates the name of the SQL Server instance with

which to connect This is the server against which all tuning analysis and supporting

table updates will be made

-U LoginId—Indicates the login ID to use in establishing a connection to SQL

Server (specified via the -Soption)

-P Password—Specifies the password for the specified login ID.

-E—Uses a trusted connection to connect to the server.

-d DatabaseName—Identifies the database to connect to when tuning.

-D DatabaseName—Provides a list of database names for tuning Names are

sepa-rated by commas

-Tl TableName—Provides a list of table names that should be tuned Names are

separated by commas If only one database is specified through the -Doption, table

names do not need to be qualified with the database name Otherwise, the fully

qualified name, in the form [Database].[Schema].[Table], is required for each

table

-Tf TableListFileName—Indicates the name of a file containing the list of tables

to be tuned Tables listed within the file must appear on separate lines, and the

names must be qualified by database name and, optionally, by schema name The

Trang 10

optional table-scaling feature may be invoked by following the name of a table with

a number that indicates the projected number of rows in that table (for example,

’[myDatabase].[dbo].[myTable] 500’)

-if WorkloadFileName—Specifies the path and filename of the workload file to

use as input for tuning These are the accepted formats:

*.trc—SQL Server Profiler trace file.

*.xml—SQL Server Profiler XML trace file.

*.sql—SQL Server script.

-it WorkloadTableName—Indicates the name of the table containing the workload

trace for tuning The name is specified as [Database].[Schema].[Table]

-s SessionName—Specifies the name of the new tuning session.

-of ScriptFileName—Indicates that T-SQL script with recommendations should

be written to a file If a filename is supplied, the recommendations are written to

that destination; otherwise, the filename is generated based on the session name

-or ReportFileName—Indicates that the report should be written to a file If a

file-name is supplied, the report is written to that destination; otherwise, the filefile-name is

generated based on the session name

-rl Report—Specifies the list of analysis reports to generate You select one or more

of the following:

ALL—Generate all reports.

NONE—Do not generate any reports.

STMT_COST—Statement cost report.

EVT_FREQ—Event frequency report.

STMT_DET—Statement detail report.

CUR_STMT_IDX—Statement-index relations report (current).

REC_STMT_IDX—Statement-index relations report (recommended).

STMT_COSTRANGE—Statement cost range report.

CUR_IDX_USAGE—Index usage report (current).

REC_IDX_USAGE—Index usage report (recommended).

CUR_IDX_DET—Index detail report (current).

REC_IDX_DET—Index detail report (recommended).

VIW_TAB—View-table relations report.

WKLD_ANL—Workload analysis report.

DB_ACCESS—Database access report.

Ngày đăng: 05/07/2014, 02:20

TỪ KHÓA LIÊN QUAN