• Escorts you through the lifecycle of a query to establish an under-standing of the fundamental concepts and architectures • Examines the use of memory including the physical component
Trang 1Christian Bolton, Justin Langford, Brent Ozar, James Rowland-Jones, Steven Wort
When faced with a variety of SQL Server issues, you need to be able
to troubleshoot SQL Server as well as its underlying operating system
To that end, this author group of SQL Server experts presents you with
invaluable advice that brings together—and simplifies—practical internal
information concerning SQL Server along with troubleshooting
techniques and methodologies Packed with real-world examples of
ways to effectively use troubleshooting tools, this book shows you how
to efficiently and accurately determine the root of your SQL Server
problem so you can successfully resolve it.
• Escorts you through the lifecycle of a query to establish an
under-standing of the fundamental concepts and architectures
• Examines the use of memory including the physical components, Windows
memory management, and SQL Server’s own memory architecture
• Reviews SQL Server wait types and how to monitor them with
Extended Events
• Equips you with the knowledge to confidently specify and monitor
your storage performance requirements
• Details SQL Server’s locking model, the internal use of latches,
and row versioning
• Shows you how to use SQLDiag, RML Utilities, SQL Nexus, the
Management Data Warehouse, and how to build your own SQL
Server Management Studio reports
Christian Bolton is coauthor of Professional SQL Server 2005 Performance Tuning
and Technical Director for Coeo Ltd
Justin Langford is coauthor of Professional SQL Server 2005 Performance Tuning
and leads the Managed Support team for Coeo Ltd
Brent Ozar is a SQL Server expert for Quest Software
James Rowland-Jones is an advisory consultant for EMC Consulting
Steven Wort is a developer in the Windows Division at Microsoft
Wrox guides are crafted to make learning programming languages and
technologies easier than you think Written by programmers for programmers,
they provide a structured, tutorial format that will guide you through all the
techniques involved
Database Management / General
best practices for troubleshooting
wrox.com
Programmer Forums
Join our Programmer to Programmer forums to ask and answer programming questions about this book, join discussions on the hottest topics in the industry, and connect with fellow programmers from around the world
Code Downloads
Take advantage of free code samples from this book, as well as code samples from hundreds of other books, all ready to use
Read More
Find articles, ebooks, sample chapters and tables of contents for hundreds of books, and more reference resources on programming topics that matter
Trang 2Get more out of
wrox.com
Interact
Take an active role online by participating in our
P2P forums @ p2p.wrox.com
Wrox Online Library
Hundreds of our books are available online
through Books24x7.com
Wrox Blox
Download short informational pieces and code
to keep you up to date and out of trouble!
Join the Community
Sign up for our free monthly newsletter at newsletter.wrox.com
Browse
Ready for more Wrox? We have books and e-books available on NET, SQL Server, Java, XML, Visual Basic, C#/ C++, and much more!
Contact Us
We always like to get feedback from our readers Have a book idea?
Need community support? Let us know by e-mailing wrox-partnerwithus@wrox.com
www.it-ebooks.info
Trang 3AND TROUBLESHOOTING
INTRODUCTION xxv
CHAPTER 1 SQL Server Architecture 1
CHAPTER 2 Understanding Memory 23
CHAPTER 3 SQL Server Waits and Extended Events 59
CHAPTER 4 Working with Storage 95
CHAPTER 5 CPU and Query Processing 137
CHAPTER 6 Locking and Latches 185
CHAPTER 7 Knowing Tempdb 269
CHAPTER 8 Defi ning Your Approach To Troubleshooting 305
CHAPTER 9 Viewing Server Performance with PerfMon and the PAL Tool 329
CHAPTER 10 Tracing SQL Server with SQL Trace and Profi ler 369
CHAPTER 11 Consolidating Data Collection with SQLDiag and the PerfStats Script 437
CHAPTER 12 Introducing RML Utilities for Stress Testing and Trace File Analysis 459
CHAPTER 13 Bringing It All Together with SQL Nexus 481
CHAPTER 14 Using Management Studio Reports and the Performance Dashboard 505
CHAPTER 15 Using SQL Server Management Data Warehouse 539
CHAPTER 16 Shortcuts to Effi cient Data Collection and Quick Analysis Wrox.com INDEX 555
Trang 5and Troubleshooting
Trang 7and Troubleshooting
Christian Bolton Justin Langford Brent Ozar James Rowland-Jones Jonathan Kehayias Cindy Gross Steven Wort
Trang 810475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-48428-9
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108
of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization
through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers,
MA 01923, (978) 750-8400, fax (978) 646-8600 Requests to the Publisher for permission should be addressed to the
Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201)
748-6008, or online at http://www.wiley.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with
respect to the accuracy or completeness of the contents of this work and specifi cally disclaim all warranties, including
without limitation warranties of fi tness for a particular purpose No warranty may be created or extended by sales or
pro-motional materials The advice and strategies contained herein may not be suitable for every situation This work is sold
with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services
If professional assistance is required, the services of a competent professional person should be sought Neither the
pub-lisher nor the author shall be liable for damages arising herefrom The fact that an organization or Web site is referred to
in this work as a citation and/or a potential source of further information does not mean that the author or the publisher
endorses the information the organization or Web site may provide or recommendations it may make Further, readers
should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was
written and when it is read.
For general information on our other products and services please contact our Customer Care Department within the
United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats Some content that appears in print may not be available
in electronic books.
Library of Congress Control Number: 2009941346
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are
trademarks or registered trademarks of John Wiley & Sons, Inc and/or its affi liates, in the United States and other
coun-tries, and may not be used without written permission SQL Server is a registered trademark of Microsoft Corporation
in the United States and/or other countries All other trademarks are the property of their respective owners Wiley
Publishing, Inc is not associated with any product or vendor mentioned in this book.
Trang 9This is dedicated to Erika, who has been dedicated
to me despite my long working hours I love you dearly, and I love working on next chapters.
—Brent Ozar
Trang 11CHRISTIAN BOLTON is the Technical Director for Coeo Ltd., a leading provider of SQL Server consulting and managed support services in the UK and Europe Prior to this Christian worked for 5 years at Microsoft, leading the SQL Server Premier Field Engineering team in the UK He is a Microsoft Certifi ed Architect, Master and MVP for SQL Server, and co-author of Professional SQL Server 2005 Performance Tuning
He works out of London and lives in the south of England with his wife and children He can be contacted at christian@coeo.com Christian authored chapters 1, 2, 7, 13 and the online chapter 16
in addition to lending his authoring expertise where needed on other chapters and functioned as the lead author for the entire project
JUSTIN LANGFORD leads the Managed Support team for Coeo Ltd, delivering sourced 24x7 operations for mission-critical SQL Server platforms Before join-ing Coeo, Justin worked for Microsoft in the Premier Field Engineering team and has worked with some of Microsoft’s largest fi nance and government customers in Europe Justin co-authored Wrox Professional SQL Server 2005 Performance Tuning and lives in London with his girlfriend, Claire Outside work he enjoys sailing and has a keen inter-est in classic British sports cars Justin can be contacted at justinl@coeo.com Justin authored chap-ters 9, 11, 12, and 15
out-BRENT OZAR is a SQL Server Expert for Quest Software He has over a decade of broad IT experience, performing SQL Server database administration, systems admin-istration, SAN administration, virtualization administration, and project management
In his current role, Brent trains DBAs on performance tuning, disaster recovery, and virtualization He has spoken around the globe at events for PASS, SQLBits, SSWUG, and other organizations Brent founded the Virtualization Virtual Chapter for the Professional Association for SQL Server (PASS), and serves as the Editor-in-Chief at SQLServerPedia.com
Brent blogs at www.BrentOzar.com and discusses diverse topics at http://twitter.com/BrentO When he’s not talking SQL Server, he enjoys traveling, working with social media, snorkeling, and sam-pling new restaurants He is the author of chapters 4 and 14
JAMES ROWLAND-JONES works for EMC Consulting EMEA as an Advisory sultant His principle focus is the delivery of large, scalable, data warehousing, and business intelligence projects Within this fi eld James specializes in data integration, database architecture, and performance tuning He is very active in the technical community and is one of the organizers for SQLBits, Europe’s largest SQL Server community conference James has received the Microsoft MVP award for 2009 and 2010 You can
Con-fi nd him online at http://consultingblogs.emc.com/jamesrowlandjones, twitter (@jrowlandjones), linkedin http://www.linkedin.com/in/jrowlandjones, or even using an old fashioned email, james.rowland-jones@emc.com James authored chapters 6 and 10
Trang 12T-SQL, in late 2006, he transitioned to the role of Database Administrator He has experience in upgrading and consolidating SQL environments, and has experience in running SQL Server in Virtual Environments on VMWare ESX 3.5+ He is a member of the Tampa
SQL Server User Group and a regular speaker about SQL Server at events Jonathan authored
chapter 3
CINDY GROSS started her SQL Server life as a DBA with a hospital and health plan company in
1993, and moved to Microsoft in 2000 where she has worked ever since Her roles at Microsoft
have included PSS Product Support Engineer, SQL Content Lead, Yukon Readiness Lead, and most
recently Dedicated Support Engineer (DSE), all for SQL Server Cindy enjoys delivering training
throughout the United States as well as in Europe and India, including presentations at SQL PASS
In 2008 she started the Boise SQL Server User Group, an affi liate of the SQLCommunity.org site
(where she is a worldwide SQL Server Community Leader) to share SQL Server wisdom in the Idaho
SQL Server community Most recently she obtained the Microsoft Certifi ed Master: SQL Server
Qualifi cation, which was a hard-fought prize Over the years Cindy has learned from many
won-derful friends and colleagues and they all deserve a word of thanks for contributing to her success
Cindy authored chapter 8
STEVEN WORT has been working with SQL Server since the early days of SQL Server way back in 1992-93 He is currently a developer in the Windows Division at Microsoft, where he works on performance and scalability issues on large database systems for the Windows Telemetry team Steven has been at Microsoft since 2000
Prior to working in the Windows Division, Steven spent 2 years working in the SQL Server group, working on performance and scalability Steven’s fi rst 3 years at Microsoft were spent
working in support as an escalation engineer on the SIE team During this time, Steven was able
to travel the world working with some of Microsoft’s customers on their performance and
scal-ability issues Before coming to Microsoft, Steven spent 20 years working in the United Kingdom
as a freelance consultant, specializing in database application development When Steven isn’t busy
working, he can be found spending time with his family and enjoying many fi tness activities in the
outdoors of the Pacifi c Northwest Steven authored chapter 5
Trang 13EXECUTIVE EDITOR
Robert Elliott
SENIOR PROJECT EDITOR
Ami Frank Sullivan
TECHNICAL EDITORS
James Boother Jimmy MayPaul NielsenTony RogersonJames Rowland-JonesSimon Sabin
Lynsey Stanford
COMPOSITOR
Chris Gillespie, Happenstance Type-O-Rama
Trang 15FROM CHRISTIAN BOLTON: This book has been a far greater challenge and rewarding experience than I ever imagined As with anything worth shedding blood, sweat, and tears over, it has taken
a number of people, generous with their time and talents, to bring this project to life
First of all, I’d like to thank my wife, Gemma, for her support and eternal patience during the many evenings and weekends I spent researching, writing, and reviewing content for “just a little longer.”
My children, Ava and Leighton, deserve a special thank you also for frequently pulling me back to what really matters with cheeky grins, demands to ride on my shoulders, spin in my chair, and an offer to draw a picture of a princess for me to put in the book
I’d also like to thank my fellow authors and contributors for their outstanding efforts in bringing new, interesting, and well researched material to make this book unique:
Justin Langford has been a great friend for many years and is always the fi rst to offer support
➤
and encouragement to any project
James Rowland-Jones for setting impossible goals for his chapters on Locking and SQL Trace
➤
and then going past them
Brent Ozar, for transferring his easy-reading blog style into professional book chapters on
➤
Storage and Management Studio Reports that are a pleasure to read
Jonathan Kehayias for his excellent chapter on Waits and Extended Events that would have
➤
been a pale shadow of its current form had he not been involved in the book
Cindy Gross for bringing her years of experience at Microsoft and defi ning what it takes to
➤
be a Professional when troubleshooting SQL Server
Steven Wort for working to extremely tight timescales on the CPU and Query Processing
➤
chapter and working tirelessly to improve and expand on the original specs
Starting a new chapter from a blank page is one of the hardest things you can do as an author, but it
is ultimately rewarding when you see the fi nished product I often think that Technical Editors don’t get enough praise for the work they do to make the authors look good, so I want to say a big thank you to our team of Technical Editors for their diligent research, tips, advice, and patience through multiple revisions: Simon Sabin, James Rowland-Jones, James Boother, Jimmy May, Paul Nielsen, Steven Wort, and Tony Rogerson I’d also like to thank Ami Sullivan, our Project Editor at Wiley, for keeping the schedule moving and working very hard to compensate for our writing delays, and Robert Elliott, our Executive Editor, for buying into the original vision and helping me to refi ne the proposal that eventually became this book
Writing about SQL Server Internals with a suffi cient abstraction in certain areas to introduce key topics and then drilling down into the heart of the product in others presents a diffi cult challenge for anyone, but it is much harder writing from outside Microsoft; and I’d like to thank Bob Ward,
Trang 16inspiration and support whether knowingly or not: Mark Anderson, Sunil Agarwal, Chirag Roy,
Aaron Bertrand, Denny Cherry, Grant Fritchey, and Paul Randal
Finally, I’d like to thank you for buying this book Everyone involved has given their best game to
make it stand-out; especially the authors and contributors who have given a little bit of what makes
them special in their fi eld to create a book that they’re proud to put their name to I hope it lives up
to your expectations and you fi nd it a worthy investment
FROM JAMES ROWLAND-JONES: Firstly I’d like to thank Christian for the opportunity to be involved
with the book, Simon Sabin and Tony Rogerson (my TE’s) for their efforts and constructive
feed-back, and also to Ami Sullivan, our editor, for her endless support and patience The management
team at EMC Consulting and especially Rob Grigg have been a constant source of support; both on
the book and in the community with user groups and SQLBits, so a big thank you to them I’d also
like to thank Bob Ward and Thomas Kejser for their reviews and insight during some tough times
on the locking chapter Finally, I’d like to thank all my family, but especially my wife Jane and our
children Lucy, Kate, and Oliver Without you life is strangely pointless
FROM BRENT OZAR: Thanks to Jimmy May for hooking me up with such a great team of authors
My involvement with this book wouldn’t have happened without his encouragement and trust
Similarly, I’d like to thank the authors for giving me an opportunity to work with them I’m
hum-bled to have my names next to such great technical minds Thanks also to Christian Hasker, Rony
Lerner, Don Duncan, and Joe Sullivan; I have consistently hit the lottery when it comes to
manag-ers, and I couldn’t have picked a better string of guys to mentor me and grow my career If anybody
doesn’t succeed under any of them, it’s their own fault
To my coworkers Andy Grant, Brett Epps, Heather Eichman, and everybody else at Quest Software,
thanks for making my work so much fun Thanks to everybody on Twitter for laughing with me
while I keep punching harder and faster My day is infi nitely more enjoyable thanks to folks like
@SQLRockstar, @SQLChicken, @SQLAgentMan, @KBrianKelley, @Wendy_Dance, @GFritchey,
@MrDenny, @StatisticsIO, @MikeHillwig, @Peschkaj, @SQLSarg, @SQLCraftsman, and many
others
Finally, I’d like to thank Dad, Mom, and Caryl for my dashing good looks and brilliant wit I just
wish you’d given me some humility so that I could be perfect
Trang 17The Life Cycle of a Query 3
Trang 18Extended Events 70
Architecture 71
Examining Waits with Extended Events 90 Summary 94
WORKING WITH STORAGE 9
Types of Storage 95
Storage Performance Testing 112
Confi guring Software for Storage 123
Query Optimization 149
Trang 19Statistics 152
Query Plans 165
Executing Your Queries 175
Consequence of Concurrent Access 188
Trang 20Sub-latches and Super-latches 262 Latching in Action 263
Overview and Usage 270
Troubleshooting Common Issues 279
Confi guration Best Practices 296
Summary 303
DEFINING YOUR APPROACH TO TROUBLESHOOTING 30
Approaching the Problem Correctly 306
Defi ning the Problem 309
Trang 21Gathering Data 315
Analyzing Data 317
Testing Solutions 318 Troubleshooting Other Components 318
PERFMON AND THE PAL TOOL 329
Performance Monitor Overview 330
Reliability and Performance Monitor in Windows Server 2008 330
Getting Started with PerfMon 338
Getting More from Performance Monitor 349
Getting Started with Performance Analysis for Logs (PAL) 357
Other PerfMon Log Analysis Tools 363
Trang 22sys.traces 376sys.trace_categories 386sys.trace_events 387sys.trace_columns 387sys.trace_subclass_values 389sys.trace_event_bindings 391
SQL Trace Procedures and Functions 392
sp_trace_create 392sp_trace_setevent 394
sp_trace_setstatus 403sp_trace_generateevent 404fn_trace_gettable 406fn_trace_geteventinfo 408
Securing SQL Trace 410
When Tracing Login Can View Object Defi nitions
Trang 23Profi ler 420
Summary 435
CONSOLIDATING DATA COLLECTION WITH CHAPTER 11:
SQLDIAG AND THE PERFSTATS SCRIPT 437
Approaching Data Collection 438 What Is SQLDiag? 439
Using the PerfStats Script 451
Summary 457
INTRODUCING RML UTILITIES FOR STRESS CHAPTER 12:
TESTING AND TRACE FILE ANALYSIS 459
When to Use RML Utilities 460
What Are RML Utilities? 462
Trang 24BRINGING IT ALL TOGETHER WITH SQL NEXUS 48
Getting Started 484 Data Collection 484
Importing Data 489 Available Reports 491 Example Scenario Using SQL Nexus 491
Adding Your Own Reports 502
Summary 504
USING MANAGEMENT STUDIO REPORTS CHAPTER 14:
AND THE PERFORMANCE DASHBOARD 505
Using the Standard Reports 506
Using the Performance Dashboard 524
Building Custom Reports 531
Trang 27WHILE PUTTING TOGETHER THE PROPOSAL that eventually became this book, the aim was to write a troubleshooting guide that covered the additional tools available from the SQL Server community.
It soon became clear, however, that to effectively talk about the tools, so many digressions were necessary to explain the results that the fl ow and impact were interrupted The decision was made
to alter the approach to include architectural information, not just on SQL Server, but on the whole platform on which SQL Server depends
If you’re troubleshooting an apparent “SQL Server” issue, you need to be able to troubleshoot the underlying operating system and storage as well as SQL Server, so we wanted to bring together and simplify the architectural details of these components too
A fair amount of Windows and storage internals information is available already, but very little of
it that condenses and fi lters the right material to be easily consumed by SQL Server professionals
The available material is either too light or too in depth — with nothing to help bridge the gap
Combining this need with the need for practical internals information on SQL Server, a look at building a troubleshooting methodology, and relevant information on all the extra tools, three goals for the book were established:
To provide in-depth architectural information on SQL Server (and the environment on which
➤
it depends) that is easy to consume
To introduce a troubleshooting approach using the same techniques and methodologies that
➤
Microsoft uses internally
To present some of the additional free SQL Server troubleshooting tools that are available
➤
with real-world examples demonstrating how they can be used together to effi ciently and accurately determine the root cause of issues on systems running SQL Server
WHO THIS BOOK IS FOR
This book is intended for those people who regard themselves as, or who aspire to be, SQL Server professionals in predominantly relational environments What I mean by a SQL Server professional,
is anyone that regards SQL Server as one of their core product skills and continually strives to develop their knowledge of the product and how to use it
It is not a beginner’s book and makes assumptions that the reader knows the basics of how to install, use, and confi gure SQL Server and is aware of some of the challenges that troubleshooting SQL Server problems using only the native tools presents Every effort has been made however, to provide
a gentle route into each area for those readers who are less confi dent in some of the topics presented
Trang 28The book is presented in two parts The fi rst covers internal information which is intended to
pro-vide an in-depth grounding in core concepts and propro-vides the knowledge to help understand the
output and positioning of the tools covered in part two Those readers who are confi dent with the
subject matter presented in part one will fi nd that they can start reading from part two and dip back
into part one as required to clarify any understanding
WHAT THIS BOOK COVERS
Before launching into a description of the structure of the book and each chapter, it’s important
for you to understand some key drivers and assumptions that originally led to the topics the book
covers
Understanding Internals
You don’t need to understand too much about how SQL Server works to be successful in many SQL
Server–based job roles You can fi nd numerous well-established, prescriptive guidelines and a very
active and helpful community to help you Eventually, however, you will reach a point when that’s
just not enough (usually when something serious has gone wrong)
During an unexpected service outage, for example, you need to make quick decisions in order to
balance the demands of restoring the service as quickly as possible while gathering enough data to
help you diagnose the issue so you can prevent it from happening again In that situation you cannot
depend on external help or goodwill; it won’t arrive fast enough to help you Understanding
inter-nals will enable you to make quick decisions for problem resolution independently
When I worked for Microsoft, one of our customers encountered corruption in a large
business-critical database running on SQL Server The business decided to take the database offl ine until it
was fi xed because it held fi nancial trade data, and mistakes would have been disastrous
but killed it after eight hours in favor of a database restore The backup was corrupt so they had no
time-consuming disaster and led to a large fi ne having to be paid by the customer for failing to provide a
service to the fi nancial markets
The simple lessons to learn from this example are to test your backups and to know how long
CHECKDB takes to run (and that it takes longer when corruption is detected, as it takes another pass
with deeper checks) These are “best practices” that can be followed with little understanding of
actual internals
However, the reason for including this example is the information that resulted from the postmortem
The original error message that detected the problem contained details of a corrupt page Armed with
determine to which database object it belonged
Trang 29In this case it actually belonged to a non-clustered index that could have just been rebuilt without
it’s useful to know the “internals”; so you can work things out for yourself and take the best course
of action
This book covers internals information for Windows and SQL Server that helps you understand the environment in which your application(s) works, how to confi gure your server to optimize for differ-ent requirements, and how to avoid making blind decisions in the heat of the moment because you don’t know why you’re seeing a particular behavior
Additional Troubleshooting Tools
The second part of this book, which was actually its original source of inspiration, deals with a range of free troubleshooting tools that can be used together to form a structured, effective, trouble-shooting strategy We wanted to write a practical guide to these useful tools that can make your life
so much easier on a daily basis (but which can seem overly complicated and diffi cult to learn to the uninitiated)
HOW THIS BOOK IS STRUCTURED
The fi rst part of the book starts with a high-level overview of SQL Server’s architecture, leading into chapters on the three core resources that are important to SQL Server: memory, storage, and CPU Nestled in between these chapters at strategic points are additional chapters which cover material that is critical to understand for effective troubleshooting: SQL Server Waits and Extended Events, Locking and Latches, and tempdb
This section provides an overview of each chapter to put it into context within the book and to help you decide where to start reading
Chapter 1: SQL Server Architecture
This chapter takes you lightly through the life cycle of a query, with enough depth to help you stand fundamental concepts and architectures without getting lost in the complexities of individual components (some of which are looked at closely in later chapters)
under-This chapter will appeal to readers at all levels of skill, whether you’re a developer, a DBA, or a soned SQL Server veteran
sea-Chapter 2: Understanding Memory
With this chapter we wanted to expand the scope of “memory” to include the physical components and Windows memory management, rather than just cover SQL Server’s internal usage so you’ll
be able to read about the different types of memory modules you can buy and learn how Windows manages physical memory using a Virtual Memory Manager It also compares 32-bit and 64-bit architectures and the options you have for tuning them
Trang 30For SQL Server itself, you’ll learn about architectural elements such as memory nodes, clerks, caches,
and the buffer pool, as well as the often misunderstood concept of memtoleave and how to measure
it You will also read all about AWE usage and how to implement it in this chapter
The objective of this chapter is to provide you with a thorough understanding of how SQL Server
uses memory Once you understand the core architecture of SQL Server’s memory management, you
will be well prepared to diagnose memory-related problems as well
Chapter 3: SQL Server Waits and Extended Events
This chapter introduces the benefi ts of reviewing SQL Server Waits and the architecture that supports
this feature It looks into how they occur and what they mean; the common wait types of concern;
which wait types can be safely ignored; and what new wait types there are in SQL Server 2008
It then covers a new feature in SQL Server 2008 called Extended Events and shows how they can
be used to get a deeper look into what waits are occuring for individual tasks and why Finally, it
demonstrates how to implement and manage events using a freeware tool called the Extended Events
Manager which was written by the author
The objective of this chapter is to introduce and reinforce the benefi ts of adding waits analysis to
your troubleshooting method and how to take it to the next level with Extended Events
Chapter 4: Working with Storage
This chapter equips you with the knowledge to confi dently specify and monitor your storage
require-ments, from understanding the uses for different types of physical disks and knowing the real-world
implications for different RAID levels, to being comfortable with the technologies that make up a
storage area network (SAN) and various optimization tips that you can employ on different types
of storage
We compare SANs and direct-attached storage (DAS) so you can be clear about the environment
in which each is appropriate, and you’ll learn about the implementation details and implications of
performance-tuning tips like increasing HBA queue depth and implementing disk sector alignment
The objective of this chapter is to ensure that you and your storage administrator can communicate
using common terminology and address key storage performance bottlenecks in a cooperative and
collaborative way
Chapter 5: CPU and Query Processing
This chapter covers two key, interrelated areas First you’ll read about CPUs, looking at how they
work and where the technology is heading so you can decide what features are more important to
you when choosing the processors that will be available in your server
Then, the chapter takes an in-depth look at how SQL Server processes queries because
understand-ing how a query is processed will help you determine how to tune it However, understandunderstand-ing what
drives SQL Server to determine this plan will also aid you in understanding why SQL Server made
Trang 31that choice Again, understanding not only how, but also why, enables you to make tuning decisions more quickly and effectively
The objective of this chapter is to distill enough information about CPUs to help you choose what
to buy (if indeed you have any infl uence in the process) and to help you understand how to infl uence the decisions that SQL Server’s Query Processor makes in order to fi ne-tune the performance of your queries
Chapter 6: Locking and Latches
This chapter takes a very in-depth look at how SQL Server manages isolation and concurrency and contains full details on how SQL Server implements locking and row versioning depending on how its confi gured
The chapter also clarifi es another type of lock that SQL Server uses internally called a latch, and
explores the use and detailed implementation of latches within SQL Server — including what can go wrong, how to monitor for problems, and how to resolve them or mitigate against risk
The objective of this chapter is to provide you with the knowledge to be able to choose the most appropriate isolation level for any scenario, evaluate the potential benefi ts of using Snapshot Isolation and row versioning, and to be able to confi dently troubleshoot latch issues
Chapter 7: Knowing Tempdb
This chapter describes which features use tempdb and what the performance implications can
be for enabling them, as well as how to monitor and tune the database for best performance and availability
You’ll read about tempdb allocation problems in some depth, including how to detect, resolve, and mitigate any allocation issues by creating multiple data fi les, optimizing temporary object reuse, and using trace fl ag 1118
The objective of this chapter is for you to not only understand how best to confi gure tempdb, but also to know when it is likely to be used Once you are armed with this information, you should be able to analyze a given workload for your SQL Server and know whether or not you will need to invest signifi cant time tuning tempdb
The Troubleshooting Tools Chapters
Part II starts with both a human-oriented and process-driven look at how to approach ing Then, it jumps into the tools and technologies that work well independently but are brought together into one easy solution for analysis with SQL Nexus
troubleshoot-The fi nal chapters look at the built-in and customizable reporting capabilities of Management Studio, and the brand-new Management Data Warehouse feature in SQL Server 2008 Finally, you will learn several shortcuts, tips, and tricks we use on a daily basis to achieve maximum customer satisfaction by ensuring fast problem resolution with minimal impact
Trang 32Chapter 8: Defi ning Your Approach to Troubleshooting
Your troubleshooting will be far more effective if you do more than just rely on a “gut feeling” or
your previous experience with a set of symptoms Think of troubleshooting as a science rather than
an art and you won’t go far wrong
This chapter covers the troubleshooting approach that Microsoft uses within its SQL Server
sup-port teams It looks at having the right attitude and how to manage your sponsors, and helps you
to defi ne the problem and understand what to do after you’ve fi xed a problem to prevent it from
happening again
Chapter 9: Viewing Server Performance with PerfMon and the PAL Tool
Performance Monitor (PerfMon) has a been a staple data gathering and reporting tool since
Windows NT4, but it has obviously increased in size and scope since those early days
This chapter demonstrates how to optimize your data collection using Performance Monitor to
reduce the impact on the monitored system, and how to load the data straight into SQL Server to
run your own T-SQL queries against the results It also introduces you to the Performance Analysis
of Logs (PAL) tool, which makes analysis of large data captures much easier to consume and draw
conclusions from
Chapter 10: Tracing SQL Server with SQL Trace and Profi ler
This in-depth chapter covers the Profi ler tool that is provided with SQL Server and the underlying
technology used called SQL Trace It will teach you tracing terminology, what you should be tracing
to get the right balance of useful data while minimizing server impact, and how to build less
inten-sive “server-side” traces from scratch instead of using Profi ler
You’ll also learn about best practices for data collection, different problem scenarios for which
trac-ing can be used, and what’s new in SQL Server 2008
Chapter 11: Consolidating Data Collection with SQLDiag and the PerfStats Script
SQLDiag is a great tool that was introduced in SQL Server 2005 to help coordinate the collection of
Performance Monitor logs and SQL Traces, as well as the gathering of other system data
In this chapter you’ll learn how to confi gure, customize, and run SQLDiag, as well as be introduced
to Microsoft’s Performance Statistics (PerfStats) script, which adds locking, blocking, and wait stats to
the list of collectors that SQLDiag coordinates
This tool is one of the secrets of the trade for effi cient data collection, and this chapter is a “must
read” for anyone not using it extensively already
Chapter 12: Introducing RML Utilities for Stress Testing and Trace File Analysis
This chapter describes how to confi gure and run OStress and ReadTrace, which are part of the
RML Utilities package, and how to interpret the results ReadTrace in particular is a very special
Trang 33tool that you’ll come back to time and time again after you’ve been introduced to it, as it helps you draw conclusions within seconds — conclusions that would have been unbelievably laborious to reach in the past
Chapter 13: Bringing It All Together with SQL Nexus
SQL Nexus is a freeware tool written by SQL Server escalation engineers at Microsoft, and it is the crown jewel of the troubleshooting tools because it consolidates the analysis and reporting from all the other tools mentioned up to this chapter
In this chapter you’ll learn how to confi gure, run, and draw conclusions from the reports created by this tool, which is by far the most useful piece of software in the troubleshooting kit bag of people who have taken the time to learn it
Chapter 14: Using Management Studio Reports and the Performance Dashboard
This chapter takes you through some of the most useful Management Studio reports available, describing how you can create your own custom reports and introducing a set of custom reports written by the SQL Server support team at Microsoft, collectively known as the Performance Dashboard
Chapter 15: Using SQL Server Management Data Warehouse
The Management Data Warehouse feature provides a centralized repository for SQL Server 2008 performance data across an organization It is made up of three key components: the Performance Data Collector, the Data Warehouse, and the Reports
It is intended to provide an out-of-the-box solution for performance management to SQL Server professionals who are responsible for performance and capacity management This chapter describes what this feature can do and how to set up and confi gure it for yourself
Chapter 16: Shortcuts to Effi cient Data Collection and Quick Analysis
This is a web-only chapter and contains tips, tricks, and real-world scenarios for quick and easy data collection, and on-the-fl y analysis of data that can be rolled out quickly and effi ciently every day if necessary to give you, your customers, and your internal and external sponsors confi dence in the health of a business application running on SQL Server
This last part of the book provides complete coverage of numerous free support tools you can choose to employ This chapter talks about the ones the authors use every day in consulting, devel-opment, and operational environments across many customers with both simple and very complex SQL Server architectures
Trang 34CONVENTIONS
To help you get the most from the text and keep track of what’s happening, we’ve used a number
of conventions throughout the book
Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.
Notes, tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.
As for styles in the text:
New terms and important words are
➤ italicized when introduced.
Keyboard strokes are shown like this: Ctrl+A
We use a monofont type with no highlighting for most code examples.
We use bolded monofont to emphasize code that is of particular importance in
the present context.
SOURCE CODE
As you work through the examples in this book, you may choose either to type in all the code
manually or to use the source code fi les that accompany the book All of the source code used in
(either by using the Search box or by using one of the title lists) and click the Download Code link
on the book’s detail page to obtain all the source code for the book
Code snippets that are downloadable from wrox.com are easily identifi ed with an icon; the fi lename
of the code snippet follows in a code note that appears after the code, much like the one that follows
this paragraph If it is an entire code listing, the fi lename should appear in the listing title
This code [fi lename] is available for download at wrox.com
Trang 35Because many books have similar titles, you may fi nd it easiest to search by ISBN; this book’s ISBN is 978-0-470-48428-9.
Once you download the code, just decompress it with your favorite compression tool Alternately,
to see the code available for this book and all other Wrox books
or one of the title lists Then, on the book details page, click the Book Errata link On this page you can view all errata that has been submitted for this book and posted by Wrox editors A complete
booklist.shtml
.shtml and complete the form there to send us the error you have found Once the information is checked, a message is posted to the book’s errata page and the problem is fi xed in subsequent editions
of the book
P2P.WROX.COM
system for you to post messages relating to Wrox books and related technologies and to interact with other readers and technology users The forums offer a subscription feature to email you topics
of interest of your choosing when new posts are made to the forums Wrox authors, editors, other industry experts, and your fellow readers are present on these forums
At http://p2p.wrox.com you will fi nd a number of different forums that will help you not only as you read this book, but also as you develop your own applications To join the forums, just follow these steps:
1. Go to p2p.wrox.com and click the Register link
Trang 36provide and click Submit
com-plete the joining process
You can read messages in the forums without joining P2P but in order to post your own messages, you must join.
Once you join, you can post new messages and respond to messages other users post You can read
messages at any time on the Web If you would like to have new messages from a particular forum
emailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing
For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to
questions about how the forum software works as well as many common questions specifi c to P2P
and Wrox books To read the FAQs, click the FAQ link on any P2P page
Trang 37and Troubleshooting
Trang 39SQL Server Architecture
WHAT’S IN THIS CHAPTER
Understanding database transactions and the ACID properties
trouble-This chapter distills the core architecture of SQL Server and puts the most important nents into the context of executing a simple query to help you understand the fundamentals of the core engine
compo-You will learn how SQL Server deals with your network connection, unravels what you’re asking it to do, decides how it will execute your request, and fi nally how data is retrieved and modifi ed on your behalf
You will also discover when the transaction log is used and how it’s affected by the confi gured recovery model; what happens when a checkpoint occurs and how you can infl uence the fre-quency; and what the lazywriter does
1
Trang 40The chapter starts by defi ning a “transaction” and what the requirements are for a database system
to reliably process them You’ll then look at the life cycle of a simple query that reads data, taking a
walk through the components employed to return a result set, before looking at how the process
dif-fers when data needs to be modifi ed
Finally, you’ll read about the components and terminology that support the recovery process in SQL
Server, and the SQLOS “framework” introduced in SQL Server 2005 that consolidates a lot of the
low-level functions required by many SQL Server components
Some areas of the life cycle described in this chapter are intentionally shallow in order to keep the fl ow manageable, and where that’s the case you are directed to the chapter or chapters that cover the topic in more depth.
DATABASE TRANSACTIONS
A transaction is a unit of work in a database that typically contains several commands that read
from and write to the database The most well-known feature of a transaction is that it must
com-plete all of the commands in their entirety or none of them This feature, called atomicity, is just one
of four properties defi ned in the early days of database theory as requirements for a database
trans-action, collectively known as ACID properties
ACID Properties
The four required properties of a database transaction are atomicity, consistency, isolation, and
durability
Atomicity
Atomicity means that all the effects of the transaction must complete successfully or the changes are
rolled back A classic example of an atomic transaction is a withdrawal from an ATM machine; the
machine must both dispense the cash and debit your bank account Either of those actions
complet-ing independently would cause a problem for either you or the bank
Consistency
The consistency requirement ensures that the transaction cannot break the integrity rules of the
database; it must leave the database in a consistent state For example, your system might require
that stock levels cannot be a negative value, a spare part cannot exist without a parent object, or the
data in a sex fi eld must be male or female In order to be consistent, a transaction must not break
any of the constraints or rules defi ned for the data