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

Hướng dẫn học Microsoft SQL Server 2008 part 96 doc

10 111 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 764,71 KB

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

Nội dung

To disallowremote access, uncheck the ‘‘Allow remote connections to this server’’ check box in Management Studio in the Server Properties Connections tab refer to Figure 39-8 or set ther

Trang 1

Server will not execute it By default, the query governor cost limit option is set to 0 This value allows

all queries to execute, no matter how long they will take

The query governor cost limit option will not abort queries with an estimated duration

of less than the limit but a longer actual duration.

In Management Studio, thequery governor cost limitconfiguration option can be set by typing

the limit in the ‘‘Use query governor to prevent long-running queries’’ box in the Server Properties

Con-nections tab (refer to Figure 39-8)

The following code sets thequery governor cost limitto 300 seconds for the entire server:

EXEC sp_configure ‘show advanced options’, 1;

RECONFIGURE;

EXEC sp_configure ‘query governor cost limit’, 300;

RECONFIGURE;

In code, the query governor can also be changed for the current connection The following code

over-rides the currently configuredquery governor cost limitvalue for the current connection and sets

it to 15 seconds:

SET QUERY_GOVERNOR_COST_LIMIT 15;

The query governor cost limit option can be used to stop long-running queries before they start, thereby helping to prevent system resources from being consumed by these long-running queries.

Remote access

Theremote accessoption allows running local stored procedures from remote servers or remote

stored procedures from the local server By default, theremote accessoption is enabled

The remote access option applies only to servers added using sp_addserver and is included for backward compatibility Using this feature is not recommended, as it will be removed in the next version of Microsoft SQL Server Use the sp_addlinkedserver feature instead.

To disallowremote access, uncheck the ‘‘Allow remote connections to this server’’ check box in

Management Studio in the Server Properties Connections tab (refer to Figure 39-8) or set theremote

accessoption to0in code:

EXEC sp_configure ‘remote access’, 0;

RECONFIGURE;

The SQL Server service must be restarted in order for theremote accessoption to take effect

Remote login timeout

Theremote login timeoutconfiguration option specifies the number of seconds to wait before

returning from a failed attempt to connect to a remote SQL Server The default value forremote

login timeoutis 20 seconds

In Management Studio, set theremote login timeoutoption by entering the new timeout, in

seconds, in the ‘‘Remote login timeout’’ box in the Server Properties Advanced tab (refer to Figure 39-9

later in the chapter)

Trang 2

EXEC sp_configure ‘remote login timeout’, 30;

RECONFIGURE;

To cause an indefinite wait, you can change the value for the remote login timeout

option to 0.

Remote query timeout

Theremote query timeoutoption sets the number of seconds SQL Server will wait on a remote

query before assuming it failed and generating a timeout error The default value of 600 seconds (10

minutes) seems sufficient for executing a remote query:

EXEC sp_configure ‘remote query timeout’, 600;

RECONFIGURE;

In Management Studio, you can set theremote query timeoutoption by entering the desired time

in the ‘‘Remote query timeout (in seconds, 0 = no timeout)’’ box in the Server Properties Connections

tab (refer to Figure 39-8)

Enforce DTC

When updating multiple servers within a transaction (logical unit of work), SQL Server can enforce

dual-phase commits using the Microsoft Distributed Transaction Coordinator

From code, the Enforce DTC property is enabled by setting theremote proc transoption to1:

EXEC sp_configure ‘remote proc trans’, 1;

RECONFIGURE;

In Management Studio, theremote proc transoption can be set by checking the ‘‘Require

dis-tributed transactions for server-to-server communication’’ box in the Server Properties Connections tab

(refer to Figure 39-8)

We don’t recommend using this feature in new development work, as it will be removed

in the next version of Microsoft SQL Server Plan to modify applications that currently use

this feature, and use the sp_addlinkedserver feature instead.

Transactions are explained in Chapter 66, ‘‘Managing Transactions, Locking, and Blocking.’’

Network packet size

Packets are blocks of information sent over the network to transfer requests and results between clients

and servers The network packet size may be changed from its default of 4KB by means of thenetwork

packet sizeoption However, very rarely should network packet size need reconfiguring Consider

this property a fine-tuning tool and use it only when the data being passed tends to greatly exceed the

default size, such as large text or image data

In Management Studio, thenetwork packet sizeoption can be set by entering the new size (in

bytes) in the ‘‘Network packet size’’ box in the Server Properties Advanced tab (refer to Figure 39-9 later

in the chapter)

Trang 3

FIGURE 39-9

