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

10 174 0
Hướng dẫn học Microsoft SQL Server 2008 part 95 doc

Đ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 902 Part VI Enterprise Data Management Depending on the number of connections and the percentage of time those connections are active (ver- sus idle), making the number of worker threads less than the number of connections can force connec- tion pooling, conserve memory, and improve performance. In Management Studio, the max worker threads option is set by typing or selecting a value in the Maximum Worker Threads box in the Server Properties Processor tab (refer to Figure 39-6). From code, the maximum number of worker threads is set by means of the sp_configure stored pro- cedure and the max worker threads option. For example, the following code sets the max worker threads to 128: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; EXEC sp_configure ‘max worker threads’, 128; RECONFIGURE; The SQL Server service must be restarted for the max worker threads setting to take effect. Best Practice O n SQL Server 2005 and SQL Server 2008, the default value of 0 for the max worker threads property provides the best performance of SQL Server. This default value indicates that SQL Server will automatically determine the correct number of active worker threads based on user requests. If you do need to change the default value, then I recommend not setting the max worker threads option to a small value, which might prevent enough threads from servicing incoming client requests in a timely manner and could lead to ‘‘thread starvation.’’ Conversely, don’t set the max worker threads option to a large value, which wastes memory, because each active thread consumes 512KB on 32-bit servers and up to 4MB on 64-bit servers. To view information about the connections established to an instance of SQL Server, query the sys.dm_exec_connections dynamic management view. This information includes statistics about each of the databases, connections by both local and remote users, and details about each connection. Priority boost Different processes in Windows operate at different priority levels, ranging from 0 to 31. The highest priorities are executed first and are r eserved for the operating-system processes. Typically, Windows scheduling priority-level settings for applications are 4 (low), 7 (normal), 13 (high), and 24 (real-time). By default, SQL Server installs with a Windows scheduling priority level of 7. The default value of priority boost gives SQL Server enough CPU resources without adversely affecting other applications. 902 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 903 Configuring SQL Server 39 Best Practice I n almost all cases, it is recommended to leave the priority boost option to the default value of 0. Raising the priority of SQL Server may drain essential ope rating system and networking functions, resulting in a poorly performing SQL Server; and in some cases it may even result in a SQL Server shutdown. If you do change the priority boost from 0 to 1, then be sure to test it thoroughly and evaluate all other performance-tuning opportunities first. If you still insist on changing the priority boost configuration option, you can use either Manage- ment Studio or T-SQL code. In Management Studio, priority boost is set to 1 by checking the Boost SQL Server priority checkbox in the Server Properties Processor tab (refer to Figure 39-6 earlier in this chapter). Using T-SQL code, the following command sets the priority boost option to 1. This will set the Windows scheduling priority level to 13 (high): EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; EXEC sp_configure ‘priority boost’, 1; RECONFIGURE; The SQL Server service must be restarted for the priority boost option to take effect. Lightweight pooling You can use the lightweight pooling option for multi-processing servers to reduce the overhead of frequently switching processes among the CPUs. Best Practice F or most SQL Servers, the default value of 0 for the lightweight pooling configuration option of fers the best performance. In fact, changing the value from 0 to 1 may result in decreased performance. Ifyoudochangelightweight pooling to 1, then be sure to test it thoroughly and evaluate all other performance-tuning opportunities first. If you still insist on changing the lightweight pooling configuration option, you can use either Management Studio or T-SQL code. In Management Studio, lightweight pooling can be set to 1 (default is 0) by checking the Use Windows Fibers (lightweight pooling) check box in the Server Properties Processor tab (refer to Figure 39-6 earlier i n this chapter). 903 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 904 Part VI Enterprise Data Management In code, set the lightweight pooling option as follows: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; EXEC sp_configure ‘lightweight pooling’, 1; RECONFIGURE; The SQL Server service must be restarted for the lightweight pooling option to take effect. The need for the lightweight pooling option is reduced by improved context switching in Microsoft Windows Server 2003 and 2008. The lightweight pooling and clr enabled configuration options are mutually exclusive. You can use one of the two options: lightweight pooling or clr enabled. Parallelism On a multi-processor server, SQL Server detects the best number of processors that can be used to run a single statement for each parallel plan. The max degree of parallelism configuration option can be used to limit the number of processors used in a parallel plan execution. SQL Server’s Query Optimizer is a cost-based optimizer, which means it chooses a plan that returns the results in a reasonable amount of time with a reasonable resource cost. SQL Server always considers a serial plan first. If this serial plan costs less than the cost threshold for parallelism value, then no parallel plan is generated. The cost threshold for parallelism option refers to the cost of the query in seconds on a specific hardware configuration. If the cheapest serial plan costs more than the cost threshold for parallelism, then a parallel plan is produced. The parallel plan cost is compared with the serial plan cost and the cheaper one is chosen. Complex queries benefit the most from parallelism, as generating a parallel query execution plan, syn- chronizing the parallel query, and terminating the query all require additional overhead. To determine whether a query i s using parallelism, view the query execution plan in Management Studio. A symbol shows the merger of different parallel query execution threads. The default value of the max degree of parallelism option is 0, which tells SQL Server to use all the available processors. In Management Studio, the max degree of parallelism option can be set by entering the maxi- mum number of processors to be used in a parallel plan in the Max Degree of Parallelism b ox in the Server Properties Advanced tab (see Figure 39-9, later in the chapter). The following code sets the max degree of parallelism option to 4: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; GO EXEC sp_configure ‘max degree of parallelism’, 4; RECONFIGURE; 904 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 905 Configuring SQL Server 39 Best Practice T he default value of 0 for the max degree of parallelism option works well for SQL Servers that have up to eight processors. The performance of the SQL Server can actually degrade if more than eight processors are used in a parallel plan. I recommend changing the max degree of parallelism option on SQL Servers that have more than eight processors from the default value of 0 to 8 or less. For servers that have NUMA configured, max degree of parallelism should not exceed the number of CPUs assigned to each NUMA node. For servers that have hyperthreading enabled, max degree of parallelism should not exceed the number of physical processors. Although a parallel query execution plan can be much faster, there is a point at which the parallel query execution becomes inefficient and can even extend the execution time. For example, parallel queries performing small joins and aggregations on small data sets might be inefficient; and due to different degrees of parallelism chosen at execution time, response times for one query can be different depending on resource availability such as CPU and memory. Paul recommends setting the max degree of parallelism option to 1 for OLTP workloads. I don’t agree 100%, but certain applications do need max degree of parallelism set to 1 — for example, the max degree of parallelism option is set to ‘‘1’’ during the configuration of BizTalk Server for the SQL Server instance(s) that host the BizTalk Server MessageBox database(s). As per BizTalk’s documentation, changing this to anything other than 1 can have a significant negative impact on the BizTalk Server stored procedures and performance. With this in mind, I recommend checking with your application vendor for any best practices for the max degree of parallelism option. If you are unable to contact the vendor or you are using an in-house application, then you may want to test different values of the max degree of parallelism option to see which value offers the maximum performance gains. If you find that setting the max degree of parallelism option to 1 or any low value works best for your workload, I recommend changing the option back to 0 (or 8 if you have more than eight CPUs) when you a re performing database maintenance tasks such as index creation, index rebuild, and checkdb, as doing so will speed up these tasks if they can leverage more CPUs. You can change the max degree of parallelism option without needing to restart SQL Server. While these server-tuning options can affect performance, performance begins with the database schema, queries, and indexes. No amount of server tuning can overcome poor design and development. The default value of the cost threshold for parallelism option works well for most SQL Servers. Change the default value only after performing thorough testing and consid- ering other performance-tuning opportunities. If you insist on changing the default value of the cost threshold for parallelism option, then you can use either Management Studio or T-SQL code. In Management Studio, the cost threshold 905 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 906 Part VI Enterprise Data Management for parallelism option can be set by entering the desired value in the Cost Threshold for Paral- lelism box in the Server Properties Advanced tab (refer to Figure 39-9, later in the chapter). The following code sets the cost threshold for parallelism option to 30 seconds: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; EXEC sp_configure ‘cost threshold for parallelism’, 30; RECONFIGURE; Security-configuration properties The security-configuration properties, shown in Table 39-4, are used to control the security features of SQL Server. The same security-configuration options established during the installation are again presented in the Security tab of the Server Properties page (see Figure 39-7), so the configuration may be adjusted after installation. Server authentication mode The two server authentication modes are exactly the same as those presented during SQL Server instal- lation: ■ Windows Authentication mode: This uses Windows Authentication to validate connections. ■ SQL Server and Windows Authentication mode: This uses both SQL and Windows Authentication to validate connections. TABLE 39-4 Security-Configuration Properties Property Level* Graphic Control Code Option Server Authentication Mode S Management Studio - Security Audit Level S Management Studio - C2 Audit Tracing Common Criteria Compliance S S Management Studio EXEC sp_configure ‘c2 audit mode’ EXEC sp_configure ‘common criteria compliance enabled’ Cross Database Ownership Chaining S D Management Studio EXEC sp_configure ‘cross db ownership chaining’ ALTER DATABASE xxx SET DB_CHAINING {ON | OFF} * The configuration level refers to Server, Database, or Connection. 906 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 907 Configuring SQL Server 39 During installation, if you select SQL Server and Windows Authentication mode, you are prompted for a sa password. When you select Windows Authentication mode, the sa account gets a random strong password, unknown to the user. When you change to SQL Server and Windows Authentication mode, t he sa account is disabled. You need to enable the sa account and then change the sa password in order to use the account. FIGURE 39-7 Security tab of Management Studio’s SQL Server Properties dialog Security-audit level The login auditing options configure the level of user-login auditing performed by SQL Server. You can choose one of the following four login auditing options (refer to Figure 39-7): ■ None ■ Failed logins only ■ Successful logins only ■ Both failed and successful logins 907 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 908 Part VI Enterprise Data Management Based on the setting, SQL Server will record every successful or failed user login attempt to the Win- dows application log and the SQL Server log. The SQL Server service must be restarted in order for the login auditing options to take effect. C2 audit tracing C2 auditing is a U.S. government standard for monitoring database security. SQL Server supports C2 auditing. To configure SQL Server for C2 auditing, enable the c2 audit mode option. Enabling the c2 audit mode option configures the SQL Server to all security-related events. You can find all the events by browsing through them in SQL Server Profiler. By default, a trace file (C2 audit log) is stored in the default SQL Server data directory. The trace file rolls over automatically when it reaches 200MB. This continues until the data drive fills up or C2 auditing is turned off. In Management Studio, the c2 audit mode option can be turned on by selecting the ‘‘Enable C2 audit tracing’’ box in the Server Properties Security tab (refer to Figure 39-7). In code, turn on the c2 audit mode option as follows: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; EXEC sp_configure ‘c2 audit mode’, 1; RECONFIGURE; The SQL Server service must be restarted for the c2 audit mode option to take effect. The C2 auditing mode has been superseded by Common Criteria Compliance. Common Criteria Com- pliance can be enabled only with code, using the sp_configure system stored procedure: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; EXEC sp_configure ‘common criteria compliance enabled’, 1; RECONFIGURE; The SQL Server service must be restarted in order for the common criteria compliance enabled option to take effect. In addition to enabling the option, you also must download and run a script from the Microsoft SQL Server Common Criteria website at www.microsoft.com/sql/ commoncriteria/certifications.mspx . Cross-database ownership chaining By default, all database objects, such as tables, views, and stored procedures, have owners. When an object references another object, an ownership chain is formed. When the same user owns the source object and the target object, SQL Server checks permission on the source objects, and not on the target objects. Cross-database ownership chaining occurs when the source object depends on objects in another data- base. Cross-database ownership chaining works in the same way as ownership chaining in a database, 908 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 909 Configuring SQL Server 39 except that an unbroken ownership chain is based on all the object owners being mapped to the same login account. If your application uses more than one database and it calls objects from one database that is based on objects in another database, then cross-database chaining is used. If the source object in the source database and the target object in the target database are owned by the same login, SQL Server does not check permissions on the target objects. The cross db ownership chaining option enables control of the cross-database ownership chaining for all databases. By default, the cross db ownership chaining option is turned off (0), which ensures maximum security. If you turn this option on (1), then database owners and members of the db_ddladmin or the db_owners database roles can create objects that are owned by other users. These objects can potentially target objects in other databases, so you must fully trust these users with data in all databases. In Management Studio, cross-database ownership chaining can be turned on by checking the ‘‘Cross database ownership chaining’’ option in the Server Properties Security tab. In code, use the following to turn on cross-database ownership chaining: EXEC sp_configure ‘cross db ownership chaining’, 1; RECONFIGURE; When the cross db ownership chaining option is turned off (0), cross database ownership chaining can be controlled at the database level with the SET DB_CHAINING option of the ALTER DATABASE command. For more information about locking down SQL Server’s security, refer to the chapters in Part VII, ‘‘Security.’’ Connection-configuration properties The connection-configuration properties, shown in Table 39-5, are used to set connection options in SQL Server. The Server Properties Connections tab (see Figure 39-8) sets connection-level properties, including defaults, number of connections permitted, and timeout settings. Maximum concurrent user connections The user connections option is used to specify the maximum number of simultaneous user con- nections allowed on SQL Server. This option is self-configuring; SQL Server automatically adjusts the maximum number of user connections as needed, up to a maximum of 32,767 connections. The default for the user connections option is zero, which m eans unlimited user connec- tions are allowed. For most SQL Servers, this default value works best. If you change this option, don’t set the value too high, as each connection has overhead regardless of whether the con- nection is being used. However, don’t set this option to a small value such as 1 or 2, which might pre- vent administrators from connecting to administer the SQL Server. The Dedicated Admin Connection can always connect. 909 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 910 Part VI Enterprise Data Management TABLE 39-5 Connection-Configuration Properties Property Level* Graphic Control Code Option Max Concurrent User Connections S Management Studio EXEC sp_configure ‘user connections’ Query Cost Governor CS Management Studio EXEC sp_configure ‘query governor cost limit’ SET QUERY_GOVERNOR_COST_LIMIT 15 Permit Remote Server Connections S Management Studio EXEC sp_configure ‘remote access’ Remote Login Timeout S Management Studio EXEC sp_configure ‘remote login timeout’ Remote Query Timeout S Management Studio EXEC sp_configure ‘remote query timeout’ Enforce DTC S Management S tudio EXEC sp_configure ‘remote proc trans’ Network Packet Size S Management Studio EXEC sp_configure ‘network packet size’ * The configuration level refers to Server, Database, or Connection. The maximum concurrent user connections option should probably not b e set to a given number of users because applications often open several connections to SQL Server. For example, ODBC- and ADO-based applications open a connection for every connection object in code — possibly as many as one for every form, list box, or combo box. Access tends to open at least two connections. In Management Studio, the user connections configuration option can be set by typing a value from 0 through 32767 in the ‘‘Max number of concurrent connections’’ box in the Server Properties Connec- tions tab (refer to Figure 39-8). The following code sets the maximum number of user connections to 10240: EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; GO EXEC sp_configure ‘user connections’, 10240; RECONFIGURE; The SQL Server service must be restarted in order for the user connections option to take effect. 910 www.getcoolebook.com Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 911 Configuring SQL Server 39 FIGURE 39-8 Connections tab of Management Studio’s SQL Server Properties dialog To determine the maximum number of simultaneous user connections allowed on a SQL Server instance using code, examine the value in the @@ MAX_CONNECTIONS global variable. The number returned is neither the actual number of connections nor the configured value — it is the maximum number allowed: SELECT @@MAX_CONNECTIONS; Result: 32767 Query governor cost limit In the same way that a small gas-engine governor controls the top speed of the engine, the query gover- nor limits the queries that SQL Server will run according to the estimated query cost on a specific hard- ware configuration. If a user submits a query that exceeds the limit set by the query governor, then SQL 911 www.getcoolebook.com . threads’, 128; RECONFIGURE; The SQL Server service must be restarted for the max worker threads setting to take effect. Best Practice O n SQL Server 2005 and SQL Server 2008, the default value of. 905 Configuring SQL Server 39 Best Practice T he default value of 0 for the max degree of parallelism option works well for SQL Servers that have up to eight processors. The performance of the SQL Server. 908 Part VI Enterprise Data Management Based on the setting, SQL Server will record every successful or failed user login attempt to the Win- dows application log and the SQL Server log. The SQL

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

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

Tài liệu liên quan