Expert Oracle Database architecture : Oracle Database 9i ... - GBV

15 downloads 454 Views 527KB Size Report
Expert Oracle. Database Architecture. Oracle Database 9/, 10gr, and 11g Programming. Techniques and Solutions. Second Edition. TECHNiSCHE.
Expert Oracle Database Architecture Oracle Database 9/, 10gr, and 11g Programming

Techniques

and Solutions

Second Edition

TECHNiSCHE

JNFORMATIONSBIBLIOTHEK UN!VERSITAT£BIBLIOTHEK HANNOVER

Thomas

Kyte Apress

Contents

Contents at

Glance

a

xviii

Foreword Foreword from the First Edition About the Author

xix xxii

About the Technical Reviewers

xxiii

Acknowledgments

xxiv ».xxv

Introduction.

Setting Up Your Environment

Chapter

1:

Developing Successful Oracle Applications

The Black Box

Approach

How

Not) to Develop Database Applications

(and

How

Understanding

xxxii

1 2

My Approach

Oracle Architecture

...........3 11 12

Understanding Concurrency Control

21

Multi-Versioning

25

Database

Independence?

32

How Do I Make It Run Faster?

46

The DBA-Developer Relationship

48

Summary

vi

v

49

CONTENTS

Chapter 2: Architecture Overview..

51

Defining

52

Database and Instance

The SGA and

Connecting

Background

Processes

58

to Oracle

60

Dedicated Server

60

Shared Server

62

Mechanics of

Connecting

over TCP/IP

63

Summary

66

Chapter 3: Files

67

Parameter Files

68

What Are Parameters?

69

Legacy init.ora Parameter Files

73

Server Parameter Files

(SPFILEs)

74

Converting to SPFILEs

75

Trace Files

82

Requested Trace Files

83

Trace Files Generated in

Response

to Internal Errors

88

Trace File Wrap-up

93

Alert File

93

Data Files

96

A Brief Review of File

The

System Mechanisms

Storage Hierarchy

Dictionary-Managed

in

and

an

Oracle Database

Locally-Managed Tablespaces

,

96 97

101

Temp Files

103

Control Files

105

Redo Log Files

105

Online Redo Log

106

Archived Redo Log

108

Password Files

109

vii

CONTENTS

Change Tracking File

113

Flashback Logs

114

Flashback Database

114

Flash Recovery Area

115

DMP Files Data

116

(EXP/IMP Files)

117

Pump Files

Flat Files

120

Summary

120 121

Chapter 4: Memory Structures The Process Global Area and User Global Area Manual PGA Memory Management

123

Automatic PGA Memory Management

129

Choosing Between

Manual and Auto

Memory Management

PGA and UGA Wrap-up

The

System Global Area

140 142

142

Fixed SGA

148

Redo Buffer

148

Block Buffer Cache

149

Shared Pool

156

Large Pool

159

Java Pool

160

Streams Pool

160

Automatic SGA Automatic

Memory Management

Memory Management

Summary Chapter 5: Oracle Processes Server Processes

viii

122

161 162

164 165

166

Dedicated Server Connections

166

Shared Server Connections

169

II CONTENTS

Database Resident Connection Pooling

170

(DRCP)

Connections vs. Sessions

170

Dedicated Server vs. Shared Server vs. DRCP

176

Dedicated/Shared Server

179

Background

Wrap-up

180

Processes

181

Focused Background Processes

Utility Background

190

Processes

193

Slave Processes

193

I/O Slaves Pnnn: Parallel

193

Query Execution Servers

194

Summary Chapter 6: Locking

and

195

Latching

What Are Locks?

195

Locking Issues

198

Lost

198

Updates

199

Pessimistic Locking

Optimistic Locking Optimistic

or

Pessimistic

,

Locking?

201

207

Blocking

208

Deadlocks

211

Lock Escalation

215

Types

216

DML Locks

216

DDL Locks

225

Latches

230

Mutexes

240

Manual Locking and User-Defined Locks

240

Lock

Summary

241

CONTENTS

Chapter 7: Concurrency and Mutti-versioning What Are Concurrency Controls?

243

Transaction Isolation Levels

244

READ UNCOMMITTED

246

READ COMMITTED

248

REPEATABLE READ

249

SERIALIZABLE

252

READ ONLY

254

Implications of Multi-version Read Consistency A Common Data An

Explanation

Warehousing Technique That Fails

for

Higher Than Expected I/O

on

Hot Tables

Write Consistency

Seeing Why

a

Restart

Is a Restart

255 255 256

259

Consistent Reads and Current Reads

259 262

Important

to Us?

Summary

264

265

Chapter 8: Transactions

267

Transaction Control Statements

267

Atomicity

269

Statement-Level

Atomicity

269

Procedure-Level

Atomicity

271

Transaction-Level Atomicity

275

DDL and

275

Atomicity

Durability

275

WRITE Extensions to COMMIT

276

COMMITS in

277

a

Non-Distributed PL/SQL Block

Integrity Constraints and Transactions IMMEDIATE Constraints DEFERRABLE Constraints and

x

243

279 279

Cascading Updates

280

CONTENTS

Bad Transaction Habits Committing in

a

284

Loop

284

Using Autocommit

290

Distributed Transactions

291

Autonomous Transactions

,

293

How Autonomous Transactions Work

293

When to Use Autonomous Transactions

295

Summary

,

Chapter 9: Redo and Undo

298 299

What Is Redo?

300

What Is Undo?

300

How Redo and Undo Work

Together

Example INSERT-UPDATE-DELETE

Scenario

Commit and Rollback Processing

304 304

308

What Does

a

COMMIT Do?

308

What Does

a

ROLLBACK Do?

315

Investigating Redo Measuring

Redo

Can I Turn Off Redo

Why

316

Can't I Allocate

316

Log a

Generation?

New

Log?

318 321

Block Cleanout

323

Log Contention

326

Temporary Tables and Redo/Undo

328

Investigating Undo

332

What Generates the Most and Least Undo?

332

0RA-01555: snapshot too old Error

334

Summary

344

xi

CONTENTS

Chapter 10: Database Tables Types of Tables

345

Terminology

347

Segment

347

Segment Space Management

350

High-water Mark

350

FREELISTS

352

PCTFREE and PCTUSED

356

LOGGING and NOLOGGING

359

INITRANS and MAXTRANS

359

Heap Organized Index

Tables

359

Organized Tables

363

Index

Organized Tables Wrap-up

Index Clustered Tables Index Clustered Tables

Wrap-up

Hash Clustered Tables Hash Clustered Tables

Wrap-up

378 378 386

386 394

Sorted Hash Clustered Tables

395

Nested Tables

397

Nested Tables Syntax

398

Nested Table

405

Storage

Nested Tables

Wrap-up

Temporary Tables Temporary Tables Wrap-up

Object Tables Object Tables Wrap-up

Summary

xii

345

408

409 415

416 423

423

CONTENTS

Chapter

11: indexes

425

An Overview of Oracle Indexes

425

B*Tree Indexes

427

Index

Key Compression

Reverse

430

Key Indexes

433

Descending Indexes

439

When Should You Use a B*Tree index?

441

B*Trees Wrap-up

452

Bitmap Indexes

452

When Should You Use a

Bitmap Index?

Bitmap Join Indexes Bitmap

Indexes

453 457

Wrap-up

459

Function-Based Indexes

460

Important Implementation Details

460

A

461

Simple

Function-Based Index

Example

Indexing Only

Some of the Rows

470

Implementing

Selective

472

Caveat

Uniqueness

Regarding ORA-01743

472

Function-Based Indexes Wrap-up

473

Application Domain Indexes

Frequently Asked

Questions and

474

Myths About Indexes

475

Do Indexes Work on Views?

475

Do Nulls and Indexes Work

475

Should

Why

Foreign Keys

Isn't

My

Myth: Space Myth:

Most

Summary

Index

Together?

Be Indexed?

477

Used?

479

Getting

Is Never Reused in an Index

Discriminating

Elements Should Be First

485 488

491

xiii

CONTENTS

Chapter 12: Datatypes An Overview of Oracle Character and

Datatypes

Binary String Types

493 496

NLS Overview

496

Character Strings

499

Binary Strings: RAW Types

506

Number

508

Types

NUMBER Type Syntax and Usage

510

BINARY_FLOAT/BINARY_DOUBLE Type Syntax and Usage

513

Non-native Number Types

514

Performance Considerations

514

516

Long Types Restrictions

on

LONG and LONG RAW Types

Coping with Legacy LONG Types

Dates, Timestamps, and Interval Types

516 518

523

Formats

523

DATE Type

525

TIMESTAMP INTERVAL

LOB

Type

531 538

Type

541

Types

Internal LOBs

541

BFILEs

552

ROWID/UROWID

Types

Chapter

554 555

Summary 13:

Partitioning

Partitioning Overview

xiv

493

557 557

Increased Availability

558

Reduced Administrative Burden

560

Enhanced Statement Performance

564

11 CONTENTS

Table Partitioning Schemes

566

Range Partitioning

567

Hash Partitioning

569

List

574

Partitioning

Interval

Partitioning

Reference

575

Partitioning

581

,

Composite Partitioning

586

Row Movement

588

Table

Partitioning

Schemes

590

Wrap-up

Partitioning Indexes Local Indexes

vs.

591

Global Indexes

592

Local Indexes

593

Global Indexes

599

Partitioning and Performance, Revisited

612

Auditing and Segment Space Compression

618

Summary

619

Chapter 14: Parallel Execution

..........621

When to Use Parallel Execution A Parallel

622 623

Processing Analogy

Oracle Exadata

624

Parallel Query

624

Parallel DML

630

Parallel DDL

633

Parallel DDL and Data

Loading Using

Parallel DDL and Extent

Parallel

Trimming

Procedural Parallelism Pipelined

634

636

645

Recovery

Parallel

External Tables

Functions

Do-It-Yourself Parallelism

645 646

.-649

xv

m CONTENTS

Old School Do-It-Yourself Parallelism

652

656

Summary Chapter 15: Data Loading and Unloading

657

SQIAoader. Loading

657

Data with SQLLDR FAQs

661

SQLLDR Caveats

686

SQLLDR

686

Summary

External Tables

686

Setting Up External

Tables

687

Dealing with Errors Using

an

693

External Table to Load Different Files

Multiuser Issues

696

External Tables

697

Summary

Flat File Unload Data

-

Pump Unload

698 706

Summary

708

Chapter 16: Data Encryption Types of Encryption

....709 709

Data in Motion

709

Data at Rest

710

Manual Application

Encryption

The Oracle Wallet

Transparent

Column Level

713 714

Encryption

Transparent Tablespace Encryption

717 719

What Encryption Is Not About

722

Implementing Manual Application Encryption

723

Reasons to Avoid the Manual

xvi

696

Approach

723

Performance Implications of the Manual Approach

724

When to Use the Manual Approach

729

CONTENTS

729

Implementing Column Level Encryption How to Use Column

729

Encryption

730

Data Storage with Column Encryption

Measuring

the Performance

Influences

on

the

Impact

of Column

Encryption

734

,

734

Magnitude

Limitations of Column

740

Encryption

741

Implementing Tablespace Encryption How to Use Data

Storage

Measuring

Deciding

741

Tablespace Encryption with

the Performance Impact of

on an

741

Tablespace Encryption

743

Tablespace Encryption

748

Encryption Technique

749

Summary

Index

-

751

xvii