oracle database 11g performance tuning...

7
www.it-ebooks.info

Upload: dangque

Post on 23-Mar-2018

249 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Oracle Database 11g Performance Tuning Recipesdocview1.tlvnimg.com/.../ringphone/oracle_database_11g_performance... · Solutions in the recipes are ... Oracle Database 11g Performance

AlapatiKuhn

Padfield

US $49.99

Shelve inDatabases/Oracle

User level:Beginning–Advanced

www.apress.com

RELATED

BOOKS FOR PROFESSIONALS BY PROFESSIONALS®

Oracle Database 11g Performance Tuning RecipesInside this book, you will find the solution to your Oracle performance problems. Oracle Database 11g Performance Tuning Recipes takes an example-based approach in which each chapter covers a specific problem domain. Recipes within each chapter show you, by example, how to perform common tasks. Solutions in the recipes are backed by clear explanations of background and theory from the author team.

With Oracle Database 11g Performance Tuning Recipes, you’ll learn how to:

• Optimize the use of memory and storage• Monitor performance and troubleshoot problems• Identify and improve poorly performing SQL statements• Adjust the most important optimizer parameters to your advantage• Create indexes that get used and make a positive impact upon performance• Automate and stabilize performance using key features such as SQL Tuning Advisor and SQL Plan Baselines

Oracle Database 11g Performance Tuning Recipes offers you a set of solutions ready for immediate implementation. It gives you the power to solve any common database performance problem.

www.it-ebooks.info

Page 2: Oracle Database 11g Performance Tuning Recipesdocview1.tlvnimg.com/.../ringphone/oracle_database_11g_performance... · Solutions in the recipes are ... Oracle Database 11g Performance

iv

Contents at a Glance

About the Authors .................................................................................................... xvi

About the Technical Reviewer ................................................................................ xvii

Acknowledgments ................................................................................................. xviii

■Chapter 1: Optimizing Table Performance ............................................................... 1

■Chapter 2: Choosing and Optimizing Indexes ........................................................ 43

■Chapter 3: Optimizing Instance Memory ............................................................... 83

■Chapter 4: Monitoring System Performance ....................................................... 113

■Chapter 5: Minimizing System Contention .......................................................... 147

■Chapter 6: Analyzing Operating System Performance ........................................ 185

■Chapter 7: Troubleshooting the Database ........................................................... 209

■Chapter 8: Creating Efficient SQL ........................................................................ 253

■Chapter 9: Manually Tuning SQL .......................................................................... 299

■Chapter 10: Tracing SQL Execution ..................................................................... 327

■Chapter 11: Automated SQL Tuning ..................................................................... 367

■Chapter 12: Execution Plan Optimization and Consistency ................................. 409

■Chapter 13: Configuring the Optimizer ................................................................ 447

■Chapter 14: Implementing Query Hints ............................................................... 491

■Chapter 15: Executing SQL in Parallel ................................................................. 525

Index ....................................................................................................................... 555

www.it-ebooks.info

Page 3: Oracle Database 11g Performance Tuning Recipesdocview1.tlvnimg.com/.../ringphone/oracle_database_11g_performance... · Solutions in the recipes are ... Oracle Database 11g Performance

C H A P T E R 1

1

Optimizing Table Performance

This chapter details database features that impact the performance of storing and retrieving data within a table. Table performance is partially determined by database characteristics implemented prior to creating tables. For example, the physical storage features implemented when first creating a database and associated tablespaces subsequently influence the performance of tables. Similarly, performance is also impacted by your choice of initial physical features such as table types and data types. Therefore implementing practical database, tablespace, and table creation standards (with performance in mind) forms the foundation for optimizing data availability and scalability.

An Oracle database is comprised of the physical structures used to store, manage, secure, and retrieve data. When first building a database, there are several performance-related features that you can implement at the time of database creation. For example, the initial layout of the datafiles and the type of tablespace management are specified upon creation. Architectural decisions instantiated at this point often have long-lasting implications.

A tablespace is the logical structure that allows you to manage a group of datafiles. Datafiles are the physical datafiles on disk. When configuring tablespaces, there are several features to be aware of that can have far-reaching performance implications, namely locally managed tablespaces and automatic segment storage–managed tablespaces. When you reasonably implement these features, you maximize your ability to obtain acceptable future table performance.

The table is the object that stores data in a database. Database performance is a measure of the speed at which an application is able to insert, update, delete, and select data. Therefore it’s appropriate that we begin this book with recipes that provide solutions regarding problems related to table performance.

