Tài liệu MASTERING SQL SERVER 2000- P20 pdf

50 337 0
Tài liệu MASTERING SQL SERVER 2000- P20 pdf

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

CHAPTER 26 • MONITORING AND OPTIMIZING SQL SERVER 2000 970 12. Click Next. 13. Under Select Tables to Tune, click Select All Tables. 14. Click Next; the Wizard will now start tuning your indexes. 15. You will be asked to accept the index recommendations; click Next. 2627ch26.qxd 8/22/00 11:22 AM Page 970 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 971 16. If there were recommendations, you would be asked to schedule them for later or run them now, but because there are no recommendations for this workload file, you are taken directly to the final screen. Click Finish to complete the Wizard. 17. When you receive a message stating that the Wizard has completed, click OK. 18. Exit Profiler. Tips and Techniques If you want the best results from SQL Server’s monitoring tools, you need to know and use the proper techniques. If you don’t, the end result will not be what you are hoping for—or what you need. Setting a Measurement Baseline You will never know if your system is running slower than normal unless you know what normal is, which is what a measurement baseline does: It shows you the resources (memory, CPU, etc.) SQL Server consumes under normal circumstances. You create the measurement baseline before putting your system into production so that you have something to compare your readings to later on. TIPS AND TECHNIQUES Advanced Topics PART VI 2627ch26.qxd 8/22/00 11:22 AM Page 971 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 26 • MONITORING AND OPTIMIZING SQL SERVER 2000 972 The first thing you need to create an accurate measurement baseline is a test net- work with just your SQL Server and one or two client machines. You limit the number of machines involved because all networks have broadcast traffic, which is processed by all the machines on the network. This broadcast traffic can throw your counts off—sometimes a little, sometimes quite a bit. You may instead want to consider shut- ting down as many machines as possible and generating your baseline off-hours if your budget does not allow for a test network. You can then start your baseline. The Windows NT counters mentioned at the out- set of this chapter as well as the preset SQL Server counters should provide an accu- rate baseline with which you can compare future readings. Then you can move to the next technique. Data Archiving and Trend Tracking Although the consequences of throwing away your SQL Server monitoring records are not quite as severe as facing an IRS auditor without records and receipts, you still need to save, or archive, your records. One of the primary reasons to do so is to back up requests for additional equipment. For example, if you ask for funds to buy more memory for the SQL Server, but don’t bring any proof that the system needs the RAM, you are probably not going to get the money. If you bring a few months’ worth of reports, however, and say, “After tracking SQL Server for a time, we’ve found this…” management may be far more willing to give you the money you need. Using archived data in such fashion is known as trend tracking. One of the most valuable functions of using your archived data for trend tracking is proactive troubleshooting—that is, anticipating and avoiding problems before they arise. Suppose you added 50 new users to your network about three months ago and are about to do it again. If you archived your data from that period, you would be able to recall what those 50 users did to the performance of the SQL Server, and you could compensate for it. On the other hand, if you threw that data away, you might be in for a nasty surprise when your system unexpectedly slows to a crawl. Optimization Techniques SQL Server can dynamically adjust most of its settings to compensate for problems. It can adjust memory use, threads spawned, and a host of other settings. In some cases, unfortunately, those dynamic adjustments may not be enough—you may need to make some manual changes. We’ll look at a few specific areas that may require your personal attention. 2627ch26.qxd 8/22/00 11:22 AM Page 972 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 973 Queries and Stored Procedures The first thing to ask yourself when you are getting slow response times is whether you could be using a stored procedure instead of a local query. Stored procedures are different from local code in two ways: They are stored on the SQL Server, so they do not need to be transmitted over the network, which causes congestion. In addition, stored procedures are precompiled on the server; this saves system resources, because local code must be compiled once it gets to the system. Overall, stored procedures are the way to go, but if you need to use local queries, you should consider how they are written, because poorly constructed queries can wreak havoc on your system. If, for example, you have a query that is returning every row of a table when only half of that is required, you should consider rewriting the query. Improper use of WHERE clauses can also slow your queries down. Make sure that your WHERE clauses reference indexed columns for optimal performance. Tempdb Is your tempdb big enough to handle the load that your queries put on it? Think of tempdb as a scratchpad for SQL Server; when queries are performed, SQL Server uses this scratchpad to make notes about the result set. If tempdb runs out of room to make these notes, system response time can slow down. Tempdb should be between 25 and 40% of the size of your largest database (for example, if your largest database is 100MB, tempdb should be 25 to 40MB). Query Governor Right out of the box, SQL Server will run any query you tell it to, even if that query is poorly written. You can change that by using the Query Governor. This is not a sepa- rate tool, but is part of the database engine and is controlled by the Query Governor Cost Limit. This setting tells SQL Server not to run queries longer than x (where x is a value higher than zero). If, for example, the Query Governor Cost Limit is set to 2, any query that is estimated to take longer than 2 seconds would not be allowed to run. SQL Server can estimate the running time of a query because SQL Server keeps statistics about the number and composition of records in tables and indexes. The Query Gover- nor Cost Limit can be set by using the command sp_configure ‘query governor cost limit’, ‘1’ (the 1 in this code can be higher). The Cost Limit can also be set on the Server Settings tab of the Server Properties page in Enterprise Manager. OPTIMIZATION TECHNIQUES Advanced Topics PART VI 2627ch26.qxd 8/22/00 11:22 AM Page 973 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 26 • MONITORING AND OPTIMIZING SQL SERVER 2000 974 NOTE If the Query Governor Cost Limit is set to zero (the default), all queries will be allowed to run. Setting Trace Flags A trace flag is used to temporarily alter a particular SQL Server behavior. Much like a light switch can be used to turn off a light and then turn it back on again, a trace flag can be used to turn off (or on) a behavior in SQL Server. Trace flags are enabled with DBCC TRACEON and turned off with DBCC TRACEOFF. The command to enable trace flag 1204 would look like this: DBCC TRACEON(1204). Table 26.3 lists some of the trace flags available to you. TABLE 26.3: USES OF TRACE FLAGS Trace Flag Use 107 This instructs the server to interpret numbers with a decimal point as type float instead of decimal. 260 This trace flag prints version information for extended stored procedure Dynamic Link Libraries. If you write your own extended stored procedures, this trace flag will prove useful in troubleshooting. 1204 This will tell you what type of locks are involved in a deadlock and what com- mands are affected. 1205 This flag returns even more detailed information about the commands affected by a deadlock. 1704 This will print information when temporary tables are created or dropped. 2528 This trace flag disables parallel checking of objects by the DBCC CHECKDB, DBCC CHECKFILEGROUP, and DBCC CHECKTABLE commands. If you know that the server load is going to increase while these commands are running, you may want to turn these trace flags on so that SQL Server checks only a single object at a time and therefore places less load on the server. Under ordinary circumstances, though, you should let SQL Server decide on the degree of parallelism. 3205 This will turn off hardware compression for backups to tape drives. 3604 When turning on or off trace flags, this flag will send output to the client. 3605 When turning on or off trace flags, this flag will send output to the error log. 7505 This enables 6.x handling of return codes when a call to dbcursorfetchx causes the cursor position to follow the end of the cursor set. 2627ch26.qxd 8/22/00 11:22 AM Page 974 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 975 Max Async I/O It should go without saying that SQL Server needs to be able to write to disk, because that’s where the database files are stored—but is it writing to disk fast enough? If you have multiple hard disks connected to a single controller, multiple hard disks con- nected to multiple controllers, or a RAID system involving striping, the answer is probably no. The maximum number of asynchronous input/output (Max Async I/O) threads by default in SQL Server is 32. This means that SQL Server can have 32 out- standing read and 32 outstanding write requests at a time. Thus, if SQL Server needs to write some data to disk, SQL Server can send up to 32 small chunks of that data to disk at a time. If you have a powerful disk subsystem, you will want to increase the Max Async I/O setting. The value to which you increase this setting depends on your hardware, so if you increase the setting, you must then monitor the server. Specifically, you will need to monitor the Physical Disk: Average Disk Queue Performance Monitor counter, which should be less than two (note that any queue should be less than two). If you adjust Max Async I/O and the Average Disk Queue counter goes above two, you have set Max Async I/O too high and will need to decrease it. NOTE You will need to divide the Average Disk Queue counter by the number of phys- ical drives to get an accurate count. That is, if you have three hard disks and a counter value of six, you would divide six by three—which tells you that the counter value for each disk is two. LazyWriter LazyWriter is a SQL Server process that moves information from the data cache in memory to a file on disk. If LazyWriter can’t keep enough free space in the data cache for new requests, performance slows down. To make sure this does not hap- pen, monitor the SQL Server: Buffer Manager – Free Buffers Performance Monitor counter. LazyWriter tries to keep this counter level above zero; if it dips or hits zero, you have a problem, probably with your disk subsystem. To verify this, you need to check the Physical Disk: Average Disk Queue Performance Monitor counter and ver- ify that it is not more than two per physical disk (see above). If the queue is too high, LazyWriter will not be able to move data efficiently from memory to disk, and the free buffers will drop. OPTIMIZATION TECHNIQUES Advanced Topics PART VI 2627ch26.qxd 8/22/00 11:22 AM Page 975 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 26 • MONITORING AND OPTIMIZING SQL SERVER 2000 976 RAID RAID (Redundant Array of Inexpensive Disks) is used to protect your data and speed up your system. In a system without RAID, data that is written to disk is written to that one disk. In a system with RAID, that same data would be written across multiple disks, providing fault tolerance and improved I/O. Some forms of RAID can be imple- mented inexpensively in Windows NT, but this uses such system resources as proces- sor and memory. If you have the budget for it, you might consider getting a separate RAID controller that will take the processing burden off Windows NT. RAID is dis- cussed in detail in Chapter 4, but here is a quick refresher: RAID 0 Stripe Set: This provides I/O improvement, but not fault tolerance. RAID 1 Mirroring: This provides fault tolerance and read-time improve- ment. This can also be implemented as duplexing, which is a mirror that has separate controllers for each disk. RAID 0+1 Mirrored Stripe Set: This is a stripe set without parity that is duplicated on another set of disks. This requires a third-party controller, because Windows NT does not support this level of RAID natively. RAID 5 Stripe Set with Parity: This provides fault tolerance and improved I/O. Adding Memory SQL Server, like most BackOffice products, needs significant amounts of RAM. The more you put in, the happier SQL Server will be. There is one caveat about adding RAM, however: your level 2 cache. This is much faster (and more expensive) than standard RAM and is used by the processor for storing frequently used data. If you don’t have enough level 2 cache to support the amount of RAM in your system, your server may slow down rather than speed up. Microsoft tells you that the minimum amount of RAM that SQL Server needs is 32 to 64MB, but because SQL Server benefits greatly from added RAM, you should consider using 256MB of RAM, which requires 1MB of level 2 cache. Manually Configuring Memory Use Although SQL Server can dynamically assign itself memory, it is not always best to let it do so. A good example of this is when you need to run another BackOffice program, such as Exchange, on the same system as SQL Server. If SQL Server is not constrained, it will take so much memory that there will be none left for Exchange. The relevant 2627ch26.qxd 8/22/00 11:22 AM Page 976 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 977 constraint is the max server memory setting; by adjusting it, you can stop SQL Server from taking too much RAM. If, for example, you set it to 102,400—100 × 1024 (the size of a megabyte)—SQL Server will never use more than 100MB of RAM. You could also set min server memory, which tells SQL Server to never use less than the set amount; this should be used in conjunction with set working size. Windows NT uses virtual memory, which means that data that is in memory and has not been accessed for a while can be stored on disk. The set working size option stops Windows NT from moving SQL Server data from RAM to disk, even if SQL Server is idle. This can improve SQL Server’s performance, because data will never need to be retrieved from disk (which is about 100 times slower than RAM). If you decide to use this option, you should set min server memory and max server memory to the same size, and then change the set working size option to 1. Summary This chapter has stressed the importance of monitoring and optimization. Monitor- ing allows you to find potential problems before your users find them; without it, you have no way of knowing how well your system is performing. Performance Monitor can be used to monitor both Windows NT and SQL Server. Some of the more important counters to watch are Physical Disk: Average Disk Queue (which should be less than two) and SQLServer:Buffer Manager: Buffer Cache Hit Ratio (which should be as high as possible). Query Analyzer allows you to see how a query will affect your system before you place the query in production. The Profiler is used to monitor queries after they have been placed in general use; it is also useful for monitoring security and user activity. Once you have used Profiler to log information about query use to a trace file, you can run the Index Tuning Wizard to optimize your indexes. Once you have created all logs and traces, you need to archive them. The various log files can be used later for budget justification and trend tracking. For example, suppose you added 50 users to your system six months ago and are about to add 50 more. If you kept records on what kind of load the last 50 users placed on your sys- tem, you will be better prepared for the next 50. This chapter also presented some tips for repairing a slow-running system. You can change the Max Async I/O setting if your disk is not working hard enough to support the rest of the system, and you may need to upgrade your disk subsystem if the SQL Server: Buffer Manager – Free Buffers Performance Monitor counter hits zero. RAID can also speed up your SQL Server. If you can afford a separate controller, you should SUMMARY Advanced Topics PART VI 2627ch26.qxd 8/22/00 11:22 AM Page 977 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 26 • MONITORING AND OPTIMIZING SQL SERVER 2000 978 get one to take some of the burden off Windows NT. If you can’t afford one, you can use Windows NT RAID level 1 for fault tolerance and speed. Now that you know how to optimize your server and keep it running at peak per- formance, it will be much easier to perform all of the tasks on your SQL Server. This is especially true of the next topic that we will discuss—replication. 2627ch26.qxd 8/22/00 11:22 AM Page 978 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 27 Replication FEATURING: Understanding Replication 980 Setting Up Replication 990 Creating and Subscribing to a Transactional Publication 999 Creating and Subscribing to a Snapshot Publication 1017 Creating and Subscribing to a Merge Publication 1028 Using Replication Monitor 1040 Summary 1046 2627ch27.qxd 8/22/00 11:24 AM Page 979 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... database server Heterogeneous replication is the process of replicating data from SQL Server to another type of database system The only requirement for the subscriber in this case is that it must be Open Database Connectivity (ODBC) compliant If the target is ODBC compliant, it can be the recipient of a push subscription from SQL Server If you find that you need to pull a subscription from SQL Server. .. folder reside You will work with the local server, so check the radio button labeled Make Server Its Own Distributor and click Next Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark 8/22/00 11:24 AM Page 993 SETTING UP REPLICATION 993 4 The next screen asks whether you would like to customize the distribution server properties or let SQL Server do it for you If you want to place... to a SQL Server to use it as a distributor; this keeps unauthorized users out of your system The default is to have the replication agent use the account that the SQLServerAgent service uses, but if you want, you may create a SQL Server login for the replication agent to use In this case, accept the default of impersonation • For even more security, you can require a password for the foreign server. .. click Next Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark 8/22/00 11:24 AM Page 1003 CREATING AND SUBSCRIBING TO A TRANSACTIONAL PUBLICATION 1003 9 On the next screen, you are asked what database systems the subscribers will be running If all servers are running SQL Server 2000, all properties can be replicated Subscribers that are not running SQL Server 2000 may not be able... to the people who have subscribed, SQL Servers need special servers called distributors to collect data from publishers to distribute to subscribers Subscriber: A subscriber is a server that requires a copy of the data that is stored on the publisher The subscriber is akin to the people who need to read the news, so they subscribe to the newspaper FIGURE 27.1 SQL Server can publish, distribute, or... C$ share on any given server, the account used by the SQLServerAgent service needs to be an administrator on the distribution server, or replication will fail Once the distributor is ready to go, you can proceed with replication The first step is to configure the distributor, which we will do now N OTE For the exercises in this chapter, you will need to have two instances of SQL Server running To configure... 10 Now you are asked which servers should be configured as subscribers to this publisher You will select both servers and click Next Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark 8/22/00 11:24 AM Page 997 SETTING UP REPLICATION 997 11 Review the selections you have made and, if they are correct, click Finish to configure replication 12 SQL Server will display a list of... Enterprise Manager by selecting it from the SQL Server 2000 program group under Programs on the Start menu 2 Select your default instance of SQL Server and then on the Tools menu, point to Replication and click Configure Publishing, Subscribers and Distribution This starts the Configure Publishing and Distribution Wizard Click Next Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Advanced... distribution server Snapshot agent: Just by reading the name of this agent, you would expect it to work with snapshot replication, but it works with all types of replication This agent makes a copy of the publication on the publisher and either copies it to the distributor, where it is stored in the distribution working folder (\\ distribution _server\ Program Files\Microsoft SQL Server\ MSSQL$ (instance)\REPLDATA),... SECOND servers (if you do not have a SECOND server, please refer to Appendix B) Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark 8/22/00 11:24 AM Page 995 SETTING UP REPLICATION 995 7 When you check the box to enable SECOND, you are presented with a warning informing you that you need to provide some security information about SECOND so that it can log in to the distribution server . default in SQL Server is 32. This means that SQL Server can have 32 out- standing read and 32 outstanding write requests at a time. Thus, if SQL Server needs to. option stops Windows NT from moving SQL Server data from RAM to disk, even if SQL Server is idle. This can improve SQL Server s performance, because data

Ngày đăng: 26/01/2014, 08:20

Từ khóa liên quan

Mục lục

  • CONTENTS

  • Introduction

  • PART I • INTRODUCING SQL SERVER

    • 1 Introduction to SQL Server 2000

      • Tour for DBAs

      • Tour for Developers

      • Tour for Users

      • Summary

      • 2 Overview of Database Concepts

        • Databases

        • Tables

        • Views

        • Stored Procedures

        • Ownership and Security

        • Jobs, Alerts, and Operators

        • Replication

        • Application Programming Interfaces

        • Summary

        • 3 Overview of SQL Server

          • Programs Installed with SQL Server

          • Parts of a Database

          • SQL Server Storage Concepts

          • Summary

          • 4 Database Design and Normalization

            • What Is Normalization?

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

Tài liệu liên quan