Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing...

51
Oracle Database 12c Performance Tuning Recipes A Problem-Solution Approach Sam R. Alapati Darl Kuhn Bill Padfield

Transcript of Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing...

Page 1: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

Oracle Database 12c Performance Tuning

RecipesA Problem-Solution Approach

Sam R. Alapati

Darl Kuhn

Bill Padfield

Page 2: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

Oracle Database 12c Performance Tuning Recipes: A Problem-Solution Approach

Copyright © 2013 by Sam R. Alapati, Darl Kuhn, and Bill Padfield

This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law.

ISBN-13 (pbk): 978-1-4302-6187-2

ISBN-13 (electronic): 978-1-4302-6188-9

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.

President and Publisher: Paul ManningLead Editor: Jonathan GennickTechnical Reviewer: Stéphane Faroult and Arup NandaEditorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Louise Corrigan, James DeWolf,

Jonathan Gennick, Jonathan Hassell, Robert Hutchinson, Michelle Lowman, James Markham, Matthew Moodie, Jeff Olson, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Gwenan Spearing, Matt Wade, Steve Weiss, Tom Welsh

Coordinating Editor: Kevin SheaCopy Editors: Angie Wood and Kim WimpsettCompositor: SPi GlobalIndexer: SPi GlobalArtist: SPi GlobalCover Designer: Anna Ishchenko

Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com.

For information on translations, please e-mail [email protected], or visit www.apress.com.

Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales.

Any source code or other supplementary materials referenced by the author in this text is available to readers at www.apress.com. For detailed information about how to locate your book’s source code, go to www.apress.com/source-code.

Page 3: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

To Dale, Shawn, and Keith, with love and affection.

—Sam Alapati

To Lisa, Heidi, and Brandi.

—Darl Kuhn

With love to Oyuna, Evan, and my family.

—Bill Padfield

Page 4: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c
Page 5: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

v

Contents at a Glance

About the Authors �������������������������������������������������������������������������������������������������������������� xlv

About the Technical Reviewers ��������������������������������������������������������������������������������������� xlvii

Acknowledgments ������������������������������������������������������������������������������������������������������������ xlix

Introduction ��������������������������������������������������������������������������������������������������������������������������li

Chapter 1: Optimizing Table Performance ■ �������������������������������������������������������������������������1

Chapter 2: Choosing and Optimizing Indexes ■ ������������������������������������������������������������������51

Chapter 3: Optimizing Instance Memory ■ �������������������������������������������������������������������������95

Chapter 4: Monitoring System Performance ■ �����������������������������������������������������������������125

Chapter 5: Minimizing System Contention ■ ��������������������������������������������������������������������157

Chapter 6: Analyzing Operating System Performance ■ ��������������������������������������������������193

Chapter 7: Troubleshooting the Database ■ ����������������������������������������������������������������������217

Chapter 8: Creating Efficient SQL ■ ����������������������������������������������������������������������������������259

Chapter 9: Manually Tuning SQL ■ ������������������������������������������������������������������������������������307

Chapter 10: Tracing SQL Execution ■ ��������������������������������������������������������������������������������335

Chapter 11: Automated SQL Tuning ■ �������������������������������������������������������������������������������375

Chapter 12: Execution Plan Optimization and Consistency ■ �������������������������������������������415

Chapter 13: Configuring the Optimizer ■ ��������������������������������������������������������������������������457

Chapter 14: Implementing Query Hints ■ �������������������������������������������������������������������������501

Chapter 15: Executing SQL in Parallel ■ ���������������������������������������������������������������������������537

Index ���������������������������������������������������������������������������������������������������������������������������������569

Page 6: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c
Page 7: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

vii

Contents

About the Authors �������������������������������������������������������������������������������������������������������������� xlv

About the Technical Reviewers ��������������������������������������������������������������������������������������� xlvii

Acknowledgments ������������������������������������������������������������������������������������������������������������ xlix

Introduction ��������������������������������������������������������������������������������������������������������������������������li

Chapter 1: Optimizing Table Performance ■ �������������������������������������������������������������������������1

1-1. Building a Database That Maximizes Performance ...............................................................2

Problem ................................................................................................................................................................. 2

Solution.................................................................................................................................................................. 3

How It Works .......................................................................................................................................................... 6

1-2. Creating Tablespaces to Maximize Performance ...................................................................7

Problem ................................................................................................................................................................. 7

Solution.................................................................................................................................................................. 7

How It Works .......................................................................................................................................................... 8

1-3. Matching Table Types to Business Requirements ..................................................................8

Problem ................................................................................................................................................................. 8

Solution.................................................................................................................................................................. 9

How It Works .......................................................................................................................................................... 9

1-4. Choosing Table Features for Performance ...........................................................................10

Problem ............................................................................................................................................................... 10

Solution................................................................................................................................................................ 10

How It Works ........................................................................................................................................................ 11

Page 8: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

viii

1-5. Selecting Data Types Appropriately .....................................................................................12

Problem ............................................................................................................................................................... 12

Solution................................................................................................................................................................ 12

How It Works ........................................................................................................................................................ 13

1-6. Avoiding Extent Allocation Delays When Creating Tables .....................................................16

Problem ............................................................................................................................................................... 16

Solution................................................................................................................................................................ 16

How It Works ........................................................................................................................................................ 17

1-7. Maximizing Data-Loading Speeds .......................................................................................18

Problem ............................................................................................................................................................... 18

Solution................................................................................................................................................................ 18

How It Works ........................................................................................................................................................ 19

1-8. Efficiently Removing Table Data...........................................................................................20

Problem ............................................................................................................................................................... 20

Solution................................................................................................................................................................ 20

How It Works ........................................................................................................................................................ 21

1-9. Displaying Automated Segment Advisor Advice ..................................................................23

Problem ............................................................................................................................................................... 23

Solution................................................................................................................................................................ 23

How It Works ........................................................................................................................................................ 24

1-10. Manually Generating Segment Advisor Advice ..................................................................26

Problem ............................................................................................................................................................... 26

Solution................................................................................................................................................................ 26

How It Works ........................................................................................................................................................ 28

1-11. Automatically E-mailing Segment Advisor Output .............................................................29

Problem ............................................................................................................................................................... 29

Solution................................................................................................................................................................ 29

How It Works ........................................................................................................................................................ 30

Page 9: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

ix

1-12. Rebuilding Rows Spanning Multiple Blocks ......................................................................31

Problem ............................................................................................................................................................... 31

Solution................................................................................................................................................................ 31

How It Works ........................................................................................................................................................ 34

1-13. Detecting Row Chaining and Row Migration .....................................................................35

Problem ............................................................................................................................................................... 35

Solution................................................................................................................................................................ 35

How It Works ........................................................................................................................................................ 36

1-14. Differentiating Between Row Migration and Row Chaining ...............................................36

Problem ............................................................................................................................................................... 36

Solution................................................................................................................................................................ 37

How It Works ........................................................................................................................................................ 37

1-15. Proactively Preventing Row Migration/Chaining ................................................................37

Problem ............................................................................................................................................................... 37

Solution................................................................................................................................................................ 37

How It Works ........................................................................................................................................................ 38

1-16. Detecting Unused Space in a Table ....................................................................................38

Problem ............................................................................................................................................................... 38

Solution................................................................................................................................................................ 38

How It Works ........................................................................................................................................................ 39

1-17. Tracing to Detect Space Below the High-Water Mark ........................................................40

Problem ............................................................................................................................................................... 40

Solution................................................................................................................................................................ 40

How It Works ........................................................................................................................................................ 41

1-18. Using DBMS_SPACE to Detect Space Below the High-Water Mark ...................................41

Problem ............................................................................................................................................................... 41

Solution................................................................................................................................................................ 41

How It Works ........................................................................................................................................................ 42

Page 10: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

x

1-19. Freeing Unused Table Space ..............................................................................................42

Problem ............................................................................................................................................................... 42

Solution................................................................................................................................................................ 42

How It Works ........................................................................................................................................................ 43

1-20. Compressing Data for Direct Path Loading ........................................................................44

Problem ............................................................................................................................................................... 44

Solution................................................................................................................................................................ 44

How It Works ........................................................................................................................................................ 45

1-21. Compressing Data for All DML ...........................................................................................46

Problem ............................................................................................................................................................... 46

Solution................................................................................................................................................................ 46

How It Works ........................................................................................................................................................ 47