We start by describing aspects of database and tablespace creation that impact table performance. We next move on to topics such as choosing table types and data types that meet performance-related business requirements. Later topics include managing the physical implementation of tablespace usage. We detail issues such as detecting table fragmentation, dealing with free space under the high-water mark, row chaining, and compressing data. Also described is the Oracle Segment Advisor. This handy tool helps you with automating the detection and resolution of table fragmentation and unused space.

www.it-ebooks.info

Page 4: Oracle Database 11g Performance Tuning Recipesdocview1.tlvnimg.com/.../ringphone/oracle_database_11g_performance... · Solutions in the recipes are ... Oracle Database 11g Performance

CHAPTER 1 ■ OPTIMIZING TABLE PERFORMANCE

2

1-1. Building a Database That Maximizes Performance

Problem You realize when initially creating a database that some features (when enabled) have long-lasting ramifications for table performance and availability. Specifically, when creating the database, you want to do the following:

• Enforce that every tablespace ever created in the database must be locally managed. Locally managed tablespaces deliver better performance than the deprecated dictionary-managed technology.

• Ensure users are automatically assigned a default permanent tablespace. This guarantees that when users are created they are assigned a default tablespace other than SYSTEM. You don’t want users ever creating objects in the SYSTEM tablespace, as this can adversely affect performance and availability.

• Ensure users are automatically assigned a default temporary tablespace. This guarantees that when users are created they are assigned a temporary tablespace other than SYSTEM. You don’t ever want users using the SYSTEM tablespace for a temporary sorting space, as this can adversely affect performance and availability.

Solution Use a script such as the following to create a database that adheres to reasonable standards that set the foundation for a well-performing database:

CREATE DATABASE O11R2 MAXLOGFILES 16 MAXLOGMEMBERS 4 MAXDATAFILES 1024 MAXINSTANCES 1 MAXLOGHISTORY 680 CHARACTER SET AL32UTF8 DATAFILE '/ora01/dbfile/O11R2/system01.dbf' SIZE 500M REUSE EXTENT MANAGEMENT LOCAL UNDO TABLESPACE undotbs1 DATAFILE '/ora02/dbfile/O11R2/undotbs01.dbf' SIZE 800M SYSAUX DATAFILE '/ora03/dbfile/O11R2/sysaux01.dbf' SIZE 500M DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/ora02/dbfile/O11R2/temp01.dbf' SIZE 500M

www.it-ebooks.info

Page 5: Oracle Database 11g Performance Tuning Recipesdocview1.tlvnimg.com/.../ringphone/oracle_database_11g_performance... · Solutions in the recipes are ... Oracle Database 11g Performance

CHAPTER 1 ■ OPTIMIZING TABLE PERFORMANCE

3

DEFAULT TABLESPACE USERS DATAFILE '/ora01/dbfile/O11R2/users01.dbf' SIZE 50M LOGFILE GROUP 1 ('/ora01/oraredo/O11R2/redo01a.rdo', '/ora02/oraredo/O11R2/redo01b.rdo') SIZE 200M, GROUP 2 ('/ora01/oraredo/O11R2/redo02a.rdo', '/ora02/oraredo/O11R2/redo02b.rdo') SIZE 200M, GROUP 3 ('/ora01/oraredo/O11R2/redo03a.rdo', '/ora02/oraredo/O11R2/redo03b.rdo') SIZE 200M USER sys IDENTIFIED BY topfoo USER system IDENTIFIED BY topsecrectfoo;

The prior CREATE DATABASE script helps establish a good foundation for performance by enabling features such as the following:

• Defines the SYSTEM tablespace as locally managed via the EXTENT MANAGEMENT LOCAL clause; this ensures that all tablespaces ever created in database are locally managed. If you are using Oracle Database 11g R2 or higher, the EXTENT MANAGEMENT DICTIONARY clause has been deprecated.

• Defines a default tablespace named USERS for any user created without an explicitly defined default tablespace; this helps prevent users from being assigned the SYSTEM tablespace as the default. Users created with a default tablespace of SYSTEM can have an adverse impact on performance.

• Defines a default temporary tablespace named TEMP for all users; this helps prevent users from being assigned the SYSTEM tablespace as the default temporary tablespace. Users created with a default temporary tablespace of SYSTEM can have an adverse impact on performance, as this will cause contention for resources in the SYSTEM tablespace.

