Microsoft Press Configuring sql server 2005 môn 70 - 431 phần 7 pdf

98 279 0
Microsoft Press Configuring sql server 2005 môn 70 - 431 phần 7 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

552 Chapter 15 Monitoring and Troubleshooting SQL Server Performance C:\PerfLogs directory. You can then open this log file in System Monitor for further analysis, which Lesson 5, “Correlating Performance and Monitoring Data,” covers as it explains how to leverage performance counters. Quick Check 1. How do you launch System Monitor? 2. For what purpose do you use System Monitor? Quick Check Answers 1. You launch System Monitor from the Start menu by selecting Performance within the Administrative Tools menu on any machine running Windows. 2. You use System Monitor to gather numeric data related to various system and application metrics. System Monitor cannot tell you what is executing, but it can quantify an activity for a given system or application component. PRACTICE Configuring a System Monitor Counter Log In this practice, you will configure a System Monitor counter log, which you will use in Lesson 5 to practice how to correlate data between Profiler and System Monitor. 1. Launch System Monitor by choosing Start, Administrative Tools, Performance. 2. Expand the Performance Logs And Alerts node. 3. Right-click Counter Logs and choose New Log Settings. 4. Specify a name for your log file settings and click OK. 5. Click Add Counters and add the following counters: A. Network Interface\Output Queue Length B. Processor\% Processor Time C. SQL Server:Buffer Manager\Buffer Cache Hit Ratio D. SQL Server:Buffer Manager\Page Life Expectancy E. SQL Server:SQL Statistics\Batch Requests/Sec F. SQL Server:SQL Statistics\SQL Compilations/Sec G. SQL Server:SQL Statistics\SQL Re-compilations/Sec C1562271X.fm Page 552 Friday, April 29, 2005 7:59 PM Lesson 2: Working with System Monitor 553 6. Set the interval to one second. 7. Specify a user to run the counter log and enter the user’s password. 8. Leave the Log Files and Schedules tabs at their defaults. 9. Click OK. By default, System Monitor stores log files in the folder C:\PerfLogs. If this folder does not yet exist, you are prompted to create it. Click Yes. 10. Right-click your new counter log and choose Start. Lesson Summary ■ System Monitor provides a key tool for gathering statistical data related to hard- ware and software metrics, which Profiler does not capture. ■ You should always capture System Monitor counters in a log if you plan to do any analysis of the data or correlating with other tools. ■ To define the counters that System Monitor captures in the counter log, you can use Add Objects to gather all counters associated with a particular object or Add Counters to specify individual counters. Lesson Review The following questions are intended to reinforce key information presented in this lesson. The questions are also available on the companion CD if you prefer to review them in electronic form. NOTE Answers Answers to these questions and explanations of why each answer choice is right or wrong are located in the “Answers” section at the end of the book. 1. A System Monitor counter log can gather which types of information? (Choose all that apply.) A. The applications currently running in Windows B. Numerical data related to hardware performance C. Queries being executed against SQL Server D. The number of orders being placed per second C1562271X.fm Page 553 Friday, April 29, 2005 7:59 PM 554 Chapter 15 Monitoring and Troubleshooting SQL Server Performance Lesson 3: Using the Database Engine Tuning Advisor The Database Engine Tuning Advisor (DTA) is the greatly enhanced replacement to the Index Tuning Wizard tool that shipped with previous versions of SQL Server. DTA plays an important role in an overall performance solution, letting you leverage the query optimizer to receive recommendations on indexes, indexed views, or partitions that could improve performance. Hackers have developed sophisticated algorithms for breaking into secure systems, but the most time-honored approach and the one that has a 100 percent success rate is the brute force attack. DTA applies the same concept, taking a workload file as an input and then exhaustively testing each query against all possible permutations of indexes, indexed views, and partitions to come up with the best possible solution. This lesson will explain all of the options available in DTA and how to integrate this powerful tool into your performance-tuning work. After this lesson, you will be able to: ■ Build a workload file. ■ Configure DTA to analyze a workload. ■ Save recommendations from DTA. Estimated lesson time: 45 minutes IMPORTANT If DTA fails to start There have been many reports of DTA failing to start and displaying a C++ compile error. This is a known issue related to incompatible registry settings that older applications might have added. If you cannot get DTA to start, see the Microsoft article “Bug Details: Database Engine Tuning Advisor” (at http://lab.msdn.microsoft.com/productfeedback/ViewFeedback.aspx?FeedbackID=631e881c- 4b0f-4c5c-b919-283a71cea5fe) for information about how to fix the problem. Real World Michael Hotek I have been doing performance-tuning work in SQL Server for well over a decade. What I have heard for too long from too many people is that perfor- mance tuning is an art form. That could not be further from the truth. Compos- ing the next number one hit, painting a masterpiece, or building an original C1562271X.fm Page 554 Friday, April 29, 2005 7:59 PM Lesson 3: Using the Database Engine Tuning Advisor 555 piece of furniture is an art. Performance tuning is nothing more than the appli- cation of knowledge based on a set of rules to produce a result. Although processor utilization, amount of memory available, and disk I/O can affect database query performance, SQL Server’s query optimizer plays a critical role in the performance of any query. SQL Server is a piece of software that is written based on rules. The optimizer applies a defined, but not documented, set of rules to determine how to gather the data that a query requests. We can only deduce these basic rules by understanding how data is organized in SQL Server as well as inspecting showplans to see the query paths that various queries have taken. From these pieces of information, we can start to apply the rules of per- formance tuning. At many organizations, gathering and analyzing data to determine where the performance issues are is the first hurdle. The second hurdle is in understanding what to do about the issues to improve performance. Although many perfor- mance issues require changes to the code that is executing, many more can be solved simply by adding indexes, dropping indexes, or changing indexes, which is where DTA plays an important role in any environment. It enables you to get at core issues related to indexing without having to spend large amounts of time on analysis. One of the first things I do at a customer site when dealing with performance issues is to start Profiler and begin capturing queries. I can then take that Profiler trace and feed it directly into DTA. Using the trace I give it, DTA simply takes each query and applies the rules of the optimizer in a nearly exhaustive manner. It uses the query costing values to determine whether a particular query could benefit from having indexes or indexed views created for it or whether partition- ing the table would improve performance. The index recommendations let me zero in on particular areas as well as partic- ular queries that I need to look at. In many cases, running DTA regularly and using its recommendations can help avoid or mitigate performance issues. Although running DTA doesn’t eliminate the need for further analysis, as I will describe in subsequent lessons in this chapter, it can at least keep your phone from ringing off the hook with users upset at the responsiveness of a system and let you spend more time doing even deeper analysis to accomplish even better performance. C1562271X.fm Page 555 Friday, April 29, 2005 7:59 PM 556 Chapter 15 Monitoring and Troubleshooting SQL Server Performance Building a Workload File DTA requires you to provide it with a workload that it can analyze. You can provide the workload in a variety of formats, including a trace file, a trace table, or a Transact- SQL script. The most common workload used within DTA is a trace file. You can generate this trace by using SQL Server Profiler, which ships with a template designed to capture the data DTA needs to perform its analysis. To generate the trace file, launch Profiler, select the Tuning trace template, and save the results to a file. Alternatively, you can load the trace into a table that DTA uses to perform its analysis. NOTE Using a Transact-SQL script as a workload file A Transact-SQL script makes for an interesting workload file, which simply contains a batch of SQL that you want to analyze. Although there isn’t anything earth-shattering about creating a file that contains a batch of SQL, this option takes on a new meaning when you integrate it with your devel- opment processes. For example, you can highlight a query in a batch of SQL in the query window within SSMS, right-click the query, and select Send To Database Engine Tuning Advisor. This action launches DTA against the SQL batch you highlighted, letting you perform targeted analysis while you are developing queries. Configuring DTA to Analyze a Workload Analyzing a workload in DTA consists of three basic steps: 1. Launch DTA and connect to your server. 2. Select a workfile to analyze. 3. Specify tuning options. Let’s walk through each of these steps. First, launch DTA so that you can configure a new analysis session, as shown in Figure 15-14. Each session you create will be saved, so you can go back and review previous analysis sessions and view the recommendations that DTA generated. To easily identify ses- sions, make sure to give each one a descriptive name. You need to specify the work- load source along with the database for the workload analysis. You also have to specify the databases and tables that you want to tune within the workload. DTA uses the database you specify for the workload analysis as the basis for making tuning deci- sions. And by specifying the databases and tables for tuning, you let DTA ignore some of the events in the workload file. C1562271X.fm Page 556 Friday, April 29, 2005 7:59 PM Lesson 3: Using the Database Engine Tuning Advisor 557 Figure 15-14 Configuring an analysis session After you specify the general options for the tuning session, click the Tuning Options tab (see Figure 15-15). Figure 15-15 Specifying tuning options to consider C1562271X.fm Page 557 Friday, April 29, 2005 7:59 PM 558 Chapter 15 Monitoring and Troubleshooting SQL Server Performance One of the most important options to set when configuring a tuning session that involves workloads from production systems is to limit the tuning time. Otherwise, DTA could run for several days before completing. DTA performs its analysis by loading the specified workload and starting the first command to tune. DTA then interrogates the query optimizer with various options and compares the query cost that the optimizer returns. DTA repeats this interroga- tion process until it cannot find any options that produce a query plan of a lower cost. DTA then logs any recommendations for that query—such as creating an index, an indexed view, or partitioning the table—and moves on to the next statement to repeat the process. CAUTION DTA’s performance impact DTA actively sends requests to the query optimizer, which then returns a query cost. The query cost is based on the live distribution statistics for data within the database being tuned. Therefore, DTA generally uses your production database when it is in an analysis session. Thus, you must be very careful when executing a DTA analysis because the load it puts on the database can affect perfor- mance. If possible, restore a backup of your production database on another server and use it for the DTA analysis session. In general, you will specify that DTA look for both indexes and indexed views to create for better performance. However, you can restrict the structures that DTA will consider. DTA also analyzes whether partitioning a table might improve query performance. When you are configuring partitioning options in DTA, keep in mind that if you are using the SWITCH command with partitioning, you will want to restrict DTA’s analysis to aligned partitions only. MORE INFO Partitioning For information about partitioning, see Chapter 6, “Creating Partitions.” The final tuning options you can specify for DTA concern whether to keep physical design structures (PDSs). If you specify the option to keep them all, DTA recom- mends only creation of indexes, indexed views, or partitioning. If you specify any of the other options, DTA also includes recommendations regarding dropping struc- tures if that could improve performance. With the Advanced Options page, shown in Figure 15-16, you can specify whether you want to have online or offline recommendations. C1562271X.fm Page 558 Friday, April 29, 2005 7:59 PM Lesson 3: Using the Database Engine Tuning Advisor 559 Figure 15-16 Specifying advanced tuning options NOTE Restrictions on online operations Online operations are restricted by the edition of SQL Server 2005 that you are running. See SQL Server 2005 Books Online for more information about the specific capabilities of your edition. After you configure your DTA tuning session, you can start an analysis by clicking Start Analysis, which displays extended information on the session, as Figure 15-17 shows. Figure 15-17 Viewing the analysis progress C1562271X.fm Page 559 Friday, April 29, 2005 7:59 PM 560 Chapter 15 Monitoring and Troubleshooting SQL Server Performance DTA displays the progress of each action in the middle of the screen; you will notice that the majority of the time is spent on the Performing Analysis action. As DTA com- pletes its analysis of each statement, it displays the statement in the bottom pane. When DTA encounters a statement that it has already analyzed, it increments the Frequency counter for that statement and continues to the next statement in the workload. To view DTA’s performance recommendations, select the Recommendations tab (see Figure 15-18). Figure 15-18 Viewing performance recommendations DTA displays all recommendations, and you can sort and filter them by using the col- umn headers on the grid. Scrolling to the right displays the definition of each recommendation as a hyperlink (see Figure 15-19). Clicking a hyperlink launches a pop-up window that contains the complete Transact-SQL statement required to implement the recommendation. C1562271X.fm Page 560 Friday, April 29, 2005 7:59 PM Lesson 3: Using the Database Engine Tuning Advisor 561 Figure 15-19 Viewing performance recommendations continued Each analysis session produces several reports that you can view by selecting the Reports tab shown in Figure 15-20. Figure 15-20 Viewing analysis reports C1562271X.fm Page 561 Friday, April 29, 2005 7:59 PM [...]... moment Understanding Isolation Levels SQL Server 2005 specifies five different isolation levels that affect the way transactions are handled and the duration of locks Table 1 5-2 describes each of these isolation levels C1562 271 X.fm Page 584 Friday, April 29, 2005 7: 59 PM 584 Chapter 15 Monitoring and Troubleshooting SQL Server Performance Table 1 5-2 SQL Server 2005 Isolation Levels Isolation level... Mode: S Key Lock HoBt ID: 72 0 575 94044 678 144 associated objid: 72 0 575 94044 678 144 Index name: PK_Product_ProductID Key Lock HoBt ID: 72 0 575 94045005824 associated objid: 72 0 575 94045005824 Index name: PK_ProductInventory_ ProductID_LocationID Request Mode: S Owner Mode: X Server process Id: 56 Server batch Id: 0 Execution context Id: 0 Deadlock priority: 0 Log Used: 484 Owner Id: 15 271 6 Transaction descriptor:... engine, which made it difficult to manage and monitor SQL Server 2005 opens up the black box by providing a large set of detailed interfaces that expose virtually every operational statistic within the database engine C1562 271 X.fm Page 574 Friday, April 29, 2005 7: 59 PM 574 Chapter 15 ■ Monitoring and Troubleshooting SQL Server Performance SQL Server s DMVs and DMFs are broken into four general categories,... performance C1562 271 X.fm Page 578 Friday, April 29, 2005 7: 59 PM 578 Chapter 15 Monitoring and Troubleshooting SQL Server Performance Figure 1 5-2 1 Correlating a System Monitor counter log with a Profiler trace Correlating DMVs/DMFs with SQL Server Profiler Traces Continuing with the earlier trace for queries executing longer than three seconds, you determine that each query has a less-than-optimal query... always want to consider the impact of maintenance operations as well C1562 271 X.fm Page 570 Friday, April 29, 2005 7: 59 PM 570 Chapter 15 Monitoring and Troubleshooting SQL Server Performance Query Statistics The query statistics DMVs and DMFs encompass the entire group of functionality related to executing a query in SQL Server This functionality is broken into two distinct groups: connections to... sys.dm_os_wait_stats, which provides the same data that you could gather by using DBCC SQLPERF(WAITSTATS) in SQL Server 2000 This DMV plays an important role in any performance analysis by aggregating the amount of time processes had to wait for various resources to be allocated MORE INFO Wait types SQL Server 2000 had 77 wait types SQL Server 2005 exposes 194 wait types Although a complete discussion of each wait... threads to cooperate with each other to maximize the amount of actual work being performed C1562 271 X.fm Page 576 Friday, April 29, 2005 7: 59 PM 576 Chapter 15 Monitoring and Troubleshooting SQL Server Performance Controlling this cooperative behavior is the job of the User Mode Scheduler (UMS) When SQL Server starts, it creates one UMS for each logical or physical processor that it is allowed to use... relatively aggressive escalation mechanism NOTE Do database-level locks exist? You might find a database-level lock mentioned in some texts about SQL Server This type of lock does not exist Some people use this term simply to indicate that SQL Server has acquired a tablelevel lock on all tables within a database C1562 271 X.fm Page 583 Friday, April 29, 2005 7: 59 PM Lesson 6: Resolving Blocking and Deadlocking... to be packaged and sent back to the client, which requires memory, processor, and network I/O C1562 271 X.fm Page 577 Friday, April 29, 2005 7: 59 PM Lesson 5: Correlating Performance and Monitoring Data 577 All this processing means that memory has to be allocated at least five times If there is memory pressure on the system, the thread has to wait for memory to be allocated each time it is required,... that workload file as a source for DTA to analyze for performance improvements 1 Open SSMS and connect to your SQL Server instance 2 Open a new query window and change the context to the AdventureWorks database 3 Open SQL Server Profiler (choose Tools, SQL Server Profiler), connect to your SQL Server instance, and create a new trace 4 Specify the trace template called Tuning and set Profiler to save the . Time C. SQL Server: Buffer ManagerBuffer Cache Hit Ratio D. SQL Server: Buffer ManagerPage Life Expectancy E. SQL Server :SQL StatisticsBatch Requests/Sec F. SQL Server :SQL Statistics SQL Compilations/Sec G Compilations/Sec G. SQL Server :SQL Statistics SQL Re-compilations/Sec C1562 271 X.fm Page 552 Friday, April 29, 2005 7: 59 PM Lesson 2: Working with System Monitor 553 6. Set the interval to one second. 7. Specify. session, as Figure 1 5-1 7 shows. Figure 1 5-1 7 Viewing the analysis progress C1562 271 X.fm Page 559 Friday, April 29, 2005 7: 59 PM 560 Chapter 15 Monitoring and Troubleshooting SQL Server Performance DTA

Ngày đăng: 09/08/2014, 09:21

Từ khóa liên quan

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

Tài liệu liên quan