Advanced tab of Management Studio’s SQL Server Properties dialog

The following code sets the network packet size to 2KB:

EXEC sp_configure ‘network packet size’, 2048;

RECONFIGURE;

The sys.dm_exec_connections dynamic management view contains information about the network packet size (the column named net_packet_size) used for information and data transfer.

Advanced server-configuration properties

The advanced server-configuration properties, shown in Table 39-6, enable you to set advanced SQL

Server configuration options

The Advanced tab of Management Studio’s Server Properties dialog (see Figure 39-9) is used to view or

modify these settings

Trang 4

Advanced Server-Configuration Properties

Filestream Access

Level

S Management Studio EXEC sp_configure ‘filestream

access level’

Extensible Key

Management

provider enabled’

Default Full-text

Language

S Management Studio EXEC sp_configure ‘default

full-text language’

Default Language S Management Studio EXEC sp_configure ‘default

language’

Two-Digit Year Cutoff S Management Studio EXEC sp_configure ‘two digit

year cutoff’

Max Text Replication

Size

S Management Studio EXEC sp_configure ‘max text

repl size’

* The configuration level refers to Server, Database, or Connection.

Filestream access level

SQL Server 2008 introduces a new feature called Filestream that enables the storing of structured data

in the database, and the storing of associated unstructured (i.e., BLOB) data such as text documents,

images, and videos directly in the NTFS file system By default, Filestream is not enabled You can

enable it during the SQL Server 2008 installation in the Database Engine Configuration page of the

setup You can also enable the Filestream feature after installation using the SQL Server Configuration

Manager as follows:

1 Open SQL Server Configuration Manager from Start➪ Programs ➪ Microsoft SQL Server 2008

➪ Configuration Tools ➪ SQL Server Configuration Manager

2 Click SQL Server Services under SQL Server Configuration Manager.

3 Right-click the SQL Server service (on the right-hand side) for which you want to enable

Filestream and select Properties

4 Click the Filestream tab (see Figure 39-10) and select the ‘‘Enable Filestream for Transact-SQL

access’’ check box

If you want to read and write Filestream data from Windows, select the ‘‘Enable Filestream

for file I/O streaming access’’ check box Enter the name of the Windows share in which the

Filestream data will be stored in the ‘‘Windows Share Name’’ box

If you want to allow remote clients to access the Filestream data stored on this share, select

‘‘Allow remote clients to have streaming access to Filestream data.’’

5 Click Apply.

Trang 5

FIGURE 39-10

Enable the Filestream feature using SQL Server Configuration Manager

After enabling Filestream during setup or by using SQL Server Configuration Manager, the next step is

to configure it in SQL Server using thefilestream_access_levelconfiguration option The

possi-ble Filestream access settings are as follows:

■ 0: Disable Filestream support for this SQL Server instance

■ 1: Enable Filestream for Transact-SQL access only

■ 2: Enable Filestream for Transact-SQL and Win32 streaming access The following example configures Filestream for both Transact-SQL and Win32 streaming access:

EXEC sp_configure ‘filestream_access_level’, 2;

RECONFIGURE;

Extensible Key Management

The Extensible Key Management (EKM) feature in SQL Server 2008 enables third-party EKM and

hard-ware security module vendors to register their devices in SQL Server This capability makes it possible

for DBAs to use third-party EKM products along with SQL Server’s built-in encryption

The EKM feature is available only on Enterprise, Developer, and Evaluation editions of SQL Server 2008 Trying to enable this option on other editions will result in an error By default, the EKM feature is 0 ( OFF ) for all editions.

Trang 6

EXEC sp_configure ‘show advanced options’, 1;

RECONFIGURE;

EXEC sp_configure ‘EKM provider enabled’, 1;

RECONFIGURE;

Default full-text language

The default language for full-text index columns can be set using thedefault full-text language

configuration option Linguistic analysis of full-text indexed data varies according to the language of

the data

The default value for the default full-text language option is the language of the SQL

Server instance In addition, the default value set by this option only applies when no

lan-guage is indicated in the CREATE or ALTER FULLTEXT INDEX statement.

In Management Studio, thedefault full-text languageconfiguration option can be set by

speci-fying the local identifier (lcid) for the language you want, as listed in the sys.fulltext_languages

table in the ‘‘Default full-text language’’ box in the Server Properties Advanced tab (refer to

Figure 39-9)

The following example sets thedefault full-text languageoption to U.S English using T-SQL

code:

EXEC sp_configure ‘show advanced options’, 1;

RECONFIGURE;

EXEC sp_configure ‘default full-text language’, 1033;

