Oracle Database Architecture Companion eBook Available Expert SECOND EDITION 7.5 x 9.25 spine = 1.5625" 832 page count THE EXPERT’S VOICE ® IN ORACLE Expert Oracle Database Architecture Oracle Database 9i, 10g, and 11g Programming Techniques and Solutions Thomas Kyte Forewords by Jonathan Lewis and Ken Jacobs (aka “Dr. DBA”) SECOND EDITION Kyte this print for content only—size & color not accurate CYAN MAGENTA YELLOW BLACK PANTONE 123 C BOOKS FOR PROFESSIONALS BY PROFESSIONALS ® US $59.99 Shelve in: Databases/Oracle User level: Intermediate–Advanced www.apress.com SOURCE CODE ONLINE Companion eBook See last page for details on $10 eBook version ISBN 978-1-4302-2946-9 9 781430 229469 5 59 9 9 THE APRESS ROADMAP Expert Oracle Database Architecture Oracle SQL Recipes Beginning Oracle PL/SQL Beginning Oracle SQL Troubleshooting Oracle Performance Pro ODP.NET for Oracle Database 11g Expert Oracle Database Architecture: Oracle Database 9i, 10g, and 11g Programming Techniques and Solutions, Second Edition Dear Reader, Expert Oracle Database Architecture, 2nd Edition is a book that explores and defines the Oracle database. In this book I’ve selected what I consider to be the most important Oracle architecture features, and I teach them in a proof- by-example manner. You’ll learn what each feature is, how it works, how to implement software using it, and the common pitfalls associated with it. Most importantly, you’ll avoid the pitfall of treating Oracle Database as a black box. This second edition adds material reflecting the way that Oracle Database 11g Release 2 works, updates stories about implementation pitfalls, and discusses new capabilities in the database such as transparent column and tablespace encryption. You may be surprised at the number of changes from the first edi- tion. I was. Many times in preparing this edition I learned of changes in the way that Oracle Database works that I was not yet aware of. Expert Oracle Database Architecture, 2nd Edition is a reflection of what I do every day. The material covers topics and questions that I see people continually struggling with, and I cover these issues from a perspective of “When I use this, I do it this way.” This book is the culmination of many years’ experience using the Oracle database, in myriad situations. Ultimately, my goal in this book is to help DBAs and developers work together to build correct, high-performance, and scalable Oracle applications. Don’t treat Oracle Database as a black box. Take time to understand Oracle Database, and you will find that there are few information management prob- lems that you cannot solve quickly and easily. Tom Kyte Thomas Kyte, Author of Expert Oracle Database Architecture, First Edition Expert One-On-One TM Oracle Effective Oracle by Design Co-author of: Beginning Oracle Programming www.it-ebooks.info www.it-ebooks.info Praise for Expert Oracle Database Architecture: 9i and 10g Programming Techniques and Solutions “This book will help you make the best use of Oracle technology. Emulating Tom’s rational methodology, and demand for proof by example, will make you a far better technology thinker. Without question, this is one of the most important Oracle books you can possess.” —Ken Jacobs, (aka “Dr. DBA”) Vice President of Product Strategy (Server Technologies), Oracle Corporation “It’s an excellent book, full of plenty of deep insights about Oracle technology.” —Sean Hull, Heavyweight Internet Group (http://iheavy.com) www.it-ebooks.info www.it-ebooks.info Expert Oracle Database Architecture Oracle Database 9i, 10g, and 11g Programming Techniques and Solutions Second Edition ■ ■ ■ Thomas Kyte www.it-ebooks.info Expert Oracle Database Architecture: Oracle Database 9i, 10g, and 11g Programming Techniques and Solutions, Second Edition Copyright © 2010 by Thomas Kyte All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-2946-9 ISBN-13 (electronic): 978-1-4302-2947-6 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 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, are not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Jonathan Gennick Technical Reviewers: Christopher Beck, Melanie Caffrey, and Jason Straub Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Debra Kelly Copy Editors: Mary Behr and Sharon Terdeman Compositor: Mary Sudul Indexer: BIM Indexing and Proofreading Services Artist: April Milne Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. For information on translations, please e-mail rights@apress.com, 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/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at www.apress.com. www.it-ebooks.info v Contents at a Glance ■ Chapter 1: Developing Successful Oracle Applications 1 ■ Chapter 2: Architecture Overview 51 ■ Chapter 3: Files 67 ■ Chapter 4: Memory Structures 121 ■ Chapter 5: Oracle Processes 165 ■ Chapter 6: Locking and Latching 195 ■ Chapter 7: Concurrency and Multi-versioning 243 ■ Chapter 8: Transactions 267 ■ Chapter 9: Redo and Undo 299 ■ Chapter 10: Database Tables 345 ■ Chapter 11: Indexes 425 ■ Chapter 12: Datatypes 493 ■ Chapter 13: Partitioning 557 ■ Chapter 14: Parallel Execution 621 ■ Chapter 15: Data Loading and Unloading 657 ■ Chapter 16: Data Encryption 709 Index 751 www.it-ebooks.info ■ CONTENTS vi Contents Contents at a Glance v Foreword xviii Foreword from the First Edition xix About the Author xxii About the Technical Reviewers xxiii Acknowledgments xxiv Introduction xxv Setting Up Your Environment xxxii ■ Chapter 1: Developing Successful Oracle Applications 1 My Approach 2 The Black Box Approach 3 How (and How Not) to Develop Database Applications 11 Understanding Oracle Architecture 12 Understanding Concurrency Control 21 Multi-Versioning 25 Database Independence? 32 How Do I Make It Run Faster? 46 The DBA-Developer Relationship 48 Summary 49 www.it-ebooks.info ■ CONTENTS vii ■ Chapter 2: Architecture Overview 51 Defining Database and Instance 52 The SGA and Background Processes 58 Connecting to Oracle 60 Dedicated Server 60 Shared Server 62 Mechanics of Connecting over TCP/IP 63 Summary 66 ■ Chapter 3: Files 67 Parameter Files 68 What Are Parameters? 69 Legacy init.ora Parameter Files 73 Server Parameter Files (SPFILEs) 74 Converting to SPFILEs 75 Trace Files 82 Requested Trace Files 83 Trace Files Generated in Response to Internal Errors 88 Trace File Wrap-up 93 Alert File 93 Data Files 96 A Brief Review of File System Mechanisms 96 The Storage Hierarchy in an Oracle Database 97 Dictionary-Managed and Locally-Managed Tablespaces 101 Temp Files 103 Control Files 105 Redo Log Files 105 Online Redo Log 106 Archived Redo Log 108 Password Files 109 www.it-ebooks.info ■ CONTENTS viii Change Tracking File 113 Flashback Logs 114 Flashback Database 114 Flash Recovery Area 115 DMP Files (EXP/IMP Files) 116 Data Pump Files 117 Flat Files 120 Summary 120 ■ Chapter 4: Memory Structures 121 The Process Global Area and User Global Area 122 Manual PGA Memory Management 123 Automatic PGA Memory Management 129 Choosing Between Manual and Auto Memory Management 140 PGA and UGA Wrap-up 142 The System Global Area 142 Fixed SGA 148 Redo Buffer 148 Block Buffer Cache 149 Shared Pool 156 Large Pool 159 Java Pool 160 Streams Pool 160 Automatic SGA Memory Management 161 Automatic Memory Management 162 Summary 164 ■ Chapter 5: Oracle Processes 165 Server Processes 166 Dedicated Server Connections 166 Shared Server Connections 169 www.it-ebooks.info [...]... application architecture; it does not compare three tier to client/server Rather, it covers what the database can do and what you must understand about the way it works Since the database is at the heart of any application architecture, the book should have a broad audience As the title suggests, Expert Oracle Database Architecture concentrates on the database architecture and how the database itself... manager for Oracle Corporation, providing front-end and back-end Oracle solutions for the business needs of various clients She is co-author of several technical publications including Expert Oracle Practices: Oracle Database Administration from the Oak Table published by Apress, as well as Oracle Web Application Programming for PL/SQL Developers, The Oracle DBA Interactive Workbook, and Oracle Database. .. from my experiences developing Oracle software, and from working with fellow Oracle developers to help them build reliable and robust applications based on the Oracle database The book is basically a reflection of what I do every day and of the issues I see people encountering each and every day I covered what I felt was most relevant, namely the Oracle database and its architecture I could have written... works I cover the Oracle database architecture in depth: the files, memory structures, and processes that comprise an Oracle database and instance I then move on to discuss important database topics such as locking, concurrency controls, how transactions work, and redo and undo, and why it is important for you to know about these things Lastly, I examine the physical structures in the database such as... advanced Oracle database administration and PL/SQL development She is also a frequent Oracle conference speaker ■ Jason Straub has a bachelor's degree in mathematics and has been applying it to the computer science field for the past 15 years developing database driven Web applications Jason is on his second tour at Oracle Corporation and worked for Microsoft Corporation in between He has been developing Oracle. .. addition, I am the Tom behind the “Ask Tom” column in Oracle Magazine, where I answer people’s questions about the Oracle database and tools On a typical day, I receive and answer dozens of questions at http://asktom .oracle. com Every two months, I publish a “best of” in the magazine (all of the questions asked are available on the Web, stored in an Oracle database, of course) Additionally, I give technical... Developing Successful Oracle Applications This chapter sets out my essential approach to database programming All databases are not created equal, and in order to develop database- driven applications successfully and on time, you need to understand exactly what your particular database can do and how it does it If you do not know what xxvii www.it-ebooks.info ■ INTRODUCTION your database can do, you... that are very misunderstood by many in the Oracle world, namely “instance” and database. ” We also take a quick look at the System Global Area (SGA) and the processes behind the Oracle instance, and examine how the simple act of “connecting to Oracle takes place Chapter 3: Files This chapter covers in depth the eight types of files that make up an Oracle database and instance From the simple parameter... co-inventor of two US Patents on software methodologies, which were the basis for what is now known as Oracle Application Express Chris has reviewed other Oracle books including Tom’s first book, Expert One-On-One, and is himself the coauthor of two books, Beginning Oracle Programming and Mastering Oracle PL/SQL He resides in Northern Virginia with his wife, Marta, and four children, and when not spending... xxi www.it-ebooks.info ■ FOREWORD FROM THE FIRST EDITION About the Author ■ I am Tom Kyte I have been working for Oracle since version 7.0.9 (that’s 1993 for people who don’t mark time by Oracle versions) However, I’ve been working with Oracle since about version 5.1.5c (the $99 single-user version for DOS on 360KB floppy disks) Before coming to work at Oracle, I worked for more than six years as a systems . ROADMAP Expert Oracle Database Architecture Oracle SQL Recipes Beginning Oracle PL/SQL Beginning Oracle SQL Troubleshooting Oracle Performance Pro ODP.NET for Oracle Database 11g Expert Oracle Database. Oracle Database Architecture Companion eBook Available Expert SECOND EDITION 7.5 x 9.25 spine = 1.5625" 832 page count THE EXPERT S VOICE ® IN ORACLE Expert Oracle Database Architecture . Oracle Database Architecture: Oracle Database 9i, 10g, and 11g Programming Techniques and Solutions, Second Edition Dear Reader, Expert Oracle Database Architecture, 2nd Edition is a book