Solid performance starts with a correctly configured database. The prior recommendations help you create a reliable infrastructure for your table data.

How It Works A properly configured and created database will help ensure that your database performs well. It is true that you can modify features after the database is created. However, oftentimes a poorly crafted CREATE DATABASE script leads to a permanent handicap on performance. In production database environments, it’s sometimes difficult to get the downtime that might be required to reconfigure an improperly configured database. If possible, think about performance at every step in creating an environment, starting with how you create the database.

When creating a database, you should also consider features that affect maintainability. A sustainable database results in more uptime, which is part of the overall performance equation. The CREATE DATABASE statement in the “Solution” section also factors in the following sustainability features:

www.it-ebooks.info

Page 6: Oracle Database 11g Performance Tuning Recipesdocview1.tlvnimg.com/.../ringphone/oracle_database_11g_performance... · Solutions in the recipes are ... Oracle Database 11g Performance

xviii

Acknowledgments

The authors owe thanks to the great publishing team at Apress for helping them throughout the writing process. Jonathan Gennick, senior acquisitions editor, helped significantly in outlining the topics (recipes) for this book, and helped us produce the best book we possibly could, by nudging us along with incisive comments/suggestions/criticisms, all of which have tremendously increased both the presentation style of the book as well as the quality of the contents. Jonathan is that rare editor who is not only technically proficient, but also a consummate editor of books, in the traditional sense of the term. Thank you, Jonathan, for your patience and hard work throughout this project! All three of us are beneficiaries of your sagacious advice and continual encouragement over the past few months.

The authors would like to thank the tremendous work done by the technical editor of the book, Surachart Opun, senior analyst at True Internet, who somehow found time from his prolific blogging and other work to perform a marvelous review of our draft chapters. Surachart not only caught several mistakes in code and elsewhere, but also made numerous suggestions to improve the presentation of the various recipes. Thank you, Surachart, for all your painstaking and cheerful work in helping us out with the book. Anita Castro, coordinating editor, has superbly guided us throughout this project, and helped keep things on schedule. Managing a three-author project isn’t a piece of cake by any means, but Anita sure makes it seem that way! Mary Ann Fugate copyedited the chapters with great skill, and we appreciate her contributions toward improving the quality of this book.

Personal Acknowledgments First of all, my heartfelt thanks to the great help and cooperation from my two co-writers—Darl Kuhn and Bill Padfield—it sure was great working with you, Darl and Bill—I've enjoyed every minute of it! I’d like to acknowledge the support and encouragement of my company, Miro Consulting Inc., Woodbridge, New Jersey, whose CEO, Scott Rosenberg, is not only a great leader but also an enthusiastic promoter of Oracle technology with our many clients across the United States. Miro’s president, Eliot Colon, its vice president of technical services, Wayne Federico, and its vice president, Bob Kinkade, have always been supportive of my work at Miro, and I’ve learned a lot from working with each of them.

I’d like to express the generosity and help offered by my friends Kishore Rachamalla, Praveen Katapally, and Sreeny Chinta during my tenure at ERCOT in Taylor, Texas, where I started initial work on this and another book. I’m grateful for the kindness and show of support by Sam Nataros, whose gift from the heart I’ll always cherish—thank you, Sam, your gesture inspires me every single day!

My family, of course, has sacrificed the most in making this book possible, and thus I’m grateful to Valerie, Shannon, Nicholas, and Nina for their help and support over the past few years while I was working on this and another book. Last but not least, I’d like to acknowledge my debt to my other family—my mother, Swarna Kumari, my father, Appa Rao, and my brothers, Hari Hara Prasad and Siva Sankara Prasad, Aruna, Vanaja, Ashwin, Teja, Aparna, and Soumya, for their abiding love and faith in me.

Sam Alapati

www.it-ebooks.info

Page 7: Oracle Database 11g Performance Tuning Recipesdocview1.tlvnimg.com/.../ringphone/oracle_database_11g_performance... · Solutions in the recipes are ... Oracle Database 11g Performance

■ ACKNOWLEDGMENTS

xix