RECONFIGURE;

In this case, the value of1033refers to U.S English You need to change this value only when you

need to support something other than the default system language

Many of the language settings in SQL Server rely on a locale identifier (LCID).

You can find a list of common LCID values at http://krafft.com/scripts/

deluxe-calendar/lcid chart.htm

The details of full-text search are discussed in Chapter 19, ‘‘Using Integrated Full-Text

Search.’’

Default language

The default language for all newly created logins can be set in both Management Studio and code using

thedefault languageconfiguration option The default language is used both for messages from

the server and for formatting dates It can be overridden by the CREATE LOGINorALTER LOGIN

statement

In Management Studio, set thedefault languageconfiguration option by selecting the language

from the ‘‘Default language’’ drop-down list in the Server Properties Advanced tab (refer to Figure 39-9)

Trang 7

From code, set thedefault languageconfiguration option by specifying the unique language ID of

the language you want, as listed in thesys.syslanguagestable For example, to set the default

lan-guage to British English, first query thesys.syslanguagestable to get the language ID for British

English Then use the language ID as shown here:

EXEC sp_configure ‘default language’, 23;

RECONFIGURE;

The language for a session can be changed during the session with the SET LANGUAGE statement.

Two-digit-year cutoff

The two-digit-year cutoff converts a two-digit year to a four-digit year based on the values supplied The

default time span for SQL Server is 1950–2049, which represents a cutoff year of 2049 If the two-digit

year falls on or after the first value (default50), then it is interpreted as being in the twentieth century

If it falls on or before the second value (default49), then it is interpreted as being in the twenty-first

century For example,01/01/69is interpreted as01/01/1969, and01/01/14is interpreted as

01/01/2014

In Management Studio, thetwo digit year cutoffconfiguration option can be set by specifying

an integer that represents the cutoff year in the ‘‘Two digit year cutoff’’ box in the Server Properties

Advanced tab (refer to Figure 39-9)

The following code sets thetwo digit year cutoffto2041:

EXEC sp_configure ‘show advanced options’, 1;

RECONFIGURE;

EXEC sp_configure ‘two digit year cutoff’, 2041;

RECONFIGURE;

Best Practice

Use four-digit date formats to avoid ambiguity with dates To maintain backward compatibility, leave the

default setting for the two digit year cutoff configuration option

Max text replication size

By default, text or image data greater than 65536 bytes (64KB) cannot be added to a replicated column

or a captured column Themax text repl sizeoption applies to transactional replication and the

Change Data Capture feature This option does not apply to snapshot and merge replication The

max-imum size of 65536 bytes is configurable usingmax text repl sizeconfiguration option

In Management Studio, themax text repl sizeconfiguration option can be set by specifying

maximum size in the ‘‘Max text replication size’’ box in the Server Properties Advanced tab (refer to

Figure 39-9)

Trang 8

EXEC sp_configure ‘max text repl size’, 131072;

RECONFIGURE;

The details of replication and change data capture are discussed in Chapter 36,

‘‘Replicat-ing Data,’’ and Chapter 60, ‘‘Change Data Capture’’ respectively.

Configuring database auto options

Five database-configuration options determine the automatic behaviors of SQL Server databases, as

described in Table 39-7 In Management Studio, they are all set in the Options tab of the Database

Properties page (refer to Figure 39-2 earlier in this chapter)

Auto close

Auto close directs SQL Server to release all database resources (cached data pages, compiled stored

procedures, saved query execution plans) when all users exit the database and all processes are

complete This frees memory for other databases Although this option improves performance slightly for

other databases, reloading the database takes longer, as will recompiling the procedures and recalculating

the query execution plans, once the database is again opened by a SQL Server when a user accesses the

database again

If the database is used regularly, do not enable auto close If the database is used occasionally, then auto

close might be appropriate to save memory

Many front-end client applications repeatedly open and close a connection to SQL Server.

Setting auto close ON in this type of environment is a sure way to kill SQL Server

perfor-mance.

TABLE 39-7

Index-Configuration Properties

Auto Close D Management Studio ALTER DATABASE <DB Name> SET

auto_close Auto Shrink D Management Studio ALTER DATABASE <DB Name> SET

auto_shrink Auto Create Statistics D Management Studio ALTER DATABASE <DB NAME> SET

auto_create_statistics Auto Update Statistics D Management Studio ALTER DATABASE <DB NAME> SET

auto_update_statistics Auto Update Statistics

Asynchronously

D Management Studio ALTER DATABASE <DB Name> SET

auto_update_statistics_async

* The configuration level refers to Server, Database, or Connection.

