oracle performance tuning tips & techniques

13
ORACLe Oracle Press™ Oracle Performance Tuning Tips & Techniques Rkh Niemiec Osborne/McGraw-Hill Berkeley New York St. Louis San Francisco Auckland Bogota Hamburg London Madrid Mexico City Milan Montreal New Delhi Panama City Paris Säo Paulo Singapore Sydney Tokyo Toronto

Upload: others

Post on 29-Apr-2022

47 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Oracle Performance Tuning Tips & Techniques

ORACLe Oracle Press™

Oracle Performance Tuning Tips & Techniques

Rkh Niemiec

Osborne/McGraw-Hill

Berkeley New York St. Louis San Francisco Auckland Bogota Hamburg London Madrid Mexico City Milan Montreal New Delhi Panama City Paris Säo Paulo Singapore Sydney Tokyo Toronto

Page 2: Oracle Performance Tuning Tips & Techniques
Page 3: Oracle Performance Tuning Tips & Techniques

f x i P v i Oracle Performance Tuning Tips & Techniques

Index-Organized Tables (Oracle8) 88 Partitioned Indexes (Oracle8 Only) 88

Local (Commonly Used Indexes) 89 Global 91

Fast Index Rebuilding 93 Tips Review 93 References 95

3 Disk I/O and Fragmentation (DBA) 97 Distributing "Key" Data Files Across Available Hardware Disks 99

Storing Data and Index Files in Separate Locations 99 Avoiding I/O Disk Contention 100 Moving Data Files to Balance File I/O 102 Viewing File/Tablespace Information Using Enterprise Manger 103

Avoiding Disk Contention by Using Partittons (Oracle8) 106 Cetting More Information About Partitions 108

Avoiding and Fixing Fragmentation 109 Using the Correct Table Size 110 Create a New Tablespace and Move the Data to It 110 Exporting, Compressing, and then Reimporting the Table 112 Increasing the Size of the Next Extent 112 To Avoid Chaining, Set Percents Correctly 113 Rebuilding the Database to Resolve Fragmentation 113

Increase the Log File Size and LOG_CHECKPOINT_INTERVAL for Speed 116

Determining If Redo Log File Size 1s a Problem 116 Determining the Size of Your Log Files and

Checkpoint Interval 117 Increasing Chances of Recovery—Committing After Each Batch 119 Creating Enough Rollback Segments 119

Avoiding Contention Among Rollback Segments 120 Monitoring Rollback Segment Waits and Contention 120 Increasing Rollback Segments 121 Killing Problem Sessions 121 Isolating Large Transactions to Their Own Rollback Segments 122

Don't Sort in the SYSTEM Tablespace 124 Having Multiple Control Files on Different Disks and Controllers 125 Using Disk Arrays to Improve Performance 1 25

What Are Some of the RAID Levels Available? 125 How Does This Impact Setup and Maintenance? 126 Is the Disk Array Made for a 24-Hour Shop? 126 What Is the Cost? 127

Using Raw Devices to Improve I/O for Write-Intensive Data 127 Reasons for Using Raw Devices 127 Drawbacks 128

Other Disk I/O Precautions and Tips 129 Issues to Consider in the Planning Stages 129 Tips Review 130 References 131

Page 4: Oracle Performance Tuning Tips & Techniques

4 Tuning the initora (DBA Related) 133 What Are the Crucial init.ora Tuning Parameters? 135 Changing the init.ora without a Restart 136 Viewing the init.ora Parameters with Enterprise Manager 137 Increasing Performance by Tuning the DB_BLOCK_BUFFERS 137 Setting DB_BLOCK_SIZE to Reflect the Size of Your Data Reads 138

Setting DB_BLOCK_BUFFERS to 25 Percent of the Size Allocated to Main Memory 1 39

Getting the Hit Ratio Using Enterprise Manager 1 40 Keeping the Hit Ratio for the Data Cache Above 95 Percent 141 Monitoring the V$SQLAREA View to Find Bad Queries 1 42 Tuning Queries to Avoid Performance Hits 147 Use the x$bh table to Monitor Buffer Use 151 Using the CACHE Parameter to Pin Data into Memory 1 52 Tuning the SHARED_POOL_SIZE for Optimal Performance 1 56 Using the Buffer Pools in Oracle8 1 65 Tuning the SORT_AREA_SIZE for Optimal Use of Memory 1 67 Modifying the Size of Your SCA to Avoid Paging

