Architecture and Performance Considerations 475Summary 485 Existing Java Class as a Persistent Object Type 501 Creating Instances of Object Types in the Database 504 Summary 520 Protocol
Trang 2Professional Oracle® Programming Rick Greenwald, Robert Stackowiak, Gary Dodge, David Klein, Ben Shapiro,
Christopher G Chelliah
Trang 4Professional Oracle® Programming
Trang 6Professional Oracle® Programming Rick Greenwald, Robert Stackowiak, Gary Dodge, David Klein, Ben Shapiro,
Christopher G Chelliah
Trang 7Copyright © 2005 by Wiley Publishing Inc All rights reserved.
Published by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or byany means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permittedunder Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permis-sion of the Publisher, or authorization through payment of the appropriate per-copy fee to the CopyrightClearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8700 Requests
to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY:THE PUBLISHER AND THE AUTHOR MAKE
NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS
OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDINGWITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE NO WARRANTYMAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS THE ADVICE ANDSTRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION THIS WORK ISSOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERINGLEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES IF PROFESSIONAL ASSISTANCE ISREQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT.NEITHER THE PUBLISHER NOT THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HERE-FROM THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS ACITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THATTHE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION ORWEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE FURTHER, READERS SHOULD BEAWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAP-PEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ
For general information on our other products and services please contact our Customer Care Departmentwithin the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002
Trademarks:Wiley, the Wiley Publishing logo, Wrox, the Wrox logo, and Programmer to Programmer aretrademarks or registered trademarks of John Wiley & Sons, Inc and/or its affiliates All other trademarksare the property of their respective owners Wiley Publishing, Inc., is not associated with any product orvendor mentioned in this book
Wiley also publishes its books in a variety of electronic formats Some content that appears in print may not
be available in electronic books
Library of Congress Cataloging-in-Publication Data:
Professional Oracle programming / Rick Greenwald [et al.]
ISBN 10: 0-7645-7482-5
Printed in the United States of America
10 9 8 7 6 5 4 3 2 1
1B/QS/QW/QV/IN
Trang 8About the Authors
Rick Greenwaldhas been in the technology industry for over 20 years and is the author of 12 previousbooks, most of them on Oracle He has been involved with development and databases for his entirecareer, including stops at Data General, Cognos, Gupta Technologies, and his current employer, Oracle.Computers and computing are a sideline for Rick — his real job is father to his three wonderful girls,with a primary hobby of music appreciation
Robert Stackowiakis Senior Director of Business Intelligence (BI) in Oracle’s Technology Business Unit
He is recognized worldwide for his expertise in business intelligence and data warehousing in leadingthe North American BI team at Oracle His background includes over 20 years in IT related roles atOracle, IBM, Harris Computer Systems, and the U.S Army Corps of Engineers including management
of technical teams, software development, sales and sales consulting, systems engineering, and businessdevelopment
Gary Dodge has been focused on database technology since his first COBOL programming job with IMSDB/DC in 1976 He joined Oracle Corporation in 1987 and has served in various management and technical positions within both the sales and consulting divisions He has been a frequent speaker ondatabase topics at many local and national information technology conferences In addition to several
magazine articles, he is co-author (with Tim Gorman) of Oracle8 Data Warehousing and Essential Oracle8i
Data Warehousing, both published by John Wiley & Sons
David Kleinhas been in the technology industry for over 20 years with a variety of companies, includingData General, Wang Laboratories, Gupta Technologies, Oracle, and a few consulting services companies
He has had many roles, including management of application development and database design teams,sales and sales consulting, systems engineering and marketing Recently, he has focused on developingclassroom and online training courses An active wife and two boys and a 200-year-old house take up anyfree time
Ben Shapirois the president of ObjectArts Inc., a New York City-based technology consulting company,and has been designing database systems with Oracle since 1997 ObjectArts has worked with manylarge corporate clients developing XML-based publishing tools and web-based applications BeforeObjectArts, Ben worked with several NYC-based startup companies as a technical lead building contentmanagement software
Christopher G Chelliahjoined Oracle as a Consultant in 1995 He brings with him project management,architecture, and development experience from a number of large, multinational sites in the mining, oiland gas, and telecom industries Chris has been involved with emerging and database technologies forhis entire career and is an accomplished software architect with a flair for business development Hisexpertise has been actively sought by a number of major Oracle clients in Australia, Europe, and theUnited States Chris, his wife and two kids are currently in Singapore, where he leads a team definingand executing on innovative E-Government strategies for Oracle’s Public Sector industry in Asia Pacific
Trang 10Mary Beth Wakefield
Senior Production Editor
Text Design & Composition
Wiley Composition Services
Trang 12of labor pains, the worth and beauty of this offspring owes an enormous amount to them.
Rick Greenwald, in particular, would like to thank two people First of all, the process of writing three (is it three already) titles and several revisions of books with Bob Stackowiak has been a wonderful experience, both professionally and personally I am delighted to count Bob as a friend, and, thanks tohim, I still don’t know what BI stands for
Secondly, throughout my writing career, Steven Feurstein has been a mentor as well as a sterling example
of what an author and person should be like I hope to someday reach his level in terms of writing and,even more importantly, humanity
And, of course, I would like to thank my family — LuAnn for helping me have a life that supports writingand working, and Elinor Vera, Josephine, and Robin Greenwald for giving me all the inspiration anyonewould ever need
In addition, Rick would like to acknowledge all those people who came through with suggestions andknowledge at crucial times, including Richard Foote, Raj Mattamal and Tyler Muth
Trang 16Normalization 54
Denormalization 63
Trang 17Chapter 6: The Oracle Data Dictionary 93
Summary 112
Trang 19B-Tree Indexes 193
Trang 21Oracle’s Built-In SQL Functions 268
Chapter 14: Distributed Queries, Transactions, and Databases 315
Trang 23Working with Collections 366
Summary 396
Trang 24xxi
Trang 25Architecture and Performance Considerations 475
Summary 485
Existing Java Class as a Persistent Object Type 501 Creating Instances of Object Types in the Database 504
Summary 520
Protocol-Based Access to XML in the Oracle Repository 522 SQL-Based Access to XML Data in the Oracle Repository 529 Enabling a New Schema for Use with XDB Repositories 533
Trang 26Creating the Content Management Application Front End 558
Summary 627
Summary 638
SQL*Loader 640
Transformations 643
Trang 27Partitioning and the Speed of ETL 645
Summary 652
Summary 669
Windows Functions for Cumulative and Moving Aggregates 675
Trang 28Summary 723
Trang 30Introduction
Professional Oracle Programming is intended for application developers who use Oracle as their database.
As such, this book does not devote much space to topics which are primarily of interest to databaseadministrators, such as backup and recovery Most importantly, this book is designed to help a program-mer understand the database issues that can have a direct impact on the operation and performance oftheir applications
What Does This Book Cover?
Although it is impossible to cover all the topics that a professional developer could use to the level ofdepth required in a single book, this volume attempts to provide a foundation for these developers, aswell as guidance and examples of some of the key areas of interest and necessity These areas includeaccessing data using SQL, handling issues such as multi-user concurrency and data integrity and security,the basics of programming with Java, PL/SQL and XML, and data warehousing For a more completelist of topics, please refer to the section called “How Is This Book Structured?” later in this introduction
Who Is This Book For?
The entire topic of Oracle databases is certainly not a new one Oracle has been one of, if not the, leadingdatabases in the world for almost two decades now The standard Oracle documentation runs over 13,000pages, and leaves out a lot of the good stuff Determining the proper audience for this book, and writing
at a level appropriate for that audience, was the biggest conceptual challenge for all of the authors.Through discussions early in this project, the authors and publishers of this book came up with a fairlydistinct profile of our presumed reader This book is intended for people whose primary job is to createapplication systems They are developers, rather than database administrators
Following through on this profile, we believe that you, the professional developer, are well informedand skilled in the creation of these application systems In our experience, even professional developersmay think of the database they use as nothing more than a place to store data
This description of you, the target reader, has guided the selection of topics as well as the actual content
of this book
Trang 31What You Need to Use This Book
Although you do not necessarily need to have a working instance of an Oracle database to benefit fromthis book, the book includes many examples that can be run against your Oracle database
All of the examples have been created against Oracle Database 10g, although, with a few noted exceptions,
you could run the examples against Oracle9i Since Oracle is a cross-platform database, the actual
operating system that your version of Oracle runs on is unimportant
All of the examples can be run in either the standard Oracle utilities, such as iSQL*Plus, that come withthe product, or a standard development environment, including tools such as TOAD Directions on how
to run the examples are included in Chapter 7 of this book on installing an Oracle database, or in thechapter in which the examples are given
Most of the screen shots in this book have used a Windows client platform, but that platform is simply astandard used for consistency, not a requirement
How Is This Book Str uctured?
In a broad sense, this book is divided up into three main areas — information you need to know abouthow the Oracle database works, information that can help you to use the capabilities of the Oracledatabase in creating your application systems, and information to help you achieve optimal performancewith your application systems Although these three areas are covered in the order listed in the book,you will find relevant information for each of these areas throughout all of the chapters, along with tips,techniques, and code samples
Part I: Oracle Essentials
Although the Oracle database is a standards-compliant SQL database, the architecture of the Oracledatabase and the way it operates include some unique features that are crucial to your effective use ofOracle The first part of Oracle for Professional Developers covers topics that every developer mustunderstand in order to use the Oracle database effectively Please don’t think of these chapters as simplyintroductory material, since some of the information in these chapters can have an enormous effect onthe eventual operation of your applications
The topics covered in this section include:
❑ A brief introduction to the architecture and components of the Oracle database
❑ A detailed look at how Oracle processes your SQL requests and the impact this can have onyour application code
❑ A description of how Oracle handles data access by multiple users, and how this impacts yourapplication design
❑ A primer on effective database design
❑ A discussion on how Oracle administers security and how you can use this for your applications
Trang 32❑ An overview of the Oracle data dictionary, which contains information about the objects andoperations of a specific Oracle database
❑ A brief tutorial on installing an Oracle database
Part II: Data Topics
The second section of this book focuses on how to access and manipulate the data in the Oracledatabase The topics in this section are relevant to all developers, regardless of the language they areusing to implement their applications
The topics covered in this section include:
❑ An introdution to both basic SQL and some of the more sophisticated uses of this powerful dataaccess language
❑ Indexes, which help to speed the performance of data retrieval
❑ Constraints, which are used to both validate and limit the data added to your Oracle database
❑ A discussion of a variety of other database objects, such as sequences
❑ The use of functions, both built-ins that come with the Oracle database and your own customdefined functions
❑ A discussion of data manipulation as a distributed database environment
Part III: Database Programming Languages
The Oracle database allows you to include logic that runs in the database itself.Traditionally, the language
used for this work is PL/SQL — a set of procedural extensions based on the SQL language Oracle8i
introduced a Java engine into the database, which allowed you to use this language for implementingprocedural logic in the database
Part III of this book includes three chapters on PL/SQL and one on Java The PL/SQL chapters are dividedinto one on the basics of PL/SQL, one on using PL/SQL in conjunction with SQL, and one of PL/SQLpackages, which are a way of organizing and exposing the logic you create with PL/SQL
Part IV: Programming Techniques
Part IV of this book dives into the wide and varied area of implementing logic with various programmingtechniques to use in the database and your applications
The topics covered include:
❑ The use of triggers, which contain logic that is automatically executed whenever certain types ofdata access and manipulation are performed
❑ Regular expressions, which are a powerful syntax for implementing matching conditions, and
the expression filter — both of these features are new with Oracle Database 10g
Trang 33❑ The use of your Oracle database with object types, both for storage and for interactions withobjects in your applications
❑ The use of Oracle with XML
❑ HTML-DB, a development environment that comes as part of Oracle Database 10g
Part V: Business Intelligence Techniques
Business intelligence describes the process of using raw data in a database as the raw material for analysisthat can affect the direction of business operations Business intelligence in the Oracle database encompassesthe use of several specific features and techniques, which are covered in this section
The topics covered include:
❑ Moving data between different databases, which is often used to take data from an OLTP system
to a system used for business intelligence
❑ Data loading and management, which covers the manipulations that are sometimes required toprepare data for use in business intelligence operations
❑ And specific query features used for business intelligence, such as analytic functions
Part VI: Optimization
Creating an application is the first part of any programming project But no application will be acceptable
to your constituents if it does not run efficiently
This final section of the book introduces you to the concepts behind optimization in the Oracle database.The chapter includes a discussion of how Oracle determines the optimal access paths to your data, how
to see what Oracle has determined, and how to shape the behavior of your Oracle database in this area.Although database optimization is a subject worthy of many excellent volumes, this chapter is intended
to give you all the information you need to start to make your applications perform well
The Bigger Picture
As mentioned at the start of this introduction, no one book is complete enough to cover everything youwill need to know to use Oracle as an effective database for your applications We have tried to give you
a map that can be used over the course of many years of working with an Oracle database If you believethat there are destinations we have left off of this map, or descriptions that could be more useful orinformative, we welcome your comments
Conventions
To help you get the most from the text and keep track of what’s happening, we’ve used a number of conventions throughout the book
Trang 34Tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.
As for styles in the text:
❑ We highlight important words when we introduce them
❑ We show keyboard strokes like this: Ctrl+A
❑ We show file names, URLs, and code within the text like so: persistence.properties
❑ We present code in two different ways:
In code examples we highlight new and important code with a graybackground
The gray highlighting is not used for code that’s less important inthe present context, or has been shown before
Source Code
As you work through the examples in this book, you may choose either to type in all the code manually
or to use the source code files that accompany the book All of the source code used in this book is available for download at http://www.wrox.com Once at the site, simply locate the book’s title (either
by using the Search box or by using one of the title lists) and click the Download Code link on the book’sdetail page to obtain all the source code for the book
Because many books have similar titles, you may find it easiest to search by ISBN; for this book the ISBN is 0-7645-7482-5.
Once you download the code, just decompress it with your favorite compression tool Alternately, youcan go to the main Wrox code download page at http://www.wrox.com/dynamic/books/
download.aspxto see the code available for this book and all other Wrox books
Errata
We make every effort to ensure that there are no errors in the text or in the code However, no one is perfect, and mistakes do occur If you find an error in one of our books, like a spelling mistake or faultypiece of code, we would be very grateful for your feedback By sending in errata you may save anotherreader hours of frustration and at the same time you will be helping us provide even higher qualityinformation
Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.
Trang 35To find the errata page for this book, go to http://www.wrox.comand locate the title using the Searchbox or one of the title lists Then, on the book details page, click the Book Errata link On this page you canview all errata that has been submitted for this book and posted by Wrox editors A complete book listincluding links to each book’s errata is also available at www.wrox.com/misc-pages/booklist.shtml.
If you don’t spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml
and complete the form there to send us the error you have found We’ll check the information and, if ate, post a message to the book’s errata page and fix the problem in subsequent editions of the book
appropri-p2p.wrox.com
For author and peer discussion, join the P2P forums at p2p.wrox.com The forums are a Web-based system for you to post messages relating to Wrox books and related technologies and interact with otherreaders and technology users The forums offer a subscription feature to e-mail you topics of interest ofyour choosing when new posts are made to the forums Wrox authors, editors, other industry experts,and your fellow readers are present on these forums
At http://p2p.wrox.comyou will find a number of different forums that will help you not only as youread this book, but also as you develop your own applications To join the forums, just follow these steps:
1. Go to p2p.wrox.comand click the Register link
2. Read the terms of use and click Agree
3. Complete the required information to join as well as any optional information you wish to
pro-vide and click Submit
4. You will receive an e-mail with information describing how to verify your account and plete the joining process
com-You can read messages in the forums without joining P2P but in order to post your own messages, you must join.
Once you join, you can post new messages and respond to messages other users post You can read messages at any time on the Web If you would like to have new messages from a particular forume-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing
For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P andWrox books To read the FAQs, click the FAQ link on any P2P page
Trang 36Oracle Architecture
and Storage
The core theoretical purpose of a relational database is to separate logical interaction with datawithin the database from the physical storage of that data As a user or developer, you shouldn’treally have to know how an Oracle database works internally, or stores its data, in order to use itproperly At a high level, this is certainly true You don’t need to know anything about the Oracledatabase to write SQL, the access language used to interact with the database, or to create programsthat use SQL
The Oracle database automatically takes care of translating your logical requests to access the datawithin its control But, like all applications, the way your Oracle database is actually implementedcan have an impact on what you do and do not do in the creation and maintenance of your applicationsystems Having a basic understanding of how Oracle does its jobs provides a foundation for the rest
of this book And understanding the ways that Oracle stores your data, which is also covered in thischapter, can have a direct impact on the way you write your applications that use that data
This first chapter introduces you to a lot of the behind-the-scenes underpinnings of the Oracledatabase — the architecture of the database and how the data is stored within it You very wellmay not ever have to use this information in your day-to-day tasks, but the substance of this chapter is necessary for the more detailed information about programming
This chapter covers the architecture of the Oracle database as well as the storage options for yourdata Depending on how the responsibilities are divided in your particular environment, there may
be database administrators (DBAs) who do most of the work of translating your logical requirementsinto physical storage, or you may be called upon to perform some of these tasks yourself In eithercase, this chapter gives you some familiarity with the way your Oracle database handles your data
Trang 37The Oracle database is a relational database The theory of relational databases was first put forward by
Dr E F Codd, a research scientist working for IBM, in the mid-1970s Codd proposed a number of rulesfor a database to follow to be considered a relational database For the first decade or so after these ruleswere proposed, early relational databases fought to show that they were the most compliant with Codd’srules Those early days are far behind us now, and the basic features of a relational database, such as guar-anteeing transactional integrity and allowing ad hoc access to data, are well established in all major rela-tional databases
The Oracle database consists of two main parts: the instance, which is the software service that acts as anintermediary between application requests and its data, and the actual data files, which are where the data iskept The instance is a dynamic process and uses a variety of tasks and memory to support its operations Thedata files are stored on disk, so the data itself will survive most service interruptions, except for catastrophicmedia failure
The Instance
The Oracle instance is the collection of processes that handle requests from a client for a data Some ofthese processes are shown in Figure 1-1 Figure 1-1 also includes some of the main areas of memory that
an instance uses
Figure 1-1: Oracle instance architecture
An Oracle instance is either started as part of the process of booting a server or can be started explicitlywith commands Although you start an instance with a single command, there are actually three distinctsteps in the startup process:
❑ Starting the instance process itself
PGA
User User
User User
User
Redo Log buffers
Trang 38❑ Mounting the database, which consists of opening the control files for the instance
❑ Opening the database, which makes the database available for user requests
An instance can be stopped with another command or via the system console, which follows the samesequence of events in reverse You can stop an instance gracefully by stopping users from logging on tothe database and only shutting down when the last active user has logged off, or you can simply stopthe instance, which may result in incomplete transactions (described in detail in Chapter 3, “HandlingMultiple Users”)
Processes Supporting an Instance
A number of processes are associated with an instance and perform specific tasks for the instance
Listener
The Listener is a process that listens on the network for requests coming in to an Oracle instance A Listenerprocess can support one or more Oracle instances The Listener acts as the intermediary between userrequests from remote machines and the instance The failure of the Listener will mean that the instance itsupports is not accessible by a remote client — such as any application that accesses the instance
Files Supporting an Instance
There are a number of files that are used by an instance The basic files for storing data are discussed in thenext section on data organization An Oracle instance has its own set of files that do not store user databut are used to monitor and manage the Oracle instance itself
Initialization Files
Many parameters exist that affect the way that your Oracle instance operates These parameters are typically set and maintained by a database administrator and, as such, are beyond the scope of this book.The initial values for these parameters are kept in initialization files
3
Trang 39Prior to Oracle9i, each instance had its own specific initialization file called INIT.ORA, as well as an optional file with additional configuration information called CONFIG.ORA Starting with Oracle9i, you
could have a virtual initialization file called the SPFILE, which could be shared with multiple instances.SPFILE was especially handy for two reasons: You could change a configuration parameter for a runninginstance and not have to save the change to the SPFILE, which means that the value of the parameterwould be reset to the stored value on the next startup You can also use the SPFILE with Real ApplicationClusters, discussed later in this chapter, where multiple instances worked together in a cluster and sharedthe same initialization procedures
Control File
The control file is used to store key information about an instance, such as the name of the instance, thetime the database was created, and the state of backup and log files for the database An Oracle instancerequires a control file in order to operate Although a control can be rebuilt, most Oracle installations usemultiple copies of the control file to avoid this possibility
Redo Log Files
One of key features of a relational database is its ability to recover to a logically consistent state, even inthe event of a failure Every relational database, including Oracle, uses a set of redo log files These fileskeep track of every interaction with the database In the event of a database failure, an administrator canrecover the database by restoring the last backup and then applying the redo log files to replay userinteractions with the database
Redo log files eventually fill up and roll over to start a new volume You can set up Oracle to avoid writingover existing logfiles by creating the database to automatically archive log files in ARCHIVELOG mode,which is discussed in detail in the Oracle documentation
Since redo logs are crucial for restoring a database in the event of a failure, many Oracle shops set up aninstance to keep multiple copies of a redo log file
Rollback Segments
Unlike all other major databases, Oracle also uses rollback segments to store previous versions of data inthe database The use of rollback segments makes it possible for the Oracle database to avoid the use ofread locks, which can significantly reduce performance degradation based on multiuser access as well asproviding a consistent view of data at any particular point in time For more on rollback segments andhow they support multiuser concurrency, see Chapter 3, “Handling Multiple Users,” which covers thisimportant topic in detail
Because rollback segments track every change to data, the rollback segments are updated as soon as achange is made This real-time update lets the Oracle database delay writing its redo log files until atime when these writes can be done efficiently
Oracle 10g includes the ability to designate an automatic UNDO tablespace, which assigns the responsibility
for managing rollback segments to the Oracle database itself
Memory Used by an Instance
Figure 1-1, shown previously, includes several areas of memory that are used by an individual Oracleinstance
Trang 40System Global Area
The System Global Area (SGA) is an area of memory that is accessible to all user processes of an Oracleinstance Three main areas are used by the SGA:
❑ The redo log buffer holds information used for recovery until the information can be written tothe redo log
❑ The shared pool holds information that can be shared across user processes, such as executionplans for SQL statements, compiled stored procedures, and information retrieved from theOracle data dictionary
❑ The database buffer pools are a group of memory areas that are used to hold data blocks A datablock held in a buffer pool can be accessed much more rapidly than going to disk to retrieve the block, so efficient use of these memory pools is essential for achieving optimal performance.Following are the three basic database buffer pools:
❑ The DEFAULT pool holds all database objects, unless otherwise specified
❑ The KEEP pool is used to hold objects in memory if specified for a table or index
❑ The RECYCLE pool is used for objects that are not likely to be reused again.Keep the following two points in mind:
❑ For all of these pools, the Oracle instance uses a Least Recently Used (LRU) algorithm to determine what data blocks to swap out
❑ In addition to these main pools, the Oracle instance can also use a large pool,which is used for shared server, backup and recovery, and I/O operations Youcan either configure a large pool or Oracle can create it automatically, if you configure adaptive parallelism, which is described further in Chapter 2
Program Global Area
The Program Global Area (PGA) is an area of memory that is just available to a single server process.The PGA contains items like user variables and cursor information for an individual user’s SQL state-ment, such as the number of rows that have been retrieved so far The PGA is also used for sorting datafor an individual user process
Each time a new SQL statement is received for a user, a new space in the PGA has to be initialized Toavoid this overhead, transaction-intensive applications, such an online transaction processing (OLTP)applications, typically use a small set of SQL statements that are continually reused by a user process,reducing this potential source of overhead
You can have a single server process handle more than one user process by configuring shared servers, which are described in Chapter 2, “Using SQL.”
The database administrator typically does the memory allocations for these areas, but setting these values inappropriately can have a dramatic affect on the perfor-
mance of your applications Oracle 10g makes it easier to manage these portions of
memory, since it eliminates the need to specify an allocation for the individual
com-ponents of each of these pools With Oracle 10g, you can simply set a maximum size
for the SGA and the PGA, and Oracle will take care of the allocation for the ual components of these areas.
individ-5