1-22. Compressing Data at the Column Level .............................................................................48

Problem ............................................................................................................................................................... 48

Solution................................................................................................................................................................ 48

How It Works ........................................................................................................................................................ 49

Chapter 2: Choosing and Optimizing Indexes ■ ������������������������������������������������������������������51

2-1. Understanding B-tree Indexes .............................................................................................53

Problem ............................................................................................................................................................... 53

Solution................................................................................................................................................................ 53

How It Works ........................................................................................................................................................ 59

2-2. Deciding Which Columns to Index ........................................................................................60

Problem ............................................................................................................................................................... 60

Solution................................................................................................................................................................ 60

How It Works ........................................................................................................................................................ 62

2-3. Creating a Primary Key Constraint and Index ......................................................................63

Problem ............................................................................................................................................................... 63

Solution................................................................................................................................................................ 63

How It Works ........................................................................................................................................................ 64

Page 11: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xi

2-4. Ensuring Unique Column Values ..........................................................................................65

Problem ............................................................................................................................................................... 65

Solution................................................................................................................................................................ 65

How It Works ........................................................................................................................................................ 66

2-5. Indexing Foreign Key Columns ............................................................................................68

Problem ............................................................................................................................................................... 68

Solution................................................................................................................................................................ 68

How It Works ........................................................................................................................................................ 69

2-6. Deciding When to Use a Concatenated Index ......................................................................72

Problem ............................................................................................................................................................... 72

Solution................................................................................................................................................................ 72

How It Works ........................................................................................................................................................ 73

2-7. Reducing Index Size Through Compression .........................................................................74

Problem ............................................................................................................................................................... 74

Solution................................................................................................................................................................ 75

How It Works ........................................................................................................................................................ 75

2-8. Implementing a Function-Based Index ................................................................................76

Problem ............................................................................................................................................................... 76

Solution................................................................................................................................................................ 76

How It Works ........................................................................................................................................................ 77

2-9. Indexing a Virtual Column ....................................................................................................78

Problem ............................................................................................................................................................... 78

Solution................................................................................................................................................................ 78

How It Works ........................................................................................................................................................ 78

2-10. Limiting Index Contention when Several Processes Insert in Parallel ...............................79

Problem ............................................................................................................................................................... 79

Solution................................................................................................................................................................ 79

How It Works ........................................................................................................................................................ 80

Page 12: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xii

2-11. Toggling the Visibility of an Index to the Optimizer ............................................................80

Problem ............................................................................................................................................................... 80

Solution................................................................................................................................................................ 81

How It Works ........................................................................................................................................................ 81

2-12. Creating a Bitmap Index in Support of a Star Schema ......................................................82

Problem ............................................................................................................................................................... 82

Solution................................................................................................................................................................ 82

How It Works ........................................................................................................................................................ 83

2-13. Creating a Bitmap Join Index .............................................................................................85

Problem ............................................................................................................................................................... 85

Solution................................................................................................................................................................ 85

How It Works ........................................................................................................................................................ 86

2-14. Creating an Index-Organized Table ....................................................................................86

Problem ............................................................................................................................................................... 86

Solution................................................................................................................................................................ 86

How It Works ........................................................................................................................................................ 87

2-15. Monitoring Index Usage .....................................................................................................88

Problem ............................................................................................................................................................... 88

Solution................................................................................................................................................................ 88

How It Works ........................................................................................................................................................ 89

2-16. Maximizing Index Creation Speed......................................................................................89

Problem ............................................................................................................................................................... 89

Solution................................................................................................................................................................ 89

How It Works ........................................................................................................................................................ 90

2-17. Reclaiming Unused Index Space........................................................................................91

Problem ............................................................................................................................................................... 91

Solution................................................................................................................................................................ 92

How It Works ........................................................................................................................................................ 92

Page 13: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xiii

Chapter 3: Optimizing Instance Memory ■ �������������������������������������������������������������������������95

3-1. Automating Memory Management ......................................................................................95

Problem ............................................................................................................................................................... 95

Solution................................................................................................................................................................ 95

How It Works ........................................................................................................................................................ 96

3-2. Managing Multiple Buffer Pools ...........................................................................................98

Problem ............................................................................................................................................................... 98

Solution................................................................................................................................................................ 99

How It Works ........................................................................................................................................................ 99

3-3. Setting Minimum Values for Memory .................................................................................100

Problem ............................................................................................................................................................. 100

Solution.............................................................................................................................................................. 100

How It Works ...................................................................................................................................................... 101

3-4. Monitoring Memory Resizing Operations ...........................................................................101

Problem ............................................................................................................................................................. 101

Solution.............................................................................................................................................................. 101

How It Works ...................................................................................................................................................... 102

3-5. Optimizing Memory Usage .................................................................................................103

Problem ............................................................................................................................................................. 103

Solution.............................................................................................................................................................. 103

How It Works ...................................................................................................................................................... 103

3-6. Tuning PGA Memory Allocation ..........................................................................................104

Problem ............................................................................................................................................................. 104

Solution.............................................................................................................................................................. 104

How It Works ...................................................................................................................................................... 104

3-7. Configuring the Server Query Cache .................................................................................107

Problem ............................................................................................................................................................. 107

Solution.............................................................................................................................................................. 107

How It Works ...................................................................................................................................................... 108

Page 14: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xiv

3-8. Managing the Server Result Cache ...................................................................................109

Problem ............................................................................................................................................................. 109

Solution.............................................................................................................................................................. 109

How It Works ...................................................................................................................................................... 111

3-9. Caching SQL Query Results ...............................................................................................111

Problem ............................................................................................................................................................. 111

Solution.............................................................................................................................................................. 112

How It Works ...................................................................................................................................................... 112

3-10. Caching Client Result Sets ...............................................................................................115

Problem ............................................................................................................................................................. 115

Solution.............................................................................................................................................................. 115

How It Works ...................................................................................................................................................... 116

3-11. Caching PL/SQL Function Results ....................................................................................117

Problem ............................................................................................................................................................. 117

Solution.............................................................................................................................................................. 117

How It Works ...................................................................................................................................................... 118

3-12. Configuring the Oracle Database Smart Flash Cache ......................................................120

Problem ............................................................................................................................................................. 120

Solution.............................................................................................................................................................. 120

How It Works ...................................................................................................................................................... 121

3-13. Tuning the Redo Log Buffer ..............................................................................................122

Problem ............................................................................................................................................................. 122

Solution.............................................................................................................................................................. 122

How It Works ...................................................................................................................................................... 122

3-14. Limiting PGA Memory Allocation ......................................................................................123

Problem ............................................................................................................................................................. 123

Solution.............................................................................................................................................................. 123

How It Works ...................................................................................................................................................... 124

Page 15: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xv

Chapter 4: Monitoring System Performance ■ �����������������������������������������������������������������125

4-1. Implementing Automatic Workload Repository (AWR) .......................................................125

Problem ............................................................................................................................................................. 125

Solution.............................................................................................................................................................. 126

How It Works ...................................................................................................................................................... 126

4-2. Modifying the Statistics Interval and Retention Periods ....................................................128

Problem ............................................................................................................................................................. 128

Solution.............................................................................................................................................................. 128

How It Works ...................................................................................................................................................... 129

4-3. Generating an AWR Report Manually .................................................................................129

Problem ............................................................................................................................................................. 129

Solution.............................................................................................................................................................. 129

How It Works ...................................................................................................................................................... 131

4-4. Generating an AWR Report via Enterprise Manager ...........................................................133

Problem ............................................................................................................................................................. 133

Solution.............................................................................................................................................................. 133

How It Works ...................................................................................................................................................... 134

4-5. Generating an AWR Report for a Single SQL Statement.....................................................135

Problem ............................................................................................................................................................. 135

Solution.............................................................................................................................................................. 135

How It Works ...................................................................................................................................................... 136

4-6. Creating a Statistical Baseline for Your Database ..............................................................136

Problem ............................................................................................................................................................. 136

Solution.............................................................................................................................................................. 136

How It Works ...................................................................................................................................................... 138

4-7. Managing AWR Baselines via Enterprise Manager ............................................................140

Problem ............................................................................................................................................................. 140

Solution.............................................................................................................................................................. 140

How It Works ...................................................................................................................................................... 141

Page 16: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xvi

4-8. Managing AWR Statistics Repository .................................................................................142

Problem ............................................................................................................................................................. 142