and Swapping 170 Using SHOWUSER, SHOWOTHER, and USERSQL to Find

System Drains 171 Other Queries for Pinpointing

Performance Problems 1 74 Using the V$SYSSTAT View to View System Memory Use 1 76 The OPTIMIZER_MODE: Cost- Versus Rule-Based

Optimization 178 Creating Enough Latches, Dispatchers, and Open Cursors 1 82 The Top 25 init.ora Parameters 1 84 Changes to the init.ora Parameters in OracleS 1 86 Undocumented init.ora Parameters 1 86 A Test Case That Yielded a 69 Percent Gain in Performance 187 The Typical Server 1 93 Model of a Typical Server 1 94

Tips Review 196 References 198

5 Enterprise Manager and Tuning Pack (DBA and Developer) 201 The Instance Manager 203

Instance Manager—Status Screen 204 Instance Manager—Startup Options 204 Instance Manager—init.ora Parameters 204 Instance Manager—View a Single Session 205

The Schema Manager 206 Schema Manager—View Specific Tables 206 Schema Manager—View Specific Indexes 207 Schema Manager—View SYS Information 208 Schema Manager—Viewing Packages, Procedures, and Triggers 208

The Security Manager 209 Security Manager—Creating a Profile 210

The Storage Manager 212

Page 5: Oracle Performance Tuning Tips & Techniques

>t j V Ü i Oracle Performance Tuning Tips & Techniques

The Oracle SQL Worksheet 214 The Performance Manager 215

Performance Manager—Buffer Cache Hit Ratio 215 Performance Manager—Library Cache Hit Ratio 215 Performance Manager—Data Dictionary Cache Hit Ratio 216 Performance Manager—SQL Area 218 Performance Manager—Memory Sort Hit Ratio 219 Performance Manager—Overview Screen 220 Performance Manager—System I/O Rate 221 Performance Manager—Database Instance Information 223

The Performance Manager— Building Your Own Charts 224 TopSessions Monitor 227 Oracle Tuning Pack—SQL Analyze 229

SQL Anaiyze—The EXPLAIN PLAN 230 SQL Analyze—Execution Statistfes 231 SQL Anaiyze—Comparing Different Plans 232 SQL Analyze—Tuning Wizard 234

Oracle Tuning Pack—Oracle Expert 236 Oracle Expert—Focusing on a Schema 237 Oracle Expert—Set Up the Rules for the Tuning Session 238 Oracle Expert—Making Changes and Measuring the Impact 239 Oracle Expert—Viewing the Recommendations 240 Oracle Expert—Drill Down to Recommendation Detail 240 Oracle Expert—Recommended System-Wide Changes 241

Oracle Tuning Pack 1.6—Tablespace Viewer 242 Oracle Expert Analysis Report 243 Oracle Expert Implementation Script 245 Tips Review 246 References 248

6 Using EXPLAIN PLAN, TRACE, and TKPROF (Developer and DBA) 251 The Oracle TRACE Utility 253

Simple Steps for TRACE with a Simple Query 253 The Sections of a TRACE Output 257 A More Complex TKPROF Output 258 Using EXPLAIN PLAN Alone 259 EXPLAIN PLAN—Read It Top to Bottom or Bottom to Top? 263 Reading the EXPLAIN PLAN 264 Yet Another EXPLAIN PLAN Output Method: Building the Tree Structure 269 Another Example Using the Tree Approach 271 TRACing/EXPLAINing Problem Queries in Developer Products 274 Importanf Columns in the PLAN_TABLE TABLE 274 Helpful Oracle-Supplied Packages 277 init.ora Parameters for Undocumented TRACE 278

Tips Review 279 References 280

7 Basic Hint Syntax (Developer and DBA) 283 Available Hints and Croupings 285

Execution Path 285 Access Methods 285

Page 6: Oracle Performance Tuning Tips & Techniques

