The Real MTCS SQL Server 2008 Exam 70/432 Prep Kit- P120 pptx

5 75 0
The Real MTCS SQL Server 2008 Exam 70/432 Prep Kit- P120 pptx

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

Thông tin tài liệu

Performance Tuning • Chapter 13 577 EXERCISE 13.2 Mo n i t o r De a D l o c k s This exercise will demonstrate how to enable a trace flag to proactively monitor for deadlocks within SQL Server: 1. Start SQL Server Configuration Manager from Start > Programs > Microsoft SQL Server 2008 > Configuration Tools. 2. Select SQL Server Services from the left-hand pane. 3. Locate the SQL Server instance where the trace flag is to be added in the right-hand pane. 4. Double-click the SQL Server service. 5. Click the Advanced tab. 6. Locate the startup parameters field. 7. Move cursor to the right-most position. 8. Add a semicolon and T1222 to the end of the string—the command should finish up something like this: -dC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\ master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL.3\ MSSQL\LOG\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\ MSSQL.3\MSSQL\DATA\mastlog.ldf; -T8029; T1222 9. Click OK. 10. Restart the SQL Server service for the trace flag to take effect. To view the output of the traceflag—that is, to monitor whether any deadlocks have occurred: 1. Start SQL Server Management Studio. 2. Expand the Management folder. 3. Expand SQL Server logs. 4. Double-click the log file. Alternately, run sp_readerrorlog from a query window to read the contents of the active error log. 578 Chapter13•PerformanceTuning Guide to the DYNAMIC Management Views (DMVs) DMVs are almost certainly the single most useful tool for troubleshooting and performance tuning for SQL Server databases. DMVs and DYNAMIC Management Functions (DMFs) provide Administrators with a simple yet powerful insight into the workings of SQL Server and hardware resources (disk, memory, CPU). There were 89 DMVs introduced to SQL Server 2005 and 47 new DMVs released with SQL Server 2008. These can be grouped in two broad types: Server Scoped (require VIEW SERVER STATE permission on the server)  Database Scoped (require VIEW DATABASE STATE permission on the  database) DMVs can be categorized as follows (there are others that don’t fit into these categories): Common Language Runtime  Cryptographic  Database Mirroring  Execution  Extended Events  Filestream  Full-Text Search  Index  I/O  Query Notifications  Replication  Service Broker  SQL Server Operating System  Transaction  As mentioned in the Profiler section earlier in this chapter, there’s a SQL trace running continuously in the background and cycling itself while SQL Server is running. This trace gathers the data used by the DMVs; you should be aware of those that provide snapshot information and others that provide data cumulatively PerformanceTuning•Chapter13 579 since the last service restart. The trace data is not persisted anywhere within SQL Server, although this is possible (covered in the Performance Data collection, later). DMVs provide information that often could be reached only by querying meta- data or system tables. SQL Server administrators often like a real-time view of current server activity, and they might use the Activity Monitor within Management Studio, or if they have a background with SQL Server 2000 or earlier. They’ll probably use SP_WHO or SP_WHO2—both provide session level activity view. There are, how- ever, a couple of DMVs in Table 13.4 that provide this information plus much more. DYNAMIC Management View Purpose sys.dm_exec_requests Provides information about a request currently executed by SQL Server Sys.dm_exec_sessions An overview of all current sessions (SPIDs) within SQL Server Table 13.4 Using DMVs to View Current Activity within SQL Server It’s easy to SELECT all data within a DMV, however there are great opportuni- ties to write useful queries to interrogate DMVs. One such example is sys.dm_db_ index_physcial_stats. This DMV shows the level of index fragmentation. In previous versions this was available from the DBCC SHOWCONTIG command, however this was very intensive for Disk IO, and the results were cumbersome and difficult to manipulate without significant effort. The following example shows a query that categorizes index fragmentation as High (more than 30%), Medium (less than 30%), and Low (less than 5%), ordering the results by greatest fragmentation first since this is where we should pay most attention: SELECT    OBJECT_NAME(indstat.object_id,indstat.database_id)ASobj_name,    QUOTENAME(sysind.name)[index_name],    CASE       WHENavg_fragmentation_in_percent<5THEN'LOW'       WHENavg_fragmentation_in_percent<30THEN'MEDIUM'       ELSE'HIGH'    ENDasfrag_level,    indstat.* 580 Chapter13•PerformanceTuning FROMsys.dm_db_index_physical_stats(DB_ID(),NULL,NULL,NULL,'LIMITED') ASindstat INNERJOINsys.indexessysindONindstat.object_id=sysind.object_idAND indstat.index_id=sysind.index_id ORDERBYavg_fragmentation_in_percentDESC The output of the sys.dm_db_index_physcial_stats can be used as the input to an index maintenance job. In this scenario it is possible to build a SQL Server Agent job that takes action based on the output of the sys.dm_db_index_physcial_ stats, such as an index reorganize (for indexes with low or medium fragmentation) or rebuilding indexes (for those indexes with heavy fragmentation). Extending the idea of good indexing maintenance, SQL Server can also suggest indexes that would help improve query performance. This information is provided by a group of DMVs, the most useful of which is sys.dm_db_missing_index_details. Using the output from this DMV, we can generate the CREATE INDEX statement to add the new index and improve performance! However, there numerous limitations of the missing indexes feature; for example, it doesn’t consider the cost of maintaining an index and it doesn’t specify an order for columns to be used in the index. There are DMVs such as sys.dm_os_ ∗ that reflect aspects of the SQL Server Operating System and can be useful barometers for understanding more about SQL Server Internals, system memory consumption, requirements, and the like. The follow- ing query uses the sys.dm_exec_query_stats to provide the top 10 queries consuming most CPU: SELECTTOP10   SUM(qrystat.total_worker_time)ASTotal_CPU_Time,   SUM(qrystat.execution_count)ASNumber_of_Executions,   COUNT(*)asNumber_of_Statements,   qrystat.plan_handle FROM   sys.dm_exec_query_statsqrystat GROUPBYqrystat.plan_handle ORDERBYsum(qrystat.total_worker_time)DESC PerformanceTuning•Chapter13 581 EXERCISE 13.3 Re v i e w uS e f u l DMVS Take a look at the following DMVs to become familiar with the contents: sys.dm_exec_requests sys.dm_exec_sessions sys.dm_exec_sql_text sys.dm_exec_query_stats sys.dm_os_wait_stats sys.dm_db_index_usage_stats sys.dm_db_index_operational_stats sys.dm_db_missing_index_details Partitioning Organizations collect more data and retain data for longer than ever before. The phenomenal growth of the storage manufacturing industry over the past 10 years is a testament to continually increasing data collection. Given adequate capacity, storing large quantities of data within SQL Server is no big problem, until we need to retrieve some data or perform any maintenance. New challenges arise from retrieving single rows or range searches of multiterabyte databases, while maintaining good response times. Partitioning was first available in SQL Server 7.0, although in different versions this application logic was required to determine the partition holding a specific row. In SQL Server 2000 it was possible to define a view that unified the data and in SQL Server 2005 table partitions were completely transparent to applications. SQL Server 2008 Enterprise edition provides the next generation of table and index partitioning, which introduces a round-robin thread model to satisfy queries accessing multiple partitions. Additionally, SQL Server 2008 includes new level of lock escalation, which means locks can escalate from row or page locks to partition locks. This differs from SQL Server 2005, where row or page locks could be escalated directly to table locks. Horizontal Partitioning Horizontal Partitioning involves dividing a large table into a number of smaller tables, each containing all columns for a subset of rows. Dividing rows into separate tables means each table is much smaller and access times are typically more efficient, . FilesMicrosoft SQL Server MSSQL.3 MSSQLLOGERRORLOG;-lC:Program FilesMicrosoft SQL Server MSSQL.3MSSQLDATAmastlog.ldf; -T8029; T1222 9. Click OK. 10. Restart the SQL Server service for the trace. pane. 3. Locate the SQL Server instance where the trace flag is to be added in the right-hand pane. 4. Double-click the SQL Server service. 5. Click the Advanced tab. 6. Locate the startup parameters. deadlocks within SQL Server: 1. Start SQL Server Configuration Manager from Start > Programs > Microsoft SQL Server 2008 > Configuration Tools. 2. Select SQL Server Services from the left-hand

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

Mục lục

  • The Real MCTS SQL Server 2008 Exam 70-432 Prep Kit: Database Implementation and Maintenance

  • Copyright Page

  • Technical Editor

  • Lead Authors

  • Contributing Authors

  • Contents

  • Chapter 1: MCTS SQL Server 2008 Exam 432 New Features in SQL Server 2008

    • Introduction

      • A Word About the Test

      • New Feature Overview

        • Installation

        • Compressed Backups

        • Enhanced Configuration and Management of Audits

        • New Table Value Parameter

        • FileStream Data Types

        • Sparse Column Support

        • Encryption Enhancements

          • Key Management and Encryption

          • High Availability

          • Performance

            • Performance Data Management

            • Resource Governor (similar to Query Governor)

            • Freeze Plan

            • SQL Server 2008 Declarative Management Framework

            • Development Improvements

              • LINQ Support

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

Tài liệu liên quan