Solution.............................................................................................................................................................. 142

How It Works ...................................................................................................................................................... 142

4-9. Creating AWR Baselines Automatically ..............................................................................144

Problem ............................................................................................................................................................. 144

Solution.............................................................................................................................................................. 144

How It Works ...................................................................................................................................................... 145

4-10. Quickly Analyzing AWR Output .........................................................................................145

Problem ............................................................................................................................................................. 145

Solution.............................................................................................................................................................. 145

How It Works ...................................................................................................................................................... 147

4-11. Manually Getting Active Session Information ..................................................................147

Problem ............................................................................................................................................................. 147

Solution.............................................................................................................................................................. 147

How It Works ...................................................................................................................................................... 151

4-12. Getting ASH Information from Enterprise Manager..........................................................152

Problem ............................................................................................................................................................. 152

Solution.............................................................................................................................................................. 152

How It Works ...................................................................................................................................................... 153

4-13. Getting ASH Information from the Data Dictionary ..........................................................154

Problem ............................................................................................................................................................. 154

Solution.............................................................................................................................................................. 154

How It Works ...................................................................................................................................................... 155

Chapter 5: Minimizing System Contention ■ ��������������������������������������������������������������������157

5-1. Understanding Response Time ..........................................................................................157

Problem ............................................................................................................................................................. 157

Solution.............................................................................................................................................................. 157

How It Works ...................................................................................................................................................... 158

Page 17: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xvii

5-2. Identifying SQL Statements with the Most Waits ...............................................................159

Problem ............................................................................................................................................................. 159

Solution.............................................................................................................................................................. 160

How It Works ...................................................................................................................................................... 160

5-3. Analyzing Wait Events ........................................................................................................160

Problem ............................................................................................................................................................. 160

Solution.............................................................................................................................................................. 161

How It Works ...................................................................................................................................................... 161

5-4. Understanding Wait Class Events ......................................................................................162

Problem ............................................................................................................................................................. 162

Solution.............................................................................................................................................................. 162

How It Works ...................................................................................................................................................... 163

5-5. Examining Session Waits ...................................................................................................163

Problem ............................................................................................................................................................. 163

Solution.............................................................................................................................................................. 163

How It Works ...................................................................................................................................................... 164

5-6. Examining Wait Events by Class ........................................................................................164

Problem ............................................................................................................................................................. 164

Solution.............................................................................................................................................................. 165

How It Works ...................................................................................................................................................... 167

5-7. Resolving Buffer Busy Waits ..............................................................................................167

Problem ............................................................................................................................................................. 167

Solution.............................................................................................................................................................. 167

How It Works ...................................................................................................................................................... 168

5-8. Resolving Log File Sync Waits ...........................................................................................169

Problem ............................................................................................................................................................. 169

Solution.............................................................................................................................................................. 169

How It Works ...................................................................................................................................................... 169

Page 18: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xviii

5-9. Minimizing Read by Other Session Wait Events .................................................................170

Problem ............................................................................................................................................................. 170

Solution.............................................................................................................................................................. 170

How It Works ...................................................................................................................................................... 171

5-10. Reducing Direct Path Read Wait Events ...........................................................................171

Problem ............................................................................................................................................................. 171

Solution.............................................................................................................................................................. 172

How It Works ...................................................................................................................................................... 173

5-11. Minimizing Recovery Writer Waits ...................................................................................173

Problem ............................................................................................................................................................. 173

Solution.............................................................................................................................................................. 173

How It Works ...................................................................................................................................................... 174

5-12. Finding Out Who’s Holding a Blocking Lock .....................................................................174

Problem ............................................................................................................................................................. 174

Solution.............................................................................................................................................................. 174

How It Works ...................................................................................................................................................... 175

5-13. Identifying Blocked and Blocking Sessions .....................................................................176

Problem ............................................................................................................................................................. 176

Solution.............................................................................................................................................................. 176

How It Works ...................................................................................................................................................... 177

5-14. Dealing with a Blocking Lock ...........................................................................................177

Problem ............................................................................................................................................................. 177

Solution.............................................................................................................................................................. 177

How It Works ...................................................................................................................................................... 178

5-15. Identifying a Locked Object .............................................................................................179

Problem ............................................................................................................................................................. 179

Solution.............................................................................................................................................................. 179

How It Works ...................................................................................................................................................... 179

Page 19: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xix

5-16. Resolving enq: TM Lock Contention .................................................................................180

Problem ............................................................................................................................................................. 180

Solution.............................................................................................................................................................. 180

How It Works ...................................................................................................................................................... 180

5-17. Identifying Recently Locked Sessions .............................................................................182

Problem ............................................................................................................................................................. 182

Solution.............................................................................................................................................................. 182

How It Works ...................................................................................................................................................... 182

5-18. Analyzing Recent Wait Events in a Database ...................................................................185

Problem ............................................................................................................................................................. 185

Solution.............................................................................................................................................................. 185

How It Works ...................................................................................................................................................... 186

5-19. Identifying Time Spent Waiting Because of Locking ........................................................186

Problem ............................................................................................................................................................. 186

Solution.............................................................................................................................................................. 186

How It Works ...................................................................................................................................................... 186

5-20. Minimizing Latch Contention ...........................................................................................188

Problem ............................................................................................................................................................. 188

Solution.............................................................................................................................................................. 189

How It Works ...................................................................................................................................................... 190

Chapter 6: Analyzing Operating System Performance ■ ��������������������������������������������������193

6-1. Detecting Disk Space Issues .............................................................................................195

Problem ............................................................................................................................................................. 195

Solution.............................................................................................................................................................. 195

How It Works ...................................................................................................................................................... 196

6-2. Identifying System Bottlenecks .........................................................................................198

Problem ............................................................................................................................................................. 198

Solution.............................................................................................................................................................. 198

How It Works ...................................................................................................................................................... 199

Page 20: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xx

6-3. Determining Top System-Resource-Consuming Processes ...............................................200

Problem ............................................................................................................................................................. 200

Solution.............................................................................................................................................................. 200

How It Works ...................................................................................................................................................... 201

6-4. Detecting CPU Bottlenecks ................................................................................................202

Problem ............................................................................................................................................................. 202

Solution.............................................................................................................................................................. 203

How It Works ...................................................................................................................................................... 203

6-5. Identifying Processes Consuming CPU and Memory .........................................................204

Problem ............................................................................................................................................................. 204

Solution.............................................................................................................................................................. 204

How It Works ...................................................................................................................................................... 204

6-6. Determining I/O Bottlenecks ..............................................................................................205

Problem ............................................................................................................................................................. 205

Solution.............................................................................................................................................................. 205

How It Works ...................................................................................................................................................... 207

6-7. Detecting Network-Intensive Processes ............................................................................208

Problem ............................................................................................................................................................. 208

Solution.............................................................................................................................................................. 208

How It Works ...................................................................................................................................................... 209

6-8. Mapping a Resource-Intensive Process to a Database Process ........................................210

Problem ............................................................................................................................................................. 210

Solution.............................................................................................................................................................. 210

How It Works ...................................................................................................................................................... 212

6-9. Terminating a Resource-Intensive Process ........................................................................213

Problem ............................................................................................................................................................. 213

Solution.............................................................................................................................................................. 213

How It Works ...................................................................................................................................................... 215

Page 21: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxi

Chapter 7: Troubleshooting the Database ■ ����������������������������������������������������������������������217

7-1. Determining the Optimal Undo Retention Period ...............................................................217

Problem ............................................................................................................................................................. 217

Solution.............................................................................................................................................................. 217

How It Works ...................................................................................................................................................... 219

7-2. Finding What’s Consuming the Most Undo ........................................................................222

Problem ............................................................................................................................................................. 222

Solution.............................................................................................................................................................. 222

How It Works ...................................................................................................................................................... 223

7-3. Resolving an ORA-01555 Error ..........................................................................................223

Problem ............................................................................................................................................................. 223

Solution.............................................................................................................................................................. 223

How It Works ...................................................................................................................................................... 224

7-4. Monitoring Temporary Tablespace Usage ..........................................................................225

Problem ............................................................................................................................................................. 225

Solution.............................................................................................................................................................. 225

How It Works ...................................................................................................................................................... 226

7-5. Identifying Who Is Using the Temporary Tablespace ..........................................................226

Problem ............................................................................................................................................................. 226

Solution.............................................................................................................................................................. 226

How It Works ...................................................................................................................................................... 227

