Tải bản đầy đủ (.pdf) (7 trang)

a0004 01 expert oracle database architectur morebook vn 2325

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (235.24 KB, 7 trang )


5300FM.qxd

8/22/05

4:35 PM

Page i

Expert Oracle Database
Architecture
9i and 10g Programming
Techniques and Solutions

Thomas Kyte


5300FM.qxd

8/22/05

4:35 PM

Page ii

Expert Oracle Database Architecture: 9i and 10g Programming Techniques and Solutions
Copyright © 2005 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 (pbk): 1-59059-530-0


Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Lead Editor: Tony Davis
Technical Reviewer: Jonathan Lewis, Roderick Manalac, Michael Möller, Gabe Romanescu
Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis,
Jason Gilmore, Jonathan Hassell, Chris Mills, Dominic Shakeshaft, Jim Sumser
Associate Publisher: Grace Wong
Project Manager: Sofia Marchant
Copy Edit Manager: Nicole LeClerc
Assistant Production Director: Kari Brooks-Copony
Production Editor: Katie Stence
Compositor: Dina Quan
Proofreader: Linda Marousek
Indexer: Broccoli Information Management
Artist: Kinetic Publishing Services, LLC
Interior Designer: Van Winkle Design Group
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail , or
visit .
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley,
CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail , or visit .
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 in the Source Code section.



5300FM.qxd

8/22/05

4:35 PM

Page iii

Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiv
About the Technical Reviewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Setting Up Your Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv

■CHAPTER 1

Developing Successful Oracle Applications

...............1

My Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
The Black Box Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
How (and How Not) to Develop Database Applications . . . . . . . . . . . . . . . . 9
Understanding Oracle Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Understanding Concurrency Control . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Multi-Versioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Database Independence? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

“How Do I Make It Run Faster?” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
The DBA–Developer Relationship . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

■CHAPTER 2

Architecture Overview

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

Defining Database and Instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
The SGA and Background Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Connecting to Oracle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Dedicated Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Shared Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Mechanics of Connecting over TCP/IP . . . . . . . . . . . . . . . . . . . . . . . . 60
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

iii


5300FM.qxd

iv

8/22/05

4:35 PM

Page iv


■CONTENTS

■CHAPTER 3

Files

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

