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

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

10 107 0

Đ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

Nội dung

Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 912 Part VI Enterprise Data Management 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, the query governor cost limit configuration 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 the query governor cost limit to 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 configured query governor cost limit value 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 The remote access option allows running local stored procedures from remote servers or remote stored procedures from the local server. By default, the remote access option 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 disallow remote 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 the remote access option to 0 in code: EXEC sp_configure ‘remote access’, 0; RECONFIGURE; The SQL Server service must be restarted in order for the remote access option to take effect. Remote login timeout The remote login timeout configuration option specifies the number of seconds to wait before returning from a failed attempt to connect to a remote SQL Server. The default value for remote login timeout is 20 seconds. In Management Studio, set the remote login timeout option 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). 912 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 913 Configuring SQL Server 39 The following code changes the default value of 20 to 30: 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 The remote query timeout option sets the number of seconds SQL Server will wait on a remote query before assuming it failed a nd 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 the remote query timeout option 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 the remote proc trans option to 1: EXEC sp_configure ‘remote proc trans’, 1; RECONFIGURE; In Management Studio, the remote proc trans option 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 the network packet size option. 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, the network packet size option 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). 913 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 914 Part VI Enterprise Data Management 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. 914 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 915 Configuring SQL Server 39 TABLE 39-6 Advanced Server-Configuration Properties Property Level* Graphic Control Code Option Filestream Access Level S Management Studio EXEC sp_configure ‘filestream access level’ Extensible Key Management S- EXEC sp_configure ‘EKM 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. 915 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 916 Part VI Enterprise Data Management 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 the filestream_access_level configuration 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. 916 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 917 Configuring SQL Server 39 Use the following to turn the EKM feature ON in code: 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 the default 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, the default full-text language configuration 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 the default full-text language option 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 of 1033 refers 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 the default language configuration option. The default language is used both for messages from the server and for formatting dates. It can be overridden by the CREATE LOGIN or ALTER LOGIN statement. In Management Studio, set the default language configuration option by selecting the language from the ‘‘Default language’’ drop-down list in the Server Properties Advanced tab (refer to Figure 39-9). 917 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 918 Part VI Enterprise Data Management From code, set the default language configuration option by specifying the unique language ID of the language you want, as listed in the sys.syslanguages table. For example, to set the default lan- guage to British English, first query the sys.syslanguages table 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 (default 50), then it is interpreted as being in the twentieth century. If it falls on or before the second value (default 49), then it is interpreted as being in the twenty-first century. For example, 01/01/69 is interpreted as 01/01/1969,and01/01/14 is interpreted as 01/01/2014. In Management Studio, the two digit year cutoff configuration 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 the two digit year cutoff to 2041: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; EXEC sp_configure ‘two digit year cutoff’, 2041; RECONFIGURE; Best Practice U se 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. The max text repl size option applies to transactional r eplication and the Change Data Capture f eature. This option does not apply to snapshot and merge replication. The max- imum size of 65536 bytes is c onfigurable using max text repl size configuration option. In Management Studio, the max text repl size configuration 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). 918 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 919 Configuring SQL Server 39 The following code sets the max text repl size to 131072 (128KB): 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, r eloading 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 Property Level* Graphic Control Code Option 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. 919 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 920 Part VI Enterprise Data Management The following code sets auto close on f or the AdventureWorks2008 sample database: ALTER DATABASE AdventureWorks2008 SET AUTO_CLOSE ON; Best Practice I n 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 a gain (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 to OFF for the AdventureWorks2008 sample database: ALTER DATABASE AdventureWorks2008 SET AUTO_SHRINK OFF; Best Practice I have seen a few customers cause severe SQL Server performance degradation by setting the auto shrink option on. I highly recommended not e nabling 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 to ON. To set auto create statistics ON for AdventureWorks2008 sample database in code, do the following: ALTER DATABASE AdventureWorks2008 SET AUTO_CREATE_STATISTICS ON; 920 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 921 Configuring SQL Server 39 Auto update statistics 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_STATISTICS database option causes statistics to be r ecomputed 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 the AUTO_UPDATE_STATISTICS database option and schedule jobs to r ecompute statistics during low traffic or maintenance. In some environments, DBAs schedule jobs to manually compute the statistics, and keep the AUTO_UPDATE_STATISTICS option 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 AdventureWorks2008 sample database: ALTER DATABASE AdventureWorks2008 SET AUTO_UPDATE_STATISTICS ON; Auto update statistics asynchronously When a query triggers an AUTO_UPDATE_STATISTICS event, 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 called AUTO_UPDATE_STATISTICS_ASYNC enables you to update the statistics asyn- chronously. By default, this option is off. If the AUTO_UPDATE_STATISTICS_ASYNC database 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 the AUTO_UPDATE_STATISTICS_ASYNC option for the AdventureWorks2008 sample 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. 921 www.getcoolebook.com . 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. 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. 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

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

TỪ KHÓA LIÊN QUAN