7-6. Resolving the “Unable to Extend Temp Segment” Error ....................................................228

Problem ............................................................................................................................................................. 228

Solution.............................................................................................................................................................. 228

How It Works ...................................................................................................................................................... 228

7-7. Resolving Open Cursor Errors ............................................................................................230

Problem ............................................................................................................................................................. 230

Solution.............................................................................................................................................................. 230

How It Works ...................................................................................................................................................... 231

Page 22: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxii

7-8. Resolving a Hung Database ...............................................................................................232

Problem ............................................................................................................................................................. 232

Solution.............................................................................................................................................................. 232

How It Works ...................................................................................................................................................... 234

7-9. Invoking the Automatic Diagnostic Repository Command Interpreter ...............................236

Problem ............................................................................................................................................................. 236

Solution.............................................................................................................................................................. 236

How It Works ...................................................................................................................................................... 238

7-10. Viewing an Alert Log from ADRCI .....................................................................................240

Problem ............................................................................................................................................................. 240

Solution.............................................................................................................................................................. 240

How It Works ...................................................................................................................................................... 241

7-11. Viewing Incidents with ADRCI ..........................................................................................242

Problem ............................................................................................................................................................. 242

Solution.............................................................................................................................................................. 242

How It Works ...................................................................................................................................................... 243

7-12. Packaging Incidents for Oracle Support ..........................................................................244

Problem ............................................................................................................................................................. 244

Solution.............................................................................................................................................................. 244

How It Works ...................................................................................................................................................... 245

7-13. Running a Database Health Check ...................................................................................245

Problem ............................................................................................................................................................. 245

Solution.............................................................................................................................................................. 246

How It Works ...................................................................................................................................................... 246

7-14. Creating a SQL Test Case .................................................................................................247

Problem ............................................................................................................................................................. 247

Solution.............................................................................................................................................................. 247

How It Works ...................................................................................................................................................... 249

Page 23: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxiii

7-15. Generating an AWR Report ...............................................................................................250

Problem ............................................................................................................................................................. 250

Solution.............................................................................................................................................................. 250

How It Works ...................................................................................................................................................... 252

7-16. Comparing Database Performance Between Two Periods ...............................................253

Problem ............................................................................................................................................................. 253

Solution.............................................................................................................................................................. 253

How It Works ...................................................................................................................................................... 254

7-17. Analyzing an AWR Report .................................................................................................255

Problem ............................................................................................................................................................. 255

Solution.............................................................................................................................................................. 255

How It Works ...................................................................................................................................................... 258

Chapter 8: Creating Efficient SQL ■ ����������������������������������������������������������������������������������259

8-1. Retrieving All Rows from a Table .......................................................................................260

Problem ............................................................................................................................................................. 260

Solution.............................................................................................................................................................. 260

How It Works ...................................................................................................................................................... 261

8-2. Retrieve a Subset of Rows from a Table ............................................................................261

Problem ............................................................................................................................................................. 261

Solution.............................................................................................................................................................. 261

How It Works ...................................................................................................................................................... 262

8-3. Joining Tables with Corresponding Rows ..........................................................................263

Problem ............................................................................................................................................................. 263

Solution.............................................................................................................................................................. 263

How It Works ...................................................................................................................................................... 264

8-4. Joining Tables When Corresponding Rows May Be Missing ..............................................266

Problem ............................................................................................................................................................. 266

Solution.............................................................................................................................................................. 266

How It Works ...................................................................................................................................................... 268

Page 24: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxiv

8-5. Constructing Simple Subqueries .......................................................................................269

Problem ............................................................................................................................................................. 269

Solution.............................................................................................................................................................. 270

How It Works ...................................................................................................................................................... 270

8-6. Constructing Correlated Subqueries ..................................................................................274

Problem ............................................................................................................................................................. 274

Solution.............................................................................................................................................................. 274

How It Works ...................................................................................................................................................... 274

8-7. Comparing Two Tables to Find Missing Rows ....................................................................276

Problem ............................................................................................................................................................. 276

Solution.............................................................................................................................................................. 276

How It Works ...................................................................................................................................................... 277

8-8. Comparing Two Tables to Find Matching Rows ..................................................................278

Problem ............................................................................................................................................................. 278

Solution.............................................................................................................................................................. 278

How It Works ...................................................................................................................................................... 278

8-9. Combining Results from Similar SELECT Statements ........................................................279

Problem ............................................................................................................................................................. 279

Solution.............................................................................................................................................................. 279

How It Works ...................................................................................................................................................... 279

8-10. Searching for a Range of Values ......................................................................................281

Problem ............................................................................................................................................................. 281

Solution.............................................................................................................................................................. 281

How It Works ...................................................................................................................................................... 282

8-11. Handling Null Values ........................................................................................................285

Problem ............................................................................................................................................................. 285

Solution.............................................................................................................................................................. 285

How It Works ...................................................................................................................................................... 287

Page 25: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxv

8-12. Searching for Partial Column Values ................................................................................288

Problem ............................................................................................................................................................. 288

Solution.............................................................................................................................................................. 288

How It Works ...................................................................................................................................................... 289

8-13. Re-using SQL Statements Within the Shared Pool ...........................................................292

Problem ............................................................................................................................................................. 292

Solution.............................................................................................................................................................. 292

How It Works ...................................................................................................................................................... 293

8-14. Avoiding Accidental Full Table Scans ...............................................................................296

Problem ............................................................................................................................................................. 296

Solution.............................................................................................................................................................. 296

How It Works ...................................................................................................................................................... 297

8-15. Creating Efficient Temporary Views .................................................................................298

Problem ............................................................................................................................................................. 298

Solution.............................................................................................................................................................. 298

How It Works ...................................................................................................................................................... 299

8-16. Avoiding the NOT Clause ..................................................................................................301

Problem ............................................................................................................................................................. 301

Solution.............................................................................................................................................................. 301

How It Works ...................................................................................................................................................... 302

8-17. Controlling Transaction Sizes ...........................................................................................303

Problem ............................................................................................................................................................. 303

Solution.............................................................................................................................................................. 303

How It Works ...................................................................................................................................................... 304

Chapter 9: Manually Tuning SQL ■ ������������������������������������������������������������������������������������307

9-1. Displaying an Execution Plan for a Query ..........................................................................308

Problem ............................................................................................................................................................. 308

Solution.............................................................................................................................................................. 308

How It Works ...................................................................................................................................................... 309

Page 26: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxvi

9-2. Customizing Execution Plan Output ...................................................................................310

Problem ............................................................................................................................................................. 310

Solution.............................................................................................................................................................. 311

How It Works ...................................................................................................................................................... 312

9-3. Graphically Displaying an Execution Plan ..........................................................................314

Problem ............................................................................................................................................................. 314

Solution.............................................................................................................................................................. 314

How It Works ...................................................................................................................................................... 315

9-4. Reading an Execution Plan ................................................................................................315

Problem ............................................................................................................................................................. 315

Solution.............................................................................................................................................................. 315

How It Works ...................................................................................................................................................... 316

9-5. Monitoring Long-Running SQL Statements........................................................................317

Problem ............................................................................................................................................................. 317

Solution.............................................................................................................................................................. 318

How It Works ...................................................................................................................................................... 318

9-6. Identifying Resource-Consuming SQL Statements That Are Currently Executing ..............318

Problem ............................................................................................................................................................. 318

Solution.............................................................................................................................................................. 319

How It Works ...................................................................................................................................................... 319

9-7. Seeing Execution Statistics for Currently Running SQL .....................................................320

Problem ............................................................................................................................................................. 320

Solution.............................................................................................................................................................. 320

How It Works ...................................................................................................................................................... 321

9-8. Monitoring Progress of a SQL Execution Plan ....................................................................323

Problem ............................................................................................................................................................. 323

Solution.............................................................................................................................................................. 323

How It Works ...................................................................................................................................................... 325

Page 27: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxvii

9-9. Identifying Resource-Consuming SQL Statements That Have Executed in the Past ..........326

Problem ............................................................................................................................................................. 326

Solution.............................................................................................................................................................. 327

How It Works ...................................................................................................................................................... 327

Comparing SQL Performance After a System Change ...............................................................328

Problem ............................................................................................................................................................. 328

Solution.............................................................................................................................................................. 328

How It Works ...................................................................................................................................................... 333

Chapter 10: Tracing SQL Execution ■ ��������������������������������������������������������������������������������335