Thanks to fellow co-authors Sam Alapati and Bill Padfield, and also thanks to the numerous DBAs and developers from whom I’ve learned performance tuning techniques over the years: Dave Jennings, Bob Suehrstedt, Scott Schulze, Pete Mullineaux, Janet Bacon, Sue Wagner, Mohan Koneru, Arup Nanda, Charles Kim, Bernard Lopuz, Barb Sannwald, Tim Gorman, Shawn Heisdorffer, Doug Davis, Sujit Pattanaik, Ken Roberts, Roger Murphy, Mehran Sowdaey, Kevin Bayer, Dan Fink, Guido Handley, Margaret Carson, Nehru Kaja, Tim Colbert, Glenn Balanoff, Bob Mason, Shari Plantz-Masters, Mike Nims, Denise Duncan, Brad Blake, Ravi Narayanaswamy, Abid Malik, Abdul Ebadi, Kevin Hoyt, Trent Sherman, Sandra Montijo, Jim Secor, Maureen Frazzini, Sean Best, Stephan Haisley, Geoff Strebel, Patrick Gates, Krish Hariharan, Buzzy Cheadle, Mark Blair, Gary Dodge, Karen Kappler, Mike Hutchinson, Liz Brill, Ennio Murroni, Mike O’Neill, Beth Loker, Mike Eason, Greg Roberts, Debbie Earman, Tom Wheltle, Ken Toney, Gabor Gyurovszky, Scott Norris, Joey Canlas, Eric Wendelin, Gary Smith, Mark Lutze, Kevin Quinlivan, Dave Bourque, Roy Backstrom, Larry Carpenter, Joe Meeks, Ashish Ray, John Lilly, Dave Wood, Laurie Bourgeois, Steve Buckmelter, Casey Costley, John DiVirgilio, John Goggin, Brett Guy, Simon Ip, Pascal Ledru, Kevin O’Grady, Peter Schow, Todd Sherman, Jeff Shoup, Mike Tanaka, Todd Wichers, Doug Cushing, Will Thornburg, Steve Roughton, Ambereen Pasha, Dinesh Neelay, Kye Bae, Thom Chumley, Jeff Sherard, Dona Smith, Erik Jasiak, Gary Schut, Don Gritzmacher, Aaron Isom, Kristi Jackson, Karolyn Vowles, Amin Jiwani, Paula Still, K. P. Muthe, Joe Pinkerton, Arvin Kuhn, Darin Christensen, Terry Roam, Doug Drake, Marilyn Wenzel, Doc Heppler, Mert Lovell, Carl Beasly, Brian Beasly, Odean Bowler, and Jim Stark.

Darl Kuhn I’d like to thank my gracious co-authors, Sam Alapati and Darl Kuhn, for all of their help and support, and for taking on a rookie for this project. I couldn’t have made it without their help.

There are so many people I can thank that have helped me over the years in my career, so please know that I appreciate every single individual who has encouraged and helped me along. First of all, I’d like to thank Bob Ranney for giving me the opportunity to be a DBA. I also would like to thank some of my key managers over the years that have helped me, including Beth Bowen, Larry Wyzgala, John Zlamal, Linda Scheldrup, Amy Neff, and Maureen Frazzini.

Of course, there are many DBAs, developers, system administrators, and architects that have helped me greatly in my career. First, I need to thank the DBAs on my current team who make the everyday grind a blast. These folks have helped me so much professionally and have become great friends over the many years we have worked together. This includes Dave Carter, Debbie Fitzgerald, Pankaj Guleria, Pete Sardaczuk, Brad Strom, and Rebecca Western.

Over the years, I’ve learned an awful lot from the following folks, who have always been generous with their time and help, and patient with my questions. This includes Mark Nold, Mick McMahon, Sandra Montijo, Jerry Sanderson, Glen Sanderson, Jose Fernandez, Mike Hammontre, Pat Cain, Dave Steep, Gary Whiting, Ron Fullmer, Becky Enter, John Weber, Avanish Gupta, Scott Bunker, Paul Mayes, Bill Read, Rod Ermish, Rick Barry, Sun Yang, Sue Wagner, Glenn Balanoff, Linda Lee Burau, Deborah Lieou-McCall, Bob Zumpf, Kristi Sargent, Sandy Hass, George Huner, Pad Kail, Curtis Gay, Ross Bartholomay, Carol Rosenow, Scott Richards, Sheryl Gross, Lachelle Shambe, John Piel, Rob Grote, Rex Ellis, Zane Warton, Steve Pearson, Jim Barclay, Jason Hermstad, Shari Plantz-Masters, Denise Duncan, Bob Mason, Brad Blake, Mike Nims, Cathie Wilson, Rob Coates, Shirley Amend, Rob Bushlack, Cindy Patterson, Debbie Chartier, Blair Christensen, Meera Ganesan, and Kedar Panda.

Bill Padfield

www.it-ebooks.info