Parameter Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
What Are Parameters? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Legacy init.ora Parameter Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Server Parameter Files (SPFILEs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Parameter File Wrap-Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Trace Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Requested Trace Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Trace Files Generated in Response to Internal Errors . . . . . . . . . . . . 83
Trace File Wrap-Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Alert File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Data Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
A Brief Review of File System Mechanisms . . . . . . . . . . . . . . . . . . . . 89
The Storage Hierarchy in an Oracle Database . . . . . . . . . . . . . . . . . . 90
Dictionary-Managed and Locally-Managed Tablespaces . . . . . . . . 94
Temp Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Control Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Redo Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Online Redo Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Archived Redo Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Password Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Change Tracking File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

Flashback Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Flashback Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Flash Recovery Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
DMP Files (EXP/IMP Files) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Data Pump Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Flat Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

■CHAPTER 4

Memory Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
The Process Global Area and User Global Area . . . . . . . . . . . . . . . . . . . . . 115
Manual PGA Memory Management . . . . . . . . . . . . . . . . . . . . . . . . . 116
Automatic PGA Memory Management . . . . . . . . . . . . . . . . . . . . . . . 123
Choosing Between Manual and Auto Memory Management . . . . 133
PGA and UGA Wrap-Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
The System Global Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Fixed SGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Redo Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140


5300INDEX.qxd

8/22/05

4:33 PM

Page 723

■INDEX


transaction address (TADDR), 324
transaction API, 18
transaction ID, 210
transaction isolation levels
concurrency control, 232
dirty read, 232
non-repeatable read, 232
overview, 232–34
phantom read, 233
READ COMMITTED, 235–37
READ ONLY, 233, 241–42
READ UNCOMMITTED, 233–35
REPEATABLE READ, 233, 237–39
SERIALIZABLE, 233, 239–41
SQL/92 standard, 232
transaction locks. See TX (transaction) locks
transaction-level atomicity, 262
transactions
atomicity
overview, 257
procedure-level atomicity, 259–62
statement-level atomicity, 257–59
transaction-level atomicity, 262
autonomous transactions
how they work, 275–77
overview, 275
when to use, 277–81
bad transaction habits
committing in a loop, 266, 268–72

overview, 265–66
using autocommit, 272
distributed transactions, 273–74
integrity constraints and transactions
DEFERRABLE constraints and cascading
updates, 263–65
IMMEDIATE constraints, 262–63
overview, 262
overview, 255
transaction control statements, 256–57
Transparent Network Substrate (TNS), 60
triggers, 307, 626
TRIM function, 498, 666
true temporary tablespace, 94–95
TRUNC function, 525
TRUNCATE function, 342, 679
TRUNCATE option, 652, 679
tuning database, 42
two-phase commit (2PC), 174
TX (transaction) locks, 209–15, 229, 231
DML locks, 209
INITRANS parameter, 214
MAXTRANS parameter, 214
transactional mechanisms, 209
using, 210
Type2 undo segment type, 340

U
Undo, 21, 25, 248. See also redo; rollback
generating, 323

how works with redo, 287–91
introduction, 323
issues with undo segments, 323
ORA-01555: snapshot too old error, 325
delayed block cleanout, 332–36
overview, 325–26
undo segments are too small, 326–32
overview, 283, 323
redo log buffer, 287
and temporary tables, 319–22
what generates most and least undo, 323–25
UNDO_RETENTION clause, 326, 551
UNIFORM locally-managed tablespaces,
634–37, 639
UNIFORM SIZE tablespace, 631
UNIFORM tablespace, 636
UNIFORM_TEST, 636
unique index, 424
unloader PL/SQL utility
control file, 693
RUN function, 696
unloading data in SQLLDR friendly format,
692
unloading data, 692, 701–3
UNRECOVERABLE clause, 310
unused indexes, reasons for, 475
functions used implicitly on columns, 477
functions used on columns, 477
index on nullable columns, 477
index used to be slower, 481

index would be slower, 480
leading edge of index not used in query, 475
UPDATE GLOBAL INDEXES clause, 597
UPDATE statement, 203, 234, 246, 248, 268, 307,
323, 394, 474
UPDATE trigger, 581
UPDATE/INSERT, 639
updates
blocked, 203
cascading, 263–65
lost, preventing, 17–20
UPPER function, 660
UROWID data type, 491
US7ASCII character set, 492
USER, 88
User Global Area (UGA), 115–17, 119–20, 126,
130–31
USER_DUMP_DEST parameter, 80
USER_IND_EXPRESSIONS view, 467
USER_INDEXES view, 444
user-defined locks, 229

723


5300INDEX.qxd

724

8/22/05


4:33 PM

Page 724

■INDEX

utility background processes
CJQ0 and Jnnn processes (job queues),
179–80
CTWR (change tracking processes), 181
database architecture, 178
EMNn (event monitor processes), 180
MMAN (memory manager), 180
MMON, MMNL, and Mnnn (manageability
monitors), 180
overview, 179
QMNC and Qnnn (advanced queues), 180
QMNn, 180
RVWR (recovery writer), 181
SNPn, 179
UTL_FILE function, 693
UTL_FILE function, Windows, 694
UTL_FILE tool, 113
UTL_MAIL, 252
UTL_RAW variable, 668
UTL_RAW.CAST_TO_VARCHAR2 package, 673
UTL_SMTP, 252

V

V$ view, 78, 170
V$CONTROLFILE, 54
V$DATAFILE, 54
V$INSTANCE view, 81
V$LOCK table, 211–17
V$LOCK view, 6
V$LOGFILE, 54
V$MYSTAT view, 300, 302
V$PARAMETER view, 67, 81
V$PROCESS view, 81
V$SESSION table, 39, 211, 622, 625
V$SESSION view, 81
V$SGA_DYNAMIC_COMPONENTS view, 138
V$SGASTAT view, 135
V$SQL, 6

V$STATNAME view, 300
V$TRANSACTION table, 211, 625
V$UNDOSTAT command, 270
VALUES ( DEFAULT ) clause, 576
VAR attribute, 663, 667
VARCHAR2 data type, 490, 499
VARCHAR2 object, 417
VARCHAR2 type, 496, 502, 541
vendor extensions, 35
vendor-specific database features, 31
version column, optimistic locking using,
190–93
vertical scaling, 177
VIEW_TEXT column, 516

views, 471
Visual Basic code, 41
VSIZE function, 509

W
WAIT method, 216
watch_stat.sql script, 118, 125, 127
WE8ISO8859P1 character set, 492, 669
willing to wait mode, 221
WORKAREA_SIZE_POLICY parameter, 124
write consistency
consistent reads and current reads, 247–49
importance of restart, 252–53
overview, 246–47
seeing a restart, 249–52
WRITEAPPEND package, 673

X
X$ tables, 142
X$BH table, 142

Y
YEAR TO MONTH type, 537



×