Join Orders 286 foin Operations 286 Parallel Execution 287 Cache Hints 287

Specifying a Hint 287 Specifying Multiple Hints 288 Hint the Alias, and Not the Table 289

The CHOOSE Hint 289 The RULE Hint 290 The FIRST_ROWS Hint 291 The ALL_ROWS Hin! 292 The FÜLL Hin! 293 The INDEX Hint 294 The INDEX_ASC Hint 295 The INDEX_DESC Hint 296 The INDEX_FFS Hint (Oracle8 Only) ' 296 The ORDERED Hint 297 The ROWID Hint 298 The STAR Hint (Oracle 7.3+ Only) 299 The DRIVING_SLTE Hint (OracleS Only) 301 The USE_MERCE Hint 302 The USE_NL Hint 303 The PUSH_SUBQ Hint (OracleS Only) 304 The PARALLEL Hint 304 The NO_PARALLEL Hint 306 The APPEND Hint (Oracle8 Only) 306 The NO_APPEND Hint (OracleS Only) 307 The CACHE Hint 308 The NOCACHE Hint 308 The CLUSTER Hint 309 The HASH Hint 310

Tips Review 310 References 313

8 Query Tuning (Developer and DBA) 315 What Queries Do I Tune? Querying the V$SQLAREA View 317

Selecting from the V$SQLAREA View to Find the Worst Queries 317

When Should an Index Be Used? 318 What Happens When I Forget the Index? 319 Creating an Index 319 Check the Index on a Table 320

Query DBA_IND_COLUMNSto Find Indexes for a Table 320 Properly Indexed? 320 What If I Create a Bad Index? 321 Caution Should Be Exercised When Dropping Indexes 322 Indexing the SELECT and WHERE 324 The Fast Füll Scan 325 Concatenated Indexes Must Use the Leading Column 326 A "Magically" Faster Query 327

Page 7: Oracle Performance Tuning Tips & Techniques

X Oracle Performance Tuning Tips & Techniques

Caching a Table in Memory 328 Using Multiple Indexes (Use the Most Selective) 330 Indexes That Get Suppressed 332 The "Currous" OR 333 Inequalities and the Optimizer 335 The EXISTS Function 336 Tips Review 337 References 339

9 Table Joins and Other Advanced Query Tuning 341 )oin Methods 343

NESTED LOOP5 Joins 343 SORT-MERGE Joins 344 CLUSTER Joins 345 HASH Joins (Oracle 7.3+) 346 INDEX Joins (Oracle8i) 347

Table Join Initialization Parameters 348 SORT-MERGE Join Parameters 348 HASH join Parameters 348

Comparing the Primary Join Methods 349 Two-Table Join—Equal-Size Tables—Rule-Based 350 Two-Table Join—Equal-Size Tables—Cost-Based 352 Two-Table INDEXED Join—Equal-Size Tables—Cost-Based 355 Forcing a Specific Join Method 362 Early Elimination of Candidate Rows 365 Two-Table Join—Large and Small Table 366 Two-Table Join—Small and Large with Concatenated Index 376 Three-Table Joins—Not as Much Fun (Cost-Based) 381

A Three-Table Join—Advanced (Cost-Based Optimizer) 383 A Three-Table join—Advanced 384

Index "Breakpoint" for a Small Table 386 The Iniist Iterator in OracleS (Using the IN) 389 Third-Party Product Tuning 391 Distributed Queries 395 When You Have Everything Tuned 397 Tuning Using Simple Mathematical Techniques 398

Traditional Mathematical Analysis 399 Seven Steps of the Methodology 399 Deriving Performance Equations 400 Simple Quadratic Equation Determination 403 Mathematical Techniques Conclusions 411

Tips Review 412 References 414

10 Using PL/SQL to Enhance Performance (Developer and DBA) 417 Reusing Memory with PL/SQL 419 Finding PL/SQL Not Using Bind Variables 420 Finding Reusable PL/SQL with V$SQLAREA and Specific Objects 421 Shared Pool and Pinning PL/SQL Objects 422

Pinning (Caching) PL/SQL Object Statements into Memory 422 Pinning All Packages 423