10-1. Preparing Your Environment ............................................................................................335

Problem ............................................................................................................................................................. 335

Solution.............................................................................................................................................................. 335

How It Works ...................................................................................................................................................... 336

10-2. Tracing a Specific SQL Statement ....................................................................................338

Problem ............................................................................................................................................................. 338

Solution.............................................................................................................................................................. 338

How It Works ...................................................................................................................................................... 339

10.3. Enabling Tracing in Your Own Session .............................................................................340

Problem ............................................................................................................................................................. 340

Solution.............................................................................................................................................................. 340

How It Works ...................................................................................................................................................... 340

10-4. Finding the Trace Files .....................................................................................................340

Problem ............................................................................................................................................................. 340

Solution.............................................................................................................................................................. 340

How It Works ...................................................................................................................................................... 341

10-5. Examining a Raw SQL Trace File ......................................................................................342

Problem ............................................................................................................................................................. 342

Solution.............................................................................................................................................................. 342

How It Works ...................................................................................................................................................... 342

Page 28: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxviii

10-6. Analyzing Oracle Trace Files ............................................................................................343

Problem ............................................................................................................................................................. 343

Solution.............................................................................................................................................................. 343

How It Works ...................................................................................................................................................... 343

10-7. Formatting Trace Files with TKPROF ................................................................................344

Problem ............................................................................................................................................................. 344

Solution.............................................................................................................................................................. 344

How It Works ...................................................................................................................................................... 344

10-8. Analyzing TKPROF Output ................................................................................................345

Problem ............................................................................................................................................................. 345

Solution.............................................................................................................................................................. 345

How It Works ...................................................................................................................................................... 345

10-9. Analyzing Trace Files with Oracle Trace Analyzer ............................................................348

Problem ............................................................................................................................................................. 348

Solution.............................................................................................................................................................. 348

How It Works ...................................................................................................................................................... 350

10-10. Tracing a Parallel Query .................................................................................................351

Problem ............................................................................................................................................................. 351

Solution.............................................................................................................................................................. 351

How It Works ...................................................................................................................................................... 352

10-11. Tracing Specific Parallel Query Processes .....................................................................353

Problem ............................................................................................................................................................. 353

Solution.............................................................................................................................................................. 353

How It Works ...................................................................................................................................................... 353

10-12. Tracing Parallel Queries in a RAC System ......................................................................353

Problem ............................................................................................................................................................. 353

Solution.............................................................................................................................................................. 353

How It Works ...................................................................................................................................................... 354

Page 29: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxix

10-13. Consolidating Multiple Trace Files .................................................................................354

Problem ............................................................................................................................................................. 354

Solution.............................................................................................................................................................. 354

How It Works ...................................................................................................................................................... 355

10-14. Finding the Correct Session for Tracing .........................................................................355

Problem ............................................................................................................................................................. 355

Solution.............................................................................................................................................................. 355

How It Works ...................................................................................................................................................... 356

10-15. Tracing a SQL Session ....................................................................................................356

Problem ............................................................................................................................................................. 356

Solution.............................................................................................................................................................. 356

How It Works ...................................................................................................................................................... 357

10-16. Tracing a Session by Process ID ....................................................................................358

Problem ............................................................................................................................................................. 358

Solution.............................................................................................................................................................. 358

How It Works ...................................................................................................................................................... 359

10-17. Tracing Multiple Sessions ..............................................................................................359

Problem ............................................................................................................................................................. 359

Solution.............................................................................................................................................................. 359

How It Works ...................................................................................................................................................... 359

10-18. Tracing an Instance or a Database .................................................................................360

Problem ............................................................................................................................................................. 360

Solution.............................................................................................................................................................. 360

How It Works ...................................................................................................................................................... 360

10-19. Generating an Event 10046 Trace for a Session ............................................................361

Problem ............................................................................................................................................................. 361

Solution.............................................................................................................................................................. 361

How It Works ...................................................................................................................................................... 361

Page 30: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxx

10-20. Generating an Event 10046 Trace for an Instance .........................................................363

Problem ............................................................................................................................................................. 363

Solution.............................................................................................................................................................. 363

How It Works ...................................................................................................................................................... 363

10-21. Setting a Trace in a Running Session ............................................................................363

Problem ............................................................................................................................................................. 363

Solution.............................................................................................................................................................. 364

How It Works ...................................................................................................................................................... 364

10-22. Enabling Tracing in a Session After a Login ...................................................................364

Problem ............................................................................................................................................................. 364

Solution.............................................................................................................................................................. 364

How It Works ...................................................................................................................................................... 365

10-23. Tracing the Optimizer’s Execution Path .........................................................................365

Problem ............................................................................................................................................................. 365

Solution.............................................................................................................................................................. 365

How It Works ...................................................................................................................................................... 366

10-24. Generating Automatic Oracle Error Traces .....................................................................368

Problem ............................................................................................................................................................. 368

Solution.............................................................................................................................................................. 368

How It Works ...................................................................................................................................................... 369

10-25. Tracing a Background Process.......................................................................................369

Problem ............................................................................................................................................................. 369

Solution.............................................................................................................................................................. 369

How It Works ...................................................................................................................................................... 370

10-26. Enabling Oracle Listener Tracing ...................................................................................370

Problem ............................................................................................................................................................. 370

Solution.............................................................................................................................................................. 370

How It Works ...................................................................................................................................................... 371

Page 31: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxxi

10-27. Setting Archive Tracing for Data Guard ..........................................................................372

Problem ............................................................................................................................................................. 372

Solution.............................................................................................................................................................. 372

How It Works ...................................................................................................................................................... 372

Chapter 11: Automated SQL Tuning ■ �������������������������������������������������������������������������������375

11-1. Displaying Automatic SQL Tuning Job Details ..................................................................377

Problem ............................................................................................................................................................. 377

Solution.............................................................................................................................................................. 378

How It Works ...................................................................................................................................................... 378

11-2. Displaying Automatic SQL Tuning Advisor Advice ............................................................379

Problem ............................................................................................................................................................. 379

Solution.............................................................................................................................................................. 379

How It Works ...................................................................................................................................................... 381

11-3. Generating a SQL Script to Implement Automatic Tuning Advice .....................................383

Problem ............................................................................................................................................................. 383

Solution.............................................................................................................................................................. 383

How It Works ...................................................................................................................................................... 384

11-4. Modifying Automatic SQL Tuning Features ......................................................................384

Problem ............................................................................................................................................................. 384

Solution.............................................................................................................................................................. 384

How It Works ...................................................................................................................................................... 385

11-5. Disabling and Enabling Automatic SQL Tuning ................................................................386

Problem ............................................................................................................................................................. 386

Solution.............................................................................................................................................................. 386

How It Works ...................................................................................................................................................... 387

11-6. Modifying Maintenance Window Attributes .....................................................................388

Problem ............................................................................................................................................................. 388

Solution.............................................................................................................................................................. 388

How It Works ...................................................................................................................................................... 389

Page 32: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxxii

11-7. Creating a SQL Tuning Set Object ....................................................................................390

Problem ............................................................................................................................................................. 390

Solution.............................................................................................................................................................. 390

How It Works ...................................................................................................................................................... 390

11-8. Viewing Resource-Intensive SQL in the AWR ...................................................................390

Problem ............................................................................................................................................................. 390

Solution.............................................................................................................................................................. 390

How It Works ...................................................................................................................................................... 391

11-9. Populating a SQL Tuning Set from High-Resource SQL in AWR .......................................393

Problem ............................................................................................................................................................. 393

Solution.............................................................................................................................................................. 393

How It Works ...................................................................................................................................................... 394

11-10. Viewing Resource-Intensive SQL in Memory .................................................................394

Problem ............................................................................................................................................................. 394

Solution.............................................................................................................................................................. 395

How It Works ...................................................................................................................................................... 395

11-11. Populating a SQL Tuning Set from Resource-Consuming SQL in Memory .....................396

Problem ............................................................................................................................................................. 396

Solution.............................................................................................................................................................. 396

How It Works ...................................................................................................................................................... 397

11-12. Populating a SQL Tuning Set With All SQL in Memory ....................................................397

Problem ............................................................................................................................................................. 397

Solution.............................................................................................................................................................. 398

How It Works ...................................................................................................................................................... 398

11-13. Displaying the Contents of a SQL Tuning Set .................................................................399