Trang 9

The following code sets auto close on for theAdventureWorks2008sample database:

ALTER DATABASE AdventureWorks2008 SET AUTO_CLOSE ON;

Best Practice

In general, don’t enable auto close for production SQL Server databases However, in some situations, you

may have hundreds or even thousands of databases with archived data that are never all used at the same

time For these situations you may benefit from having auto close on for some or even all databases By

default, auto close is enabled only for SQL Server Express Edition; it is off for all other editions

Auto shrink

If the database has more than 25 percent free space, then this option causes SQL Server to perform

a data and log file shrink operation This option also causes the transaction log to shrink after it’s

backed up

Performing a file shrink is a costly operation because several pages must be moved within the file

Plus, it’s very probable that the files later have to grow again (another costly operation), causing file

fragmentation at the OS level This option also regularly checks the status of the data pages to determine

whether they can be shrunk

Shrinking the data and transaction log files is discussed in detail in Chapter 41, ‘‘Recovery Planning.’’

The following example sets the auto shrink option toOFFfor theAdventureWorks2008sample

database:

ALTER DATABASE AdventureWorks2008 SET AUTO_SHRINK OFF;

Best Practice

Ihave seen a few customers cause severe SQL Server performance degradation by setting the auto shrink

option on I highly recommended not enabling auto shrink for production SQL Server databases

Auto create statistics

Data-distribution statistics are a key factor in how the SQL Server Query Optimizer creates query

exe-cution plans This option directs SQL Server to automatically create statistics for any columns for which

statistics could be useful The default for this option is set toON

To set auto create statisticsONforAdventureWorks2008sample database in code, do the following:

ALTER DATABASE AdventureWorks2008 SET AUTO_CREATE_STATISTICS ON;

Trang 10

SQL Server’s cost-based Query Optimizer uses statistics to choose the most efficient plan for

retrieving or updating data Hence, out-of-date data-distribution statistics aren’t very useful The

AUTO_UPDATE_STATISTICSdatabase option causes statistics to be recomputed every time a specified

number of rows in the table changes The default for this option is set to on, which is best practice and

works for most environments

However, based on the row changes, sometimes the statistics may be updated too frequently, other

times too infrequently, and sometimes automatically updating the statistics may cause a delay just

when you don’t want it To avoid these situations, you can disable theAUTO_UPDATE_STATISTICS

database option and schedule jobs to recompute statistics during low traffic or maintenance

In some environments, DBAs schedule jobs to manually compute the statistics, and keep the

AUTO_UPDATE_STATISTICSoption on as a failsafe measure in case many more rows change

than normal The following code example sets the auto update statistics option on for the

AdventureWorks2008sample database:

ALTER DATABASE AdventureWorks2008 SET AUTO_UPDATE_STATISTICS ON;

Auto update statistics asynchronously

When a query triggers anAUTO_UPDATE_STATISTICSevent, the query waits until the updated

statis-tics can be used This can cause unpredictable query response times Beginning with SQL Server 2005, a

database option calledAUTO_UPDATE_STATISTICS_ASYNCenables you to update the statistics

asyn-chronously By default, this option is off If theAUTO_UPDATE_STATISTICS_ASYNCdatabase option

is enabled, then SQL Server performs the automatic update of statistics in the background The query

that causes the automatic statistics does not need to wait for the statistics to be updated and proceeds

with the old statistics This may result in a less efficient query plan but the query response times are

predictable Queries that start after the statistics are updated will use those statistics

The following code enables theAUTO_UPDATE_STATISTICS_ASYNCoption for the

AdventureWorks2008sample database:

ALTER DATABASE AdventureWorks2008 SET AUTO_UPDATE_STATISTICS_ASYNC ON;

The AUTO_UPDATE_STATISTICS_ASYNC database option is dependent on the

AUTO_UPDATE_STATISTICS option Therefore, you need to ensure that the AUTO_UPDATE

_STATISTICS option is ON and then enable AUTO_UPDATE_STATISTICS_ASYNC Like any SQL Server

con-figuration, you need to thoroughly test this option to determine whether your SQL Server applications

benefit from it.

Query execution plans rely heavily on data-distribution statistics, covered in more detail in

Chapter 64, ‘‘Indexing Strategies.’’

Cursor-configuration properties

The cursor-configuration properties, shown in Table 39-8, are used to control cursor behavior in SQL

Server

To view information about the open cursors in various databases, query the

sys.dm_exec_cursors dynamic management view.

Ngày đăng: 04/07/2014, 09:20

TỪ KHÓA LIÊN QUAN