Page 8: Oracle Performance Tuning Tips & Techniques

Contents X I

Identifying PL/SQL Objects that Need to Be Pinned 424 Using and Modifying DBMS_SHARED_POOL.S!ZES 424

Finding Large Objects 425 Get Detailed Object Information from DBA_OBJECT_SIZE 426

Getting Contiguous Space Currently in the Shared Pool 426 Finding Invalid Objects 427 Finding Disabled Triggers 429 Using PL/SQL Tables for Fast Reference Table Lookups 429 Finding and Tuning the SQL When Objects Are Used 432 The Time Component When Working with DATE Data Types 435 Tuning and Testing PL/SQL 437 PL/SQL Object Location: Implications 438 Don't Bind PL/SQL Program Units in a Form to Form Fields 439 Using Rollback Segments to Open Large Cursors 440

Use Active Transaction Management to Process Large Quantities of Data 441

Modifying SQL.BSQ to Avoid Data Dictionary Fragmentation 442 Examples—The "Look and Feel" Just for the Beginners 443 Tips Review 446 References 447

I I Using Parallel Features to Improve Performance 449 Basic Concepts of Parallel Operations 451 Parallel Query Option and Operations with Oracle7 453 Parallel DML Statements and Operations with Oracle8 454 Parallel Operations, Partitions, and Execution Methods 455 Producer/Consumer Relationship 459 Inter- and Intra-Operation Parallelization (PARALLEL and

NOPARALLEL Hints) 459 Examples of Using Inter^ and Intra-Operations (PARALLEL and

NOPARALLEL Hints) 460 Different Statements Are Determined for PARALLEL Differently 462

SELECT Statement Rules 462 SQL Statement DML Rules (Oracle8) 462 DDL Statement Rules (OracleS) 463

Create Table and Index Examples of Using Parallel Operations 464 Real-World Example of Distributing Data for Effective Parallel Operations

466 Oracle8 Parallel DML 466

Parallel DML Rules, Exceptions, and Usage Notes 467 Parallel DML Statement Examples 468

Monitor Parallel Operations Using V$PQ_SYSSTAT, V$PQ„SESSTAT, and V$PQ_TQSTAT Views 470

VSPQ_SYSSTAT View 470 VSPQ_SESSTAT View 473 V$PQ_TQSTAT View 474

Using EXPLAIN PLAN on Parallel Operations 474 Tuning Parallel Execution and the Oracle7 init.ora Parameters 476 Tuning Parallel Execution and the Oracle8 init.ora Parameters 478 Parallel Loading 482

Page 9: Oracle Performance Tuning Tips & Techniques

x i i Oracle Performance Tuning Tips & Techniques

Performance Comparisons and Monitoring Parallel Operations 483 Summary 485 Tips Review 486 References 488

12 OracleS New Features (Developer and DBA) 491 Database Scalability 493 Oracle Call Interface 494 Large Object Support 494 Partitioning 495 Important Issues Concerning Partitioning 495 Oracle's Net8 Quick Notes 496 Constraint Options 497 Index Organized Tables 498 Reverse-Key Index 498 Parallel Operations with OracleS 498 Star Query Processing 499 Security—Options 500

Security Data Dictionary Changes 500 Security—Profiles 502 Security—Passwords 504 ROWID Changes in OracleS 505

New Views in OracleS 506 Backup and Recovery 506

Parallel Server and Distributed Server 507 Notes on Upgrading to Oracle8 508 Network Computing Architecture (NCA) 509 Web Development Products (JDeveloper and Oracle Developer) 510

Oracie Developer (Dev/2000) and Web-Enabling 511 Oracie's Internet Commerce Server (OICS) 512

Desupported Features in OracleS 512 Nondeferred Linking 512

Features in Oracle8i (8.1) 513 Tips Review 513 References 514

13 Oracle8 and 8i New Tips (Developer and DBA) 517 Changing the init.ora without a Restart 519 Index-Organized Tables 521 Oracle8 Constraint Options 522 Reverse-Key Indexes 524 Partitions 524

Dropping a Partition 526 Other Partitioning Options 529