Problem ............................................................................................................................................................. 399

Solution.............................................................................................................................................................. 399

How It Works ...................................................................................................................................................... 400

Page 33: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxxiii

11-14. Selectively Deleting Statements from a SQL Tuning Set ................................................401

Problem ............................................................................................................................................................. 401

Solution.............................................................................................................................................................. 401

How It Works ...................................................................................................................................................... 401

11-15. Transporting a SQL Tuning Set .......................................................................................402

Problem ............................................................................................................................................................. 402

Solution.............................................................................................................................................................. 402

How It Works ...................................................................................................................................................... 404

11-16. Creating a Tuning Task ...................................................................................................404

Problem ............................................................................................................................................................. 404

Solution.............................................................................................................................................................. 405

How It Works ...................................................................................................................................................... 407

11-17. Running the SQL Tuning Advisor ....................................................................................407

Problem ............................................................................................................................................................. 407

Solution.............................................................................................................................................................. 408

How It Works ...................................................................................................................................................... 410

11-18. Generating SQL Tuning Advice from the Automatic Database Diagnostic Monitor ........411

Problem ............................................................................................................................................................. 411

Solution.............................................................................................................................................................. 411

How It Works ...................................................................................................................................................... 414

Chapter 12: Execution Plan Optimization and Consistency ■ �������������������������������������������415

Background ...............................................................................................................................416

Seeing the Big Picture ...............................................................................................................417

12-1. Creating and Accepting a SQL Profile ..............................................................................420

Problem ............................................................................................................................................................. 420

Solution.............................................................................................................................................................. 420

How It Works ...................................................................................................................................................... 423

12-2. Determining if a Query is Using a SQL Profile ..................................................................424

Problem ............................................................................................................................................................. 424

Solution.............................................................................................................................................................. 424

How It Works ...................................................................................................................................................... 425

Page 34: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxxiv

12-3. Automatically Accepting SQL Profiles ..............................................................................425

Problem ............................................................................................................................................................. 425

Solution.............................................................................................................................................................. 426

How It Works ...................................................................................................................................................... 426

12-4. Displaying SQL Profile Information ..................................................................................428

Problem ............................................................................................................................................................. 428

Solution.............................................................................................................................................................. 428

How It Works ...................................................................................................................................................... 428

12-5. Selectively Testing a SQL Profile ......................................................................................429

Problem ............................................................................................................................................................. 429

Solution.............................................................................................................................................................. 429

How It Works ...................................................................................................................................................... 430

12-6. Transporting a SQL Profile to a Different Database ..........................................................430

Problem ............................................................................................................................................................. 430

Solution.............................................................................................................................................................. 431

How It Works ...................................................................................................................................................... 432

12-7. Disabling a SQL Profile ....................................................................................................433

Problem ............................................................................................................................................................. 433

Solution.............................................................................................................................................................. 433

How It Works ...................................................................................................................................................... 433

12-8. Dropping a SQL Profile .....................................................................................................434

Problem ............................................................................................................................................................. 434

Solution.............................................................................................................................................................. 434

How It Works ...................................................................................................................................................... 434

12-9. Creating a Plan Baseline for a SQL Statement in Memory ...............................................435

Problem ............................................................................................................................................................. 435

Solution.............................................................................................................................................................. 435

How It Works ...................................................................................................................................................... 436

Page 35: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxxv

12-10. Creating Plan Baselines for SQL Contained in SQL Tuning Set ............................................438

Problem ............................................................................................................................................................. 438

Solution.............................................................................................................................................................. 438

How It Works ...................................................................................................................................................... 440

12-11. Automatically Adding Plan Baselines .............................................................................440

Problem ............................................................................................................................................................. 440

Solution.............................................................................................................................................................. 440

How It Works ...................................................................................................................................................... 441

12-12. Altering a Plan Baseline .................................................................................................442

Problem ............................................................................................................................................................. 442

Solution.............................................................................................................................................................. 442

How It Works ...................................................................................................................................................... 442

12-13. Determining If Plan Baselines Exist ...............................................................................443

Problem ............................................................................................................................................................. 443

Solution.............................................................................................................................................................. 443

How It Works ...................................................................................................................................................... 444

12-14. Determining if a Query is Using a Plan Baseline ............................................................445

Problem ............................................................................................................................................................. 445

Solution.............................................................................................................................................................. 446

How It Works ...................................................................................................................................................... 446

12-15. Displaying Plan Baseline Execution Plans .....................................................................447

Problem ............................................................................................................................................................. 447

Solution.............................................................................................................................................................. 447

How It Works ...................................................................................................................................................... 447

12-16. Manually Adding a New Execution Plan to Plan Baseline (Evolving)..............................448

Problem ............................................................................................................................................................. 448

Solution.............................................................................................................................................................. 448

How It Works ...................................................................................................................................................... 450

Page 36: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxxvi

12-17. Toggling the Automatic Acceptance of New Low-Cost Execution Plans ........................451

Problem ............................................................................................................................................................. 451

Solution.............................................................................................................................................................. 451

How It Works ...................................................................................................................................................... 451

12-18. Disabling Plan Baselines ................................................................................................451

Problem ............................................................................................................................................................. 451

Solution.............................................................................................................................................................. 452

How It Works ...................................................................................................................................................... 452

12-19. Removing Plan Baseline Information .............................................................................452

Problem ............................................................................................................................................................. 452

Solution.............................................................................................................................................................. 452

How It Works ...................................................................................................................................................... 453

12-20. Transporting Plan Baselines ...........................................................................................454

Problem ............................................................................................................................................................. 454

Solution.............................................................................................................................................................. 454

How It Works ...................................................................................................................................................... 455

Chapter 13: Configuring the Optimizer ■ ��������������������������������������������������������������������������457

13-1. Choosing an Optimizer Goal .............................................................................................457

Problem ............................................................................................................................................................. 457

Solution.............................................................................................................................................................. 457

How It Works ...................................................................................................................................................... 458

13-2. Enabling Automatic Statistics Gathering ..........................................................................458

Problem ............................................................................................................................................................. 458

Solution.............................................................................................................................................................. 458

How It Works ...................................................................................................................................................... 459

13-3. Setting Preferences for Statistics Collection ...................................................................460

Problem ............................................................................................................................................................. 460

Solution.............................................................................................................................................................. 461

How It Works ...................................................................................................................................................... 461

Page 37: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxxvii

13-4. Manually Generating Statistics ........................................................................................466

Problem ............................................................................................................................................................. 466

Solution.............................................................................................................................................................. 466

How It Works ...................................................................................................................................................... 467

13-5. Locking Statistics ............................................................................................................467

Problem ............................................................................................................................................................. 467

Solution.............................................................................................................................................................. 468

How It Works ...................................................................................................................................................... 468

13-6. Handling Missing Statistics .............................................................................................469

Problem ............................................................................................................................................................. 469

Solution.............................................................................................................................................................. 469

How It Works ...................................................................................................................................................... 469

13-7. Exporting Statistics ..........................................................................................................471

Problem ............................................................................................................................................................. 471

Solution.............................................................................................................................................................. 471

How It Works ...................................................................................................................................................... 472

13-8. Restoring Previous Versions of Statistics ........................................................................472

Problem ............................................................................................................................................................. 472

Solution.............................................................................................................................................................. 472

How It Works ...................................................................................................................................................... 473

13-9. Gathering System Statistics .............................................................................................473

Problem ............................................................................................................................................................. 473

Solution.............................................................................................................................................................. 474

How It Works ...................................................................................................................................................... 475

13-10. Validating New Statistics ...............................................................................................477

Problem ............................................................................................................................................................. 477

Solution.............................................................................................................................................................. 477

How It Works ...................................................................................................................................................... 478

Page 38: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxxviii

13-11. Forcing the Optimizer to Use an Index ...........................................................................479

Problem ............................................................................................................................................................. 479

Solution.............................................................................................................................................................. 479

How It Works ...................................................................................................................................................... 479

13-12. Enabling Query Optimizer Features ...............................................................................480

Problem ............................................................................................................................................................. 480

Solution.............................................................................................................................................................. 480

How It Works ...................................................................................................................................................... 481

13-13. Keeping the Database from Creating Histograms ..........................................................482

Problem ............................................................................................................................................................. 482

Solution.............................................................................................................................................................. 482

How It Works ...................................................................................................................................................... 482

13-14. Improving Performance When Not Using Bind Variables ...............................................483

