Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Contents
About the Author .............................................................................................xxxiAbout the Technical Reviewer ..................................................................xxxiiAcknowledgments .............................................................................................xxxiiiIntroduction .....................................................................................................xxxv
Part OneDatabase Basics, Data Modeling, and UNIX/Linux ........................................................................................1
Chapter 1 The Oracle DBA’s World ...............................................3
The Oracle DBA’s Role .......................................................................................3The DBA’s Security Role .....................................................................................4The DBA’s System Management Role ...............................................................6The DBA’s Database Design Role ......................................................................8
Different DBA Job Classifications ..........................................................10Types of Databases ...........................................................................................10
Online Transaction Processing and Decision Support System Databases ..............................................................11Development, Test, and Production Databases .............................................11
Background and Training ................................................................................12Background and Training for an Oracle DBA .................................................12Certification ......................................................................................................15Resources and Organizations for Oracle DBAs ..............................................16Managing High-Performance Databases .......................................................18Improving Your Troubleshooting Skills ...........................................................19
The Daily Routine of a Typical Oracle DBA .........................................21Some General Advice .........................................................................................21
Know When You Need Help .............................................................................22Remember You Are Not Alone .........................................................................22Think Outside the Box ......................................................................................22
Summary ...................................................................................................................23
vii
*0228_Ch00_FINAL 3/13/03 1:19 PM Page vii
Chapter 2 Relational Database Modeling and Database Design ................................................................25
Relational Databases: A Brief Introduction .......................................26The Relational Database Model ...................................................................26
Database Schemas ...........................................................................................27Data Definition and Data Manipulation Languages .....................................27Relational Algebra ............................................................................................28Relational Calculus ...........................................................................................29SQL and Relational Theory ..............................................................................29
Relational Database Life Cycle ................................................................30Requirements Gathering and Analysis .....................................................30Logical Database Design ...............................................................................31
Entity-Relationship Modeling .........................................................................32Normalization ...................................................................................................38The Normal Forms ...........................................................................................40ERM Tools: The Oracle Designer .....................................................................44
Physical Database Design .............................................................................45Transformation of Entities and Relationships ...............................................46Designing Different Types of Tables ................................................................47Table Structures and Naming Conventions ...................................................47Column Specifications and Choosing Data Types .........................................47Business Rules and Data Integrity ..................................................................47
Implementation of the Physical Design ................................................48Database Sizing and Database Storage ..........................................................48Implementing Database Security ...................................................................48Moving to the New System ..............................................................................49Reverse Engineering a Database .....................................................................49
Object-Relational and Object Databases ..............................................49The Relational Model .......................................................................................50The Object Model .............................................................................................50The Object-Relational Model ..........................................................................51
Summary ..................................................................................................................53
Chapter 3 Essential UNIX (and Linux) for the Oracle DBA ........................................................55
Overview of the UNIX Operating System ..................................................55Understanding the UNIX Shell(s) ...............................................................57
Accessing the UNIX System .............................................................................58Logging Into and Logging Out of UNIX ..........................................................58
Overview of Basic UNIX Commands ...............................................................60
Contents
viii
*0228_Ch00_FINAL 3/13/03 1:19 PM Page viii
Introducing the UNIX Environment .............................................................63Displaying the Environment ...........................................................................64Working with Shell Variables ...........................................................................65Modifying the Environment ............................................................................65
Input and Output in UNIX ..............................................................................65Navigating Files and Directories in UNIX ...........................................66
Files in the UNIX System .................................................................................67Types of Files .....................................................................................................67Linking Files ......................................................................................................67Managing Files ..................................................................................................68Permissions: Reading from or Writing to Files in UNIX ................................69UNIX Directory Structure ................................................................................72Directory Management ....................................................................................72Important UNIX Directories ............................................................................73
Writing Files with the vi Editor .............................................................74Creating and Modifying Files Using vi ............................................................74Using the Head and Tail Commands ..............................................................75
Shell Scripting ..................................................................................................76Creating a Simple UNIX Shell Program ..........................................................76Using Shell Variables ........................................................................................76
Control Flow Structures in Korn Shell Programming .......................79Looping .............................................................................................................79Conditional Branching .....................................................................................81
Dealing with UNIX Processes ........................................................................82Running Programs in the Background with Nohup ......................................83Terminating Processes with the Kill Command .............................................83
UNIX System Administration and the Oracle DBA ................................84UNIX Backup and Restore Utilities .................................................................84The Crontab and Automation of Scripts ........................................................85Using Telnet ......................................................................................................86Remote Login and Remote Copy .....................................................................87Using ssh, the Secure Shell ..............................................................................87Using FTP to Send and Receive Files ..............................................................87UNIX System Performance Monitoring Tools ................................................88
Disks and Storage in UNIX ............................................................................92Disk Storage Configuration Choices ...............................................................92Monitoring Disk Usage ....................................................................................93Disk Storage, Performance, and Availability ..................................................94
RAID Systems ........................................................................................................95RAID Levels .......................................................................................................96Choosing the Ideal Disk Configuration ..........................................................98Redundant Disk Controllers ..........................................................................100RAID and Backups ..........................................................................................100RAID and Oracle .............................................................................................101
Contents
ix
*0228_Ch00_FINAL 3/13/03 1:19 PM Page ix
Storage Technologies .....................................................................................101Storage Area Networks ...................................................................................102Networked Attached Storage .........................................................................102InfiniBand .......................................................................................................103Oracle and Storage System Compatibility ....................................................103
Summary ................................................................................................................104
Part TwoThe Oracle RDBMS...............................................................................105
Chapter 4 Installing the Oracle9i RDBMS .........................107
Installing Oracle on UNIX Systems ........................................................107Reviewing the Documentation .....................................................................108Determining Disk and Memory Requirements ...........................................109
Following the Optimal Flexible Architecture ...................................110Mount Points ..................................................................................................112Directory and File Naming Conventions ......................................................112
Performing Preinstallation Tasks ...........................................................115UNIX System Administrator’s Tasks ..............................................................116Oracle Owner’s Tasks ......................................................................................120
A Final Checklist for the Installation ..............................................122Installing the Oracle Software ...............................................................123After the Installation ................................................................................134
UNIX Post-Installation Tasks .........................................................................134User Oracle Post-Installation Tasks ...............................................................135
Uninstalling Oracle .......................................................................................136Summary .................................................................................................................137
Chapter 5 Introduction to the Oracle9i Architecture ..............................................139
Oracle Database Structures ........................................................................139The Logical Structures ...................................................................................140Physical Database Structures ........................................................................146Trace Files .......................................................................................................152Data Files and Tablespaces ............................................................................152Automatic Undo Management ......................................................................157Oracle Managed Files .....................................................................................159
Oracle Processes ..............................................................................................159Interaction Between the User and Oracle Processes ...................................160The Server Process .........................................................................................160The Background Processes ............................................................................161
Contents
x
*0228_Ch00_FINAL 3/13/03 1:19 PM Page x
Oracle Memory Structures ............................................................................166Oracle System Global Area (SGA) ..................................................................167The Program Global Area (PGA) ....................................................................175
Monitoring Memory Allocation ...................................................................178Dynamically Modifying the SGA ...................................................................181Using Oracle’s SGA and PGA Advisories .......................................................183
Managing Memory Parameters with Oracle Enterprise Manager ....185A Simple Oracle Database Transaction ..................................................187Data Consistency and Data Concurrency ................................................189
The Database Writer and the Write Ahead Protocol ....................................190The System Change Number .........................................................................190The Central Role of the Oracle Control File .................................................191
The Oracle Data Dictionary and the Dynamic Performance Views ..........................................................................192
The Oracle Data Dictionary ...........................................................................192The Dynamic Performance (V$) Views .........................................................193The Oracle Optimizer .....................................................................................194Oracle Enterprise Manager ............................................................................195
Summary .................................................................................................................195
Chapter 6 Using SQL*Plus and iSQL*Plus ............................197
SQL*Plus for the DBA .....................................................................................197Using SQL*Plus in Interactive and Noninteractive Modes .........................198SQL*Plus Commands and SQL Commands .................................................198SQL*Plus Security ...........................................................................................199Setting the SQL*Plus Environment with the Set Command .......................202Setting Common SQL*Plus Variables ............................................................203SQL*Plus Command Line Arguments ..........................................................206Removing Settings with the Clear Command ..............................................207The Store Command ......................................................................................208The Show Command ......................................................................................208Exiting SQL*Plus .............................................................................................208
Key SQL*Plus “Performing” Commands ......................................................209The Sqlprompt Command .............................................................................209The Describe Command ................................................................................209The Host Command .......................................................................................210The Spool Command .....................................................................................210The Accept and Prompt Commands ............................................................211The Execute Command .................................................................................211The Pause Command .....................................................................................211Creating Command Files in SQL*Plus ..........................................................212Saving SQL Commands to a File ...................................................................212Executing SQL*Plus Scripts ...........................................................................213
Contents
xi
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xi
Executing a SQL*Plus Command Script .......................................................213Creating a Windows Batch Script ..................................................................215The Define and Undefine Commands ..........................................................216Using Comments in SQL*Plus .......................................................................217Listing Your SQL Commands .........................................................................217
Editing Within SQL*Plus ..............................................................................218Inserting and Deleting Lines in SQL*Plus ....................................................219Adding to Text ................................................................................................221Incorporating Comments with the Remark Command ..............................221Copying Tables with the Copy Command ....................................................221Making DML Changes Permanent with SQL*Plus .......................................222Creating Web Pages Using SQL*Plus .............................................................222
Key SQL*Plus Database Administration Commands ..............................223The Recover Command .................................................................................223The Start and Shutdown Commands ............................................................223The Archivelog Command .............................................................................223
Commands for Formatting SQL*Plus Output and Creating Reports .....................................................................................224
The Break Command .....................................................................................224The Column Command .................................................................................224The Compute Command ...............................................................................225The Repfooter Command ..............................................................................225The Repheader Command ............................................................................225The Btitle and Ttitle Commands ...................................................................225
Using SQL to Generate SQL ..........................................................................226Introducing the Oracle9i iSQL*Plus Interface ................................227
Installing the iSQL*Plus Software .................................................................228Configuring iSQL*Plus ...................................................................................228Using the iSQL*Plus Interface .......................................................................230Authentication Levels ....................................................................................233Executing Statements ....................................................................................235A Security Warning for iSQL*Plus ..................................................................236
Summary .................................................................................................................236
Contents
xii
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xii
Chapter 7 Schema Management in Oracle9i .........................237
Types of SQL Statements in Oracle .......................................................237System Control Statements ...........................................................................238Session Control Statements ...........................................................................239Data Manipulation Statements .....................................................................239Transaction Control Statements ...................................................................240Data Definition Statements ...........................................................................240
Oracle Schema Management ...........................................................................241Creating and Managing Tablespaces ........................................................242
Locally and Dictionary Managed Tablespaces .............................................243Creating Locally Managed Tablespaces ........................................................244Creating a Simple Table .................................................................................256
Special Oracle Tables ...................................................................................261Temporary Tables ...........................................................................................261Index-Organized Tables .................................................................................263External Tables ................................................................................................265Partitioned Tables ...........................................................................................267Data Dictionary Views for Managing Tables ................................................274Clusters ...........................................................................................................277Hash Clusters ..................................................................................................277
Oracle Indexes ..................................................................................................277Guidelines for Creating Indexes ....................................................................279Oracle Index Schemes ....................................................................................280Creating a Simple Index .................................................................................281Bitmap Indexes ...............................................................................................281Reverse Key Indexes .......................................................................................282Function-Based Indexes ................................................................................282Partitioned Indexes ........................................................................................282Monitoring Index Usage ...............................................................................284Index Maintenance ........................................................................................285
Database Integrity Constraint Management .........................................285Primary Key Constraints ................................................................................286Not Null Constraints ......................................................................................287Check Constraints ..........................................................................................287Unique Constraints ........................................................................................287Referential Integrity Constraints ...................................................................288
Contents
xiii
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xiii
Integrity Constraint States .............................................................................288Disabling Integrity Constraints .....................................................................289Rely Constraints ..............................................................................................290Deferrable and Immediate Constraints ........................................................290
Using Synonyms ..................................................................................................291Creating a Public Synonym ...........................................................................292Creating a Private Synonym ..........................................................................293Viewing Information on Synonyms ..............................................................294
Using Sequences ..............................................................................................294Using Triggers ..................................................................................................296Using Views .........................................................................................................296Using Materialized Views ............................................................................297
Using the Summary Advisor ..........................................................................298Creating Materialized Views ..........................................................................303
Summary ................................................................................................................307
Chapter 8 Oracle Transaction Management ..........................309
Transactions ......................................................................................................310Anatomy of a SQL Transaction ...................................................................311
Parsing .............................................................................................................311Binding ............................................................................................................312Execution ........................................................................................................312
Transaction Properties ...............................................................................312Transaction Concurrency Control ...........................................................313
Concurrency Problems ..................................................................................314Schedules and Serializability .........................................................................315The ISO Transaction Standard .......................................................................315Oracle Transaction Management ..................................................................316
Oracle’s Isolation Levels .........................................................................318Changing the Default Isolation Level ...........................................................319The Read-Only Isolation Level ......................................................................320The Serializable Isolation Level .....................................................................320The Read Committed vs. the Serializable Level of Isolation .......................320
Implementing Oracle’s Concurrency Control ......................................322Oracle Locking Methods ................................................................................323Oracle Lock Types ...........................................................................................324Oracle Lock Modes .........................................................................................325Explicit Locking in Oracle ..............................................................................328Managing Oracle Locks ..................................................................................330
Using Undo Records to Provide Read Consistency ...........................332Automatic Undo Management ......................................................................333
Contents
xiv
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xiv
Querying Old Data with Oracle Flashback ..........................................340Implementing Flashback Query ....................................................................342Discrete Transactions .....................................................................................346
Autonomous Transactions .............................................................................346Resumable Storage Allocation ..................................................................349
Resumable Operations ...................................................................................349Common Resumable Errors ..........................................................................350Using the Resumable Space Allocation Feature ..........................................350Notification of Suspended Operations .........................................................351Monitoring Resumable Space Allocation .....................................................352
Managing Long Transactions ......................................................................352Benefits of Using the Workspace Manager ...................................................353Table Versioning and Workspaces .................................................................353Managing the Workspace Manager ...............................................................359
Summary ................................................................................................................360
Part ThreeDatabase Creation, Connectivity, and User Management ....................................................................261
Chapter 9 Creating an Oracle Database ...............................363
Getting Ready to Create the Database ..................................................364Installing the Software ...................................................................................364Creating the File System for the Database ...................................................365Ensuring Enough Memory Is Allocated ........................................................367Getting Necessary Authorizations ................................................................367Setting the Operating System Environment Variables ................................367Creating the Initialization File .......................................................................368Important Oracle9i Initialization Parameters ..............................................370Rollback Segment Parameters .......................................................................383
Undocumented Initialization Parameters ..............................................391Viewing the Current Initialization Parameter Values .................391
Reading the Init.ora File (or the SPFILE) ......................................................392The V$PARAMETER Table ..............................................................................392The Show Parameter Command ...................................................................392
Creating the Database ...................................................................................393Setting Operating System Variables ..............................................................394Ensuring You Have the Privileges to Create Databases ...............................394Creating the Init.ora File ................................................................................395Starting the Oracle Instance ..........................................................................396
Contents
xv
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xv
The Create Database Script ...........................................................................399Running Oracle Scripts to Create Data Dictionary Objects ........................403Creating Additional Tablespaces ...................................................................404Changing the Passwords for the Default Users ............................................406Changing the Archive Logging Mode ............................................................406Running the Pupbld.sql File ..........................................................................408What Next? ......................................................................................................409
The Server Parameter File (SPFILE) ......................................................409Creating a Server Parameter File ...................................................................410Scope of Dynamic Parameter Changes ........................................................413
Starting and Shutting Down the Database ...........................................414Starting the Database .....................................................................................414Restricting Database Access ..........................................................................417Shutting Down the Database .........................................................................418Quiescing a Database .....................................................................................421Suspending a Database ..................................................................................423Using V$VIEWS to Monitor Database Status ................................................423
Summary .................................................................................................................424
Chapter 10 Connectivity and Networking ...............................425
Oracle Networking and Database Connectivity ...................................426Networking Concepts: How Oracle Networking Works ........................427
Database Instance Name ...............................................................................428Database Service Name .................................................................................428Connect Descriptors ......................................................................................429Connect Identifiers .........................................................................................429Connect Strings ..............................................................................................430
The Listener and Connectivity .................................................................431Automatic Service Registration .....................................................................432Listener Commands .......................................................................................433Listener Management ....................................................................................434
Naming and Connectivity ..............................................................................435Local Naming ..................................................................................................436Host Naming Method .....................................................................................439External Naming Method ..............................................................................439Oracle Names ..................................................................................................440The Directory Naming Method .....................................................................440
Oracle and Java Database Connectivity ................................................461Establishing Database Connectivity .............................................................461Working with the Database ...........................................................................462A Complete Program ......................................................................................465
Connectivity Troubleshooting ...................................................................466Summary .................................................................................................................468
Contents
xvi
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xvi
Chapter 11 User Management and Database Security .....469
Managing Users ..................................................................................................470Preliminary Tasks Before Creating Users ......................................................470Creating a New User .......................................................................................471User Profiles and Resource Management ....................................................472Profile Parameters and Limits .......................................................................473
Using the Database Resource Manager ....................................................477Using the Database Resource Manager ........................................................478Creating Resource Plans and Plan Directives ..............................................483Enabling the Database Resource Manager ..................................................485
Managing Access to Data ..............................................................................486Privileges in an Oracle Database ...................................................................486Roles and Privileges ........................................................................................490Using Views and Stored Procedures to Manage Privileges ..........................493
Fine-grained Data Security ........................................................................493Using Virtual Private Databases ....................................................................494Label-Based Access Control ..........................................................................500
Auditing Database Usage ..............................................................................501Customizing Database Auditing with the Help of Triggers .........................501Enabling Auditing ...........................................................................................505Oracle Default Auditing .................................................................................506Audit Levels .....................................................................................................508Turning Auditing On ......................................................................................508Turning Auditing Off ......................................................................................509Using Fine-grained Auditing .........................................................................509Managing the Audit Trail ...............................................................................511
User Authentication .......................................................................................511Database Authentication of Users ................................................................511External Authentication .................................................................................516Proxy Authentication .....................................................................................517Centralized User Authorization .....................................................................517
Enterprise User Security ............................................................................517Shared Schemas .............................................................................................518Single Sign-On ................................................................................................518Data Encryption .............................................................................................518Using Oracle Internet Directory for Security Management ........................518
Database Security Do’s and Don’ts ........................................................519User Accounts .................................................................................................519Passwords ........................................................................................................519Operating System Authentication .................................................................520Audit Your Database .......................................................................................520Grant Privileges Appropriately ......................................................................520
Contents
xvii
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xvii
Set Appropriate Permissions .........................................................................521Safeguard the Network and the Listener ......................................................522Keep Up-to-Date ............................................................................................523Use Oracle’s Advanced Security Feature .......................................................523Take Care of Application Security .................................................................524
Useful Techniques for Managing Users ..................................................524How to Alter a Profile .....................................................................................524How to List User Information ........................................................................525How to Find Out the Memory Use for Each Active Session ........................525What SQL Is a User Currently Executing? .....................................................526How to Log In As a Different User .................................................................526Useful DBA Views to Monitor User Roles and Privileges .............................527How to Kill a User’s Session ...........................................................................527
Summary .................................................................................................................529
Part FourData Loading, Backup, and Recovery ....................531
Chapter 12 Loading and Transforming Data .........................533
Introduction to Data Loading and Transformation ..........................533Loading Data with ETL ..................................................................................534Loading Data with the Oracle9i Warehouse Builder ...................................535
The SQL*Loader Utility ................................................................................536Different Methods of Data Loading ..............................................................536The SQL*Loader Control File ........................................................................537Generating Data During the Load .................................................................547Invoking SQL*Loader .....................................................................................548
Using External Tables to Load Data ......................................................555Using External Tables for Data Loading .......................................................556Important Access Parameters for External Tables .......................................558Using SQL*Loader to Generate External Table Creation Statements .........559
Transforming Data ...........................................................................................562Deriving the Data from Existing Tables ........................................................563Using PL/SQL to Transform Data ..................................................................564Using SQL to Transform Data ........................................................................564
Some Useful SQL*Loader Data-Loading Techniques ............................573Using the When Clause During Loads ..........................................................573Loading the Username into a Table ..............................................................574Loading Large Data Fields into a Table .........................................................574Loading a Sequence Number into a Table ....................................................575
Contents
xviii
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xviii
Loading Data from a Table into an ASCII File ..............................................575Identifying and Removing Duplicate Data ...................................................575Dropping Indexes Before Bulk Data Loads ..................................................576Loading into Multiple Tables .........................................................................576Trapping Error Codes from SQL*Loader ......................................................576Loading XML Data into an Oracle XML Database .......................................577
Summary .................................................................................................................577
Chapter 13 Using the Export and Import Utilities .....579
Exporting and Importing Data ...................................................................579Using the Export Utility ............................................................................580
Export Parameters ..........................................................................................581Invoking the Export Utility ............................................................................587
Using the Import Utility ............................................................................590The Order of Importing ..................................................................................590Import Parameters .........................................................................................590Invoking the Import Utility ............................................................................598
Transportable Tablespaces ..........................................................................599Uses of Transportable Tablespaces ...............................................................600Transporting a Tablespace .............................................................................600
Some Export and Import Techniques ........................................................604Avoiding Common Export/Import Errors ....................................................605Using the Statistics Parameter Appropriately ..............................................605Understanding the Limitations of the Export and Import Utilities ...........606Performing an Efficient Database Migration ...............................................606Restoring a Database Using the Export and Import Utilities ......................607Exporting and Importing Large Databases ..................................................607UNIX Shell Script to Automate Exports ........................................................608Ensuring the Validity of the Exports ..............................................................608Optimizing Exports and Imports ..................................................................609
Summary .................................................................................................................610
Chapter 14 Backing Up Databases .................................................611
Backing Up Oracle Databases ......................................................................611Important Backup Terms ...............................................................................612Backup Strategies ...........................................................................................614Backing Up the “Other” Files .........................................................................619A Summary of Backup Methods ....................................................................619
Contents
xix
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xix
Oracle Recovery Manager ..............................................................................619Benefits of RMAN ...........................................................................................620RMAN Architecture ........................................................................................621Connecting to RMAN .....................................................................................622Scripting with RMAN .....................................................................................624Important RMAN Terms ................................................................................625RMAN Commands .........................................................................................627Configuring RMAN .........................................................................................631Creating the Recovery Catalog ......................................................................637Examples of Various Backups Using RMAN .................................................642Performing Incremental Backups .................................................................645Using RMAN to Perform Online Backups ....................................................646
Using a Media Management Layer with RMAN .........................................647Using Legato Single Server Version with RMAN ..........................................648The LSSV Architecture ...................................................................................649Installing LSSV ................................................................................................650Using LSSV ......................................................................................................651LSSV and RMAN .............................................................................................652
Creating Backups with Operating System Commands ..........................655Making Whole Database Backups .................................................................656Partial Database Backups ..............................................................................661Monitoring User-Managed Online Backups ................................................662
Enhanced Data Protection for Disaster Recovery ............................662Oracle Data Guard and Standby Databases .................................................663Physical and Logical Standby Databases ......................................................664Protection Modes ...........................................................................................665
Database Corruption and Testing Backups ...........................................666Oracle Data Block Corruption .......................................................................666Detecting Data Block Corruption .................................................................667Verification of RMAN Backups ......................................................................669Oracle’s HARD Initiative ................................................................................670
Techniques and Troubleshooting ...............................................................670Monitoring RMAN ..........................................................................................670The ORA_00257 Error .....................................................................................671
Summary .................................................................................................................671
Chapter 15 Database Recovery ........................................................673
Types of Database Failures ........................................................................673System Failure .................................................................................................673Fast-Start Fault Recovery ...............................................................................674Data Center Disasters ....................................................................................675Human Error ...................................................................................................675Media Failures ................................................................................................676
Contents
xx
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xx
Extent of Database Failure and Types of Recovery ........................677Restoring vs. Recovering a Database ............................................................677Time Needed for Recovery .............................................................................678Complete and Incomplete Recovery ............................................................679Open and Closed Recovery ............................................................................679
Reducing Your Vulnerability ......................................................................679Performing Recovery with RMAN .................................................................680
Why RMAN Is Best for Recovery ....................................................................680User-Managed Recovery of a Database ........................................................682
Typical Media Recovery Scenarios ...........................................................683Complete Recovery of a Whole Database .....................................................683Recovering a Tablespace ................................................................................686Recovering a Data File ....................................................................................688Incomplete Recovery .....................................................................................690Recovering from the Loss of Control Files ....................................................693Recovering a Data File Without a Backup ....................................................697
Cloning a Database .........................................................................................698Using RMAN ...................................................................................................698Cloning a Database Manually .......................................................................702
Techniques for Granular Recovery ...........................................................703Tablespace Point-in-Time Recovery .............................................................704Using RMAN for TSPITR ................................................................................704Using LogMiner for Precision Recovery .......................................................705Using Flashback Query for Recovery ............................................................711
Repairing Data Corruption and Trial Recovery ................................714Block Media Recovery ....................................................................................714Trial Recovery .................................................................................................715
Troubleshooting Recovery ............................................................................716The ORA-01194 Error .....................................................................................716The ORA-01152 Error .....................................................................................717The ORA-00376 Error .....................................................................................718
Summary .................................................................................................................719
Part FiveManaging the Operational Oracle Database ...721
Chapter 16 Managing the Operational Database ...............723
Oracle’s Automatic Management Features ..............................................723Fully Locally Managed Databases .................................................................724Automatic Undo Management ......................................................................726Resumable Space Allocation .........................................................................730Automating and Monitoring Recovery Time ................................................734
Contents
xxi
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xxi
Easy File Management with OMF .................................................................736Benefits of Using OMF ...................................................................................737Creating Oracle Managed Files .....................................................................737
Online Capabilities of Oracle9i .............................................................742Online Data Reorganization ..........................................................................742Online Table Redefinition ..............................................................................745Dynamic Resource Management ..................................................................751Online Database Block Changes ...................................................................753Dynamic Memory Reconfiguration ..............................................................755Using Database Quiescing for Online Maintenance ...................................759Suspending the Database ..............................................................................760
Managing the Online Redo Logs .................................................................760Managing the Archived Logs .........................................................................764Managing a Database Link ............................................................................764
Mapping Oracle Files to Physical Devices .........................................766Architecture of File Mapping .........................................................................766Setting Up File Mapping ................................................................................767
Tips and Troubleshooting ............................................................................768Problems During Quiescing a Database .......................................................768Failed Online Table Redefinitions .................................................................768Problems During Online Index Rebuilds ......................................................769
Summary .................................................................................................................769
Chapter 17 Using Oracle9i Enterprise Manager ...............771
Oracle Enterprise Manager ..........................................................................771Benefits of Using OEM to Manage Databases ..............................................773The Various Systems of OEM .........................................................................775The OEM Architecture and Components .....................................................776
Configuring OEM ................................................................................................778Configuring the Intelligent Agent .................................................................778Configuring the Management Server ...........................................................780Configuring the OEM Console ......................................................................785Configuring Reporting ..................................................................................788Running the Console from a Web Browser ...................................................791
Using the OEM Console ...................................................................................792Discovering Services ......................................................................................792The Services.ora File ......................................................................................792
Database Management Through OEM .............................................................793Database Instance Management ..................................................................794Database Schema Management ...................................................................795Database Security Management ...................................................................796Database Storage Management ....................................................................796Distributed Database Management .............................................................797
Contents
xxii
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xxii
Using the OEM Wizards ...................................................................................799The Export and Import Wizards ....................................................................800The Analyze Wizard ........................................................................................801The Backup Wizard .........................................................................................802
Using the OEM Reporting Features ...........................................................803Prebuilt and Custom Reports ........................................................................804Accessing the Reporting Web Site .................................................................804
Managing Jobs with OEM ................................................................................806The Job Detail View ........................................................................................807Creating a Job ..................................................................................................807
Managing Events with OEM ............................................................................810Creating Events ...............................................................................................810Specifying the Test Conditions ......................................................................810Selecting the Test Criteria ..............................................................................811Scheduling the Event .....................................................................................812
Configuring E-mail and Paging Notification .....................................812Configuring Paging Notification ...................................................................812Configuring E-mail Notification ...................................................................814
Oracle Management Packs ..............................................................................814Oracle Diagnostics Pack .................................................................................814Oracle Tuning Pack .........................................................................................817Oracle Change Management Pack ................................................................817
Troubleshooting OEM .......................................................................................817Summary .................................................................................................................818
Part SixPerformance Tuning and Troubleshooting the Production Database .......................................................819
Chapter 18 Improving Database Performance: SQL Query Optimization ...........................................821
An Approach to Oracle Performance Tuning .........................................821A Systematic Approach to Performance Tuning ..........................................822Reactive Performance Tuning .......................................................................822SQL Coding Practices .....................................................................................823
Optimizing Oracle Query Processing ......................................................824Parsing .............................................................................................................824Optimization ...................................................................................................824Query Execution .............................................................................................828
Contents
xxiii
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xxiii
Query Optimization and the Oracle Cost-Based Optimizer ...........828Choosing Your Optimization Mode ..............................................................829Providing Statistics About the Objects to the Optimizer .............................829Setting the Optimizer Mode ..........................................................................830Setting the Optimizer Level ...........................................................................831What Does the Optimizer Do? .......................................................................831Drawbacks of the CBO ...................................................................................833Providing Statistics to the CBO ......................................................................834
Writing Efficient SQL ...................................................................................839Efficient Where Clauses .................................................................................839Using Hints to Influence the Execution Plan ...............................................842Selecting the Best Join Method .....................................................................843Using Bitmap Join Indexes ............................................................................843Selecting the Best Join Order .........................................................................845Indexing Strategy ............................................................................................845Using the OEM Index Tuning Wizard ............................................................849Monitoring Index Utilization .........................................................................850Removing Unnecessary Indexes ...................................................................851Using Similar SQL Statements .......................................................................851Reducing SQL Overhead via “Inline” Functions ..........................................851Using Bind Variables ......................................................................................852Avoiding Improper Use of Views ...................................................................853Avoiding Unnecessary Full Table Scans ........................................................853
How the DBA Can Help Improve SQL Processing ...................................853Using Partitioned Tables ................................................................................854Using Compression Techniques ....................................................................854Using Materialized Views ...............................................................................855Using Stored Outlines to Stabilize the CBO ..................................................855Using Parallel Execution ................................................................................859Other DBA Tasks .............................................................................................859
SQL Performance Tuning Tools ...................................................................860Using the Explain Plan ...................................................................................861Using Autotrace ..............................................................................................865Using SQL Trace and TKPROF .......................................................................870Using V$SQLAREA to Find Inefficient SQL ...................................................877Using GUI Tools in Tuning .............................................................................879
A Simple Approach to Tuning SQL Statements .....................................884Identify Problem Statements .........................................................................884Locate the Source of the Inefficiency ............................................................885Tune the Statement ........................................................................................885Compare Performance ...................................................................................885
Summary .................................................................................................................886
Contents
xxiv
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xxiv
Chapter 19 Performance Tuning: Tuning the Instance ...................................................887
An Introduction to Instance Tuning ......................................................887Tuning Oracle Memory .....................................................................................890
Tuning the Shared Pool ..................................................................................892Tuning the Buffer Cache ................................................................................906Tuning the Large Pool ....................................................................................911Tuning PGA Memory ......................................................................................911Automatic PGA Memory Management ........................................................911
Evaluating System Performance .................................................................912CPU Performance ...........................................................................................912Disk I/O ...........................................................................................................919
Measuring I/O Performance ..........................................................................920Is the I/O Optimally Distributed? ..................................................................921Reducing Disk Contention ............................................................................922The Oracle SAME Guidelines for Optimal Disk Usage ................................922
Collecting Instance Performance Statistics with Statspack ....922Installing Statspack ........................................................................................923Using Statspack ..............................................................................................925
Measuring Instance Performance ...............................................................936Database Hit Ratios ........................................................................................937Database Wait Statistics .................................................................................938Know Your Application ...................................................................................952Operating System Memory Management ....................................................954
When a Database Hangs ...................................................................................954Handling a Stuck Archiver Process ...............................................................954System Utilization Problems .........................................................................956Excessive Contention for Resources .............................................................957Locking Issues .................................................................................................957Abnormal Increase in Process Size ...............................................................958Delays Due to Shared Pool Problems ...........................................................960Problems Due to Bad Statistics .....................................................................960Collecting Information During a Database Hang ........................................960
A Simple Approach to Instance Tuning ..................................................963What’s Happening in the Database? .............................................................963Are There Any Long-Running Transactions? ................................................964Is Oracle the Problem? ...................................................................................965Is the Network Okay? ......................................................................................965Is the System CPU Bound? .............................................................................966Is the System I/O Bound? ..............................................................................968Checking Memory-Related Issues .................................................................969
Contents
xxv
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xxv
Is the System Wait Bound? .............................................................................969Eliminating the Contention ...........................................................................970
Summary .................................................................................................................972
Chapter 20 The Oracle Data Dictionary and the Dynamic Performance Views ...............973
The Oracle Data Dictionary ......................................................................973How Is the Data Dictionary Created? ............................................................974
Using the Data Dictionary Static Views ..............................................975General Views .................................................................................................975User Management–Related Views .................................................................979Audit-Related Views .......................................................................................987Storage-Related Views ....................................................................................989Views for Monitoring Transactions ...............................................................993Constraint- and Index-Related Views ...........................................................995Views for Managing Database Objects .........................................................999Views for Managing Tables and Views ..........................................................999
Using the Dynamic Performance Tables ................................................1003Memory-Related Views ................................................................................1004Backup-Related Views ..................................................................................1008Session- and User-Related Views ................................................................1010Redo Log– and Archive Log–Related Views ................................................1012Recovery-Related Views ...............................................................................1015Performance Monitoring Views ..................................................................1016SQL-Related Views .......................................................................................1018Operational Performance–Related Views ...................................................1018General Views ...............................................................................................1022Storage- and File-Related Views ..................................................................1026
Summary ...............................................................................................................1027
Chapter 21 Using Oracle PL/SQL Packages ..........................1029
Overview of the Oracle-Supplied PL/SQL Packages ........................1029Who Creates the Oracle Packages? ..............................................................1029How Do You Use the Oracle Packages? .......................................................1030
DBMS_JOB .............................................................................................................1031Using the DBMS_JOB Package ....................................................................1032Other DBMS_JOB Procedures .....................................................................1033
DBMS_APPLICATION_INFO ...............................................................................1033DBMS_SESSION ...................................................................................................1035
Set_Role .........................................................................................................1036Set_Sql_Trace ................................................................................................1036Switch_Current_Consumer_Group ............................................................1037
Contents
xxvi
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xxvi
DBMS_SYSTEM .......................................................................................................1037Set_Sql_Trace_In_Session ............................................................................1039Set_Int_Param_In_Session ..........................................................................1039Set_Bool_Param_In_Session .......................................................................1039Set_Ev ............................................................................................................1040
DBMS_OUTPUT .......................................................................................................1040DBMS_REPAIR .......................................................................................................1042
Using the DBMS_REPAIR Package ..............................................................1043Fixing Block Corruption ...............................................................................1044
DBMS_OUTLN and DBMS_OUTLN_EDIT .............................................................1045Using the DBMS_OUTLN Package to Manage Stored Outlines ...............1045Tracking the Outlines in the Database .......................................................1046
DBMS_SPACE .........................................................................................................1047DBMS_SPACE_ADMIN ............................................................................................1049DBMS_PROFILER ..................................................................................................1050
A Useful Package for Developers .................................................................1050Installing the DBMS_PROFILER Package ...................................................1051Using the DBMS_PROFILER Package .........................................................1051
UTL_FILE .............................................................................................................1053Using the UTL_FILE Package ......................................................................1054A Simple Example Using the UTL_FILE Package .......................................1056
UTL_SMTP .............................................................................................................1057Procedures in the UTL_SMTP Package ......................................................1057Using the UTL_SMTP Package ....................................................................1060
DBMS_SHARED_POOL ............................................................................................1060DBMS_LOGSTDBY ..................................................................................................1062Oracle Packages in Earlier Chapters ..................................................1063
The DBMS_STATS Package ..........................................................................1063DBMS_RLS ....................................................................................................1064DBMS_FGA ...................................................................................................1065DBMS_RESOURCE_MANAGER ..................................................................1065DBMS_RESUMABLE ....................................................................................1066DBMS_OLAP .................................................................................................1066DBMS_MVIEW .............................................................................................1068DBMS_METADATA .......................................................................................1069DBMS_REDEFINITION ...............................................................................1069DBMS_FLASHBACK .....................................................................................1070DBMS_WM ....................................................................................................1070DBMS_LOGMNR ..........................................................................................1071DBMS_REFRESH ..........................................................................................1072DBMS_TTS ....................................................................................................1073DBMS_UTILITY ............................................................................................1074DBMS_STORAGE_MAP ...............................................................................1075
Summary ...............................................................................................................1076
Contents
xxvii
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xxvii
Chapter 22 Managing Oracle Databases on Windows and Linux Systems ..................................1077
Oracle9i and Windows ...................................................................................1077Database Access Methods ...........................................................................1078Oracle Support for .NET ..............................................................................1078Integration with Windows Services .............................................................1079
Essential Differences in Managing Oracle on Windows and UNIX .....................................................................................1080
Processes vs. Threads ...................................................................................1080Oracle Service Threads .................................................................................1083Services and Daemons .................................................................................1084Tuning Memory Resources ..........................................................................1085CPU and Memory Considerations ..............................................................1086Automatic Start-up and Shutdown .............................................................1086Users and Groups .........................................................................................1086The File Systems ...........................................................................................1087The Windows Copy Utilities ........................................................................1087Differences in the Use of the GUI ...............................................................1087Automating Jobs ...........................................................................................1087Diagnostic Tools ...........................................................................................1088
Installing Oracle9i on a Windows System .........................................1088The Windows Registry ...................................................................................1089
Using the Registry .........................................................................................1089Managing Oracle on Windows Systems ....................................................1090
Oracle Services .............................................................................................1090Starting Up and Shutting Down the Oracle Database ...............................1094Using the Oracle Administration Assistant for NT ....................................1097Uninstalling Oracle on Windows .................................................................1100
Oracle9i and Linux .......................................................................................1101Oracle’s Commitment to Linux ...................................................................1102Ensuring You Have a Stable Version of Linux .............................................1102Managing Oracle on Linux ..........................................................................1103
Summary ...............................................................................................................1103
Appendix A Brief Oracle9i SQL and PL/SQL Primer ......................................................1105
The Oracle9i Sample Schemas ....................................................................1106Basic SQL ..........................................................................................................1107
The Select Statement ....................................................................................1107The Insert Statement ....................................................................................1109
Contents
xxviii
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xxviii
The Delete Statement ...................................................................................1109The Update Statement .................................................................................1110Filtering Data ................................................................................................1111
Sorting the Results of a Query .............................................................1111The Order By Clause .....................................................................................1111Sorting Order ................................................................................................1111Sorting by Multiple Columns ......................................................................1111
Operators ...........................................................................................................1112Comparison Operators ................................................................................1112Logical Operators .........................................................................................1112The Set Operators .........................................................................................1113
SQL Functions ..................................................................................................1113Single-Row Functions ..................................................................................1113Aggregate Functions .....................................................................................1114Number and Date Functions .......................................................................1114General Functions and Conditional Expressions ......................................1115SQL Analytical Functions ............................................................................1116Hierarchical Retrieval of Data .....................................................................1117
Selecting Data from Multiple Tables ..................................................1118The Cartesian Product .................................................................................1118The Four Types of Oracle Joins ....................................................................1119
Grouping Operations .....................................................................................1120Nesting Group Functions ............................................................................1121The Group By Clause with a Rollup Operator ............................................1121The Group By Clause with a Cube Operator ..............................................1122The Group By Clause with a Grouping Operator .......................................1122The Group By Clause with a Grouping Sets Operator ...............................1122The Having Clause .......................................................................................1123
Writing Subqueries .......................................................................................1123Top N Analysis ..............................................................................................1123Single-Row Subqueries ................................................................................1124Multiple-Row Subqueries ............................................................................1124Multiple-Column Subqueries ......................................................................1124Advanced Subqueries ...................................................................................1124The Exists and Not Exists Operators ...........................................................1124
Abstract Data Types .....................................................................................1125The Create Type Command .........................................................................1125Object Tables .................................................................................................1125Collections ....................................................................................................1126Type Inheritance ...........................................................................................1126The Cast Operator ........................................................................................1127
Contents
xxix
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xxix
Using PL/SQL ....................................................................................................1127The Basic PL/SQL Block ...............................................................................1128Declaring Variables .......................................................................................1128Writing Executable Statements ...................................................................1129Handling Errors ............................................................................................1129
PL/SQL Control Structures ........................................................................1130Conditional Control .....................................................................................1130PL/SQL Looping Constructs ........................................................................1130
Cursors ...............................................................................................................1132Implicit Cursors ............................................................................................1132Explicit Cursors .............................................................................................1132Cursor Attributes ..........................................................................................1133Cursor For Loops ..........................................................................................1134PL/SQL Records ............................................................................................1134Cursor Variables ............................................................................................1134
Functions ...........................................................................................................1135Packages .............................................................................................................1135Oracle XML DB ..................................................................................................1136
Storing XML in Oracle XML DB ...................................................................1137The Oracle XML DB Repository ..................................................................1139Setting Up an XML Schema .........................................................................1140Creating a Relational View from an XML Document .................................1140
Oracle9i and Java .........................................................................................1141Using Java with Oracle .................................................................................1141
Summary ...............................................................................................................1143
Index ..................................................................................................................1145
Contents
xxx
*0228_Ch00_FINAL 3/13/03 1:19 PM Page xxx