Index Partitioning 53"! Exporting Partitions 532 Desupported Feature in OracleS 532 Parallel Operations with Oracle8 533

Parallel Execution Methods 535 ROWID in Oracle8 535

Page 10: Oracle Performance Tuning Tips & Techniques

Contents X I Ü

DBMS_ROWlD Package 536 The NOLOGCING Feature 538 Network Computing 539

The Integration of Java with SQL (SQLJ and JDBC) 539 Comparing SQLJ and JDBC 541

Oracle Objects 542 New Hints in OracleS 543

The DRIVING_SITE Hint 543 The INDEX_FFS Hint 543 The APPEND Hint 543 The NCLAPPEND Hint 544

Using the Buffer Pools in Oracle8 544 Features in Oracle8i (8.1) 546

Function-Based Indexes 546 Enable/Disable All Triggers 547 The NOJNDEX Hint 547 The DROP COLUMN Command 547 The DBMS_REPAIR Package 548 ALTER SYSTEM SUSPEND/RESUME 548 Reading Multiple Blocks for Disk Sorts 549 Transportable Tablespaces 549

Tips Review 550 References 552

14 The V$ Views (Developer and DBA) 555 V$ View Creation and Access 557

Getting a Count and Listing of All V$ Views 560 Finding the xS Tables Used in the Creation of the V$ Views 562 Indexes on the x$ Tables Make the V$ Views Faster in Oracle8 564 Helpful V$ Scripts 564 Y2K Compliance and the NLS_DATE_FORMAT 567 Summary of Memory Allocated (V$SGA) 567 Detail of Memory Allocated (V$SGASTAT) 568 Init.ora Settings Can Be Found in V$PARAMETER View 570 Hit Ratio for Data <V$SYSSTAT View) 571 Hit Ratio for the Data Dictionary (V$ROWCACHE View) 572 Hit Ratio for the Shared SQL and

PL/SQL (V$LIBRARYCACHE View) 573 Identifying PL/SQL Objects that Need to Be Pinned 574 Finding the Problem Queries by Querying V$SQLAREA View 574 Find Out what Users Are Doing and the Resources They

Are Using 576 Find the Objects a User Is Accessing 577 Identifying Locking Issues 579 Kill the Problem User 579 Finding Users with Multiple Sessions 580 Finding Disk I/O Issues 581 Finding Rollback Segment Contention 583 Check to See If Free Lists Is Sufficient 585 V$ View Categories 586

Page 11: Oracle Performance Tuning Tips & Techniques

x i v Oracle Performance Tuning Tips & Techniques

Summary 59Q Tips Review 590 References 592

15 The x$ Tables (DBA) 595 Misconceptions About the x$ Tables 597 Granting Access to View the x$ Tables 598 V$ Views and xS Table Creation 599

The x$ Tables That Make Up the V$ Views 601 How to Get a Listing of All x$ Tables 602 How to Get a Listing of All the x$ Indexes 604 Using Hints with the x$ Tables and Indexes 605 Data Cached in Memory (x$bh) 607 OracleS Takes More Startup Resources 607 What Memory Is Still in Use? 608

A Better Query for Memory in Use 611 Information Cached in the SHARED_POOL Memory (xSksmsp) 612 When to Pin Objects in the Shared Pool 617 Accessrng the Undocumented init.ora Parameters 618 How Many init.ora Parameters Are There and How Many

Are Documented? 621 Future Version Impact 626 Tips Review 626 References 628

16 Usirtg and Interpreting UTLESTAT/UTLBSTAT (Advanced DBA) 631 Running the Utilities 633

Frequency of Monitoring 633 The Tables That Are Populated by the Scripts 634 The Library Cache 636 Database Statistics 637 Dirty Buffer Write Queue 642 System-Wide Wait Events 643 Latches Wil l ing to Wait 645 Latches Not Wi l l ing to Wait 647 Buffer Busy Wait Statistics 648 Rollback Segments 648 Nondefault init.ora Parameters 650 The Dictionary Cache 651 Tablespace I/O 652 Data File I/O 654 Date/Time 655 Oracle Versions from the V$VERSION View 656 Summary Listing of Sections That Are Created 656