Problem ............................................................................................................................................................. 483

Solution.............................................................................................................................................................. 483

How It Works ...................................................................................................................................................... 483

13-15. Understanding Adaptive Cursor Sharing ........................................................................485

Problem ............................................................................................................................................................. 485

Solution.............................................................................................................................................................. 485

How It Works ...................................................................................................................................................... 486

13-16. Creating Statistics on Expressions ................................................................................491

Problem ............................................................................................................................................................. 491

Solution.............................................................................................................................................................. 491

How It Works ...................................................................................................................................................... 491

13-17. Creating Statistics for Related Columns ........................................................................492

Problem ............................................................................................................................................................. 492

Solution.............................................................................................................................................................. 492

How It Works ...................................................................................................................................................... 493

Page 39: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xxxix

13-18. Automatically Creating Column Groups .........................................................................493

Problem ............................................................................................................................................................. 493

Solution.............................................................................................................................................................. 493

How It Works ...................................................................................................................................................... 494

13-19. Maintaining Statistics on Partitioned Tables ..................................................................494

Problem ............................................................................................................................................................. 494

Solution.............................................................................................................................................................. 495

How It Works ...................................................................................................................................................... 495

13-20. Concurrent Statistics Collection for Large Tables ..........................................................496

Problem ............................................................................................................................................................. 496

Solution.............................................................................................................................................................. 496

How It Works ...................................................................................................................................................... 496

13-21. Determining When Statistics Are Stale ..........................................................................498

Problem ............................................................................................................................................................. 498

Solution.............................................................................................................................................................. 498

How It Works ...................................................................................................................................................... 498

13-22. Previewing Statistics Gathering Targets ........................................................................499

Problem ............................................................................................................................................................. 499

Solution.............................................................................................................................................................. 499

How It Works ...................................................................................................................................................... 500

Chapter 14: Implementing Query Hints ■ �������������������������������������������������������������������������501

14-1. Writing a Hint ...................................................................................................................501

Problem ............................................................................................................................................................. 501

Solution.............................................................................................................................................................. 501

How It Works ...................................................................................................................................................... 502

14-2. Changing the Access Path ...............................................................................................503

Problem ............................................................................................................................................................. 503

Solution.............................................................................................................................................................. 503

How It Works ...................................................................................................................................................... 504

Page 40: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xl

14-3. Changing the Join Order ..................................................................................................507

Problem ............................................................................................................................................................. 507

Solution.............................................................................................................................................................. 507

How It Works ...................................................................................................................................................... 508

14-4. Changing the Join Method ...............................................................................................508

Problem ............................................................................................................................................................. 508

Solution.............................................................................................................................................................. 509

How It Works ...................................................................................................................................................... 511

14-5. Changing the Optimizer Version .......................................................................................511

Problem ............................................................................................................................................................. 511

Solution.............................................................................................................................................................. 512

How It Works ...................................................................................................................................................... 512

14-6. Choosing Between a Fast Response and Overall Optimization ........................................513

Problem ............................................................................................................................................................. 513

Solution.............................................................................................................................................................. 513

How It Works ...................................................................................................................................................... 515

14-7. Performing a Direct-Path Insert .......................................................................................515

Problem ............................................................................................................................................................. 515

Solution.............................................................................................................................................................. 516

How It Works ...................................................................................................................................................... 517

14-8. Placing Hints in Views ......................................................................................................519

Problem ............................................................................................................................................................. 519

Solution.............................................................................................................................................................. 519

How It Works ...................................................................................................................................................... 521

14-9. Caching Query Results .....................................................................................................521

Problem ............................................................................................................................................................. 521

Solution.............................................................................................................................................................. 522

How It Works ...................................................................................................................................................... 524

Page 41: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xli

14-10. Directing a Distributed Query to a Specific Database ....................................................525

Problem ............................................................................................................................................................. 525

Solution.............................................................................................................................................................. 526

How It Works ...................................................................................................................................................... 526

14-11. Gathering Extended Query Execution Statistics .............................................................529

Problem ............................................................................................................................................................. 529

Solution.............................................................................................................................................................. 530

How It Works ...................................................................................................................................................... 531

14-12. Enabling Query Rewrite .................................................................................................531

Problem ............................................................................................................................................................. 531

Solution.............................................................................................................................................................. 531

How It Works ...................................................................................................................................................... 532

14-13. Improving Star Schema Query Performance .................................................................533

Problem ............................................................................................................................................................. 533

Solution.............................................................................................................................................................. 533

How It Works ...................................................................................................................................................... 535

Chapter 15: Executing SQL in Parallel ■ ���������������������������������������������������������������������������537

15-1. Enabling Parallelism for a Specific Query ........................................................................537

Problem ............................................................................................................................................................. 537

Solution.............................................................................................................................................................. 537

How It Works ...................................................................................................................................................... 538

15-2. Enabling Parallelism at Object Creation ...........................................................................541

Problem ............................................................................................................................................................. 541

Solution.............................................................................................................................................................. 542

How It Works ...................................................................................................................................................... 542

15-3. Enabling Parallelism for an Existing Object .....................................................................543

Problem ............................................................................................................................................................. 543

Solution.............................................................................................................................................................. 543

How It Works ...................................................................................................................................................... 544

Page 42: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xlii

15-4. Implementing Parallel DML ..............................................................................................544

Problem ............................................................................................................................................................. 544

Solution.............................................................................................................................................................. 544

How It Works ...................................................................................................................................................... 545

15-5. Creating Tables in Parallel ...............................................................................................547

Problem ............................................................................................................................................................. 547

Solution.............................................................................................................................................................. 547

How It Works ...................................................................................................................................................... 547

15-6. Creating Indexes in Parallel .............................................................................................549

Problem ............................................................................................................................................................. 549

Solution.............................................................................................................................................................. 550

How It Works ...................................................................................................................................................... 550

15-7. Rebuilding Indexes in Parallel ..........................................................................................550

Problem ............................................................................................................................................................. 550

Solution.............................................................................................................................................................. 551

How It Works ...................................................................................................................................................... 551

15-8. Moving Partitions in Parallel ............................................................................................553

Problem ............................................................................................................................................................. 553

Solution.............................................................................................................................................................. 553

How It Works ...................................................................................................................................................... 553

15-9. Splitting Partitions in Parallel ..........................................................................................555

Problem ............................................................................................................................................................. 555

Solution.............................................................................................................................................................. 555

How It Works ...................................................................................................................................................... 555

15-10. Enabling Automatic Degree of Parallelism .....................................................................556

Problem ............................................................................................................................................................. 556

Solution.............................................................................................................................................................. 556

How It Works ...................................................................................................................................................... 558

Page 43: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ Contents

xliii

15-11. Examining Parallel Explain Plans ...................................................................................559

Problem ............................................................................................................................................................. 559

Solution.............................................................................................................................................................. 560

How It Works ...................................................................................................................................................... 561

15-12. Monitoring Parallel Operations ......................................................................................562

Problem ............................................................................................................................................................. 562

Solution.............................................................................................................................................................. 562

How It Works ...................................................................................................................................................... 564

15-13. Finding Bottlenecks in Parallel Processes .....................................................................564

Problem ............................................................................................................................................................. 564

Solution.............................................................................................................................................................. 564

How It Works ...................................................................................................................................................... 565

15-14. Getting Detailed Information on Parallel Sessions .........................................................566

Problem ............................................................................................................................................................. 566

Solution.............................................................................................................................................................. 566

How It Works ...................................................................................................................................................... 567

Index ���������������������������������������������������������������������������������������������������������������������������������569

Page 44: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c
Page 45: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

xlv

About the Authors

Sam R. Alapati is a senior database architect at Cash America International in Fort Worth, Texas. Sam is an Oracle OCP 12c certification holder. Earlier, Sam worked as an Oracle DBA at AT&T, Boy Scouts of America, and Oracle Corporation. Sam has published several Oracle Database and middleware administration–related books, including forthcoming books such as Oracle WebLogic Server 12c Administration Handbook and OCP Oracle Database 12c New Features for Administrators Exam Guide.

Darl Kuhn is currently a DBA working for Oracle. He has written books on a variety of IT topics including SQL, performance tuning, Linux, backup and recovery, RMAN, and database administration. Darl also teaches Oracle classes for Regis University and does volunteer DBA work for the Rocky Mountain Oracle Users Group.

Page 46: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

■ About the Authors

