ptg 2274 CHAPTER 55 Configuring, Tuning, and Optimizing SQL Server Options What’s New in Configuring, Tuning, and Optimizing SQL Server Options There are a few new configuration options in SQL Server 2008 R2. These new configura- tion options are user instance oriented (for SQL Server 2008 Express only), for FileStream, Compression, and are Access Check Cache options. However, you must be warned that there are options available that are not obsolete yet but have no effect (even if you set them). We identify them in this chapter as they come up. SQL Server 2000 had a total of 36 options. With SQL Server 2005, the number of options nearly doubled, with a total of 64 (basic and advanced) active options. There are now 70 basic and advanced options in SQL Server 2008 R2. Not all are usable, and some apply only to certain OS platforms (64-bit) or SQL Server editions. Only 68 basic and advanced options appear on 32-bit–based platforms. NOTE You can’t use Allow Updates, Open Objects, or the Set Working Set Size sp_configure options. They have become obsolete and have no effect in SQL Server 2008, even though they are still listed. The Web Assistant Procedures option doesn’t exist anymore either. In addition, Microsoft has announced that all the ft_crawl and ft_notify options (ft = File Text) will be deprecated. This chapter discusses the configuration options as well as the Database Engine Tuning Advisor (DTA) and some of the reports available via the Data Collection service within SQL Server Management Studio’s (SSMS’s) management options. Microsoft is improving in these areas, with new tuning analysis, improved recommendation reports, and now data collection reports that can give you an overall picture of how your SQL Server instance is performing. SQL Server Instance Architecture Figure 55.1 illustrates the address space architecture of an instance of SQL Server 2008 R2. When you fire up a SQL Server instance, two main areas are allocated: the code area and memory pool area. The code area is mostly static executable code of the SQL Server kernel; SQL Server .NET Library DLLs; Open Data Services code; the stack space; and a variable code area that contains distributed query OLE DB providers, OLE automation objects, and extended stored procedures as they are needed by user requests. The memory pool area of SQL Server is the most dynamically changing part of an instance. Even now, the once-static system data structures and user connection structures (connection context) are controlled by user requests and dynamically allocate structures as they are needed. Then, there are the primary SQL Server databases master, tempdb, msdb, and model. There is another system database called a resource database that is present in each SQL Server instance. This read-only database contains system objects that are included with SQL Server. System objects are physically persisted in the resource database, ptg 2275 Configuration Options SQL Server 2008 Server Net-libs DLLs SQL Server Kernel (code) Open Data Services Stack Space (512K) Variable code Memory/BufferPool User Connection Structures System Data Structures Plan Cache Buffer Cache Other Servers Web-Based Clients Windows Clients Windows Clients Windows Clients Log Cache Master DBTemp DB MSDB Model DBResource DB FIGURE 55.1 The SQL Server 2008 R2 instance architecture. but they logically appear in the sys schema of every database and provide the results to system-level information such as server properties ( SERVERPROPERTY) and object definitions ( OBJECT_DEFINITION). Of these system-wide databases, tempdb has the most significance for performance because it is the heart of all internal tables, indexing, sorting, grouping, and other worktable activity for the entire SQL Server instance. By default, SQL Server tries to keep the amount of virtual memory allocations on a computer at 4MB to 10MB less than the physical memory available. The rest of the memory pool area is divided into procedure cache, data cache (buffer cache), and log cache. SQL Server actively adjusts these for optimal performance. Previously, the system administrator had to do all this manually. Many of the configurable options directly relate to optimizing this address space. There is a caching framework that utilizes internal and external clocks to determine how the caches are managed; it is explained in Chapter 39. Configuration Options With SQL Server 2008, many options may affect the performance of individual SQL state- ments or the overall performance of a SQL Server instance. There are instance-wide config- uration options (set using the sp_configure system stored procedure or with the server 55 ptg 2276 CHAPTER 55 Configuring, Tuning, and Optimizing SQL Server Options FIGURE 55.2 SQL Server 2008 Configuration Properties dialog from SSMS. properties dialog within SSMS), database-level options (set with ALTER DATABASE), database compatibility levels (using the sp_dbcmptlevel system stored procedure), batch-level options (using the SET command for things such as SET ANSI_NULLS), and statement-level options (such as table hints, query hints, and join hints). Always remember that a hint overrides a SET option, a SET option overrides a database option, and a database option overrides an instance-wide option. For SQL Server 2008, this chapter discusses the instance-wide configurable options in two distinct categories: basic options and advanced options. The advanced options are a super- set of the basic options. As each option is discussed, this chapter notes whether it is self- configuring. A self-configuring option is an option that adjusts itself dynamically, according to the needs of the system. In most cases, this eliminates the need for setting the values manually. Sometimes you don’t want to rely on certain self-configuring values, depending on how SQL Server is being used. This chapter identifies self-configuring values. As you can see in Figure 55.2, SQL Server provides configuration parameters that the system administrator can set to maximize the performance of a system from the proper- ties option within SSMS. You can set these and other SQL Server configuration parame- ters by using the sp_configure system stored procedure as well. Now, the only questions that need to be answered are “What configuration options do I need to set that aren’t already fine?” and “How do I set them?” ptg 2277 Configuration Options 55 To answer the “what” question, you first need to determine for what purpose the applica- tions are using SQL Server. The answer must include understanding variables such as the number of potential connections to support, resources available on the box, size of the database, type of data accesses occurring, and workload being put on SQL Server. When you know all this, it is easy to determine the configuration option setting to adjust. The following shows a generalization of the types of applications you might find in the real world that would be implemented using SQL Server 2008 and the general behavior they elicit: . Online transaction processing (OLTP)—Mix of reads, writes, updates, and deletes. Large number of concurrent users. . Data warehouse—Incremental loads (deltas), aggregation/transformation process- ing, then primarily read-only. Medium number of users. . Online analytical processing (OLAP)—Big loads, then primarily read-only. Medium to large number of simultaneous users. . Mixed server—Mix of reads, writes, updates, deletes, big loads, and big extracts. Large number of users. This is not a complete list, just a generalized list. Because these configuration options are set at the SQL Server level, it is important to know the combined behavior of all applica- tion processing. For each SQL Server configuration option discussed in this chapter, we recommend an appropriate setting, based on these generalized application processing behavior types. Now let’s answer the “How do I set them?” question. The next few sections describe all the types of configuration options available on SQL Server 2008. These sections show how to set these configuration options using both SSMS and the sp_configure system stored procedure. The rule is that you can certainly set a configuration option using SSMS, but you should keep an sp_configure version of that setting change as a backup in case you need to rebuild the entire server configuration from scratch. In addition, keeping an sp_configure version around in a file provides a great audit trail of what you did and why. If you simply execute sp_configure without parameters, you are given a list of options that can be addressed. When you have just installed a SQL Server instance, you can see only the basic configuration options. SQL Server 2008 has 16 basic configuration options available: exec sp_configure go 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 ptg 2278 filestream access level 0 2 0 0 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 By default, all SQL Server users have permission to run the sp_configure system stored procedure, but only users who have sysadmin and serveradmin fixed server roles (such as sa) can actually set the value of a parameter. The proper syntax of the sp_configure command is as follows: exec sp_configure [parameter_name [, parameter_value ]] In this syntax, parameter_name is the name of the configuration parameter you want to set, and parameter_value is the value for the parameter. Both of these parameters are optional. Parameters set by sp_configure take effect at the server level. Following is a brief explanation of the output of the sp_configure command. As you can see, the output consists of five columns: . Name—This is the name of the configurable option. . Minimum—This is the minimum legal value allowed for this parameter. Passing an illegal value causes SQL Server to return an error. . Maximum—This is the maximum legal value allowed for this parameter. Passing an illegal value causes SQL Server to return an error. . Config_value—This column reflects the values that will take effect the next time SQL Server is started. If you change static parameters, the new values are listed under this column. . Run_value—This column reflects the values that SQL Server is currently using. If you change any dynamic parameters, the new values are listed in this column. At the time of SQL Server startup, config_value for all the parameters is copied into run_value. Immediately after restart, both columns (run_value and config_value) should display the same values, corresponding to each parameter. If you specify a parameter name, SQL Server returns the current configuration value for that particular parameter, as in this example: exec sp_configure ‘clr enabled’ go name minimum maximum config_value run_value CHAPTER 55 Configuring, Tuning, and Optimizing SQL Server Options ptg 2279 Configuration Options 55 clr enabled 0 1 0 0 There are many more than 16 basic configuration options. In fact, there are 70 configura- tion options in total. They consist of the original 16 basic options plus 54 advanced options (including two for 64-bit processing). To see a complete list of all options, you turn on the show advanced option configuration option with the value 1. In addition, when using sp_configure to change a setting, you use the RECONFIGURE WITH OVERRIDE statement to make the change take effect immediately. You can also choose to use just the RECONFIGURE statement. Depending on the configuration option, it may take effect immediately, or it may not take effect until the server has been restarted. The following commands set the show advanced options configuration option and then retrieve the complete list of all configuration options: exec sp_configure ‘Show Advanced Options’, 1 /* Advanced config options */ go RECONFIGURE WITH OVERRIDE /* to have it take effect immediately */ go sp_configure go name minimum maximum config_value run_value access check cache bucket count 0 65536 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 affinity mask -2147483648 2147483647 0 0 affinity64 I/O 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 ptg 2280 EKM provider enabled 0 1 0 0 filestream access level 0 2 0 0 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 1024 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 Procedures 0 1 0 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 two digit year cutoff 1753 9999 2049 2049 user connections 0 32767 0 0 user options 0 32767 0 0 xp_cmdshell 0 1 0 0 CHAPTER 55 Configuring, Tuning, and Optimizing SQL Server Options ptg 2281 Configuration Options 55 Microsoft suggests that only very experienced SQL Server administrators change these advanced configuration options. In general, this is good advice because most of these options are set to where you might want them as you start out. As you learn more about your application and the other things happening in your SQL Server instance, you will change them more and more. You have been warned! Earlier SQL Server 2008 R2 documentation also listed a configuration option, enable_force_flush, that wasn’t present in the November Community Technology Preview (CTP) for R2. We’re not sure whether we will see it very soon. With SQL Server 2008, you can see all the configuration options and their current settings via system views. The sys.configurations view shows the option, a description, and the current value in use for each configuration option. The following example shows what you might expect to see if you query the sys.configurations view: SELECT convert(varchar(10),value_in_use) AS ‘Value in Use’, substring (name,1,30) AS ‘Configuration Option’, substring (description,1,30) AS ‘Description’ FROM sys.configurations ORDER BY 2 Go Value in Use Configuration Option Description 0 access check cache bucket coun Default hash bucket count for 0 access check cache quota Default quota for the access c 0 Ad Hoc Distributed Queries Enable or disable Ad Hoc Distr 0 affinity I/O mask affinity I/O mask 0 affinity mask affinity mask 0 affinity64 I/O mask affinity64 I/O mask 0 affinity64 mask affinity64 mask 1 Agent XPs Enable or disable Agent XPs 0 allow updates Allow updates to system tables 0 awe enabled AWE enabled in the server 0 backup compression default Enable compression of backups 0 blocked process threshold (s) Blocked process reporting thre 0 c2 audit mode c2 audit mode 0 clr enabled CLR user code execution enable 0 common criteria compliance ena Common Criteria compliance mod 5 cost threshold for parallelism cost threshold for parallelism 0 cross db ownership chaining Allow cross db ownership chain -1 cursor threshold cursor threshold 0 Database Mail XPs Enable or disable Database Mai 1033 default full-text language default full-text language 0 default language default language 1 default trace enabled Enable or disable the default ptg 2282 0 disallow results from triggers Disallow returning results fro 0 EKM provider enabled Enable or disable EKM provider 0 filestream access level Sets the FILESTREAM access lev 0 fill factor (%) Default fill factor percentage 100 ft crawl bandwidth (max) Max number of full-text crawl 0 ft crawl bandwidth (min) Number of reserved full-text c 100 ft notify bandwidth (max) Max number of full-text notifi 0 ft notify bandwidth (min) Number of reserved full-text n 0 index create memory (KB) Memory for index create sorts 0 in-doubt xact resolution Recovery policy for DTC transa 0 lightweight pooling User mode scheduler uses light 0 locks Number of locks for all users 0 max degree of parallelism maximum degree of parallelism 4 max full-text crawl range Maximum crawl ranges allowed 2147483647 max server memory (MB) Maximum size of server memory 65536 max text repl size (B) Maximum size of a text field i 0 max worker threads Maximum worker threads 0 media retention Tape retention period in days 1024 min memory per query (KB) minimum memory per query (kByt 0 min server memory (MB) Minimum size of server memory 1 nested triggers Allow triggers to be invoked w 4096 network packet size (B) Network packet size 0 Ole Automation Procedures Enable or disable Ole Automati 0 open objects Number of open database object 0 optimize for ad hoc workloads When this option is set, plan 60 PH timeout (s) DB connection timeout for full 0 precompute rank Use precomputed rank for full- 0 priority boost Priority boost 0 query governor cost limit Maximum estimated cost allowed -1 query wait (s) maximum time to wait for query 0 recovery interval (min) Maximum recovery interval in m 1 remote access Allow remote access 0 remote admin connections Dedicated Admin Connections ar 20 remote login timeout (s) remote login timeout 0 remote proc trans Create DTC transaction for rem 600 remote query timeout (s) remote query timeout 0 Replication XPs Enable or disable Replication 0 scan for startup procs scan for startup stored proced 1 server trigger recursion Allow recursion for server lev 0 set working set size set working set size 1 show advanced options show advanced options 1 SMO and DMO XPs Enable or disable SMO and DMO 0 SQL Mail XPs Enable or disable SQL Mail XPs 0 transform noise words Transform noise words for full 2049 two digit year cutoff two digit year cutoff 0 user connections Number of user connections all CHAPTER 55 Configuring, Tuning, and Optimizing SQL Server Options ptg 2283 Obsolete Configuration Options 55 0 user options user options 0 xp_cmdshell Enable or disable command shel Dynamically changing configuration options are also updated so that their values are visible through the system views. Fixing an Incorrect Option Setting Setting a parameter value too high might cause SQL Server to crash during startup. For example, if you set the value of the memory option to a value that is higher than the physical memory on the machine, SQL Server does not start. In this case, you start SQL Server with the -f option, which causes SQL Server to start with the default parameter values (the same values used by the Setup program when you installed SQL Server). After SQL Server is running, you can change the incorrect value to the correct one and restart SQL Server without the -f option. Setting Configuration Options with SSMS As mentioned previously, you can set SQL Server configuration options by using SSMS. You simply invoke SSMS from the Microsoft SQL Server program group and right-click the Server folder. In Figure 55.2, you can see the SQL Server Properties pane, the different server categories of options that are available (General, Processors, Memory, and so on), and the selected option category properties that can be adjusted. Keep in mind that some of these options are not configuration options that correspond to sp_configure (for example, the Root Directory or Platform properties of the General Server Instance proper- ties options). However, as you will see, Microsoft has done a nice job of organizing and presenting the option information. In addition, you can look at either the configured option value or the running values. If you are manipulating these, they may not be the same. Not all 70 configuration options can be set from SMSS; only about half of them can. It’s therefore best to get to know the sp_configure system stored procedure. Remember that you must have sysadmin and serveradmin fixed server roles to make changes. All the sp_configure settings and options used in this chapter are included in a SQL script named SQLConfigOptions.sql that you can find on the CD for this book. Obsolete Configuration Options Many configuration options available in SQL Server 7.0 or SQL Server 2000 have become obsolete or do not function any longer. Some options, such as time slice, were intro- duced in SQL Server 7.0 and then immediately became obsolete. The following configuration options are obsolete in SQL Server 2008: . Allow Update (remains listed but cannot be set) . your SQL Server instance is performing. SQL Server Instance Architecture Figure 55.1 illustrates the address space architecture of an instance of SQL Server 2008 R2. When you fire up a SQL Server. Tuning, and Optimizing SQL Server Options What’s New in Configuring, Tuning, and Optimizing SQL Server Options There are a few new configuration options in SQL Server 2008 R2. These new configura- tion. that are included with SQL Server. System objects are physically persisted in the resource database, ptg 2275 Configuration Options SQL Server 2008 Server Net-libs DLLs SQL Server Kernel (code) Open