Tips Review 657 References 659

17 Performing a Quick System Review (DBA) 661 Total Performance Index (TPI) f,62 Memory Performance Index (MPI) 663

Buffer Hit Ratio 663

Page 12: Oracle Performance Tuning Tips & Techniques

Contents X V

Dictionary Cache Hit Ratio 665 Library Cache Hit Ratio 665 Sorting in Memory Hit Ratio 666 Percent of Data Buffers Still Free 667 Shared Pool Still Contiguous 668 Top 10 "Memory Abusers" as a Percent of All Statements 669 Top 25 "Memory Abusers" Statements Tuned 670 Pinning/Caching Objects 671

Disk Performance Index (DPI) 672 Top 25 "Disk-Read Abuser" Statements Tuned 673 Top 10 Disk-Read Abusers as Percent of Al l Statements 674 TabIes/Indexes Separated 676 Chaining in Mission-Critical Tables 676 Key Oracle Files Separated 677 Rollback Segment Balance 677 Temporary Segment Balance 678 Minor Fragmentation Issues 679 Major Fragmentation Issues 680

Education Performance Index (EPI) 681 System Performance Index (SPI) 684 Total Performance Index (TPI) 687 Overall System Review Example 688

Rating System 688 Example System Review Rating 689 Items Requiring Immediate Action 691 Other Items Requiring Action 691

System Information List 694 Memory-Related Values 695 Disk-Related Values 695 CPU-Related Values 697 Backup and Recovery-Related Information 698 Naming Conventions and/or OFA Standards and

Security Information 699 DBA Knowledge Rating 699

Remote TUSC DBA 700 Building the Graphical View Using Oracle Reports 700 Building the Screen View 701

Tips Review 702 References 703

18 Monitor the System Using UNIX Utilities (DBA) 705 Using the sar Command to Monitor CPU Usage 707

What's a Good Idie Percentage for the CPU? 708 Finding the Worst User on the System Using the UNIX top Command 708

Monitoring Tools 709 Using the uptime Command to Monitor CPU Load 710 Using the mpstat Command to Identify CPU Bottlenecks 712 Combining ps with Selected V$ Views 713 Using the sar Command to Monitor Disk I/O Problems 716

Page 13: Oracle Performance Tuning Tips & Techniques

X V I Oracle Performance Tuning Tips & Techniques

Using iostat Command to Identify Disk I/O Bottlenecks 717 Disk I/O Monitoring Tools 720

Using the sar Command to Monitor System Paging/Swapping 721 Using the ipcs Command to Determine Shared Memory 724 Using the vmstat Command to Monitor System Load 725 Tips Review 726 References 727

A Key init.ora Parameters (DBA) 729 The Top 25 init.ora Parameters 731 The Top 10 init.ora Parameters not to Forget 741 The Top 13 Undocumented init.ora Parameters (as I See It) 742 The Other Top 13 Undocumented init.ora Parameters 743 Listing of Documented init.ora Parameters (V$PARAMETER) 744 Listing of Undocumented init.ora Parameters (x$ksppi/xSksppcv) 757 The Top 1 0 reasons not to Write a Book 764 Tips Review 765 References 765

B The V$ Views (DBA and Developer) 767 A List of Al l the V7 V$ Views 768 A List of All the V8 GV$ and V$ Views 769 The V8 V$ Views 771 V7 Scripts of the x$ Tables Used to Create the V$ Views 772 V8 Scripts of the x$ Tables Used to Create the V$ Views 787

C The x$ Tables (DBA) 843 Version 7 x$ Tables Ordered by Name 844 Version 8 x$ Tables Ordered by Name 846 Version 8 x$ Indexes 848 Version 7 x$ Tables Cross-Referenced to the V$ Views 856 Version 8 x$ Tables Cross-Referenced to the V$ Views 859 Version 7 V$ Views Cross-Referenced to the x$ Tables 863 Version 8 CV$ Views Cross-Referenced to the x$ Tables 866 Version 7 x$ Tables Not Referenced by a V$ View 871 Version 8 x$ Tables Not Referenced by a GV$ View 871

Index 873