xlvi

Bill Padfield is an Oracle Certified Professional, working for a large telecommunications company in Denver, Colorado, as a senior database administrator. Bill helps administer and manage a large data warehouse environment consisting of more than 100 databases. Bill has been an Oracle Database administrator for more than 16 years and has been in the IT industry since 1985. Bill also teaches graduate database courses at Regis University and currently resides in Aurora, Colorado, with his wife, Oyuna, and son, Evan.

Page 47: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

xlvii

About the Technical Reviewers

Stéphane Faroult is a French consultant who first discovered relational databases and the SQL language 30 years ago. Stéphane joined Oracle France in its early days (after a brief spell with IBM and a period of time teaching at the University of Ottawa) and developed an interest in performance and tuning topics, on which he soon started writing training courses. After leaving Oracle in 1988, Stéphane briefly tried going straight and did a bit of operational research, but after only a year, he succumbed again to the allure of relational databases. For his sins, Stéphane has been performing database consultancy continuously ever since and founded RoughSea Ltd in 1998. In recent years, Stéphane has had a growing interest in education, which has taken various forms, including books (The Art of SQL, soon followed by Refactoring SQL Applications, both published by O’Reilly) and more recently a textbook (SQL Success, published by RoughSea), a series of seminars in Asia, and video tutorials (www.youtube.com/user/roughsealtd).

Arup Nanda has been an Oracle DBA for more than 18 years (and counting) working on all aspects of Oracle Database from modeling, performance tuning, backup, disaster recovery, security, and, more recently, Exadata. Currently he is the global database lead at a major multinational corporation near New York, managing, among other things, several Exadata installations. Arup has coauthored five books; published more than 500 articles in Oracle Magazine, OTN, and other publications; presented about 300 sessions at various Oracle technology conferences all over the world; and delivered 30 Oracle Celebrity Seminar series courses. He is an editor for SELECT Journal, the IOUG publication; a member of the board of directors of the Exadata SIG; an Oracle ACE director; and a member of the Oak Table Network.

Acknowledging his professional expertise and involvement in the user community, Oracle awarded him the DBA of the Year title in 2003 and Architect of the Year in 2012.

Page 48: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c
Page 49: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

xlix

Acknowledgments

Thanks to fellow coauthors Sam Alapati and Bill Padfield and also thanks to the numerous DBAs and developers who I’ve learned performance tuning techniques from over the years: Dave Jennings, Scott Schulze, Bob Suehrstedt, Pete Mullineaux, Janet Bacon, Sue Wagner, Mohan Koneru, Arup Nanda, Charles Kim, Bernard Lopuz, Barb Sannwald, Tim Gorman, Shawn Heisdorffer, Doug Davis, Sujit Pattanaik, Sudeep Pattanaik, Ken Roberts, Roger Murphy, Mehran Sowdaey, Kevin Bayer, Dan Fink, Guido Handley, Nehru Kaja, Tim Colbert, Glenn Balanoff, Bob Mason, Brad Blake, Cathy Wilson, Ravi Narayanaswamy, Abdul Ebadi, Kevin Hoyt, Trent Sherman, Sandra Montijo, Jim Secor, Maureen Frazzini, Sean Best, Stephan Haisley, Geoff Strebel, Patrick Gates, Buzzy Cheadle, Mark Blair, Karen Kappler, Mike Hutchinson, Liz Brill, Ennio Murroni, John Phillips, Mike O’Neill, Jack Donnelly, Beth Loker, Mike Eason, Greg Roberts, Debbie Earman, Bob Sell, Tom Wheltle, Chad Heckman, Ken Toney, Gabor Gyurovszky, Scott Norris, Joey Canlas, Eric Wendelin, Gary Smith, Mark Lutze, Kevin Quinlivan, Dean Price, Dave Bourque, Roy Backstrom, John Lilly, Valerie Eipper, Steve Buckmelter, John DiVirgilio, John Goggin, Simon Ip, Pascal Ledru, Kevin O’Grady, Peter Schow, Todd Sherman, Mike Tanaka, Doug Cushing, Will Thornburg, Steve Roughton, Sudha Verma, Christian Hessler, Tae Kim, Margaret Carson, Jed Summerton, Lea Wang, Ambereen Pasha, Dinesh Neelay, Kye Bae, Thom Chumley, Jeff Sherard, Erik Jasiak, Aaron Isom, Kristi Jackson, Karolyn Vowles, Britni Barovick, Amin Jiwani, Laurie Bourgeois, Vasanthan Dasan, Todd Wichers, Venkatesh Ranganathan, Dave Wood, Jeff Shoup, Brett Guy, and Jim Stark.

—Darl Kuhn

I’d like to thank Sam Alapati and Darl Kuhn for all of their help and support. Thanks to my managers over the years in helping me in my career. This includes but is not limited to Bob Ranney, Beth Bowen, Larry Wyzgala, John Zlamal, Billie Ortega, Linda Scheldrup, Amy Neff, and Maureen Frazzini. I’d like to thank my current DBA team, for their great support and friendship. This includes Dave Carter, Debbie Fitzgerald, Sandy Hass, Pankaj Guleria, Brent Wagner, Kevin Tomimatsu, and John Townley. Over the years, I’ve learned an awful lot from the following folks, who have always been generous with their time and help and have been patient with my questions. I have to thank the Oracle architect at our company, Roby Sherman, for all his support and help over the years. There are a myriad of developers, testers, system administrators, and other folks who have been a tremendous help in my career. 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, Tony Romo, Avanish Gupta, Scott Bunker, Paul Mayes, Bill Read, Rod Ermish, Rick Barry, Sun Yang, Sue Wagner, John Saxe, Glenn Balanoff, Linda Lee Burau, Deborah Lieou-McCall, Bob Zumpf, Pete Sardaczuk, Kristi Sargent, 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, Kim Lake, 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, Kedar Panda, Srivatsan Muralidaran, Tony Arlt, Atul Shirke, Deb Kingsley, Brenda Carney, Paul Obering, Don Miller, Ned Ashby, Pat Wuller, and Adric Norris.

—Bill Padfield

Page 50: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c
Page 51: Oracle Database 12c Performance Tuning Recipes - …978-1-4302-6188-9/1.pdf · Quickly Analyzing AWR Output ... Oracle Database 12c Performance Tuning Recipes Oracle Database 12c

li

Introduction

Oracle Database 12c Performance Tuning Recipes is a book of solutions—a crib sheet of sorts. Database performance problems often rear themselves suddenly, and with that suddenness comes great pressure from management and users to somehow work magic and get response time back under control. Everyone is in a panic. Everyone is upset (except idealy you!). Such is no time for a leisurely read of a book. This book is written with that pressure in mind. It is chock-full of prewritten queries and other solutions that you can immediately apply and get results.

Of course, you should not wait until the last minute. Take the time now when you’re not in crisis mode to get familiar with the content in this book. Try the solutions for monitoring and analyzing. See what you can learn about your current database performance levels. Then take action to set some benchmarks and work on improvements so as to become practiced for when a crisis eventually hits. Or better yet, maybe you can avoid a crisis altogether.

Who This Book Is ForOracle Database 12c Performance Tuning Recipes was written primarily for database administrators who manage Oracle Database environments. The book is especially useful to those administrators involved in tackling performance optimization problems. Serious SQL developers will also find the book useful, especially the chapters on aspects of SQL.

How This Book Is StructuredSolutions in this book are grouped into categories by chapter. Each chapter is composed of a number of recipes relating to the chapter’s topic. Each recipe takes the following form:

Problem: A succinct description of the problem solved by the recipe

Solution: A terse and to-the-point presentation of queries and commands to execute in order to accomplish the task described in the recipe’s problem statement

How It Works: A longer discourse on the solution and how and why it works, for those who are interested in a deeper understanding of the material

The book’s structure allows you to open it to a chapter relating to a problem you are trying to solve. Then find a recipe in the chapter that solves the problem or that can be adapted to solve the problem. Read the solution. Read the “How It Works” description to fully understand the solution. Then apply the solution to your real-world problem.

Downloading the CodeThe authors have made a zip file available with the queries and scripts from the recipe solutions. To download the zip file, first visit the book’s catalog page on the Apress.com web site. The URL is as follows:

http://www.apress.com/9781430261872

Then scroll down the page and look for a tabbed section. Click the Source Code/Downloads tab, and download the zip file of examples using the provided link.