Hướng dẫn học Microsoft SQL Server 2008 part 93 docx

10 179 0
Hướng dẫn học Microsoft SQL Server 2008 part 93 docx

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

Thông tin tài liệu

Nielsen p06.tex V4 - 07/21/2009 2:19pm Page 882 www.getcoolebook.com Nielsen c39.tex V4 - 07/23/2009 4:02pm Page 883 Configuring SQL Server IN THIS CHAPTER Making sense of SQL Server configuration Configuring the server-level configuration options Configuring the database-level configuration options Configuring the connection-level options S QL Server has a plethora of configuration options. The difficulty in master- ing them lies in the fact that they are spread across three levels: ■ Server-level options generally configure how the server works with hardware, and determine the database defaults. ■ Database-level options determine the behavior of the database, and set the connection-level defaults. ■ Connection-level options determine the current behaviors within the connection or current procedure. Several of the configuration options overlap or simply set the default for the level immediately below. This chapter pulls these three configuration levels into a single unified understanding of how they relate to and affect each other. This chapter does not cover every single SQL Server configuration option but it covers most of them that I think are important. If you are a SQL Server beginner, you may find that some of the configuration options are advanced and you may not need them immediately. Setting the Options Whether you choose to adjust the properties from SQL Server Management Studio’s graphical tool or from code is completely up to you, but not every property is available from Management Studio using the graphical interface. While the graphical interface has the advantage of being easy to use, and walks you through easily understood dialogs that prompt for the possible options in a pick-and-choose format, it lacks the repeatability of a T-SQL script run as a query. To view miscellaneous information about the com- puter system while configuring SQL Server, query the sys.dm_os_sys_info dynamic management view. 883 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 884 Part VI Enterprise Data Management New in SQL Server 2008 Configuration S QL Server 2008 offers many new configuration options, such as backup compression default and filestream access level, that give the SQL DBA much more control in configuring SQL Server 2008. The configuration options set working set size, open objects,andlocks are still present in the sp_configure stored procedure, but their functionality is unavailable in SQL Server 2008. These options have no effect. Configuring the server The server-level configuration options control server-wide settings, such as how SQL Server interacts with hardware, how it multi-threads within Windows, and whether triggers are permitted to fire other triggers. When configuring the server, keep in mind the goals of configuration: consistency and perfor- mance. Graphically, many o f the server options may be configured within the Server Properties page, which you can open by right-clicking a server in the console tree and choosing Properties from the context menu. The General tab in Management Studio’s SQL Server Properties dialog (see Figure 39-1) reports the ver- sions and environment of the server. The same information is available to code. For example, the version may be identified with the @@VERSION global variable: select @@VERSION; Result: Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86) Jul 9 2008 14:43:34 Copyright (c) 1988-2008 Microsoft Corporation Enterprise Edition on Windows NT 5.2 <X86> (Build 3790: Service Pack 2) The first line of the preceding result includes the product version of SQL Server. In this example, the SQL Server product version is 10.0.1600.22. The last line of the result can be confusing. It reports the edition of SQL Server. In this example, it is SQL Server 2008 Enterprise Edition, but the service pack reported in the last line is the Windows service pack level and not the SQL Server service pack level. In this example, it is SP2 for Windows Server 2003. That is one of the reasons why I don’t like to use the SELECT @@VERSION command. Instead, I prefer to use the SERVERPROPERTY system function to determine the information. The advantage of this method is that the function may be used as an expres- sion within a SELECT statement. The following example uses the SERVERPROPERTY function to return the SQL Server product version, product level, and edition: SELECT SERVERPROPERTY(’ProductVersion’) AS ProductVersion, SERVERPROPERTY(’ProductLevel’) AS ProductLevel, SERVERPROPERTY(’Edition’) AS Edition; 884 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 885 Configuring SQL Server 39 FIGURE 39-1 The General tab of Management Studio’s Server Properties dialog Result: ProductVersion ProductLevel Edition 10.0.1600.22 RTM Enterprise Edition In the preceding result, the ProductVersion indicates the SQL Server product version number. The ProductLevel indicates the SQL Server product level. At the time of writing this chapter, we did not have any service packs f or SQL Server 2008 and the product level is RTM (Release to Manufacturing). If a SQL Server service pack is installed, the product level will indicate the service pack level too. For example, if you run the preceding command against your SQL Server 2005 SP3 instance, the ProductLevel will return SP3. The Edition indicates the SQL Server edition. Many of the configuration properties do not take effect until SQL Server is restarted, so the General tab in the SQL Server Properties (Configure) dialog box displays the current run- ning values. Within code, many of the server properties are set by means of the sp_configure system stored pro- cedure. When executed without any parameters, this procedure reports the current settings, as in the following code (word-wrap adjusted to fit on the page): EXEC sp_configure; 885 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 886 Part VI Enterprise Data Management Result: name minimum maximum config_value run_value allow updates 0 1 0 0 backup compression default 0 1 0 0 clr enabled 0 1 0 0 cross db ownership chaining 0 1 0 0 default language 0 9999 0 0 filestream access level 0 2 2 2 max text repl size (B) −1 2147483647 65536 65536 nested triggers 0 1 1 1 remote access 0 1 1 1 remote admin connections 0 1 0 0 remote login timeout (s) 0 2147483647 20 20 remote proc trans 0 1 0 0 remote query timeout (s) 0 2147483647 600 600 server trigger recursion 0 1 1 1 show advanced options 0 1 0 0 user options 0 32767 0 0 You can always discover the minimum and maximum values for a particular configuration option by running the sp_configure command with the option, but without any value. For example, run EXEC sp_configure ‘remote login timeout’; and you’ll discover that the remote login timeout configuration option can have any value in the range of 0 to 2,147,483,647. The extended stored procedure xp_msver reports additional server and environment properties: EXEC xp_msver; Result: Index Name Internal_Value Character_Value 1 ProductName NULL Microsoft SQL Server 2 ProductVersion 655360 10.0.1600.22 3 Language 1033 English (United States) 4 Platform NULL NT INTEL X86 5 Comments NULL SQL 6 CompanyName NULL Microsoft Corporation 7 FileDescription NULL SQL Server Windows NT 8 FileVersion NULL 2007.0100.1600.022 ((SQL_PreRelease).080709-1414 ) 9 InternalName NULL SQLSERVR 10 LegalCopyright NULL Microsoft Corp. All 886 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 887 Configuring SQL Server 39 rights reserved. 11 LegalTrademarks NULL Microsoft SQL Server is a registered trademark of Microsoft Corporation. 12 OriginalFilename NULL SQLSERVR.EXE 13 PrivateBuild NULL NULL 14 SpecialBuild 116588544 NULL 15 WindowsVersion 393281542 5.2 (3790) 16 ProcessorCount 1 1 17 ProcessorActiveMask 1 00000001 18 ProcessorType 586 PROCESSOR_INTEL_PENTIUM 19 PhysicalMemory 2046 2046 (2145845248) 20 Product ID NULL NULL The information returned by sp_configure is settable, but the information returned by xp_msver is not. Configuring the database The database-level options configure the current database’s behavior regarding ANSI compatibility and recovery. Most database options can be set in Management Studio within the Database Properties page, which you can access by right-clicking a database in the console tree and choosing Properties from the context menu. The Options tab is shown in Figure 39-2. The database configuration options can be set using T-SQL ALTER DATABASE SET options. The follow- ing example sets the AdventureWorks2008 database to single-user mode to obtain exclusive access: ALTER DATABASE AdventureWorks2008 SET SINGLE_USER; View database configuration options using the sys.databases catalog view or the DATABASEPROPERTYEX() function. The following example returns all the database properties of the AdventureWorks2008 database: SELECT * FROM sys.databases WHERE name = ‘AdventureWorks2008’; Do not use the sp_dboption system stored procedure, as it will be removed in the next version of SQL Server. Configuring the connection Many of the c onnection-level options configure ANSI compatibility or specific connection-performance options. Connection-level options are very limited in scope. If the option is set within an interactive session, then the setting is in force until it’s changed or the session ends. If the option is set within a stored proce- dure, then the setting persists only for the life of that stored procedure. 887 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 888 Part VI Enterprise Data Management FIGURE 39-2 Management Studio’s Database Properties Options tab can be used to configure the most common database properties The connection-level options are typically configured by means of the SET command. The following code configures how SQL Server handles nulls within this current session: SET ANSI_NULLS OFF; Result: Command(s) completed successfully. Connection properties can also be checked by means of the SessionProperty() function: Select SESSIONPROPERTY (’ANSI_NULLS’); Result: 0 888 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 889 Configuring SQL Server 39 Management Studio allows you to set several query properties. You can review and set these properties for current queries by clicking the Query menu and then Query Options. For all future connections, review and set the properties by clicking the Tools menu a nd then Options. Figure 39-3 shows an example of the ANSI settings that SQL Server will use to run the queries. To view current settings of connection-level options, query the sys.dm_exec_connections dynamic management view. FIGURE 39-3 The ANSI settings that SQL Server uses to run your queries Configuration Options Because so many similar configuration options are c ontrolled by different commands and at different lev- els (server, database, connection), this section organizes the configuration options by topic, rather than command or level. Displaying the advanced options As with many operations, displaying advanced options can be achieved using several methods. One method is to query the sys.configurations catalog view as shown here: SELECT name, minimum, maximum, value, value_in_use FROM sys.configurations WHERE is_advanced = 1 ORDER BY name; 889 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 890 Part VI Enterprise Data Management The preceding example will display all the SQL Server advanced options. To display all the o ptions, comment the WHERE clause. Another method to display the advanced options is to turn on the show advanced options configuration, as follows: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; After a configuration setting is changed with sp_configure,theRECONFIGURE command causes the changes to take effect. If you don’t run RECONFIGURE, then the config_value field will still show the change, but the change won’t appear in the run_value field, even if you restart the service. Some configuration changes take effect only after SQL Server is restarted. After you enable the advanced option display, you can use the sp_configure command to display a list of all of the options: EXEC sp_configure; Result (with advanced options enabled): name minimum maximum config_value run_value access check cache bucket count 0 16384 0 0 access check cache quota 0 2147483647 0 0 Ad Hoc Distributed Queries 0 1 0 0 affinity I/O mask -2147483648 2147483647 0 0 affinity64 I/O mask -2147483648 2147483647 0 0 affinity mask -2147483648 2147483647 0 0 affinity64 mask -2147483648 2147483647 0 0 Agent XPs 0 1 1 1 allow updates 0 1 0 0 awe enabled 0 1 0 0 backup compression default 0 1 0 0 blocked process threshold (s) 0 86400 0 0 c2 audit mode 0 1 0 0 clr enabled 0 1 0 0 common criteria compliance enabled 0 1 0 0 cost threshold for parallelism 0 32767 5 5 cross db ownership chaining 0 1 0 0 cursor threshold -1 2147483647 -1 -1 Database Mail XPs 0 1 0 0 default full-text language 0 2147483647 1033 1033 default language 0 9999 0 0 default trace enabled 0 1 1 1 disallow results from triggers 0 1 0 0 EKM provider enabled 0 1 0 0 890 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 891 Configuring SQL Server 39 filestream access level 0 2 2 2 fill factor (%) 0 100 0 0 ft crawl bandwidth (max) 0 32767 100 100 ft crawl bandwidth (min) 0 32767 0 0 ft notify bandwidth (max) 0 32767 100 100 ft notify bandwidth (min) 0 32767 0 0 index create memory (KB) 704 2147483647 0 0 in-doubt xact resolution 0 2 0 0 lightweight pooling 0 1 0 0 locks 5000 2147483647 0 0 max degree of parallelism 0 64 0 0 max full-text crawl range 0 256 4 4 max server memory (MB) 16 2147483647 2147483647 2147483647 max text repl size (B) -1 2147483647 65536 65536 max worker threads 128 32767 0 0 media retention 0 365 0 0 min memory per query (KB) 512 2147483647 1024 1024 min server memory (MB) 0 2147483647 0 0 nested triggers 0 1 1 1 network packet size (B) 512 32767 4096 4096 Ole Automation Procedures010 0 open objects 0 2147483647 0 0 optimize for ad hoc workloads 0 1 0 0 PH timeout (s) 1 3600 60 60 precompute rank 0 1 0 0 priority boost 0 1 0 0 query governor cost limit 0 2147483647 0 0 query wait (s) -1 2147483647 -1 -1 recovery interval (min) 0 32767 0 0 remote access 0 1 1 1 remote admin connections 0 1 0 0 remote login timeout (s) 0 2147483647 20 20 remote proc trans 0 1 0 0 remote query timeout (s) 0 2147483647 600 600 Replication XPs 0 1 0 0 scan for startup procs 0 1 0 0 server trigger recursion 0 1 1 1 set working set size 0 1 0 0 show advanced options 0 1 1 1 SMO and DMO XPs 0 1 1 1 SQL Mail XPs 0 1 0 0 transform noise words 0 1 0 0 891 www.getcoolebook.com . functionality is unavailable in SQL Server 2008. These options have no effect. Configuring the server The server- level configuration options control server- wide settings, such as how SQL Server interacts with. of SQL Server. In this example, the SQL Server product version is 10.0.1600.22. The last line of the result can be confusing. It reports the edition of SQL Server. In this example, it is SQL Server. indicates the SQL Server product version number. The ProductLevel indicates the SQL Server product level. At the time of writing this chapter, we did not have any service packs f or SQL Server 2008 and

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

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan