A96524 Dbconcepts 92
A96524 Dbconcepts 92
Database Concepts
Release 2 (9.2)
March 2002
Part No. A96524-01
Oracle9i Database Concepts, Release 2 (9.2)
Contributors: Lance Ashdown, Cathy Baird, Sandeepan Banerjee, Mark Bauer, Ruth Baylis, Pradeep
Bhanot, Janet Blowney, Allen Brumm, Ted Burroughs, Larry Carpenter, Donna Carver, Chandra
Chandrasekar, Gary Chen, Amit Ganesh, Tom Grant, Mike Hartstein, John Haydu, Susan Hillson,
Dominique Jeunot, Archna Kalra Johnson, Vishy Karra, Alex Keh, Susan Kotsovolos, Sushil Kumar,
Tirthankar Lahiri, Paul Lane, Simon Law, Jeff Levinger, Yunrui Li, Bryn Llewellyn, Diana Lorentz, Lenore
Luscher, Sheryl Maring, Ben Meng, Kuassi Mensah, Tony Morales, Ari Mozes, Subramanian Muralidhar,
Ravi Murthy, Sujatha Muthulingam, Gary Ngai, Kant Patel, Ananth Raghavan, Jack Raitto, Beck
Reitmeyer, Ann Rhee, Kathy Rich, John Russell, Vivian Schupmann, Ravi Shankar, Mark Smith, Richard
Smith, Ekrem Soylemez, Marie St. Gelais, Debbie Steiner, Bob Thome, Anh-Tuan Tran, Randy Urbano,
Stephen Vivian, Daniel Wong, Wanli Yang, Ruiling Zhang, Zulaikha
The Programs (which include both the software and documentation) contain proprietary information of
Oracle Corporation; they are provided under a license agreement containing restrictions on use and
disclosure and are also protected by copyright, patent and other intellectual and industrial property
laws. Reverse engineering, disassembly or decompilation of the Programs, except to the extent required
to obtain interoperability with other independently created software or as specified by law, is prohibited.
The information contained in this document is subject to change without notice. If you find any problems
in the documentation, please report them to us in writing. Oracle Corporation does not warrant that this
document is error-free. Except as may be expressly permitted in your license agreement for these
Programs, no part of these Programs may be reproduced or transmitted in any form or by any means,
electronic or mechanical, for any purpose, without the express written permission of Oracle Corporation.
If the Programs are delivered to the U.S. Government or anyone licensing or using the programs on
behalf of the U.S. Government, the following notice is applicable:
Restricted Rights Notice Programs delivered subject to the DOD FAR Supplement are "commercial
computer software" and use, duplication, and disclosure of the Programs, including documentation,
shall be subject to the licensing restrictions set forth in the applicable Oracle license agreement.
Otherwise, Programs delivered subject to the Federal Acquisition Regulations are "restricted computer
software" and use, duplication, and disclosure of the Programs shall be subject to the restrictions in FAR
52.227-19, Commercial Computer Software - Restricted Rights (June, 1987). Oracle Corporation, 500
Oracle Parkway, Redwood City, CA 94065.
The Programs are not intended for use in any nuclear, aviation, mass transit, medical, or other inherently
dangerous applications. It shall be the licensee's responsibility to take all appropriate fail-safe, backup,
redundancy, and other measures to ensure the safe use of such applications if the Programs are used for
such purposes, and Oracle Corporation disclaims liability for any damages caused by such use of the
Programs.
Oracle is a registered trademark, and Oracle9i, Oracle8i, Oracle7, Oracle Store, Oracle Transparent
Gateway, PL/SQL, Pro*C, Pro*Cobol, Pro*C/C++, Express, SQL*Net, and SQL*Plus are trademarks or
registered trademarks of Oracle Corporation. Other names may be trademarks of their respective
owners.
Contents
Preface....................................................................................................................................................... xxxiii
Audience ........................................................................................................................................... xxxiv
Organization..................................................................................................................................... xxxiv
Related Documentation ................................................................................................................. xxxvii
Conventions...................................................................................................................................... xxxix
Documentation Accessibility .............................................................................................................. xlii
iii
SQL Overview ............................................................................................................................. 1-10
SQL Statements .................................................................................................................... 1-10
Objects Overview........................................................................................................................ 1-12
Advantages of Objects ........................................................................................................ 1-12
PL/SQL Overview...................................................................................................................... 1-13
PL/SQL Program Units ...................................................................................................... 1-13
Java Overview ............................................................................................................................. 1-14
XML Overview............................................................................................................................ 1-15
Transactions Overview .............................................................................................................. 1-17
Commit and Roll Back Transactions................................................................................. 1-18
Savepoints............................................................................................................................. 1-19
Data Consistency Using Transactions .............................................................................. 1-19
Data Integrity Overview ............................................................................................................ 1-19
Integrity Constraints ........................................................................................................... 1-20
Keys ....................................................................................................................................... 1-20
SQL*Plus Overview.................................................................................................................... 1-21
Memory Structure and Processes Overview................................................................................ 1-21
An Oracle Instance...................................................................................................................... 1-24
Real Application Clusters: Multiple Instance Systems .................................................. 1-24
Memory Structures ..................................................................................................................... 1-25
System Global Area ............................................................................................................. 1-25
Program Global Area .......................................................................................................... 1-26
Process Architecture................................................................................................................... 1-26
User (Client) Processes........................................................................................................ 1-26
Oracle Processes................................................................................................................... 1-27
The Program Interface Mechanism .......................................................................................... 1-30
Communications Software and Oracle Net Services...................................................... 1-30
An Example of How Oracle Works.......................................................................................... 1-31
Application Architecture Overview .............................................................................................. 1-32
Client/Server Architecture........................................................................................................ 1-32
The Client.............................................................................................................................. 1-32
The Server ............................................................................................................................. 1-32
Multitier Architecture: Application Servers ........................................................................... 1-32
Distributed Databases Overview................................................................................................... 1-33
Location Transparency ....................................................................................................... 1-34
iv
Site Autonomy ..................................................................................................................... 1-34
Distributed Data Manipulation ......................................................................................... 1-34
Two-Phase Commit............................................................................................................. 1-34
Replication Overview ................................................................................................................ 1-35
Table Replication ................................................................................................................. 1-35
Multitier Materialized Views............................................................................................. 1-35
Streams Overview ...................................................................................................................... 1-36
Advanced Queuing Overview.................................................................................................. 1-38
Heterogeneous Services Overview .......................................................................................... 1-39
Data Concurrency and Consistency Overview ........................................................................... 1-40
Concurrency ................................................................................................................................ 1-40
Read Consistency........................................................................................................................ 1-40
Read Consistency, Undo Records, and Transactions..................................................... 1-41
Read-Only Transactions ..................................................................................................... 1-41
Locking Mechanisms.................................................................................................................. 1-42
Automatic Locking.............................................................................................................. 1-42
Manual Locking................................................................................................................... 1-42
Quiesce Database........................................................................................................................ 1-42
Database Security Overview .......................................................................................................... 1-43
Security Mechanisms ................................................................................................................. 1-44
Database Users and Schemas............................................................................................. 1-45
Privileges .............................................................................................................................. 1-45
Roles ...................................................................................................................................... 1-46
Storage Settings and Quotas .............................................................................................. 1-47
Profiles and Resource Limits ............................................................................................. 1-47
Selective Auditing of User Actions................................................................................... 1-48
Fine-Grained Auditing ....................................................................................................... 1-49
Database Administration Overview ............................................................................................. 1-49
Enterprise Manager Overview ................................................................................................. 1-49
Database Backup and Recovery Overview............................................................................. 1-50
Why Recovery Is Important............................................................................................... 1-50
Types of Failures.................................................................................................................. 1-50
Structures Used for Recovery ............................................................................................ 1-52
Data Warehousing Overview ......................................................................................................... 1-53
Differences Between Data Warehouse and OLTP Systems.................................................. 1-54
v
Workload .............................................................................................................................. 1-54
Data Modifications .............................................................................................................. 1-54
Schema Design ..................................................................................................................... 1-54
Typical Operations .............................................................................................................. 1-54
Historical Data ..................................................................................................................... 1-55
Data Warehouse Architecture................................................................................................... 1-55
Data Warehouse Architecture (Basic)............................................................................... 1-55
Data Warehouse Architecture (with a Staging Area)..................................................... 1-56
Data Warehouse Architecture (with a Staging Area and Data Marts) ........................ 1-57
Materialized Views..................................................................................................................... 1-58
OLAP Overview.......................................................................................................................... 1-58
Change Data Capture Overview .............................................................................................. 1-59
High Availability Overview ........................................................................................................... 1-60
Transparent Application Failover ............................................................................................ 1-61
Elements Affected by Transparent Application Failover .............................................. 1-61
Online Reorganization Architecture ........................................................................................ 1-62
Data Guard Overview................................................................................................................ 1-63
Data Guard Configurations ............................................................................................... 1-63
Data Guard Components ................................................................................................... 1-63
LogMiner Overview ................................................................................................................... 1-65
Real Application Clusters .......................................................................................................... 1-65
Real Application Clusters Guard ............................................................................................. 1-66
Content Management Overview.................................................................................................... 1-67
Oracle Internet File System Overview ..................................................................................... 1-68
vi
Row Data ................................................................................................................................ 2-5
Free Space ............................................................................................................................... 2-5
Free Space Management .............................................................................................................. 2-6
Availability and Compression of Free Space in a Data Block......................................... 2-6
Row Chaining and Migrating.............................................................................................. 2-7
PCTFREE, PCTUSED, and Row Chaining......................................................................... 2-7
Extents Overview ................................................................................................................................ 2-8
When Extents Are Allocated....................................................................................................... 2-8
Determine the Number and Size of Extents ............................................................................. 2-8
How Extents Are Allocated......................................................................................................... 2-9
When Extents Are Deallocated................................................................................................. 2-10
Extents in Nonclustered Tables......................................................................................... 2-10
Extents in Clustered Tables................................................................................................ 2-11
Extents in Materialized Views and Their Logs ............................................................... 2-11
Extents in Indexes................................................................................................................ 2-11
Extents in Temporary Segments ....................................................................................... 2-11
Extents in Rollback Segments ............................................................................................ 2-12
Segments Overview.......................................................................................................................... 2-12
Introduction to Data Segments................................................................................................. 2-12
Introduction to Index Segments ............................................................................................... 2-13
Introduction to Temporary Segments ..................................................................................... 2-13
Operations that Require Temporary Segments .............................................................. 2-14
Segments in Temporary Tables and Their Indexes ........................................................ 2-14
How Temporary Segments Are Allocated ...................................................................... 2-14
Automatic Undo Management................................................................................................. 2-16
Undo Mode .......................................................................................................................... 2-16
Undo Quota.......................................................................................................................... 2-17
Undo Retention Control ..................................................................................................... 2-17
External Views ..................................................................................................................... 2-18
vii
The SYSTEM Tablespace.............................................................................................................. 3-7
The Data Dictionary .............................................................................................................. 3-8
PL/SQL Program Units Description .................................................................................. 3-8
Undo Tablespaces ......................................................................................................................... 3-8
Creation of Undo Tablespaces ............................................................................................. 3-9
Assignment of Undo Tablespaces ....................................................................................... 3-9
Default Temporary Tablespace................................................................................................. 3-10
How to Specify a Default Temporary Tablespace .......................................................... 3-10
Using Multiple Tablespaces ...................................................................................................... 3-10
Managing Space in Tablespaces ............................................................................................... 3-11
Locally Managed Tablespaces ........................................................................................... 3-11
Segment Space Management in Locally Managed Tablespaces................................... 3-12
Dictionary Managed Tablespaces ..................................................................................... 3-13
Multiple Block Sizes ................................................................................................................... 3-13
Online and Offline Tablespaces................................................................................................ 3-13
When a Tablespace Goes Offline....................................................................................... 3-14
Use of Tablespaces for Special Procedures ...................................................................... 3-14
Read-Only Tablespaces.............................................................................................................. 3-15
Temporary Tablespaces for Sort Operations .......................................................................... 3-16
Sort Segments ....................................................................................................................... 3-16
Creation of Temporary Tablespaces ................................................................................. 3-16
Transport of Tablespaces Between Databases ........................................................................ 3-17
How to Move or Copy a Tablespace to Another Database ........................................... 3-17
Datafiles Overview........................................................................................................................... 3-18
Datafile Contents ........................................................................................................................ 3-18
Size of Datafiles ........................................................................................................................... 3-19
Offline Datafiles .......................................................................................................................... 3-19
Temporary Datafiles................................................................................................................... 3-19
Control Files Overview.................................................................................................................... 3-20
Control File Contents ................................................................................................................. 3-20
Multiplexed Control Files.......................................................................................................... 3-22
viii
Base Tables ............................................................................................................................. 4-3
User-Accessible Views.......................................................................................................... 4-3
SYS, Owner of the Data Dictionary............................................................................................ 4-3
How the Data Dictionary Is Used.................................................................................................... 4-3
How Oracle Uses the Data Dictionary ...................................................................................... 4-3
Public Synonyms for Data Dictionary Views.................................................................... 4-4
Cache the Data Dictionary for Fast Access ........................................................................ 4-4
Other Programs and the Data Dictionary.......................................................................... 4-4
How to Use the Data Dictionary ................................................................................................ 4-5
Views with the Prefix USER ................................................................................................ 4-5
Views with the Prefix ALL................................................................................................... 4-6
Views with the Prefix DBA .................................................................................................. 4-6
The DUAL Table.................................................................................................................... 4-6
Dynamic Performance Tables .......................................................................................................... 4-7
Database Object Metadata ................................................................................................................ 4-7
ix
Resolution of In-Doubt Distributed Transaction .............................................................. 5-9
Open a Database in Read-Only Mode ................................................................................ 5-9
Database and Instance Shutdown ................................................................................................. 5-10
Close a Database ......................................................................................................................... 5-10
Close the Database by Terminating the Instance............................................................ 5-10
Unmount a Database.................................................................................................................. 5-11
Shut Down an Instance .............................................................................................................. 5-11
Abnormal Instance Shutdown........................................................................................... 5-11
6 Application Architecture
Client/Server Architecture................................................................................................................. 6-2
Multitier Architecture ........................................................................................................................ 6-5
Clients............................................................................................................................................. 6-6
Application Servers ...................................................................................................................... 6-6
Database Servers ........................................................................................................................... 6-7
Oracle Net Services............................................................................................................................. 6-7
Connectivity ........................................................................................................................... 6-8
Manageability......................................................................................................................... 6-8
Internet Scalability................................................................................................................. 6-8
Internet Security..................................................................................................................... 6-8
How Oracle Net Services Works ................................................................................................ 6-8
The Listener ................................................................................................................................... 6-9
Service Information Registration......................................................................................... 6-9
7 Memory Architecture
Introduction to Oracle Memory Structures.................................................................................... 7-2
System Global Area (SGA) Overview ............................................................................................ 7-3
Dynamic SGA ................................................................................................................................ 7-4
Dynamic SGA Granules........................................................................................................ 7-5
Database Buffer Cache ................................................................................................................. 7-7
Organization of the Database Buffer Cache ...................................................................... 7-7
The LRU Algorithm and Full Table Scans ......................................................................... 7-8
Size of the Database Buffer Cache....................................................................................... 7-8
Multiple Buffer Pools .......................................................................................................... 7-10
Redo Log Buffer .......................................................................................................................... 7-11
x
Shared Pool.................................................................................................................................. 7-11
Library Cache....................................................................................................................... 7-12
Shared SQL Areas and Private SQL Areas ...................................................................... 7-12
PL/SQL Program Units and the Shared Pool ................................................................. 7-12
Dictionary Cache ................................................................................................................. 7-13
Allocation and Reuse of Memory in the Shared Pool .................................................... 7-13
Large Pool .................................................................................................................................... 7-15
Control of the SGA’s Use of Memory...................................................................................... 7-16
Other SGA Initialization Parameters ....................................................................................... 7-16
Physical Memory................................................................................................................. 7-16
SGA Starting Address......................................................................................................... 7-16
Extended Buffer Cache Mechanism.................................................................................. 7-17
Program Global Areas (PGA) Overview ...................................................................................... 7-17
Content of the PGA .................................................................................................................... 7-17
Private SQL Area ................................................................................................................. 7-17
Session Memory................................................................................................................... 7-19
SQL Work Areas ......................................................................................................................... 7-19
PGA Memory Management for Dedicated Mode ................................................................. 7-20
Dedicated and Shared Servers ....................................................................................................... 7-22
Software Code Areas........................................................................................................................ 7-22
8 Process Architecture
Introduction to Processes .................................................................................................................. 8-2
Multiple-Process Oracle Systems ............................................................................................... 8-2
Types of Processes ........................................................................................................................ 8-2
User Processes Overview................................................................................................................... 8-4
Connections and Sessions ........................................................................................................... 8-4
Oracle Processes Overview ............................................................................................................... 8-5
Server Processes............................................................................................................................ 8-5
Background Processes.................................................................................................................. 8-5
Database Writer Process (DBWn) ....................................................................................... 8-8
Log Writer Process (LGWR) ................................................................................................ 8-9
Checkpoint Process (CKPT) ............................................................................................... 8-11
System Monitor Process (SMON) ..................................................................................... 8-11
Process Monitor Process (PMON) .................................................................................... 8-12
xi
Recoverer Process (RECO) ................................................................................................. 8-12
Job Queue Processes............................................................................................................ 8-12
Archiver Processes (ARCn) ................................................................................................ 8-13
Lock Manager Server Process (LMS) ................................................................................ 8-14
Queue Monitor Processes (QMNn)................................................................................... 8-14
Trace Files and the Alert Log .................................................................................................... 8-14
Shared Server Architecture ............................................................................................................. 8-15
Scalability ..................................................................................................................................... 8-16
Dispatcher Request and Response Queues............................................................................. 8-16
Dispatcher Processes (Dnnn).............................................................................................. 8-19
Shared Server Processes (Snnn) ................................................................................................ 8-19
Restricted Operations of the Shared Server ............................................................................ 8-20
Dedicated Server Configuration .................................................................................................... 8-21
The Program Interface...................................................................................................................... 8-22
Program Interface Structure...................................................................................................... 8-23
Program Interface Drivers ......................................................................................................... 8-23
Communications Software for the Operating System........................................................... 8-24
xii
CPU Method......................................................................................................................... 9-12
Active Session Pool with Queuing.................................................................................... 9-12
Degree of Parallelism Limit ............................................................................................... 9-12
Automatic Consumer Group Switching .......................................................................... 9-12
Execution Time Limit.......................................................................................................... 9-13
Undo Pool............................................................................................................................. 9-13
CPU Resource Allocation .......................................................................................................... 9-13
CPU Allocation Rules ......................................................................................................... 9-15
Levels and Priorities............................................................................................................ 9-16
Interaction with Operating-System Resource Control.............................................................. 9-17
Dynamic Reconfiguration ......................................................................................................... 9-18
Part IV Data
10 Schema Objects
Introduction to Schema Objects .................................................................................................... 10-2
Tables................................................................................................................................................... 10-5
How Table Data Is Stored.......................................................................................................... 10-6
Row Format and Size .......................................................................................................... 10-6
Rowids of Row Pieces......................................................................................................... 10-9
Column Order...................................................................................................................... 10-9
Nulls Indicate Absence of Value ............................................................................................ 10-10
Default Values for Columns.................................................................................................... 10-10
Default Value Insertion and Integrity Constraint Checking....................................... 10-11
Partitioned Tables..................................................................................................................... 10-12
Nested Tables ............................................................................................................................ 10-13
Temporary Tables..................................................................................................................... 10-13
Segment Allocation ........................................................................................................... 10-14
Parent and Child Transactions ........................................................................................ 10-14
External Tables.......................................................................................................................... 10-14
The Access Driver.............................................................................................................. 10-15
Data Loading with External Tables ................................................................................ 10-15
Parallel Access to External Tables................................................................................... 10-16
Views ................................................................................................................................................. 10-16
How Views are Stored ............................................................................................................. 10-17
xiii
How Views Are Used............................................................................................................... 10-18
Mechanics of Views .................................................................................................................. 10-19
Globalization Support Parameters in Views ................................................................. 10-19
Use of Indexes Against Views ......................................................................................... 10-19
Dependencies and Views......................................................................................................... 10-20
Updatable Join Views............................................................................................................... 10-20
Object Views .............................................................................................................................. 10-21
Inline Views ............................................................................................................................... 10-21
Materialized Views......................................................................................................................... 10-22
Define Constraints on Views................................................................................................... 10-23
Refresh Materialized Views .................................................................................................... 10-24
Materialized View Logs ........................................................................................................... 10-24
Dimensions ...................................................................................................................................... 10-25
The Sequence Generator ............................................................................................................... 10-25
Synonyms ......................................................................................................................................... 10-27
Indexes .............................................................................................................................................. 10-28
Unique and Nonunique Indexes ............................................................................................ 10-30
Composite Indexes ................................................................................................................... 10-30
Indexes and Keys ...................................................................................................................... 10-31
Indexes and Nulls ..................................................................................................................... 10-31
Function-Based Indexes ........................................................................................................... 10-32
Uses of Function-Based Indexes...................................................................................... 10-32
Optimization with Function-Based Indexes .................................................................. 10-33
Dependencies of Function-Based Indexes ..................................................................... 10-33
How Indexes Are Stored.......................................................................................................... 10-34
Format of Index Blocks ..................................................................................................... 10-34
The Internal Structure of Indexes.................................................................................... 10-35
Index Properties................................................................................................................. 10-36
Advantages of B-tree Structure ....................................................................................... 10-37
How Indexes Are Searched ..................................................................................................... 10-38
Index Unique Scan............................................................................................................. 10-38
Index Range Scan............................................................................................................... 10-40
Index Range Scan Descending......................................................................................... 10-43
Key Compression...................................................................................................................... 10-45
Prefix and Suffix Entries ................................................................................................... 10-45
xiv
Performance and Storage Considerations ..................................................................... 10-46
Uses of Key Compression ................................................................................................ 10-46
Reverse Key Indexes ................................................................................................................ 10-47
Bitmap Indexes.......................................................................................................................... 10-48
Benefits for Data Warehousing Applications................................................................ 10-48
Cardinality.......................................................................................................................... 10-49
Bitmap Index Example ..................................................................................................... 10-50
Bitmap Indexes and Nulls................................................................................................ 10-52
Bitmap Indexes on Partitioned Tables............................................................................ 10-53
Bitmap Join Indexes.................................................................................................................. 10-53
Four Join Models ............................................................................................................... 10-53
Creation of a Bitmap Join Index ...................................................................................... 10-56
Index-Organized Tables ................................................................................................................ 10-57
Benefits of Index-Organized Tables....................................................................................... 10-58
Index-Organized Tables with Row Overflow Area............................................................. 10-59
Secondary Indexes on Index-Organized Tables................................................................... 10-60
Bitmap Indexes on Index-Organized Tables ........................................................................ 10-61
Mapping Table................................................................................................................... 10-61
Partitioned Index-Organized Tables...................................................................................... 10-62
B-tree Indexes on UROWID Columns for Heap- and Index-Organized Tables ............. 10-62
Index-Organized Table Applications .................................................................................... 10-62
Application Domain Indexes ....................................................................................................... 10-62
Clusters ............................................................................................................................................. 10-63
Hash Clusters................................................................................................................................... 10-65
xv
Hash Partitioning........................................................................................................................ 11-9
Hash Partitioning Example .............................................................................................. 11-10
Composite Partitioning ............................................................................................................ 11-10
Composite Partitioning Range-Hash Example ............................................................. 11-11
Composite Partitioning Range-List Example ................................................................ 11-12
When to Partition a Table ........................................................................................................ 11-13
Partitioned Indexes......................................................................................................................... 11-13
Local Partitioned Indexes ........................................................................................................ 11-14
Global Partitioned Indexes ...................................................................................................... 11-15
Maintenance of Global Partitioned Indexes .................................................................. 11-16
Global Nonpartitioned Indexes .............................................................................................. 11-17
Partitioned Index Examples .................................................................................................... 11-18
Example of Index Creation: Starting Table Used for Examples ................................. 11-18
Example of a Local Index Creation ................................................................................. 11-18
Example of a Global Index Creation............................................................................... 11-18
Example of a Global Partitioned Index Creation .......................................................... 11-18
Example of a Partitioned Index-Organized Table Creation ........................................ 11-19
Miscellaneous Information about Creating Indexes on Partitioned Tables ..................... 11-19
Using Partitioned Indexes in OLTP Applications................................................................ 11-19
Using Partitioned Indexes in Data Warehousing and DSS Applications......................... 11-19
Partitioned Indexes on Composite Partitions....................................................................... 11-20
Partitioning to Improve Performance ......................................................................................... 11-20
Partition Pruning ...................................................................................................................... 11-20
Partition Pruning Example............................................................................................... 11-21
Partition-wise Joins................................................................................................................... 11-21
Parallel DML.............................................................................................................................. 11-22
12 Native Datatypes
Introduction to Oracle Datatypes .................................................................................................. 12-2
Character Datatypes ......................................................................................................................... 12-3
CHAR Datatype .......................................................................................................................... 12-3
VARCHAR2 and VARCHAR Datatypes ................................................................................ 12-4
VARCHAR Datatype .......................................................................................................... 12-4
Length Semantics for Character Datatypes............................................................................. 12-4
NCHAR and NVARCHAR2 Datatypes .................................................................................. 12-5
xvi
NCHAR................................................................................................................................. 12-6
NVARCHAR2 ...................................................................................................................... 12-6
Use of Unicode Data in an Oracle Database ........................................................................... 12-6
Implicit Type Conversion................................................................................................... 12-7
LOB Character Datatypes.......................................................................................................... 12-7
LONG Datatype.......................................................................................................................... 12-7
NUMBER Datatype .......................................................................................................................... 12-8
Internal Numeric Format........................................................................................................... 12-9
DATE Datatype ............................................................................................................................... 12-10
Use of Julian Dates ................................................................................................................... 12-11
Date Arithmetic......................................................................................................................... 12-11
Centuries and the Year 2000 ................................................................................................... 12-12
Daylight Savings Support ....................................................................................................... 12-12
Time Zones ................................................................................................................................ 12-12
Example: ............................................................................................................................. 12-13
LOB Datatypes ................................................................................................................................ 12-13
BLOB Datatype ......................................................................................................................... 12-14
CLOB and NCLOB Datatypes ................................................................................................ 12-15
BFILE Datatype ......................................................................................................................... 12-15
RAW and LONG RAW Datatypes ............................................................................................... 12-15
ROWID and UROWID Datatypes............................................................................................... 12-16
The ROWID Pseudocolumn.................................................................................................... 12-17
Physical Rowids........................................................................................................................ 12-17
Extended Rowids............................................................................................................... 12-18
Restricted Rowids.............................................................................................................. 12-19
Examples of Rowid Use.................................................................................................... 12-19
How Rowids Are Used..................................................................................................... 12-21
Logical Rowids.......................................................................................................................... 12-21
Comparison of Logical Rowids with Physical Rowids................................................ 12-22
Guesses in Logical Rowids............................................................................................... 12-22
Rowids in Non-Oracle Databases .......................................................................................... 12-23
ANSI, DB2, and SQL/DS Datatypes ........................................................................................... 12-23
XML Datatypes................................................................................................................................ 12-25
XMLType Datatype .................................................................................................................. 12-25
URI Datatypes ................................................................................................................................. 12-26
xvii
Data Conversion.............................................................................................................................. 12-26
xviii
SQLJ ............................................................................................................................................ 13-21
SQLJ Object Types............................................................................................................. 13-21
Datatype Evolution......................................................................................................................... 13-22
Introduction to Object Views ....................................................................................................... 13-23
Advantages of Object Views ................................................................................................... 13-23
How Object Views Are Defined ............................................................................................. 13-24
Use of Object Views.................................................................................................................. 13-25
Updates of Object Views ......................................................................................................... 13-26
Updates of Nested Table Columns in Views........................................................................ 13-26
View Hierarchies ...................................................................................................................... 13-27
xix
PL/SQL Overview ........................................................................................................................... 14-16
How PL/SQL Runs .................................................................................................................. 14-17
Native Execution................................................................................................................ 14-17
Interpreted Execution ....................................................................................................... 14-17
Language Constructs for PL/SQL.......................................................................................... 14-19
Variables and Constants ................................................................................................... 14-19
Cursors ................................................................................................................................ 14-19
Exceptions........................................................................................................................... 14-20
Dynamic SQL in PL/SQL................................................................................................. 14-20
PL/SQL Program Units ........................................................................................................... 14-21
Stored Procedures and Functions ................................................................................... 14-21
PL/SQL Packages.............................................................................................................. 14-27
PL/SQL Collections and Records........................................................................................... 14-30
Collections .......................................................................................................................... 14-30
Records................................................................................................................................ 14-30
PL/SQL Server Pages............................................................................................................... 14-30
Java Overview.................................................................................................................................. 14-31
Java and Object-Oriented Programming Terminology....................................................... 14-32
Classes ................................................................................................................................. 14-32
Class Hierarchy ......................................................................................................................... 14-34
Interfaces .................................................................................................................................... 14-35
Polymorphism ........................................................................................................................... 14-36
The Java Virtual Machine (JVM)............................................................................................. 14-37
Why Use Java in Oracle?.......................................................................................................... 14-39
Multithreading ................................................................................................................... 14-40
Automated Storage Management ................................................................................... 14-41
Footprint ............................................................................................................................. 14-41
Performance........................................................................................................................ 14-42
Dynamic Class Loading.................................................................................................... 14-43
Oracle’s Java Application Strategy......................................................................................... 14-44
Java Stored Procedures ..................................................................................................... 14-45
PL/SQL Integration and Oracle RDBMS Functionality .............................................. 14-45
xx
Resolution of Schema Object Dependencies .............................................................................. 15-4
Compilation of Views and PL/SQL Program Units ............................................................. 15-5
Views and Base Tables........................................................................................................ 15-5
Program Units and Referenced Objects ........................................................................... 15-6
Data Warehousing Considerations................................................................................... 15-7
Session State and Referenced Packages ........................................................................... 15-7
Security Authorizations...................................................................................................... 15-7
Function-Based Index Dependencies....................................................................................... 15-8
Requirements ....................................................................................................................... 15-8
DETERMINISTIC Functions.............................................................................................. 15-8
Privileges on the Defining Function ................................................................................. 15-8
Resolve Dependencies of Function-Based Indexes ........................................................ 15-9
Object Name Resolution ................................................................................................................. 15-9
Shared SQL Dependency Management ..................................................................................... 15-10
Local and Remote Dependency Management........................................................................... 15-10
Management of Local Dependencies..................................................................................... 15-10
Management of Remote Dependencies................................................................................. 15-11
Dependencies Among Local and Remote Database Procedures................................ 15-11
Dependencies Among Other Remote Schema Objects ................................................ 15-13
Dependencies of Applications......................................................................................... 15-13
16 Transaction Management
Introduction to Transactions........................................................................................................... 16-2
Statement Execution and Transaction Control....................................................................... 16-3
Statement-Level Rollback .......................................................................................................... 16-4
Resumable Space Allocation ..................................................................................................... 16-5
Transaction Management Overview ............................................................................................. 16-5
Commit Transactions ................................................................................................................. 16-6
Rollback of Transactions............................................................................................................ 16-7
Savepoints In Transactions........................................................................................................ 16-8
Transaction Naming................................................................................................................... 16-9
How Transactions Are Named.......................................................................................... 16-9
Commit Comment............................................................................................................... 16-9
The Two-Phase Commit Mechanism..................................................................................... 16-10
Discrete Transaction Management .............................................................................................. 16-11
xxi
Autonomous Transactions............................................................................................................. 16-12
Autonomous PL/SQL Blocks ................................................................................................. 16-12
Transaction Control Statements in Autonomous Blocks .................................................... 16-13
17 Triggers
Introduction to Triggers ................................................................................................................... 17-2
How Triggers Are Used............................................................................................................. 17-4
Some Cautionary Notes about Triggers ........................................................................... 17-4
Triggers Compared with Declarative Integrity Constraints ......................................... 17-5
Parts of a Trigger ............................................................................................................................... 17-6
The Triggering Event or Statement .......................................................................................... 17-7
Trigger Restriction ...................................................................................................................... 17-8
Trigger Action ............................................................................................................................. 17-8
Types of Triggers ............................................................................................................................... 17-9
Row Triggers and Statement Triggers ..................................................................................... 17-9
Row Triggers ........................................................................................................................ 17-9
Statement Triggers .............................................................................................................. 17-9
BEFORE and AFTER Triggers ................................................................................................ 17-10
BEFORE Triggers .............................................................................................................. 17-10
AFTER Triggers ................................................................................................................ 17-10
Trigger Type Combinations ............................................................................................. 17-11
INSTEAD OF Triggers ............................................................................................................. 17-12
Modify Views ..................................................................................................................... 17-12
Views That Are Not Modifiable ...................................................................................... 17-13
INSTEAD OF Triggers on Nested Tables ...................................................................... 17-13
Triggers on System Events and User Events ........................................................................ 17-14
Event Publication............................................................................................................... 17-14
Event Attributes................................................................................................................. 17-15
System Events .................................................................................................................... 17-15
User Events......................................................................................................................... 17-15
Trigger Execution ............................................................................................................................ 17-17
The Execution Model for Triggers and Integrity Constraint Checking ............................ 17-18
Data Access for Triggers .......................................................................................................... 17-20
Storage of PL/SQL Triggers.................................................................................................... 17-21
Execution of Triggers ............................................................................................................... 17-21
xxii
Dependency Maintenance for Triggers ................................................................................. 17-21
19 Direct-Path INSERT
Introduction to Direct-Path INSERT............................................................................................. 19-2
Advantages of Direct-Path INSERT .............................................................................................. 19-2
Serial and Parallel Direct-Path INSERT....................................................................................... 19-3
Direct-Path INSERT Into Partitioned and Nonpartitioned Tables ......................................... 19-4
Serial Direct-Path INSERT into Partitioned and Nonpartitioned Tables ........................... 19-4
Parallel Direct-Path INSERT into Partitioned Tables ............................................................ 19-4
Parallel Direct-Path INSERT into Nonpartitioned Tables .................................................... 19-4
Direct-Path INSERT and Logging Mode...................................................................................... 19-4
Direct-Path INSERT with Logging........................................................................................... 19-5
xxiii
Direct-Path INSERT without Logging ..................................................................................... 19-5
Additional Considerations for Direct-Path INSERT ................................................................. 19-5
Index Maintenance with Direct-Path INSERT........................................................................ 19-5
Space Considerations with Direct-Path INSERT.................................................................... 19-6
Locking Considerations with Direct-Path INSERT ............................................................... 19-6
xxiv
Deadlocks................................................................................................................................... 20-19
Deadlock Detection ........................................................................................................... 20-20
Avoid Deadlocks ............................................................................................................... 20-21
Types of Locks........................................................................................................................... 20-21
DML Locks ................................................................................................................................ 20-22
Row Locks (TX).................................................................................................................. 20-22
Table Locks (TM) ............................................................................................................... 20-23
DML Locks Automatically Acquired for DML Statements ........................................ 20-27
DDL Locks ................................................................................................................................. 20-30
Exclusive DDL Locks ........................................................................................................ 20-30
Share DDL Locks ............................................................................................................... 20-30
Breakable Parse Locks ...................................................................................................... 20-31
Duration of DDL Locks .................................................................................................... 20-31
DDL Locks and Clusters................................................................................................... 20-31
Latches and Internal Locks...................................................................................................... 20-31
Latches ................................................................................................................................ 20-31
Internal Locks..................................................................................................................... 20-32
Explicit (Manual) Data Locking ............................................................................................. 20-32
Examples of Concurrency under Explicit Locking....................................................... 20-33
Oracle Lock Management Services ........................................................................................ 20-41
Flashback Query ............................................................................................................................. 20-41
Flashback Query Benefits ........................................................................................................ 20-42
Some Uses of Flashback Query............................................................................................... 20-43
Self-Service Repair............................................................................................................. 20-43
E-Mail or Voice Mail Applications ................................................................................. 20-44
Account Balances............................................................................................................... 20-44
Packaged Applications ..................................................................................................... 20-44
21 Data Integrity
Introduction to Data Integrity ........................................................................................................ 21-2
Types of Data Integrity .............................................................................................................. 21-3
Null Rule............................................................................................................................... 21-3
Unique Column Values ...................................................................................................... 21-3
Primary Key Values ............................................................................................................ 21-3
Referential Integrity Rules ................................................................................................. 21-3
xxv
Complex Integrity Checking.............................................................................................. 21-4
How Oracle Enforces Data Integrity........................................................................................ 21-4
Integrity Constraints Description...................................................................................... 21-4
Database Triggers ................................................................................................................ 21-5
Introduction to Integrity Constraints............................................................................................ 21-5
Advantages of Integrity Constraints........................................................................................ 21-5
Declarative Ease................................................................................................................... 21-6
Centralized Rules................................................................................................................. 21-6
Maximum Application Development Productivity ....................................................... 21-6
Immediate User Feedback .................................................................................................. 21-6
Superior Performance ......................................................................................................... 21-6
Flexibility for Data Loads and Identification of Integrity Violations........................... 21-7
The Performance Cost of Integrity Constraints...................................................................... 21-7
Types of Integrity Constraints........................................................................................................ 21-7
NOT NULL Integrity Constraints ............................................................................................ 21-7
UNIQUE Key Integrity Constraints ......................................................................................... 21-8
Unique Keys ......................................................................................................................... 21-9
UNIQUE Key Constraints and Indexes.......................................................................... 21-10
Combine UNIQUE Key and NOT NULL Integrity Constraints................................. 21-11
PRIMARY KEY Integrity Constraints.................................................................................... 21-11
Primary Keys...................................................................................................................... 21-12
PRIMARY KEY Constraints and Indexes ...................................................................... 21-12
Referential Integrity Constraints ............................................................................................ 21-13
Self-Referential Integrity Constraints ............................................................................. 21-14
Nulls and Foreign Keys .................................................................................................... 21-15
Actions Defined by Referential Integrity Constraints.................................................. 21-16
Concurrency Control, Indexes, and Foreign Keys........................................................ 21-17
CHECK Integrity Constraints ................................................................................................. 21-20
The Check Condition ........................................................................................................ 21-21
Multiple CHECK Constraints .......................................................................................... 21-21
The Mechanisms of Constraint Checking.................................................................................. 21-21
Default Column Values and Integrity Constraint Checking.............................................. 21-24
Deferred Constraint Checking ..................................................................................................... 21-24
Constraint Attributes................................................................................................................ 21-24
SET CONSTRAINTS Mode ..................................................................................................... 21-25
xxvi
Unique Constraints and Indexes ............................................................................................ 21-26
Constraint States ............................................................................................................................. 21-26
Constraint State Modification ................................................................................................. 21-27
xxvii
Logical Reads ..................................................................................................................... 22-18
Other Resources ................................................................................................................. 22-19
Profiles........................................................................................................................................ 22-20
When to Use Profiles......................................................................................................... 22-20
Determine Values for Resource Limits of a Profile ...................................................... 22-20
xxviii
User Roles ........................................................................................................................... 23-19
The Mechanisms of Roles ........................................................................................................ 23-19
Grant and Revoke Roles .......................................................................................................... 23-20
Who Can Grant or Revoke Roles?.......................................................................................... 23-20
Role Names................................................................................................................................ 23-21
Security Domains of Roles and Users.................................................................................... 23-21
PL/SQL Blocks and Roles ....................................................................................................... 23-21
Named Blocks with Definer Rights ................................................................................ 23-21
Anonymous Blocks with Invoker Rights ....................................................................... 23-21
Data Definition Language Statements and Roles ................................................................ 23-22
Predefined Roles ....................................................................................................................... 23-23
The Operating System and Roles ........................................................................................... 23-23
Roles in a Distributed Environment ...................................................................................... 23-24
Fine-Grained Access Control........................................................................................................ 23-24
Dynamic Predicates.................................................................................................................. 23-25
Application Context ....................................................................................................................... 23-25
Secure Application Roles .............................................................................................................. 23-26
Creation of Secure Application Roles .................................................................................... 23-26
24 Auditing
Introduction to Auditing ................................................................................................................. 24-2
Features of Auditing .................................................................................................................. 24-2
Types of Auditing................................................................................................................ 24-2
Focus of Auditing ................................................................................................................ 24-3
Audit Records and the Audit Trail ................................................................................... 24-3
Mechanisms for Auditing.......................................................................................................... 24-4
When Are Audit Records Generated?.............................................................................. 24-4
Events Always Audited to the Operating System Audit Trail ..................................... 24-5
When Do Audit Options Take Effect?.............................................................................. 24-6
Audit in a Distributed Database ....................................................................................... 24-6
Audit to the Operating System Audit Trail..................................................................... 24-6
Statement Auditing .......................................................................................................................... 24-7
Privilege Auditing ............................................................................................................................ 24-7
Schema Object Auditing ................................................................................................................. 24-8
Schema Object Audit Options for Views and Procedures.................................................... 24-8
xxix
Fine-Grained Auditing .................................................................................................................... 24-9
Focus Statement, Privilege, and Schema Object Auditing ..................................................... 24-10
Successful and Unsuccessful Statement Executions Auditing........................................... 24-10
BY SESSION and BY ACCESS Clauses of Audit Statement............................................... 24-11
BY SESSION ....................................................................................................................... 24-11
BY ACCESS......................................................................................................................... 24-12
Defaults and Excluded Operations ................................................................................. 24-12
Audit By User............................................................................................................................ 24-13
Audit in a Multitier Environment ............................................................................................... 24-13
Glossary
Index
xxx
Send Us Your Comments
Oracle9i Database Concepts, Release 2 (9.2)
Part No. A96524-01
Oracle Corporation welcomes your comments and suggestions on the quality and usefulness of this
document. Your input is an important part of the information used for revision.
Did you find any errors?
Is the information clearly presented?
Do you need more information? If so, where?
Are the examples correct? Do you need more examples?
What features did you like most?
If you find any errors or have any other suggestions for improvement, please indicate the document
title and part number, and the chapter, section, and page number (if available). You can send
comments to us in the following ways:
Electronic mail: infodev_us@oracle.com
FAX: (650) 506-7227 Attn: Server Technologies Documentation Manager
Postal service:
Oracle Corporation
Server Technologies Documentation
500 Oracle Parkway, Mailstop 4op11
Redwood Shores, CA 94065
USA
If you would like a reply, please give your name, address, telephone number, and (optionally)
electronic mail address.
If you have problems with the software, please contact your local Oracle Support Services.
xxxi
xxxii
Preface
This manual describes all features of the Oracle server, an object-relational database
management system. It describes how the Oracle server functions and lays a
conceptual foundation for much of the practical information contained in other
Oracle server manuals. Information in this manual applies to the Oracle server
running on all operating systems.
This preface contains these topics:
Audience
Organization
Related Documentation
Conventions
Documentation Accessibility
xxxiii
Audience
Oracle9i Database Concepts is intended for database administrators, system
administrators, and database application developers.
To use this document, you need to know the following:
Relational database concepts in general
Concepts and terminology in Chapter 1, "Introduction to the Oracle Server"
The operating system environment under which you are running Oracle
Organization
This document contains:
xxxiv
Part III: The Oracle Instance
xxxv
Chapter 13, "Object Datatypes and Object Views"
This chapter gives an overview of the object extensions that Oracle provides.
xxxvi
Part VII: Data Protection
Glossary
The glossary defines terms used in this manual.
Related Documentation
For more information, see these Oracle resources:
Oracle9i Database Migration for information about upgrading a previous release
of Oracle
xxxvii
Oracle9i Database Administrator’s Guide for information about how to administer
the Oracle server
Oracle9i Application Developer’s Guide - Fundamentals for information about
developing Oracle database applications
Oracle9i Database Performance Planning for information about optimizing
performance of an Oracle database
Oracle9i Data Warehousing Guide for information about data warehousing and
business intelligence
Many books in the documentation set use the sample schemas of the seed database,
which is installed by default when you install Oracle. Refer to Oracle9i Sample
Schemas for information on how these schemas were created and how you can use
them yourself.
In North America, printed documentation is available for sale in the Oracle Store at
http://oraclestore.oracle.com/
Customers in Europe, the Middle East, and Africa (EMEA) can purchase
documentation from
http://www.oraclebookshop.com/
If you already have a username and password for OTN, then you can go directly to
the documentation section of the OTN Web site at
http://otn.oracle.com/docs/index.htm
xxxviii
Conventions
This section describes the conventions used in the text and code examples of this
documentation set. It describes:
Conventions in Text
Conventions in Code Examples
Conventions in Text
We use various conventions in text to help you more quickly identify special terms.
The following table describes those conventions and provides examples of their use.
xxxix
Convention Meaning Example
lowercase Lowercase monospace typeface indicates Enter sqlplus to open SQL*Plus.
monospace executables, filenames, directory names,
The password is specified in the orapwd file.
(fixed-width) and sample user-supplied elements. Such
font elements include computer and database Back up the datafiles and control files in the
names, net service names, and connect /disk1/oracle/dbs directory.
identifiers, as well as user-supplied
The department_id, department_name,
database objects and structures, column
and location_id columns are in the
names, packages and classes, usernames
hr.departments table.
and roles, program units, and parameter
values. Set the QUERY_REWRITE_ENABLED
initialization parameter to true.
Note: Some programmatic elements use a
mixture of UPPERCASE and lowercase. Connect as oe user.
Enter these elements as shown.
The JRepUtil class implements these
methods.
lowercase Lowercase italic monospace font You can specify the parallel_clause.
italic represents placeholders or variables.
Run Uold_release.SQL where old_
monospace
release refers to the release you installed
(fixed-width)
prior to upgrading.
font
The following table describes typographic conventions used in code examples and
provides examples of their use.
xl
Convention Meaning Example
... Horizontal ellipsis points indicate either:
That we have omitted parts of the CREATE TABLE ... AS subquery;
code that are not directly related to
the example SELECT col1, col2, ... , coln FROM
employees;
That you can repeat a portion of the
code
. Vertical ellipsis points indicate that we SQL> SELECT NAME FROM V$DATAFILE;
. have omitted several lines of code not NAME
. directly related to the example. ------------------------------------
/fsl/dbs/tbs_01.dbf
/fs1/dbs/tbs_02.dbf
.
.
.
/fsl/dbs/tbs_09.dbf
9 rows selected.
Other notation You must enter symbols other than acctbal NUMBER(11,2);
brackets, braces, vertical bars, and ellipsis acct CONSTANT NUMBER(4) := 3;
points as shown.
Italics Italicized text indicates placeholders or CONNECT SYSTEM/system_password
variables for which you must supply DB_NAME = database_name
particular values.
UPPERCASE Uppercase typeface indicates elements SELECT last_name, employee_id FROM
supplied by the system. We show these employees;
terms in uppercase in order to distinguish SELECT * FROM USER_TABLES;
them from terms you define. Unless terms DROP TABLE hr.employees;
appear in brackets, enter them in the
order and with the spelling shown.
However, because these terms are not
case sensitive, you can enter them in
lowercase.
lowercase Lowercase typeface indicates SELECT last_name, employee_id FROM
programmatic elements that you supply. employees;
For example, lowercase indicates names sqlplus hr/hr
of tables, columns, or files. CREATE USER mjones IDENTIFIED BY ty3MU9;
Note: Some programmatic elements use a
mixture of UPPERCASE and lowercase.
Enter these elements as shown.
xli
Documentation Accessibility
Our goal is to make Oracle products, services, and supporting documentation
accessible, with good usability, to the disabled community. To that end, our
documentation includes features that make information available to users of
assistive technology. This documentation is available in HTML format, and contains
markup to facilitate access by the disabled community. Standards will continue to
evolve over time, and Oracle Corporation is actively engaged with other
market-leading technology vendors to address technical obstacles so that our
documentation can be accessible to all of our customers. For additional information,
visit the Oracle Accessibility Program Web site at
http://www.oracle.com/accessibility/
xlii
Part I
What Is Oracle?
This chapter provides an overview of the Oracle server. The topics include:
Database Structure and Space Management Overview
Data Access Overview
Memory Structure and Processes Overview
Application Architecture Overview
Distributed Databases Overview
Data Concurrency and Consistency Overview
Database Security Overview
Database Administration Overview
Data Warehousing Overview
High Availability Overview
Content Management Overview
Tables Tables are the basic unit of data storage in an Oracle database. Database
tables hold all user-accessible data. Each table has columns and rows. Oracle stores
each row of a database table containing data for less than 256 columns as one or
more row pieces. A table that has an employee database, for example, can have a
column called employee number, and each row in that column is an employee’s
number.
Views Views are customized presentations of data in one or more tables or other
views. A view can also be considered a stored query. Views do not actually contain
data. Rather, they derive their data from the tables on which they are based,
referred to as the base tables of the views.
Like tables, views can be queried, updated, inserted into, and deleted from, with
some restrictions. All operations performed on a view actually affect the base tables
of the view.
Views provide an additional level of table security by restricting access to a
predetermined set of rows and columns of a table. They also hide data complexity
and store complex queries.
Indexes Indexes are optional structures associated with tables. Indexes can be
created to increase the performance of data retrieval. Just as the index in this
manual helps you quickly locate specific information, an Oracle index provides an
access path to table data.
When processing a request, Oracle can use some or all of the available indexes to
locate the requested rows efficiently. Indexes are useful when applications
frequently query a table for a range of rows (for example, all employees with a
salary greater than 1000 dollars) or a specific row.
Indexes are created on one or more columns of a table. After it is created, an index is
automatically maintained and used by Oracle. Changes to table data (such as
adding new rows, updating rows, or deleting rows) are automatically incorporated
into all relevant indexes with complete transparency to the users.
You can partition indexes.
Clusters Clusters are groups of one or more tables physically stored together
because they share common columns and are often used together. Because related
rows are physically stored together, disk access time improves.
Like indexes, clusters do not affect application design. Whether or not a table is part
of a cluster is transparent to users and to applications. Data stored in a clustered
table is accessed by SQL in the same way as data stored in a nonclustered table.
Oracle Data Blocks At the finest level of granularity, Oracle database data is stored in
data blocks. One data block corresponds to a specific number of bytes of physical
database space on disk. The standard block size is specified by the initialization
parameter DB_BLOCK_SIZE. In addition, you can specify of up to five other block
sizes. A database uses and allocates free database space in Oracle data blocks.
Extents The next level of logical database space is an extent. An extent is a specific
number of contiguous data blocks, obtained in a single allocation, used to store a
specific type of information.
Segment Description
Data segment Each nonclustered table has a data segment. All table data
is stored in the extents of the data segment.
For a partitioned table, each partition has a data segment.
Each cluster has a data segment. The data of every table in
the cluster is stored in the cluster’s data segment.
Index segment Each index has an index segment that stores all of its data.
For a partitioned index, each partition has an index
segment.
Temporary segment Temporary segments are created by Oracle when a SQL
statement needs a temporary work area to complete
execution. When the statement finishes execution, the
extents in the temporary segment are returned to the
system for future use.
Segment Description
Rollback segment If you are operating in automatic undo management
mode, then the database server manages undo space
using tablespaces. Oracle Corporation recommends that
you use "Automatic Undo Management" management.
However, if you are operating in manual undo
management mode, then one or more rollback segments
for a database are created by the database administrator
to temporarily store undo information.
The information in a rollback segment is used during
database recovery:
To generate read-consistent database information
To roll back uncommitted transactions for users
Oracle dynamically allocates space when the existing extents of a segment become
full. In other words, when the extents of a segment are full, Oracle allocates another
extent for that segment. Because extents are allocated as needed, the extents of a
segment may or may not be contiguous on disk.
See Also:
"Automatic Undo Management" on page 2-16
"Read Consistency" on page 1-40
"Database Backup and Recovery Overview" on page 1-50
Tablespaces
A database is divided into logical storage units called tablespaces, which group
related logical structures together. For example, tablespaces commonly group
together all application objects to simplify some administrative operations.
Database
Online and Offline Tablespaces A tablespace can be online (accessible) or offline (not
accessible). A tablespace is generally online, so that users can access the information
in the tablespace. However, sometimes a tablespace is taken offline to make a
portion of the database unavailable while allowing normal access to the remainder
of the database. This makes many administrative tasks easier to perform.
Datafiles
Every Oracle database has one or more physical datafiles. The datafiles contain all
the database data. The data of logical database structures, such as tables and
indexes, is physically stored in the datafiles allocated for a database.
The characteristics of datafiles are:
A datafile can be associated with only one database.
Datafiles can have certain characteristics set to let them automatically extend
when the database runs out of space.
One or more datafiles form a logical unit of database storage called a
tablespace, as discussed earlier in this chapter.
Data in a datafile is read, as needed, during normal database operation and stored
in the memory cache of Oracle. For example, assume that a user wants to access
some data in a table of a database. If the requested information is not already in the
memory cache for the database, then it is read from the appropriate datafiles and
stored in memory.
Modified or new data is not necessarily written to a datafile immediately. To reduce
the amount of disk access and to increase performance, data is pooled in memory
and written to the appropriate datafiles all at once, as determined by the database
writer process (DBWn) background process.
Control Files
Every Oracle database has a control file. A control file contains entries that specify
the physical structure of the database. For example, it contains the following
information:
Database name
Names and locations of datafiles and redo log files
Time stamp of database creation
Like the redo log, Oracle lets the control file be multiplexed for protection of the
control file.
Use of Control Files Every time an instance of an Oracle database is started, its
control file identifies the database and redo log files that must be opened for
database operation to proceed. If the physical makeup of the database is altered (for
example, if a new datafile or redo log file is created), then the control file is
automatically modified by Oracle to reflect the change. A control file is also used in
database recovery.
Data Utilities
The three utilities for moving a subset of an Oracle database from one database to
another are Export, Import, and SQL*Loader.
Export Utility The Export utility transfers data objects between Oracle databases,
even if they reside on platforms with different hardware and software
configurations. Export extracts the object definitions and table data from an Oracle
database and stores them in an Oracle binary-format Export dump file typically
located on disk or tape.
Such files can then be copied using file transfer protocol (FTP) or physically
transported (in the case of tape) to a different site. They can be used with the Import
utility to transfer data between databases that are on machines not connected
through a network or as backups in addition to normal backup procedures.
When you run Export against an Oracle database, it extracts objects, such as tables,
followed by their related objects, and then writes them to the Export dump file.
Import Utility The Import utility inserts the data objects extracted from one Oracle
database by the Export utility into another Oracle database. Export dump files can
be read only by Import. Import reads the object definitions and table data that the
Export utility extracted from an Oracle database.
The Export and Import utilities can also facilitate certain aspects of Oracle
Advanced Replication functionality, such as offline instantiation.
SQL*Loader Utility Export dump files can be read only by the Oracle Import utility. If
you need to read load data from ASCII fixed-format or delimited files, you can use
the SQL*Loader utility. SQL*Loader loads data from external files into tables in an
Oracle database. SQL*Loader accepts input data in a variety of formats, performs
filtering (selectively loading records based on their data values), and loads data into
multiple Oracle database tables during the same load session.
SQL Overview
SQL (pronounced SEQUEL) is the programming language that defines and
manipulates the database. SQL databases are relational databases, which means
that data is stored in a set of simple relations.
SQL Statements
All operations on the information in an Oracle database are performed using SQL
statements. A SQL statement is a string of SQL text. A statement must be the
equivalent of a complete SQL sentence, as in:
SELECT last_name, department_id FROM employees;
Only a complete SQL statement can run successfully. A sentence fragment, such as
the following, generates an error indicating that more text is required:
SELECT last_name
Data Definition Language (DDL) Statements These statements create, alter, maintain, and
drop schema objects. DDL statements also include statements that permit a user to
grant other users the privileges to access the database and specific objects within the
database.
Data Manipulation Language (DML) Statements These statements manipulate data. For
example, querying, inserting, updating, and deleting rows of a table are all DML
operations. The most common SQL statement is the SELECT statement, which
retrieves data from the database. Locking a table or view and examining the
execution plan of an SQL statement are also DML operations.
Transaction Control Statements These statements manage the changes made by DML
statements. They enable a user to group changes into logical transactions. Examples
include COMMIT, ROLLBACK, and SAVEPOINT.
Session Control Statements These statements let a user control the properties of the
current session, including enabling and disabling roles and changing language
settings. The two session control statements are ALTER SESSION and SET ROLE.
System Control Statements These statements change the properties of the Oracle
server instance. The only system control statement is ALTER SYSTEM. It lets users
change settings, such as the minimum number of shared servers, kill a session, and
perform other tasks.
Embedded SQL Statements These statements incorporate DDL, DML, and transaction
control statements in a procedural language program, such as those used with the
Oracle precompilers. Examples include OPEN, CLOSE, FETCH, and EXECUTE.
See Also:
Oracle9i SQL Reference
"Database Security Overview" on page 1-43 for more
information about privileges
"Transactions Overview" on page 1-17 for more information
about transaction control statements
Objects Overview
Oracle object technology is a layer of abstraction built on Oracle's relational
technology. New object types can be created from any built-in database types or
any previously created object types, object references, and collection types.
Metadata for user-defined types is stored in a schema available to SQL, PL/SQL,
Java, and other published interfaces.
An object type differs from native SQL datatypes in that it is user-defined, and it
specifies both the underlying persistent data (attributes) and the related behaviors
(methods). Object types are abstractions of the real-world entities, for example,
purchase orders.
Object types and related object-oriented features, such as variable-length arrays and
nested tables, provide higher-level ways to organize and access data in the
database. Underneath the object layer, data is still stored in columns and tables, but
you can work with the data in terms of the real-world entities--customers and
purchase orders, for example--that make the data meaningful. Instead of thinking in
terms of columns and tables when you query the database, you can simply select a
customer.
Internally, statements about objects are still basically statements about relational
tables and columns, and you can continue to work with relational data types and
store data in relational tables. But you have the option to take advantage of
object-oriented features too. You can use object-oriented features while continuing
to work with most of your relational data, or you can go over to an object-oriented
approach entirely. For instance, you can define some object data types and store the
objects in columns in relational tables. You can also create object views of existing
relational data to represent and access this data according to an object model. Or
you can store object data in object tables, where each row is an object.
Advantages of Objects
In general, the object-type model is similar to the class mechanism found in C++
and Java. Like classes, objects make it easier to model complex, real-world business
entities and logic, and the reusability of objects makes it possible to develop
database applications faster and more efficiently. By natively supporting object
types in the database, Oracle enables application developers to directly access the
data structures used by their applications. No mapping layer is required between
client-side objects and the relational database columns and tables that contain the
data. Object abstraction and the encapsulation of object behaviors also make
applications easier to understand and maintain.
PL/SQL Overview
PL/SQL is Oracle’s procedural language extension to SQL. PL/SQL combines the
ease and flexibility of SQL with the procedural functionality of a structured
programming language, such as IF ... THEN, WHILE, and LOOP.
When designing a database application, consider the following advantages of using
stored PL/SQL:
PL/SQL code can be stored centrally in a database. Network traffic between
applications and the database is reduced, so application and system
performance increases. Even when PL/SQL is not stored in the database,
applications can send blocks of PL/SQL to the database rather than individual
SQL statements, thereby reducing network traffic.
Data access can be controlled by stored PL/SQL code. In this case, PL/SQL
users can access data only as intended by application developers, unless
another access route is granted.
PL/SQL blocks can be sent by an application to a database, running complex
operations without excessive network traffic.
The following sections describe the PL/SQL program units that can be defined and
stored centrally in a database.
Procedures and Functions Procedures and functions are sets of SQL and PL/SQL
statements grouped together as a unit to solve a specific problem or to perform a set
of related tasks. They are created and stored in compiled form in the database and
can be run by a user or a database application.
Procedures and functions are identical, except that functions always return a single
value to the user. Procedures do not return values.
Database Triggers Database triggers are PL/SQL, Java, or C procedures that run
implicitly whenever a table or view is modified or when some user actions or
database system actions occur. Database triggers can be used in a variety of ways
for managing your database. For example, they can automate data generation, audit
data modifications, enforce complex integrity constraints, and customize complex
security authorizations.
Autonomous Blocks You can call autonomous transactions from within a PL/SQL
block. When an autonomous PL/SQL block is entered, the transaction context of the
caller is suspended. This operation ensures that SQL operations performed in this
block (or other blocks called from it) have no dependence or effect on the state of
the caller’s transaction context.
Java Overview
Java is an object-oriented programming efficient for application-level programs.
Java has key features that make it ideal for developing server applications. These
features include the following:
Simplicity--Java is a simpler language than most others used in server
applications because of its consistent enforcement of the object model. The
large, standard set of class libraries brings powerful tools to Java developers on
all platforms.
Portability--Java is portable across platforms. It is possible to write
platform-dependent code in Java, but it is also simple to write programs that
move seamlessly across machines. Oracle server applications, which do not
support graphical user interfaces directly on the platform that hosts them, also
tend to avoid the few platform portability issues that Java has.
XML Overview
XML, eXtensible Markup Language, is the standard way to identify and describe
data on the Web. It is a human-readable, machine-understandable, general syntax
for describing hierarchical data, applicable to a wide range of applications,
databases, e-commerce, Java, web development, searching, and so on.
The Oracle server includes the Oracle XML DB, a set of built-in high-performance
XML storage and retrieval technologies. The XML DB fully absorbs the W3C XML
data model into the Oracle server and provides new standard access methods for
navigating and querying XML. You get all the advantages of relational database
technology and XML technology at the same time. Key aspects of the XML database
include the following:
A native datatype -- XMLType -- to store and manipulate XML. Multiple storage
options (CLOB, decomposed object-relational) are available with XMLType, and
DBAs can choose a storage that meets their requirements for fidelity to original,
ease of query, ease of regeneration, and so on. With XMLType, you can perform
SQL operations, such as queries and OLAP functions on XML data, as well as
XML operations, such as XPath searches and XSL transformations, on SQL data.
You can build regular SQL indexes or Oracle Text indexes on XMLType for high
performance for a broad spectrum of applications.
Native XML generation provides built in SQL operators and supplied PL/SQL
packages to return the results of SQL queries formatted as XML.
An XML repository provides foldering, access control, FTP and WebDAV
protocol support with versioning. This enables applications to retain a file
abstraction when manipulating XML data.
Complementing the XML Database is the Oracle XML Developer Kit, or XDK. XDK
is a set of commonly used building blocks or utilities for development and runtime
support. The Oracle XDK contains the basic building blocks for reading,
manipulating, transforming, and viewing XML documents. To provide a broad
variety of deployment options, the Oracle XDKs are available for Java, JavaBeans,
C, C++, and PL/SQL. Oracle XDKs consist of XML Parsers, an XSLT Processor,
XML Schema Processor, XML Class Generator, XML Transviewer Java Beans, XML
SQL Utility, and XSQL Servlet.
Advanced Queuing (AQ) is the message queuing functionality of the Oracle
database. With this functionality, message queuing operations can be performed
similar to that of SQL operations from the Oracle database. Message queuing
functionality enables asynchronous communication between applications and users
on Oracle databases using queues. AQ offers enqueue, dequeue, propagation, and
guaranteed delivery of messages, along with exception handling in case messages
cannot be delivered. Message queuing takes advantage of XMLType for XML
message payloads.
See Also:
Chapter 12, "Native Datatypes"
Oracle9i XML Database Developer’s Guide - Oracle XML DB
Transactions Overview
A transaction is a logical unit of work that comprises one or more SQL statements
run by a single user. According to the ANSI/ISO SQL standard, with which Oracle
is compatible, a transaction begins with the user’s first executable SQL statement. A
transaction ends when it is explicitly committed or rolled back by that user.
Transaction Begins
End Transaction
COMMIT WORK;
Transaction Ends
Rolling back a transaction retracts any of the changes resulting from the SQL
statements in the transaction. After a transaction is rolled back, the affected data is
left unchanged, as if the SQL statements in the transaction were never run.
Savepoints
Savepoints divide a long transaction with many SQL statements into smaller parts.
With savepoints, you can arbitrarily mark your work at any point within a long
transaction. This gives you the option of later rolling back all work performed from
the current point in the transaction to a declared savepoint within the transaction.
For example, you can use savepoints throughout a long complex series of updates,
so if you make an error, you do not need to resubmit every statement.
Note: Database triggers let you define and enforce integrity rules,
but a database trigger is not the same as an integrity constraint.
Among other things, a database trigger does not check data already
loaded into a table. Therefore, it is strongly recommended that you
use database triggers only when the integrity rule cannot be
enforced by integrity constraints.
Integrity Constraints
An integrity constraint is a declarative way to define a business rule for a column
of a table. An integrity constraint is a statement about a table’s data that is always
true and that follows these rules:
If an integrity constraint is created for a table and some existing table data does
not satisfy the constraint, then the constraint cannot be enforced.
After a constraint is defined, if any of the results of a DML statement violate the
integrity constraint, then the statement is rolled back, and an error is returned.
Integrity constraints are defined with a table and are stored as part of the table’s
definition in the data dictionary, so that all database applications adhere to the
same set of rules. When a rule changes, it only needs be changed once at the
database level and not many times for each application.
The following integrity constraints are supported by Oracle:
NOT NULL: Disallows nulls (empty entries) in a table’s column.
UNIQUE KEY: Disallows duplicate values in a column or set of columns.
PRIMARY KEY: Disallows duplicate values and nulls in a column or set of
columns.
FOREIGN KEY: Requires each value in a column or set of columns to match a
value in a related table’s UNIQUE or PRIMARY KEY. FOREIGN KEY integrity
constraints also define referential integrity actions that dictate what Oracle
should do with dependent data if the data it references is altered.
CHECK: Disallows values that do not satisfy the logical expression of the
constraint.
Keys
Key is used in the definitions of several types of integrity constraints. A key is the
column or set of columns included in the definition of certain types of integrity
constraints. Keys describe the relationships between the different tables and
columns of a relational database. Individual values in a key are called key values.
The different types of keys include:
Primary key: The column or set of columns included in the definition of a
table’s PRIMARY KEY constraint. A primary key’s values uniquely identify the
rows in a table. Only one primary key can be defined for each table.
Unique key: The column or set of columns included in the definition of a
UNIQUE constraint.
Foreign key: The column or set of columns included in the definition of a
referential integrity constraint.
Referenced key: The unique key or primary key of the same or a different table
referenced by a foreign key.
SQL*Plus Overview
SQL*Plus is a tool for entering and running ad-hoc database statements. It lets you
run SQL statements and PL/SQL blocks, and perform many additional tasks as
well. Through SQL*Plus, you can:
Enter, edit, store, retrieve, and run SQL statements and PL/SQL blocks
Format, perform calculations on, store, print, and create Web output of query
results
List column definitions for any table access, and copy data between SQL
databases
Send messages to, and accept responses from, an end user
Perform database administration
ARC0
CKPT ARC0 Offline
Storage
D000 Device
DBW0
LGWR
Legend:
User
Process Control
LMS Lock process
Files
RECO Recoverer process
PMON Process monitor
SMON System monitor
CKPT Checkpoint Redo Log
ARC0 Archiver Files
DBW0 Database writer
LGWR Log writer
D000 Dispatcher Process
Datafiles
An Oracle Instance
An Oracle server consists of an Oracle database and an Oracle server instance.
Every time a database is started, a system global area (SGA) is allocated and Oracle
background processes are started. The combination of the background processes
and memory buffers is called an Oracle instance.
Memory Structures
Oracle creates and uses memory structures to complete several jobs. For example,
memory stores program code being run and data shared among users. Two basic
memory structures are associated with Oracle: the system global area and the
program global area. The following subsections explain each in detail.
See Also:
"An Oracle Instance" on page 1-24
"Background Processes" on page 1-27 for more information
about the SGA and the Oracle background processes
Database Buffer Cache of the SGA Database buffers store the most recently used
blocks of data. The set of database buffers in an instance is the database buffer
cache. The buffer cache contains modified as well as unmodified blocks. Because
the most recently (and often, the most frequently) used data is kept in memory, less
disk I/O is necessary, and performance is improved.
Redo Log Buffer of the SGA The redo log buffer stores redo entries—a log of changes
made to the database. The redo entries stored in the redo log buffers are written to
an online redo log, which is used if database recovery is necessary. The size of the
redo log is static.
Shared Pool of the SGA The shared pool contains shared memory constructs, such as
shared SQL areas. A shared SQL area is required to process every unique SQL
statement submitted to a database. A shared SQL area contains information such as
the parse tree and execution plan for the corresponding statement. A single shared
SQL area is used by multiple applications that issue the same statement, leaving
more shared memory for other uses.
Large Pool in the SGA The large pool is an optional area that provides large memory
allocations for Oracle backup and restore operations, I/O server processes, and
session memory for the shared server and Oracle XA (used where transactions
interact with more than one database).
Statement Handles or Cursors A cursor is a handle (a name or pointer) for the memory
associated with a specific statement. (Oracle Call Interface, OCI, refers to these as
statement handles.) Although most Oracle users rely on automatic cursor handling
of Oracle utilities, the programmatic interfaces offer application designers more
control over cursors.
For example, in precompiler application development, a cursor is a named resource
available to a program and can be used specifically to parse SQL statements
embedded within the application. Application developers can code an application
so it controls the phases of SQL statement execution and thus improves application
performance.
Process Architecture
A process is a "thread of control" or a mechanism in an operating system that can
run a series of steps. Some operating systems use the terms job or task. A process
generally has its own private memory area in which it runs.
An Oracle server has two general types of processes: user processes and Oracle
processes.
Enterprise Manager). User processes also manage communication with the server
process through the program interface, which is described in a later section.
Oracle Processes
Oracle processes are invoked by other processes to perform functions on behalf of
the invoking process. The different types of Oracle processes and their specific
functions are discussed in the following sections.
Server Processes Oracle creates server processes to handle requests from connected
user processes. A server process communicates with the user process and interacts
with Oracle to carry out requests from the associated user process. For example, if a
user queries some data not already in the database buffers of the SGA, then the
associated server process reads the proper data blocks from the datafiles into the
SGA.
Oracle can be configured to vary the number of user processes for each server
process. In a dedicated server configuration, a server process handles requests for a
single user process. A shared server configuration lets many user processes share a
small number of server processes, minimizing the number of server processes and
maximizing the use of available system resources.
On some systems, the user and server processes are separate, while on others they
are combined into a single process. If a system uses the shared server or if the user
and server processes run on different machines, then the user and server processes
must be separate. Client/server systems separate the user and server processes and
run them on different machines.
See Also:
"An Oracle Instance" on page 1-24
"System Global Area" on page 1-25 for more information about
the SGA
Database Writer (DBWn) The database writer writes modified blocks from the
database buffer cache to the datafiles. Although one database writer process
(DBW0) is sufficient for most systems, you can configure additional processes
(DBW1 through DBW9 and DBWa through DBWj) to improve write performance
for a system that modifies data heavily. The initialization parameter DB_WRITER_
PROCESSES specifies the number of DBWn processes.
Because Oracle uses write-ahead logging, DBWn does not need to write blocks
when a transaction commits. Instead, DBWn is designed to perform batched writes
with high efficiency. In the most common case, DBWn writes only when more data
needs to be read into the SGA and too few database buffers are free. The least
recently used data is written to the datafiles first. DBWn also performs writes for
other functions, such as checkpointing.
Log Writer (LGWR) The log writer writes redo log entries to disk. Redo log entries are
generated in the redo log buffer of the SGA, and LGWR writes the redo log entries
sequentially into an online redo log. If the database has a multiplexed redo log,
then LGWR writes the redo log entries to a group of online redo log files.
Checkpoint (CKPT) At specific times, all modified database buffers in the SGA are
written to the datafiles by DBWn. This event is called a checkpoint. The checkpoint
process is responsible for signaling DBWn at checkpoints and updating all the
datafiles and control files of the database to indicate the most recent checkpoint.
System Monitor (SMON) The system monitor performs recovery when a failed
instance starts up again. With Real Application Clusters, the SMON process of one
instance can perform instance recovery for other instances that have failed. SMON
also cleans up temporary segments that are no longer in use and recovers
terminated transactions skipped during recovery because of file-read or offline
errors. These transactions are eventually recovered by SMON when the tablespace
or file is brought back online. SMON also coalesces free extents in the dictionary
managed tablespaces to make free space contiguous and easier to allocate.
Process Monitor (PMON) The process monitor performs process recovery when a user
process fails. PMON is responsible for cleaning up the cache and freeing resources
that the process was using. PMON also checks on dispatcher and server processes
and restarts them if they have failed.
Archiver (ARCn) The archiver copies the online redo log files to archival storage after
a log switch has occurred. Although a single ARCn process (ARC0) is sufficient for
most systems, you can specify up to 10 ARCn processes by using the dynamic
initialization parameter LOG_ARCHIVE_MAX_PROCESSES. If the workload becomes
too great for the current number of ARCn processes, then LGWR automatically
starts another ARCn process up to the maximum of 10 processes. ARCn is active
only when a database is in ARCHIVELOG mode and automatic archiving is enabled.
See Also: "The Redo Log" on page 1-52 for more information
about the archiver
Recoverer (RECO) The recoverer is used to resolve distributed transactions that are
pending due to a network or system failure in a distributed database. At timed
intervals, the local RECO attempts to connect to remote databases and
automatically complete the commit or rollback of the local portion of any pending
distributed transactions.
Job Queue Processes (Jnnn) Job queue processes are used for batch processing. Job
queue processes are managed dynamically. This enables job queue clients to use
more job queue processes when required. The resources used by the new processes
are released when they are idle.
See Also:
Oracle9i Database Administrator’s Guide for more information
about job queues.
Lock Manager Server (LMS) The Lock Manager Server process (LMS) is used for
inter-instance locking in Real Application Clusters.
Queue Monitor (QMNn) Queue monitors are optional background processes that
monitor the message queues for Oracle Advanced Queuing. You can configure up
to 10 queue monitor processes.
Client/Server Architecture
Multiprocessing uses more than one processor for a set of related jobs. Distributed
processing reduces the load on a single processor by allowing different processors
to concentrate on a subset of related tasks, thus improving the performance and
capabilities of the system as a whole.
An Oracle database system can easily take advantage of distributed processing by
using its client/server architecture. In this architecture, the database system is
divided into two parts: a front-end or a client and a back-end or a server.
The Client
The client is the front-end database application, accessed by a user through the
keyboard, display, and pointing device, such as a mouse. The client has no data
access responsibilities. It requests, processes, and presents data managed by the
server. The client workstation can be optimized for its job. For example, it might not
need large disk capacity, or it might benefit from graphic capabilities.
Often, the client runs on a different computer than the database server, generally on
a PC. Many clients can simultaneously run against one server.
The Server
The server runs Oracle software and handles the functions required for concurrent,
shared data access. The server receives and processes the SQL and PL/SQL
statements that originate from client applications. The computer that manages the
server can be optimized for its duties. For example, it can have large disk capacity
and fast processors.
of the query processing, thus removing some of the load from the database
server. It can serve as an interface between clients and multiple database
servers, including providing an additional level of security.
An end or database server that stores most of the data used in the operation
This architecture enables use of an application server to:
Validate the credentials of a client, such as a web browser
Connect to an Oracle database server
Perform the requested operation on behalf of the client
The identity of the client is maintained throughout all tiers of the connection.
Location Transparency
Location transparency occurs when the physical location of data is transparent to
the applications and users of a database system. Several Oracle features, such as
views, procedures, and synonyms, can provide location transparency. For example,
a view that joins table data from several databases provides location transparency
because the user of the view does not need to know from where the data originates.
Site Autonomy
Site autonomy means that each database participating in a distributed database is
administered separately and independently from the other databases, as though
each database were a non-networked database. Although each database can work
with others, they are distinct, separate systems that are cared for individually.
Two-Phase Commit
Oracle provides the same assurance of data consistency in a distributed
environment as in a nondistributed environment. Oracle provides this assurance
using the transaction model and a two-phase commit mechanism.
As in nondistributed systems, transactions should be carefully planned to include a
logical set of SQL statements that should all succeed or fail as a unit. Oracle’s
two-phase commit mechanism guarantees that no matter what type of system or
network failure occurs, a distributed transaction either commits on all involved
nodes or rolls back on all involved nodes to maintain data consistency across the
global distributed database.
Replication Overview
Replication is the process of copying and maintaining database objects, such as
tables, in multiple databases that make up a distributed database system. Changes
applied at one site are captured and stored locally before being forwarded and
applied at each of the remote locations. Oracle replication is a fully integrated
feature of the Oracle server. It is not a separate server.
Replication uses distributed database technology to share data between multiple
sites, but a replicated database and a distributed database are not the same. In a
distributed database, data is available at many locations, but a particular table
resides at only one location. For example, the employees table can reside at only
the db1 database in a distributed database system that also includes the db2 and
db3 databases. Replication means that the same data is available at multiple
locations. For example, the employees table can be available at db1, db2, and db3.
Table Replication
Distributed database systems often locally replicate remote tables that are
frequently queried by local users. By having copies of heavily accessed data on
several nodes, the distributed database does not need to send information across a
network repeatedly, thus helping to maximize the performance of the database
application.
Data can be replicated using materialized views.
Master Master
Level 1 Level 1
updatable MV updatable MV
Level n Level n
updatable MV updatable MV
Conflict Resolution In Oracle9i conflict resolution routines are defined at the top
level, the master site, and are pulled into the updatable materialized view site when
needed. This makes it possible to have multitier materialized views. Existing
system-defined conflict resolution methods are supported.
In addition, users can write their own conflict resolution routines. A user-defined
conflict resolution method is a PL/SQL function that returns either true or false.
True indicates that the method was able to successfully resolve all conflicting
modifications for a column group.
See Also: Oracle9i Replication and Oracle9i SQL Reference for more
information about creating and managing multitier materialized
views
Streams Overview
Oracle Streams enables the sharing of data and events in a data stream, either
within a database or from one database to another. The stream routes specified
information to specified destinations. Oracle Streams provides the capabilities
needed to build and operate distributed enterprises and applications, data
warehouses, and high availability solutions. You can use all the capabilities of
Oracle Streams at the same time. If your needs change, you can implement a new
capability of Streams without sacrificing existing capabilities.
Using Oracle Streams, you control what information is put into a stream, how the
stream flows or is routed from database to database, what happens to events in the
stream as they flow into each database, and how the stream terminates. By
configuring specific capabilities of Streams, you can address specific requirements.
Based on your specifications, Streams can capture and manage events in the
database automatically, including, but not limited to, DML changes and DDL
changes. You can also put user-defined events into a stream. Then, Streams can
propagate the information to other databases or applications automatically. Again,
based on your specifications, Streams can apply events at a destination database.
You can use Streams to:
Capture changes at a database.
You can configure a background capture process to capture changes made to
tables, schemas, or the entire database. A capture process captures changes
from the redo log and formats each captured change into a logical change
record (LCR). The database where changes are generated in the redo log is
called the source database.
Enqueue events into a queue. Two types of events may be staged in a Streams
queue: LCRs and user messages.
A capture process enqueues LCR events into a queue that you specify. The
queue can then share the LCR events within the same database or with other
databases.
You can also enqueue user events into a queue explicitly with a user
application. These explicitly enqueued events can be LCRs or user messages.
Propagate events from one queue to another. These queues may be in the same
database or in different databases.
Dequeue events from a queue.
A background apply process can dequeue events from a queue. You can also
dequeue events explicitly with a user application.
Apply events at a database.
You can configure an apply process to apply all of the events in a queue or only
the events that you specify. You can also configure an apply process to call your
own PL/SQL subprograms to process events.
The database where LCR events are applied and other types of events are
processed is called the destination database. In some configurations, the source
database and the destination database may be the same.
Concurrency
A primary concern of a multiuser database management system is how to control
concurrency, which is the simultaneous access of the same data by many users.
Without adequate concurrency controls, data could be updated or changed
improperly, compromising data integrity.
If many people are accessing the same data, one way of managing data concurrency
is to make each user wait for a turn. The goal of a database management system is
to reduce that wait so it is either nonexistent or negligible to each user. All data
manipulation language statements should proceed with as little interference as
possible, and destructive interactions between concurrent transactions must be
prevented. Destructive interaction is any interaction that incorrectly updates data or
incorrectly alters underlying data structures. Neither performance nor data
integrity can be sacrificed.
Oracle resolves such issues by using various types of locks and a multiversion
consistency model. Both features are discussed later in this section. These features
are based on the concept of a transaction. It is the application designer’s
responsibility to ensure that transactions fully exploit these concurrency and
consistency features.
Read Consistency
Read consistency, as supported by Oracle, does the following:
Guarantees that the set of data seen by a statement is consistent with respect to
a single point in time and does not change during statement execution
(statement-level read consistency)
Ensures that readers of database data do not wait for writers or other readers of
the same data
Ensures that writers of database data do not wait for readers of the same data
Ensures that writers only wait for other writers if they attempt to update
identical rows in concurrent transactions
The simplest way to think of Oracle’s implementation of read consistency is to
imagine each user operating a private copy of the database, hence the multiversion
consistency model.
Read-Only Transactions
By default, Oracle guarantees statement-level read consistency. The set of data
returned by a single query is consistent with respect to a single point in time.
However, in some situations, you might also require transaction-level read
consistency. This is the ability to run multiple queries within a single transaction, all
of which are read-consistent with respect to the same point in time, so that queries
in this transaction do not see the effects of intervening committed transactions.
If you want to run a number of queries against multiple tables and if you are not
doing any updating, you prefer a read-only transaction. After indicating that your
transaction is read-only, you can run as many queries as you like against any table,
knowing that the results of each query are consistent with respect to the same point
in time.
Locking Mechanisms
Oracle also uses locks to control concurrent access to data. Locks are mechanisms
intended to prevent destructive interaction between users accessing Oracle data.
Locks are used to ensure consistency and integrity. Consistency means that the data
a user is viewing or changing is not changed (by other users) until the user is
finished with the data. Integrity means that the database’s data and structures
reflect all changes made to them in the correct sequence.
Locks guarantee data integrity while enabling maximum concurrent access to the
data by unlimited users.
Automatic Locking
Oracle locking is performed automatically and requires no user action. Implicit
locking occurs for SQL statements as necessary, depending on the action requested.
Oracle’s lock manager automatically locks table data at the row level. By locking
table data at the row level, contention for the same data is minimized.
Oracle’s lock manager maintains several different types of row locks, depending on
what type of operation established the lock. The two general types of locks are
exclusive locks and share locks. Only one exclusive lock can be placed on a
resource (such as a row or a table); however, many share locks can be placed on a
single resource. Both exclusive and share locks always allow queries on the locked
resource but prohibit other activity on the resource (such as updates and deletes).
Manual Locking
Under some circumstances, a user might want to override default locking. Oracle
allows manual override of automatic locking features at both the row level (by first
querying for the rows that will be updated in a subsequent statement) and the table
level.
Quiesce Database
Database administrators occasionally need isolation from concurrent non-database
administrator actions, that is, isolation from concurrent non-database administrator
The actions, if any, that are audited for each schema object
Data encryption to prevent unauthorized users from bypassing Oracle and
accessing data
Security Mechanisms
The Oracle server provides discretionary access control, which is a means of
restricting access to information based on privileges. The appropriate privilege
must be assigned to a user in order for that user to access a schema object.
Appropriately privileged users can grant other users privileges at their discretion.
For this reason, this type of security is called discretionary.
Oracle manages database security using several different facilities:
Database Users and Schemas
Privileges
Roles
Storage Settings and Quotas
Profiles and Resource Limits
Selective Auditing of User Actions
Fine-Grained Auditing
Figure 1–5 illustrates the relationships of the different Oracle security facilities, and
the following sections provide an overview of users, privileges, and roles.
Users
Privileges to Privileges to
execute the execute the Application Privileges
ACCTS_PAY ACCTS_REC
application application
Security Domain Each user has a security domain—a set of properties that determine
such things as:
The actions (privileges and roles) available to the user
The tablespace quotas (available disk space) for the user
The system resource limits (for example, CPU processing time) for the user
Each property that contributes to a user’s security domain is discussed in the
following sections.
Privileges
A privilege is a right to run a particular type of SQL statement. Some examples of
privileges include the right to:
Connect to the database (create a session)
Granted Privileges Privileges are granted to users so that users can access and
modify data in the database. A user can receive a privilege two different ways:
Privileges can be granted to users explicitly. For example, the privilege to insert
records into the employees table can be explicitly granted to the user SCOTT.
Privileges can be granted to roles (a named group of privileges), and then the
role can be granted to one or more users. For example, the privilege to insert
records into the employees table can be granted to the role named CLERK,
which in turn can be granted to the users SCOTT and BRIAN.
Because roles enable easier and better management of privileges, privileges are
normally granted to roles and not to specific users. The following section explains
more about roles and their use.
Roles
Oracle provides for easy and controlled privilege management through roles. Roles
are named groups of related privileges that you grant to users or other roles.
Default Tablespace Each user is associated with a default tablespace. When a user
creates a table, index, or cluster and no tablespace is specified to physically contain
the schema object, the user’s default tablespace is used if the user has the privilege
to create the schema object and a quota in the specified default tablespace. The
default tablespace feature provides Oracle with information to direct space use in
situations where schema object’s location is not specified.
Temporary Tablespace Each user has a temporary tablespace. When a user runs a
SQL statement that requires the creation of temporary segments (such as the
creation of an index), the user’s temporary tablespace is used. By directing all users’
temporary segments to a separate tablespace, the temporary tablespace feature can
reduce I/O contention among temporary segments and other types of segments.
Tablespace Quotas Oracle can limit the collective amount of disk space available to
the objects in a schema. Quotas (space limits) can be set for each tablespace
available to a user. The tablespace quota security feature permits selective control
over the amount of disk space that can be consumed by the objects of specific
schemas.
Password restrictions:
– Account locking after multiple unsuccessful login attempts
– Password expiration and grace period
– Password reuse and complexity restrictions
Different profiles can be created and assigned individually to each user of the
database. A default profile is present for all users not explicitly assigned a profile.
The resource limit feature prevents excessive consumption of global database
system resources.
Schema Object Auditing Schema object auditing is the auditing of access to specific
schema objects without regard to user. Object auditing monitors the statements
permitted by object privileges, such as SELECT or DELETE statements on a given
table.
For all types of auditing, Oracle allows the selective auditing of successful
statement executions, unsuccessful statement executions, or both. This enables
monitoring of suspicious statements, regardless of whether the user issuing a
statement has the appropriate privileges to issue the statement. The results of
audited operations are recorded in a table called the audit trail. Predefined views of
the audit trail are available so you can easily retrieve audit records.
Fine-Grained Auditing
Fine-grained auditing allows the monitoring of data access based on content. For
example, a central tax authority needs to track access to tax returns to guard against
employee snooping. Enough detail is wanted to be able to determine what data was
accessed, not just that SELECT privilege was used by a specific user on a particular
table. Fine-grained auditing provides this functionality.
In general, fine-grained auditing policy is based on simple user-defined SQL
predicates on table objects as conditions for selective auditing. During fetching,
whenever policy conditions are met for a returning row, the query is audited. Later,
Oracle executes user-defined audit event handlers using autonomous transactions
to process the event.
Fine-grained auditing can be implemented in user applications using the DBMS_FGA
package or by using database triggers.
Types of Failures
Several circumstances can halt the operation of an Oracle database. The most
common types of failure are described in the following table.
Failure Description
User error Requires a database to be recovered to a point in time before
the error occurred. For example, a user could accidentally
drop a table. To enable recovery from user errors and
accommodate other unique recovery requirements, Oracle
provides exact point-in-time recovery. For example, if a user
accidentally drops a table, the database can be recovered to
the instant in time before the table was dropped.
Statement failure Occurs when there is a logical failure in the handling of a
statement in an Oracle program. When statement failure
occurs, any effects of the statement are automatically undone
by Oracle and control is returned to the user.
Failure Description
Process failure Results from a failure in a user process accessing Oracle, such
as an abnormal disconnection or process termination. The
background process PMON automatically detects the failed
user process, rolls back the uncommitted transaction of the
user process, and releases any resources that the process was
using.
Instance failure Occurs when a problem arises that prevents an instance from
continuing work. Instance failure can result from a hardware
problem such as a power outage, or a software problem such
as an operating system failure. When an instance failure
occurs, the data in the buffers of the system global area is not
written to the datafiles.
After an instance failure, Oracle automatically performs
instance recovery. If one instance in a Real Application
Clusters environment, another instance recovers the redo for
the failed instance. In a single-instance database, or in a Real
Application Cluster database in which all instances fail,
Oracle automatically applies all redo when you restart the
database.
Media (disk) failure An error can occur when trying to write or read a file on disk
that is required to operate the database. A common example
is a disk head failure, which causes the loss of all files on a
disk drive.
Different files can be affected by this type of disk failure,
including the datafiles, the redo log files, and the control files.
Also, because the database instance cannot continue to
function properly, the data in the database buffers of the
system global area cannot be permanently written to the
datafiles.
A disk failure requires you to restore lost files and then
perform media recovery. Unlike instance recovery, media
recovery must be initiated by the user. Media recovery
updates restored datafiles so the information in them
corresponds to the most recent time point before the disk
failure, including the committed data in memory that was
lost because of the failure.
Oracle provides for complete media recovery from all possible types of hardware
failures, including disk failures. Options are provided so that a database can be
completely recovered or partially recovered to a specific point in time.
If some datafiles are damaged in a disk failure but most of the database is intact and
operational, the database can remain open while the required tablespaces are
The Redo Log The redo log is a set of files that protect altered database data in
memory that has not been written to the datafiles. The redo log can consist of two
parts: the online redo log and the archived redo log.
The online redo log is a set of two or more online redo log files that record all
changes made to the database, including both uncommitted and committed
changes. Redo entries are temporarily stored in redo log buffers of the system
global area, and the background process LGWR writes the redo entries sequentially
to an online redo log file. LGWR writes redo entries continually, and it also writes a
commit record every time a user process commits a transaction.
Optionally, filled online redo files can be manually or automatically archived before
being reused, creating archived redo logs.
To enable or disable archiving, set the database in one of the following modes:
ARCHIVELOG: The filled online redo log files are archived before they are
reused in the cycle.
NOARCHIVELOG: The filled online redo log files are not archived.
In ARCHIVELOG mode, the database can be completely recovered from both
instance and disk failure. The database can also be backed up while it is open and
available for use. However, additional administrative operations are required to
maintain the archived redo log.
If the database’s redo log operates in NOARCHIVELOG mode, the database can be
completely recovered from instance failure but not from disk failure. Also, the
database can be backed up only while it is completely closed. Because no archived
redo log is created, no extra work is required by the database administrator.
Undo Records Undo records can be stored in either undo tablespaces or rollback
segments. Oracle uses the undo data for a variety of purposes, including accessing
before-images of blocks changed in uncommitted transactions. During database
recovery, Oracle applies all changes recorded in the redo log and then uses undo
information to roll back any uncommitted transactions.
See Also:
Oracle9i Database Administrator’s Guide for more information
about managing undo space
"Undo Space Acquisition and Management" on page 5-8 for
information about specifying the undo method at startup
"Automatic Undo Management" on page 2-16 for more
information about managing undo space
Control Files The control files of a database keep, among other things, information
about the file structure of the database and the current log sequence number being
written by LGWR. During normal recovery procedures, the information in a control
file is used to guide the automated progression of the recovery operation. Oracle
can multiplex the control file, that is, simultaneously maintain a number of
identical control files.
Database Backups Because one or more files can be physically damaged as the result
of a disk failure, media recovery requires the restoration of the damaged files from
the most recent operating system backup of a database.
You can either back up the database files with Recovery Manager, which is
recommended, or use operating system utilities. Recovery Manager (RMAN) is an
Oracle utility that manages backup and recovery operations, creates backups of
database files (datafiles, control files, and archived redo log files), and restores or
recovers a database from backups.
Workload
Data warehouses are designed to accommodate ad hoc queries. You might not
know the workload of your data warehouse in advance, so a data warehouse
should be optimized to perform well for a wide variety of possible query
operations.
OLTP systems support only predefined operations. Your applications might be
specifically tuned or designed to support only these operations.
Data Modifications
A data warehouse is updated on a regular basis by the ETL process (run nightly or
weekly) using bulk data modification techniques. The end users of a data
warehouse do not directly update the data warehouse.
In OLTP systems, end users routinely issue individual data modification statements
to the database. The OLTP database is always up to date, and reflects the current
state of each business transaction.
Schema Design
Data warehouses often use denormalized or partially denormalized schemas (such
as a star schema) to optimize query performance.
OLTP systems often use fully normalized schemas to optimize
update/insert/delete performance, and to guarantee data consistency.
Typical Operations
A typical data warehouse query scans thousands or millions of rows.For example,
"Find the total sales for all customers last month."
A typical OLTP operation accesses only a handful of records. For example,
"Retrieve the current order for this customer."
Historical Data
Data warehouses usually store many months or years of data. This is to support
historical analysis.
OLTP systems usually store data from only a few weeks or months. The OLTP
system stores only historical data as needed to successfully meet the requirements
of the current transaction.
Operational Analysis
System
Metadata
In Figure 1–6, the metadata and raw data of a traditional OLTP system is present, as
is an additional type of data, summary data. Summaries are very valuable in data
warehouses because they pre-compute long operations in advance. For example, a
typical data warehouse query is to retrieve something like August sales.
Summaries in Oracle are called materialized views.
Data Staging
Sources Area Warehouse Users
Operational Analysis
System
Metadata
Figure 1–8 Architecture of a Data Warehouse with a Staging Area and Data Marts
Metadata
Materialized Views
A materialized view provides indirect access to table data by storing the results of a
query in a separate schema object. Unlike an ordinary view, which does not take up
any storage space or contain any data, a materialized view contains the rows
resulting from a query against one or more base tables or views. A materialized
view can be stored in the same database as its base tables or in a different database.
Materialized views stored in the same database as their base tables can improve
query performance through query rewrites. Query rewrites are particularly useful
in a data warehouse environment.
OLAP Overview
Oracle integrates Online Analytical Processing (OLAP) into the database to support
business intelligence. This integration provides the power of a multidimensional
database while retaining the manageability, scalability, and reliability of the Oracle
database and the accessibility of SQL.