Hướng dẫn học Microsoft SQL Server 2008 part 94 pdf

10 419 0
Hướng dẫn học Microsoft SQL Server 2008 part 94 pdf

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

Thông tin tài liệu

Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 892 Part VI Enterprise Data Management 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 The key difference between the preceding two methods to display advanced options is that the sys.configurations catalog view only displays the configurations. The show advanced options configuration not only controls the display of advanced options through sp_configure system stored procedure, it also controls whether these advanced options can be changed. Start/Stop configuration properties The startup configuration properties, described in Table 39-1, control how SQL Server and the processes are launched. Startup parameters You use the startup parameters with the SQL Server services. The startup parameters are passed as parameters to the SQL Server program when the SQL Server service is started. Although you can add startup parameters from the Services console, I highly recommend using the SQL Server Configuration Manager, shown in Figure 39-4. One of the main reasons has to do with minimizing downtime. The Configuration Manager allows you to a dd startup parameters with the SQL Server service still running. You can restart the service during a maintenance window a nd minimize downtime. Also, the Configuration Manager is the only method for a SQL Server failover clustering instance, as it is a cluster-aware tool, whereas the Services console is not. TABLE 39-1 Start/Stop Configuration Properties Property Level* Graphic Control Code Option AutoStart SQL Server S Configuration Manager, or Services Console - AutoStart SQL Server Agent S Configuration Manager, or Services Console - AutoStart MS DTC S Services Console - Scan for startup procs S - EXEC sp_configure ‘scan for startup procs’ * The configuration level refers to Server, Database, or Connection. 892 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 893 Configuring SQL Server 39 FIGURE 39-4 Add startup parameters to the SQL Server service to change its behavior To add the startup parameters in SQL Server Configuration Manager: 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) to which you want to add startup parameters and select the Advanced tab. 4. On the Advanced tab, in the Startup Parameters box, type the startup parameters separated by semicolons (refer to Figure 39-4). Besides the standard master database location parameters, two parameters are particularly useful: ■ -m: Starts SQL Server in single-user mode. This is required to restore the master database. ■ -f: Used to start up with a minimal configuration Additional startup parameters are as follows: ■ -d: Used to include the full path of the master database file, with no spaces between the d and the path ■ -l: Used to include the full path of the master database log file, with no spaces between the l and the path 893 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 894 Part VI Enterprise Data Management ■ -e: Used to include the full path of the SQL Server error log file, with no spaces between the e and the path ■ -c: Starts SQL Server so that it is not running as a Windows service ■ -x : Allows maximum performance by disabling monitoring features. Because the monitoring features are disabled, your ability to troubleshoot performance and functional problems will be greatly reduced. ■ -g: Specifies virtual memory (in MB) available to SQL Server for memory allocations within the SQL Server process, but outside the S QL Server memory pool (extended procedure . dll files, the OLE DB providers referenced by distributed queries, and automation objects referenced in Transact-SQL statements) ■ -n: Disables logging to the Windows application log ■ -s: Used to start a named instance of SQL Server. The instance name follows directly after the s, with no spaces in between. ■ -Ttrace#: Enables trace-specific flags by trace flag number. Refer to the SQL Server 2008 Books Online topic ‘‘Trace Flags’’ for documented trace flags. I do not recommend using trace flags for an extended period of time. I usually use trace flags for troubleshooting SQL Server issues and then remove them once the issue is resolved. Also, never use undocumented trace flags, as they can cause more damage, rather than assist you in solving any issue. ■ -h: Assuming your hardware allows you to add physical memory without restarting the server, use this option to enable SQL Server to immediately begin using the hot-add memory. This is only available on SQL Server Enterprise Edition and can be used on 64-bit SQL Server and 32-bit SQL Server with AWE enabled. Startup stored procedures SQL Server can be configured to scan for a startup stored procedure every time the SQL Server starts — similar to how Microsoft DOS operating systems scan for the autoexec.bat file when they boot up. All the startup procedures need to be in the master database but there is no limit on the number of startup procedures. The key is to remember that each startup procedure will consume one worker thread while executing it. To mark an existing stored procedure to e xecute automatically when SQL Server starts, use the sp_procoption system stored procedure as follows: EXEC sp_procoption @ProcName = ‘ExistingSP’, @OptionName = ‘startup’, @OptionValue = ‘on’; You use the same sp_procoption system stored procedure to stop a stored procedure from executing at SQL Server startup: EXEC sp_procoption @ProcName = ‘ExistingSP’, @OptionName = ‘startup’, @OptionValue = ‘off’; Although you can individually mark a stored procedure for automatic execution at SQL Server startup, you can further control the execution of all the startup stored procedures by using the scan for startup procs configuration option. If this option is set to 1, SQL Server scans for and runs all stored procedures marked for automatic execution at startup. The default value of this option is 0, 894 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 895 Configuring SQL Server 39 which skips automatic execution of startup stored procedures. The scan for startup procs configuration option i s automatically set to 1 when you execute sp_procoption to mark the first stored procedure for automatic execution, and is set to 0 when you unmark the last stored procedure for automatic execution. The following code can be used to skip automatic execution for all startup stored procedures: EXEC sp_configure ‘scan for startup procs’, 0; RECONFIGURE; Memory-configuration properties SQL Server can either dynamically request memory from the operating system or c onsume a fixed amount of memory. These settings can be configured on the SQL Server Properties Memory tab, shown in Figure 39-5, or from code by means of the sp_configure stored procedure. FIGURE 39-5 Memory tab of Management Studio’s SQL Server Properties dialog The memory-configuration properties, listed in Table 39-2, control how SQL Server uses and allocates memory. 895 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 896 Part VI Enterprise Data Management TABLE 39-2 Memory-Configuration Properties Property Level* Graphic Control Code Option Dynamic Memory Minimum S Management Studio EXEC sp_configure ‘min server memory’ Dynamic Memory Maximum S Management Studio EXEC sp_configure ‘max server memory’ Fixed Memory Size S Management Studio EXEC sp_configure ‘min server memory’ and EXEC sp_configure ‘max server memory’ Minimum Query Memory S Management Studio EXEC sp_configure ‘min memory per query’ Query Wait S Management Studio EXEC sp_configure ‘query wait’ AWE Enabled S Management Studio EXEC sp_configure ‘AWE Enabled’ Index Create Memory S Management Studio EXEC sp_configure ‘index create memory’ * The configuration level refers to Server, Database, or Connection. 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 Microsoft SQL Server 2008. These options have no effect. Do not use them in new development work, as they may be removed in future SQL Server versions. Dynamic memory If SQL Server is set to use memory dynamically, then SQL Server’s memory can grow or be reduced as needed within the minimum and maximum constraints based on the physical memory available and the workload. The goal is to have enough memory available while avoiding Windows needing to swap pages from memory to the virtual-memory support file ( pagefile.sys). The minimum-memory property prohibits SQL Server from reducing memory below a certain point and hurting performance, but it does not guarantee that SQL Server will immediately allocate the minimum amount of memory at startup. The minimum simply means that o nce SQL Server memory has reached that point, it will not reduce memory below it. The maximum-memory setting prevents SQL Server from growing to the point where it contends with the operating system, or other applications, for memory. If the maximum is set too low, then perfor- mance will suffer. Multiple SQL Server instances do not cooperate when requiring memory. In servers with multiple instances, it’s highly possible for two busy instances to contend for memory and for one to become 896 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 897 Configuring SQL Server 39 memory-starved. Reducing the maximum-memory property for each instance can prevent this from happening. From T-SQL code, the minimum- and maximum-memory properties are set by means of the sp_configure system stored procedure. It’s an advanced option, so it can be changed only if the show advanced options property is on: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; The show advanced options property needs to be enabled only if it is not already turned on. Once it is turned on, you can change the advanced options and then reset it to the default value of 0. The following code sets the min-memory configuration to 1GB: EXEC sp_configure ‘min server memory’, 1024; RECONFIGURE; Result: Configuration option ‘min server memory (MB)’ changed from 0 to 1024. Run the RECONFIGURE statement to install. This code sets the max-memory configuration to 4GB: EXEC sp_configure ‘max server memory’, 4096; RECONFIGURE; Result: Configuration option ‘max server memory (MB)’ changed from 2147483647 to 4096. Run the RECONFIGURE statement to install. Fixed memory Instead of dynamically consuming memory, SQL Server may be configured to request a fixed amount of memory from the operating system. To set a fixed amount of memory from code, set the minimum- and maximum-memory properties to the same value. The following code sets the SQL Server memory to a fixed memory of 6144MB: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; EXEC sp_configure ‘min server memory’, 6144; RECONFIGURE; EXEC sp_configure ‘max server memory’, 6144; RECONFIGURE; Although calculating memory cost, polling the environment, and requesting memory may seem as if they would require overhead, you aren’t likely to see any performance gains from switching from dynamic to fixed memory. The primary purpose of using fixed memory is to configure a dedicated SQL Server com- puter to use a fixed amount of memory after the value is reached. 897 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 898 Part VI Enterprise Data Management Minimum query memory At times, the SQL Server team amazes me with the level of detailed control it passes to DBAs. SQL Server will allocate the required memory for each query as needed. The min memory per query option sets the minimum threshold for the memory (in KB) used b y each query. While increasing this property to a value higher than the default 1MB may provide slightly better performance for some queries, there i s no reason to override SQL Server automatic memory control and risk causing a memory shortage. If you insist on doing so, however, here’s how — the following code increases the minimum query memory to 2MB: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; EXEC sp_configure ‘min memory per query’, 2048; RECONFIGURE; Query wait If the memory is unavailable to execute a large query, SQL Server will wait for the estimated amount of time necessary to execute the query times 25 and then time out. Usually, you don’t need to change the query wait time, but if you have a valid reason to change this option, you can either use Management Studio or TSQL-code. In Management Studio, set the query wait option by entering the value in the ‘‘query wait’’ box in the Server Properties Advanced tab (refer to Figure 39-9 later in this chapter). The following code specifies that every query will either start executing within 20 seconds or time out: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; EXEC sp_configure ‘query wait’, 20; RECONFIGURE; Note that to revert to the default wait time of the estimated execution time times 25, you must specify the query wait time as -1. AWE enabled On 32-bit operating systems, SQL Server is normally restricted to the standard 2GB physical-memory limit (or 3GB if the /3GB switch is used in boot.ini). On 64-bit operating systems, the awe enabled option is ignored even though it is present in the sp_configure stored procedure. SQL Server x86 Standard, Enterprise, and Developer Editions, when running on Windows Server 2003 or 2008 Enterprise or Datacenter Editions, can use up to 64GB of physical memory if SQL Server is configured to address the Address Windowing Extensions (AWE) API. The AWE-enabled property turns on AWE memory addressing within SQL Server: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; EXEC sp_configure ‘awe enabled’, 1; RECONFIGURE; 898 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 899 Configuring SQL Server 39 The Windows privilege LOCK PAGES IN MEMORY must be granted to the SQL Server service account before enabling awe. A system administrator can use the Windows Group Policy tool ( gpedit.msc) to enable this privilege for the SQL Server service account. The SQL Server instance must be restarted in order for the awe enabled option to take effect. If the awe enabled option is configured successfully, then the SQL Server error log file will include an ‘‘Address Windowing Extensions enabled’’ message when the SQL Server restarts. Index create memory The amount of memory SQL Server uses to perform sorts when creating an index is generally self- configuring. However, you can control it by using sp_configure to hard-code a certain memory footprint (in KB) for index creation. For example, the following code sets the memory used to create an index to 8MB: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; EXEC sp_configure ‘index create memory’, 8096; RECONFIGURE; Processor-configuration properties You can use the processor-configuration properties (listed in Table 39-3) to control how SQL Server uses multi-processor computers. TABLE 39-3 Processor-Configuration Properties Property Level* Graphic Control Code Option Processors Used S Management Studio EXEC sp_configure ‘affinity mask’ Maximum Worker Threads S Management Studio EXEC sp_configure ‘max worker threads’ Boost SQL Server Priority on Windows S Management Studio EXEC sp_configure ‘priority boost’ Use Windows NT Fibers S Management Studio EXEC sp_configure ‘lightweight pooling’ Number of processors for parallel execution of queries S Management Studio EXEC sp_configure ‘max degree of parallelism’ Minimum query plan threshold for parallel execution S Management Studio EXEC sp_configure ‘cost threshold for parallelism’ * The configuration level refers to Server, Database, or Connection. 899 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 900 Part VI Enterprise Data Management TheProcessorstab(seeFigure39-6)oftheSQLServer Properties page determines how SQL Server will use multi-processor computers. Most of these options are moot in a single-processor server. FIGURE 39-6 The Processors tab shows the processors available on the system and enables you to set how SQL Server uses them Processor affinity In a multi-CPU server, the operating system can moveprocessestoCPUsastheloadrequires.TheSQL Server processor affinity, or the relationship between a task and a CPU, can be configured on a per-CPU basis. By enabling the affinity between SQL Server and a CPU, you make that CPU available to SQL Server, but it is not dedicated to SQL Server. Therefore, while a CPU can’t be forced to run SQL Server, it can be segmented from SQL Server. SQL Server supports processor affinity by means of two affinity mask configuration options: affinity mask (also referred to as CPU affinity mask) and affinity I/O mask.Theaffinity mask con- figuration option e nables you to specify which CPUs on a multi-processor computer are to be used to run threads from SQL Server. The affinity I/O mask configuration option enables you to specify which CPUs are configured to run SQL Server threads related to I/O operations. These two configura- tion options give you the ability to allocate particular CPUs for disk I/O processing and particular CPUs for non-disk-related CPU requirements. 900 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 901 Configuring SQL Server 39 The affinity mask is a bitmap whereby the rightmost bit specifies the lowest-order CPU(0), the next rightmost bit specifies the next lowest-order CPU(1), and so on. A one-byte (eight bits) mask covers 8 CPUs in a multi-processor server, a two-byte mask covers up to 16 CPUs, a three-byte mask covers up to 24 CPUs, and a four-byte mask covers up to 32 CPUs. A one bit specifies that the corresponding CPU is allocated, and a zero bit specifies that the corresponding CPU is not allocated. When you are configuring the affinity mask option, you must use it in conjunction with the affinity I/O mask. I recommend against enabling the same CPU for both affinity mask and affinity I/O mask configu- ration options. The bit corresponding to each CPU should be one of the following: ■ 0 for both the affinity mask and affinity I/O mask options ■ 1forthe affinity mask and 0 for the affinity I/O mask option ■ 0forthe affinity mask and 1 for the affinity I/O mask option For example, suppose that on an 8-CPU system you want to allocate CPUs 0, 1, 2, and 3 for processing SQL Server threads, CPUs 4 and 5 for disk I/O processing, and CPUs 6 and 7 for other non-SQL Server activities. This means the last four bits will be one for the affinity mask bitmap (00001111), which is 15 in decimal, and the fifth and sixth bits will be one for the affinity I/O mask (00110000), whichis48indecimal: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; EXEC sp_configure ‘affinity mask’, 15; RECONFIGURE; EXEC sp_configure ‘affinity I/O mask’, 48; RECONFIGURE; The affinity mask setting takes e ffect immediately without requiring a restart of the SQL Server ser- vice, whereas the affinity I/O mask setting takes effect only after restarting the SQL Server service. The default value of 0 for the affinity mask option indicates that all the processors on the server are available for processing SQL Server threads. The default value of 0 for the affinity I/O mask option indicates that any CPUs that are eligible to process SQL Server threads are available for disk I/O processing. In Management Studio, processor affinity is configured by means of the check boxes in the Server Prop- erties Processors tab (refer to Figure 39-6). Affinity support for SQL Servers with 33 to 64 processors is available only on 64-bit SQL Servers and requires the additional use of the affinity64 mask and affinity64 I/O mask configuration options. Max worker threads SQL Server is a multi-threaded application, meaning that it can execute on multiple processors concur- rently for increased performance. Multi-threaded applications also allow more efficient use of a single processor, because this allows another task to execute while a task waits for a process that doesn’t use the CPU to finish. The threads are designed as follows: ■ A thread for each network connection ■ A thread to handle database checkpoints ■ Multiple threads to handle user requests. When SQL Server is handling a small number of connections, a single thread is assigned to each connection. However, as the number of connections grows, a pool of threads handles the connections more efficiently. 901 www.getcoolebook.com . in SQL Server Configuration Manager: 1. Open SQL Server Configuration Manager from Start ➪ Programs ➪ Microsoft SQL Server 2008 ➪ Configuration Tools ➪ SQL Server Configuration Manager. 2. Click SQL. between SQL Server and a CPU, you make that CPU available to SQL Server, but it is not dedicated to SQL Server. Therefore, while a CPU can’t be forced to run SQL Server, it can be segmented from SQL. unavailable in Microsoft SQL Server 2008. These options have no effect. Do not use them in new development work, as they may be removed in future SQL Server versions. Dynamic memory If SQL Server is

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