721
THE EXPERT’S VOICE ® IN ORACLE Pro Oracle Database 11 g Administration Darl Kuhn Effectively manage and safeguard your organization's data Covers 11g Release 2!

Pro oracle-database-11g-administration-experts-voice-in-oracle.9781430229704.53726

Embed Size (px)

Citation preview

  • 1.this print for content onlysize & color not accurate 7.5 x 9.25 spine = 1.34375" 720 page count PPI = 534 KuhnOracleDatabase11gAdministration THE EXPERTS VOICE IN ORACLE Pro Oracle Database 11g Administration CYAN MAGENTA YELLOW BLACK PANTONE 123 C Darl Kuhn Companion eBook Available Effectively manage and safeguard your organization's data BOOKS FOR PROFESSIONALS BY PROFESSIONALS US $59.99 Shelve in: Databases / Oracle User level: IntermediateAdvanced THE APRESS ROADMAP Troubleshooting Oracle Performance Expert Oracle Practices Pro Oracle Database 11g Administration RMAN Recipes for Oracle Database 11g Beginning Oracle Database 11g Administration www.apress.com Companion eBook See last page for details on $10 eBook version ISBN 978-1-4302-2970-4 9 781430 229704 5 59 9 9 Pro Covers 11g Release 2!Pro Oracle Database 11g Administration Pro Oracle Database 11g Administration is a task-oriented guide to managing complex database environments using Oracle Database 11g. Author Darl Kuhn draws from a well of experience over a decade deep to lay out real-world tech- niques leading to success as an Oracle database administrator (DBA). He gives clear explanations on how to perform critical tasks. He weaves in theory where necessary without bogging you down in unneeded detail. Darl is not afraid to take a stand on how things should be done. He wont leave you adrift in a sea of choices, showing you three ways to do something and then walking away. Pro Oracle Database 11g Administration condenses and organizes the core job of a database administrator into one volume. You get strong coverage of fun- damentals such as software installation, database and schema creation, backup and recovery, and more. That coverage is informed by the authors experience of being asked to manage increasing numbers of databases in the same amount of time. For example, Chapter 1 provides excellent coverage of silent installs, enabling you to repeat the same Oracle binary install across many servers with- out having to run the GUI installer interactively each time. Database administration isnt about passing a certified exam, or about point- ing-and-clicking your way through a crisis. Database administration is about applying the right solution at the right time. Its about avoiding risk and making robust choices that get you home each night in time for dinner with your fam- ily. If you have buck stops here responsibility for an Oracle database, then Pro Oracle Database 11g Administration is the book you need to elevate yourself to the level of Professional Oracle Database Administrator. Darl Kuhn, Author of Linux Recipes for Oracle DBAs RMAN Recipes for Oracle Database 11g Oracle SQL Recipes

2. i Pro Oracle Database 11g Administration Darl Kuhn 3. ii Pro Oracle Database 11g Administration Copyright 2010 by Darl Kuhn All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-2970-4 ISBN-13 (electronic): 978-1-4302-2971-1 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Jonathan Gennick Technical Reviewer: Bernard Lopuz Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Anita Castro Copy Editors: Mary Behr and Tiffany Taylor Compositor: MacPS, LLC Indexer: BIM Indexing & Proofreading Services Artist: April Milne Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. For information on translations, please e-mail [email protected] or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk SaleseBook Licensing web page at www.apress.com/info/bulksales. The information in this book is distributed on an as is basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. 4. iii To Heidi, Brandi, and Lisa. 5. iv Contents at a Glance Contents .......................................................................................................... v About the Author.........................................................................................xxix About the Technical Reviewer......................................................................xxx Acknowledgments.......................................................................................xxxi Introduction................................................................................................xxxii Chapter 1: Installing the Oracle Binaries ........................................................ 1 Chapter 2: Implementing a Database............................................................ 25 Chapter 3: Configuring an Efficient Environment.......................................... 51 Chapter 4: Tablespaces and Datafiles ........................................................... 71 Chapter 5: Managing Control Files and Online Redo Logs............................. 91 Chapter 6: Users and Basic Security........................................................... 111 Chapter 7: Tables and Constraints .............................................................. 133 Chapter 8: Indexes ...................................................................................... 171 Chapter 9: Views, Synonyms, and Sequences............................................. 193 Chapter 10: Data Dictionary Basics............................................................. 213 Chapter 11: Large Objects........................................................................... 243 Chapter 12: Partitioning: Divide and Conquer............................................. 269 Chapter 13: Data Pump ............................................................................... 307 Chapter 14: External Tables ........................................................................ 345 Chapter 15: Materialized Views .................................................................. 361 Chapter 16: User-Managed Backup and Recovery...................................... 413 Chapter 17: Configuring RMAN.................................................................... 457 Chapter 18: RMAN Backups and Reporting................................................. 487 Chapter 19: RMAN Restore and Recovery ................................................... 509 Chapter 20: Oracle Secure Backup.............................................................. 545 Chapter 21: Automating Jobs...................................................................... 569 Chapter 22: Database Troubleshooting ....................................................... 595 Index ........................................................................................................... 637 6. v Contents Contents at a Glance ............................................................................................iv About the Author.............................................................................................. xxix About the Technical Reviewer........................................................................... xxx Acknowledgments............................................................................................ xxxi Introduction..................................................................................................... xxxii Chapter 1: Installing the Oracle Binaries ..............................................................1 Understanding the Optimal Flexible Architecture ...........................................................1 Oracle Inventory Directory .....................................................................................................................3 Oracle Base Directory ............................................................................................................................3 Oracle Home Directory...........................................................................................................................3 Oracle Network Files Directory ..............................................................................................................4 Automatic Diagnostic Repository...........................................................................................................4 Installing Oracle..............................................................................................................4 Step 1. Create the Operating System Group and User...........................................................................5 Step 2. Ensure That the Operating System Is Adequately Configured ...................................................6 Step 3. Obtain the Oracle Installation Software.....................................................................................7 Step 4. Unzip the Files ...........................................................................................................................7 Step 5. Configure the Response File, and Run the Installer...................................................................8 Step 6. Troubleshoot Any Issues..........................................................................................................11 Installing with a Copy of an Existing Installation ..........................................................12 Step 1. Copy the Binaries Using an Operating System Utility ..............................................................13 Step 2. Attach the Oracle Home...........................................................................................................14 7. CONTENTS vi Upgrading Oracle Software...........................................................................................15 Reinstalling After Failed Installation .............................................................................16 Applying Interim Patches..............................................................................................17 Installing Remotely with the Graphical Installer ...........................................................18 Step 1. Install X Software and Networking Utilities on the Local PC ...................................................19 Step 2. Start an X Session on the Local Computer ..............................................................................19 Step 3. Copy the Oracle Installation Media to the Remote Server .......................................................20 Step 4. Run the xhost Command..........................................................................................................21 Step 5. Log In to the Remote Computer from X ...................................................................................21 Step 6. Ensure that the DISPLAY Variable Is Set Correctly on the Remote Computer..........................21 Step 7. Execute the runInstaller Utility.................................................................................................22 Step 8. Troubleshoot............................................................................................................................22 Summary.......................................................................................................................23 Chapter 2: Implementing a Database..................................................................25 Setting Operating System Variables .............................................................................25 A Manually Intensive Approach............................................................................................................26 Oracles Approach to Setting OS Variables ..........................................................................................26 My Approach to Setting OS Variables ..................................................................................................27 Creating a Database......................................................................................................29 Step 1. Set the Operating System Variables ........................................................................................29 Step 2: Configure the Initialization File ................................................................................................30 Step 3: Create the Required Directories...............................................................................................32 Step 4: Create the Database ................................................................................................................32 Step 5. Create a Data Dictionary..........................................................................................................36 Configuring and Implementing the Listener..................................................................37 Creating a Password File ..............................................................................................39 Starting and Stopping the Database.............................................................................40 Understanding Authentication..............................................................................................................41 Starting the Database ..........................................................................................................................41 8. CONTENTS vii Stopping the Database.........................................................................................................................43 Using a Response File to Create a Database ................................................................45 Dropping a Database.....................................................................................................46 How Many Databases on One Server?..........................................................................47 Summary.......................................................................................................................50 Chapter 3: Configuring an Efficient Environment................................................51 Customizing Your Operating System Command Prompt...............................................52 Customizing Your SQL Prompt......................................................................................54 Creating Shortcuts for Frequently Used Commands.....................................................55 Using Aliases........................................................................................................................................55 Using a Function ..................................................................................................................................56 Rerunning Commands Quickly......................................................................................57 Scrolling with the Up and Down Arrow Keys .......................................................................................58 Pressing Ctrl+P and Ctrl+N..................................................................................................................58 Listing the Command History...............................................................................................................58 Searching in Reverse...........................................................................................................................59 Setting the Command Editor.........................................................................................59 Developing Standard Scripts ........................................................................................60 dba_setup ............................................................................................................................................60 dba_fcns ..............................................................................................................................................61 tbsp_chk.bsh .......................................................................................................................................62 conn.bsh ..............................................................................................................................................64 filesp.bsh .............................................................................................................................................65 login.sql................................................................................................................................................66 top.sql ..................................................................................................................................................66 lock.sql.................................................................................................................................................67 users.sql ..............................................................................................................................................67 Organizing Scripts.........................................................................................................68 Step 1: Create Directories....................................................................................................................68 9. CONTENTS viii Step 2: Copy Files to Directories..........................................................................................................69 Step 3: Configure the Startup File........................................................................................................69 Summary.......................................................................................................................70 Chapter 4: Tablespaces and Datafiles.................................................................71 Understanding the First Five.........................................................................................72 Understanding the Need for More.................................................................................72 Creating Tablespaces....................................................................................................73 Renaming a Tablespace................................................................................................76 Controlling the Generation of Redo...............................................................................76 Changing a Tablespaces Write Mode...........................................................................77 Dropping a Tablespace .................................................................................................78 Using Oracle Managed Files .........................................................................................80 Creating a Bigfile Tablespace .......................................................................................81 Displaying Tablespace Size ..........................................................................................81 Altering Tablespace Size...............................................................................................82 Toggling Datafiles Offline and Online............................................................................83 Renaming or Relocating a Datafile ...............................................................................85 Summary.......................................................................................................................90 Chapter 5: Managing Control Files and Online Redo Logs ..................................91 Managing Control Files .................................................................................................91 Viewing Control File Names and Locations..........................................................................................93 Adding a Control File............................................................................................................................94 Moving a Control File ...........................................................................................................................96 Removing a Control File.......................................................................................................................97 Managing Online Redo Logs .........................................................................................98 Displaying Online Redo-Log Information............................................................................................100 Determining the Optimal Size of Online Redo-Log Groups ................................................................102 Determining the Optimal Number of Redo-Log Groups......................................................................103 10. CONTENTS ix Adding Online Redo-Log Groups ........................................................................................................105 Resizing Online Redo-Log Groups......................................................................................................105 Adding Online Redo-Log Files to a Group ..........................................................................................106 Removing Online Redo-Log Files from a Group .................................................................................107 Moving or Renaming Redo-Log Files .................................................................................................107 Summary.....................................................................................................................108 Chapter 6: Users and Basic Security.................................................................111 Understanding Schemas vs. Users .............................................................................111 Managing Default Users..............................................................................................112 Creating Users ............................................................................................................115 Choosing a User Name and Authentication Method...........................................................................115 Assigning Default Permanent and Temporary Tablespaces ..............................................................116 Modifying Passwords..................................................................................................118 Enforcing Password Security......................................................................................119 Logging On as a Different User...................................................................................120 Modifying Users ..........................................................................................................122 Dropping Users ...........................................................................................................122 Enforcing Password Security and Resource Limits ....................................................123 Implementing Password Security ......................................................................................................124 Limiting Database Resource Usage ...................................................................................................126 Managing Privileges....................................................................................................128 Assigning Database System Privileges..............................................................................................128 Assigning Database Object Privileges................................................................................................129 Grouping and Assigning Privileges .............................................................................130 Summary.....................................................................................................................131 Chapter 7: Tables and Constraints ....................................................................133 Understanding Table Types ........................................................................................133 Creating a Table..........................................................................................................135 Creating a Heap-Organized Table ......................................................................................................135 11. CONTENTS x Implementing Virtual Columns. ...........................................................................................................138 Making Read-Only Tables ....................................................................................................................140 Understanding Deferred Segment Creation ........................................................................................141 Allowing for Parallel SQL Execution. ...................................................................................................142 Compressing Table Data......................................................................................................................143 Avoiding Redo Creation........................................................................................................................144 Creating a Table from a Query . ...........................................................................................................146 Modifying a Table .......................................................................................................146 Obtaining the Needed Lock. ................................................................................................................147 Renaming a Table ................................................................................................................................147 Adding a Column..................................................................................................................................147 Altering a Column.................................................................................................................................148 Renaming a Column.............................................................................................................................149 Dropping a Column ..............................................................................................................................149 Displaying Table DDL ..................................................................................................150 Dropping a Table . .......................................................................................................151 Undropping a Table . ...................................................................................................152 Removing Data from a Table ......................................................................................153 Using DELETE.......................................................................................................................................153 Using TRUNCATE..................................................................................................................................153 Viewing and Adjusting the High-Water Mark ..............................................................154 Tracing to Detect Space Below the High-Water Mark ........................................................................155 Using DBMS_SPACE to Detect Space Below the High-Water Mark. ..................................................156 Creating a Temporary Table .......................................................................................159 Creating an Index-Organized Table ............................................................................161 Managing Constraints .................................................................................................161 Creating Primary-Key Constraints. ......................................................................................................162 Enforcing Unique Key Values ...............................................................................................................163 Creating Foreign-key Constraints . ......................................................................................................164 Checking for Specific Data Conditions. ...............................................................................................165 12. CONTENTS xi Enforcing Not Null Conditions ............................................................................................................166 Disabling Constraints.........................................................................................................................167 Enabling Constraints..........................................................................................................................168 Summary.....................................................................................................................170 Chapter 8: Indexes ............................................................................................171 Deciding When to Create an Index..............................................................................171 What to Think About....................................................................................................172 Index-Management Guidelines ...................................................................................173 Creating Indexes .........................................................................................................175 Creating B-tree Indexes .....................................................................................................................175 Creating Concatenated Indexes .........................................................................................................176 Implementing Function-Based Indexes..............................................................................................177 Creating Unique Indexes ....................................................................................................................178 Using Bitmap Indexes ........................................................................................................................179 Creating Bitmap Join Indexes ............................................................................................................180 Implementing Reverse-Key Indexes ..................................................................................................181 Creating Key-Compressed Indexes....................................................................................................182 Parallelizing Index Creation ...............................................................................................................183 Avoiding Redo Generation When Creating an Index...........................................................................183 Implementing Invisible Indexes .........................................................................................................183 Using Index-Naming Standards .........................................................................................................185 Specifying Index Tablespaces.....................................................................................186 Placing Indexes in Tablespaces Separate from Tables......................................................................186 Placing Indexes in Tablespaces Based on Extent Size ......................................................................187 Maintaining Indexes....................................................................................................187 Renaming an Index ............................................................................................................................188 Displaying Code to Re-create an Index..............................................................................................188 Rebuilding an Index ...........................................................................................................................188 Making Indexes Unusable..................................................................................................................190 Monitoring Index Usage .....................................................................................................................190 13. CONTENTS xii Dropping an Index..............................................................................................................................191 Summary.....................................................................................................................191 Chapter 9: Views, Synonyms, and Sequences ..................................................193 Implementing Views ...................................................................................................193 Creating a View..................................................................................................................................193 Checking Updates ..............................................................................................................................194 Creating Read-Only Views .................................................................................................................195 Updatable Join Views.........................................................................................................................195 Creating an INSTEAD OF Trigger........................................................................................................197 Modifying a View Definition ...............................................................................................................198 Displaying the SQL Used to Create a View.........................................................................................198 Renaming a View ...............................................................................................................................200 Dropping a View.................................................................................................................................200 Managing Synonyms...................................................................................................200 Creating a Synonym...........................................................................................................................201 Creating Public Synonyms .................................................................................................................201 Dynamically Generating Synonyms....................................................................................................202 Displaying Synonym Metadata...........................................................................................................202 Renaming a Synonym ........................................................................................................................203 Dropping a Synonym..........................................................................................................................204 Managing Sequences..................................................................................................204 Creating a Sequence..........................................................................................................................204 Using Sequence Pseudo-columns .....................................................................................................205 Autoincrementing Columns................................................................................................................206 Using Multiple Sequences that Generate Unique Values ...................................................................207 Using One Sequence or Many............................................................................................................208 Viewing Sequence Metadata .............................................................................................................208 Renaming a Sequence .......................................................................................................................209 Dropping a Sequence.........................................................................................................................209 Resetting a Sequence ........................................................................................................................210 14. CONTENTS xiii Summary.....................................................................................................................212 Chapter 10: Data Dictionary Basics...................................................................213 Data-Dictionary Architecture ......................................................................................213 Static Views .......................................................................................................................................213 Dynamic Performance Views .............................................................................................................215 Derivable Documentation...................................................................................................................216 Logical and Physical Database Structures..................................................................218 Displaying User Information........................................................................................220 Currently Connected User ..................................................................................................................220 Users Currently Logged In..................................................................................................................221 Currently Executing SQL ....................................................................................................................222 User Accounts in the Database..........................................................................................................223 Viewing Table Information ..........................................................................................223 Viewing Accessible Tables.................................................................................................................224 Displaying Object Disk-Space Usage.................................................................................................224 Displaying Table Row Counts.............................................................................................................225 Displaying Index Information ......................................................................................227 Displaying Indexes for a Table...........................................................................................................227 Showing Foreign-Key Columns Not Indexed......................................................................................228 Displaying Constraint Information...............................................................................229 Displaying Table Constraints..............................................................................................................229 Showing Primary-Key and Foreign-Key Relationships.......................................................................230 Viewing Basic Security Information............................................................................232 Displaying Granted Roles...................................................................................................................232 Displaying System Privileges.............................................................................................................233 Displaying Object Privileges...............................................................................................................235 Displaying Object Dependencies.................................................................................236 Displaying Differences in Schemas ............................................................................238 Summary.....................................................................................................................241 15. CONTENTS xiv Chapter 11: Large Objects.................................................................................243 Describing Current LOB Types ....................................................................................243 Illustrating LOB Locators, Indexes, and Chunks..........................................................244 Distinguishing Between BasicFiles and SecureFiles ..................................................246 BasicFile.............................................................................................................................................246 SecureFile ..........................................................................................................................................246 Prerequisites for SecureFiles.............................................................................................................246 Creating a Table with a LOB Column ..........................................................................248 Creating a BasicFile LOB Column.......................................................................................................248 Creating a LOB in a Specific Tablespace ...........................................................................................249 Creating a SecureFile LOB Column ....................................................................................................250 Creating a Partitioned LOB.................................................................................................................251 Maintaining LOB Columns...........................................................................................253 Moving a LOB Column........................................................................................................................253 Adding a LOB Column ........................................................................................................................253 Removing a LOB Column....................................................................................................................253 Caching LOBs.....................................................................................................................................254 Storing LOBs In and Out of Line .........................................................................................................255 Using SecureFile Features..........................................................................................256 Compressing LOBs.............................................................................................................................256 Deduplicating LOBs............................................................................................................................257 Encrypting LOBs.................................................................................................................................258 Migrating BasicFiles to SecureFiles...................................................................................................260 Viewing LOB Metadata................................................................................................262 Loading LOBs..............................................................................................................263 Loading a CLOB..................................................................................................................................263 Loading a BLOB..................................................................................................................................265 Measuring LOB Space Consumed...............................................................................265 BasicFile Space Used.........................................................................................................................266 SecureFile Space Used ......................................................................................................................267 16. CONTENTS xv Summary.....................................................................................................................268 Chapter 12: Partitioning: Divide and Conquer...................................................269 What Tables Should Be Partitioned?...........................................................................270 Creating Partitioned Tables.........................................................................................271 Partitioning by Range.........................................................................................................................272 Partitioning by List .............................................................................................................................279 Partitioning by Hash...........................................................................................................................280 Blending Different Partitioning Methods............................................................................................281 Creating Partitions on Demand ..........................................................................................................282 Partitioning to Match a Parent Table..................................................................................................284 Partitioning on a Virtual Column ........................................................................................................286 Giving an Application Control over Partitioning..................................................................................286 Maintaining Partitions.................................................................................................287 Viewing Partition Metadata................................................................................................................287 Moving a Partition..............................................................................................................................288 Automatically Moving Updated Rows.................................................................................................289 Partitioning an Existing Table ............................................................................................................290 Adding a Partition...............................................................................................................................291 Exchanging a Partition with an Existing Table...................................................................................293 Renaming a Partition..........................................................................................................................295 Splitting a Partition ............................................................................................................................295 Merging Partitions..............................................................................................................................296 Dropping a Partition ...........................................................................................................................297 Generating Statistics for a Partition...................................................................................................298 Removing Rows from a Partition .......................................................................................................298 Manipulating Data within a Partition..................................................................................................299 Partitioning Indexes ....................................................................................................300 Partitioning an Index to Follow Its Table............................................................................................300 Partitioning an Index Differently than Its Table..................................................................................303 Partition Pruning .........................................................................................................304 17. CONTENTS xvi Summary.....................................................................................................................305 Chapter 13: Data Pump .....................................................................................307 Data Pump Architecture..............................................................................................308 Exporting Data ............................................................................................................310 Creating a Database Directory ...........................................................................................................310 Granting Access to the Directory .......................................................................................................311 Taking an Export ................................................................................................................................311 Importing Data ............................................................................................................312 Interactive Command Mode........................................................................................313 Entering Interactive Command Mode.................................................................................................313 Attaching to a Running Job................................................................................................................314 Stopping and Restarting a Job...........................................................................................................315 Terminating a Data Pump Job............................................................................................................316 Tips for Getting Started...............................................................................................316 Use a Parameter File..........................................................................................................................316 Estimating the Size of Export Jobs ....................................................................................................317 Listing the Contents of Dump Files ....................................................................................................317 Transferring Data........................................................................................................318 Exporting and Importing Directly Across the Network.......................................................................319 Copying Datafile(s).............................................................................................................................320 Exporting and Importing Tablespaces and Datafiles...................................................321 Exporting Tablespace Metadata.........................................................................................................322 Specifying Different Datafile Paths and Names .................................................................................322 Changing Segment and Storage Attributes........................................................................................322 Importing into a Different Tablespace from the Original....................................................................323 Changing the Size of Datafiles...........................................................................................................323 Filtering Data and Objects...........................................................................................324 Specifying a Query.............................................................................................................................324 Exporting a Percentage of the Data ...................................................................................................325 Excluding Objects from the Export File..............................................................................................325 18. CONTENTS xvii Excluding Statistics............................................................................................................................327 Including Only Specific Objects in an Export File...............................................................................327 Exporting Table, Index, Constraint, and Trigger DDL .........................................................................327 Excluding Objects from Import...........................................................................................................328 Including Objects in Import................................................................................................................328 Common Data Pump Tasks.........................................................................................328 Creating a Consistent Export..............................................................................................................329 Importing When Objects Already Exist...............................................................................................330 Renaming a Table ..............................................................................................................................331 Remapping Data.................................................................................................................................332 Cloning a User....................................................................................................................................333 Suppressing a Log File.......................................................................................................................333 Using Parallelism ...............................................................................................................................334 Specifying Additional Dump Files ......................................................................................................335 Reusing Output File Names................................................................................................................335 Creating a Daily DDL File....................................................................................................................336 Compressing Output ..........................................................................................................................336 Encrypting Data..................................................................................................................................337 Monitoring Data Pump Jobs........................................................................................338 Data Pump Log File............................................................................................................................338 Data-Dictionary Views........................................................................................................................338 Database Alert Log.............................................................................................................................339 Status Table.......................................................................................................................................339 Interactive Command-Mode Status ...................................................................................................340 Operating-System Utilities .................................................................................................................340 Data Pump Legacy Mode ............................................................................................341 Data Pump Mapping to the exp Utility................................................................................................341 Data Pump Mapping to the imp Utility ...............................................................................................343 Summary.....................................................................................................................344 19. CONTENTS xviii Chapter 14: External Tables ..............................................................................345 SQL*Loader vs. External Tables..................................................................................345 Loading CSV Files into the Database ..........................................................................347 Creating a Directory Object and Granting Access ..............................................................................348 Creating an External Table.................................................................................................................348 Viewing External-Table Metadata......................................................................................................349 Loading a Regular Table from the External Table..............................................................................349 Performing Advanced Transformations ......................................................................350 Viewing Text Files from SQL .......................................................................................352 Unloading and Loading Data Using an External Table ................................................354 Using Parallelism to Reduce Elapsed Time........................................................................................356 Compressing a Dump File..................................................................................................................356 Encrypting a Dump File......................................................................................................................356 Preprocessing an External Table ................................................................................357 Summary.....................................................................................................................359 Chapter 15: Materialized Views ........................................................................361 Understanding Materialized Views .............................................................................361 Materialized View Terminology..........................................................................................................363 Referencing Useful Views ..................................................................................................................364 Creating Basic Materialized Views..............................................................................365 Creating a Complete-Refreshable Materialized View.........................................................................365 Creating a Fast-Refreshable Materialized View.................................................................................369 Going Beyond the Basics ............................................................................................374 Creating MVs and Specifying Tablespace for MVs and Indexes ........................................................374 Creating Indexes on MVs....................................................................................................................374 Partitioning Materialized Views .........................................................................................................375 Compressing a Materialized View......................................................................................................376 Encrypting Materialized View Columns..............................................................................................376 Building a Materialized View on a Prebuilt Table...............................................................................377 20. CONTENTS xix Creating an Unpopulated Materialized View ......................................................................................378 Creating a Materialized View Refreshed on Commit..........................................................................378 Creating a Never-Refreshable Materialized View ..............................................................................379 Creating Materialized Views for Query-Rewrite.................................................................................380 Creating a Fast-Refreshable MV Based on a Complex Query ............................................................381 Viewing Materialized View DDL .........................................................................................................383 Dropping a Materialized View ............................................................................................................384 Modifying Materialized Views.....................................................................................385 Modifying Base-Table DDL and Propagating to Materialized Views ..................................................385 Toggling Redo Logging on a Materialized View .................................................................................388 Altering Parallelism............................................................................................................................389 Moving a Materialized View...............................................................................................................389 Managing Materialized View Logs ..............................................................................390 Creating a Materialized View Log ......................................................................................................391 Indexing Materialized View Log Columns ..........................................................................................392 Viewing Space Used by a Materialized View Log...............................................................................392 Shrinking the Space in a Materialized View Log................................................................................393 Checking the Row Count of a Materialized View Log.........................................................................393 Moving a Materialized View Log ........................................................................................................394 Dropping a Materialized View Log .....................................................................................................395 Refreshing Materialized Views ...................................................................................395 Manually Refreshing Materialized Views from SQL*Plus...................................................................396 Automating Refreshes Using a Shell Script and Scheduling Utility....................................................397 Creating an MV with a Refresh Interval .............................................................................................398 Efficiently Performing a Complete Refresh........................................................................................399 Handling the ORA-12034 Error...........................................................................................................399 Monitoring Materialized View Refreshes ....................................................................400 Viewing Materialized Views Last Refresh Times ..............................................................................400 Determining Whether a Refresh Is in Progress..................................................................................401 Monitoring Real-Time Refresh Progress............................................................................................401 21. CONTENTS xx Checking Whether MVs Are Refreshing Within a Time Period . ..........................................................402 Creating Remote Materialized View Refreshes . .........................................................403 Understanding Remote-Refresh Architectures ...................................................................................404 Viewing Materialized View Base-Table Information ...........................................................................405 Determining How Many MVs Reference a Central MV Log . ...............................................................406 Managing Materialized Views in Groups . ...................................................................408 Creating a Materialized View Group. ...................................................................................................408 Altering a Materialized View Refresh Group .......................................................................................409 Refreshing a Materialized View Group. ...............................................................................................409 DBMS_MVIEW vs. DBMS_REFRESH. ...................................................................................................409 Determining Materialized Views in a Group........................................................................................410 Adding an MV to a Refresh Group . ......................................................................................................410 Removing Materialized Views from a Refresh Group .........................................................................411 Dropping a Materialized View Refresh Group .....................................................................................411 Summary. ...................................................................................................................411 Chapter 16: User-Managed Backup and Recovery ...........................................413 Implementing a Cold-Backup Strategy for a Noarchivelog-Mode Database ..............414 Making a Cold Backup of a Noarchivelog-Mode Database.................................................................414 Restoring a Cold Backup in Noarchivelog Mode with Online-Redo Logs. ..........................................416 Restoring a Cold Backup in Noarchivelog Mode Without Online-Redo Logs. .....................................417 Scripting a Cold Backup and Restore. .................................................................................................418 Implementing Archivelog Mode ..................................................................................420 Making Architectural Decisions . .........................................................................................................421 Setting the Archive-Redo File Location. ..............................................................................................421 Enabling Archivelog Mode....................................................................................................................426 Disabling Archivelog Mode...................................................................................................................427 Reacting to a Lack of Disk Space in Your Archive Log Destination. ...................................................427 Backing Up Archive-Redo Log Files. ...................................................................................................428 Making a Cold Backup of an Archivelog-Mode Database ...................................................................428 Implementing a Hot-Backup Strategy . .......................................................................430 22. CONTENTS xxi Making a Hot Backup.........................................................................................................................430 Scripting Hot Backups........................................................................................................................434 Understanding the Split-Block Issue..................................................................................................436 Understanding the Need for Redo Generated During Backup............................................................439 Understanding that Datafiles Are Updated.........................................................................................440 Performing a Complete Recovery of an Archivelog-Mode Database ..........................441 Restoring and Recovering with the Database Offline ........................................................................441 Restoring and Recovering with a Database Online............................................................................444 Restoring Control Files.......................................................................................................................445 Performing an Incomplete Recovery of an Archivelog-Mode Database......................449 Flashing Back a Table.................................................................................................451 FLASHBACK TABLE TO BEFORE DROP................................................................................................452 Flashing Back a Table to a Previous Point in Time ............................................................................453 Flashing Back a Database...........................................................................................454 Summary.....................................................................................................................456 Chapter 17: Configuring RMAN .........................................................................457 Understanding RMAN..................................................................................................458 Starting RMAN ............................................................................................................460 RMAN Architectural Decisions ....................................................................................462 1. Running the RMAN Client Remotely or Locally ..............................................................................464 2. Specifying the Backup User...........................................................................................................465 3. Using Online or Offline Backups.....................................................................................................465 4. Setting the Archive-Redo Log Destination and File Format ...........................................................465 5. Configuring the RMAN Backup Location and File Format ..............................................................466 6. Setting Autobackup of the Control File ..........................................................................................468 7. Specifying the Location of the Autobackup of the Control File ......................................................468 8. Backing Up Archive-Redo Logs......................................................................................................469 9. Determining the Location for the Snapshot Control File ................................................................469 10. Using a Recovery Catalog ............................................................................................................470 11. Using a Media Manager ...............................................................................................................470 23. CONTENTS xxii 12. Setting the CONTROL_FILE_RECORD_KEEP_TIME Initialization Parameter.................................471 13. Configuring RMANs Backup-Retention Policy.............................................................................471 14. Configuring the Archive-Redo Logs Deletion Policy....................................................................472 15. Setting the Degree of Parallelism ................................................................................................473 16. Using Backup Sets or Image Copies ............................................................................................474 17. Using Incremental Backups .........................................................................................................475 18. Using Incrementally Updated Backups ........................................................................................475 19. Using Block-Change Tracking......................................................................................................476 20. Configuring Binary Compression..................................................................................................476 21. Configuring Encryption.................................................................................................................477 22. Configuring Miscellaneous Settings.............................................................................................477 Segueing from Decisions to Action.............................................................................478 Using a Recovery Catalog ...........................................................................................482 Creating a Recovery Catalog..............................................................................................................482 Registering a Target Database...........................................................................................................484 Backing Up the Recovery Catalog......................................................................................................484 Synchronizing the Recovery Catalog..................................................................................................485 Recovery Catalog Versions.................................................................................................................485 Dropping a Recovery Catalog.............................................................................................................485 Summary.....................................................................................................................486 Chapter 18: RMAN Backups and Reporting.......................................................487 Preparing to Run RMAN Backup Commands ..............................................................487 Setting NLS_DATE_FORMAT..............................................................................................................488 Setting ECHO Setting ECHO................................................................................................................488 Showing Variables .............................................................................................................................489 Running Backups........................................................................................................489 Backing up the Entire Database.........................................................................................................489 Backing up Tablespaces ....................................................................................................................491 Backing up Datafiles..........................................................................................................................491 Backing up the Control File................................................................................................................491 24. CONTENTS xxiii Backing up the Spfile.........................................................................................................................492 Backing up Archive Redo Logs ..........................................................................................................492 Backing up Fast Recovery Area .........................................................................................................493 Excluding Tablespaces from Backups ...............................................................................................493 Backing up Datafiles Not Backed Up .................................................................................................494 Skipping Read-Only Tablespaces ......................................................................................................494 Skipping Offline or Inaccessible Files................................................................................................494 Backing Up Large Files in Parallel .....................................................................................................495 Adding RMAN Backup Information to the Repository.........................................................................495 Creating Incremental Backups....................................................................................496 Taking Incremental Level Backups....................................................................................................497 Making Incrementally Updating Backups ..........................................................................................498 Using Block Change Tracking ............................................................................................................499 Checking for Corruption in Datafiles and Backups .....................................................499 Using VALIDATE..................................................................................................................................500 Using BACKUP...VALIDATE..................................................................................................................501 Using RESTORE...VALIDATE................................................................................................................501 Logging RMAN Output.................................................................................................501 Redirecting Output to a File ...............................................................................................................501 Capturing Output with Unix/Linux Logging Commands .....................................................................502 Logging Output to a File.....................................................................................................................503 Querying for Output in the Data Dictionary ........................................................................................503 RMAN Reporting..........................................................................................................504 Using LIST ..........................................................................................................................................504 Using REPORT ....................................................................................................................................504 Using SQL...........................................................................................................................................505 Summary.....................................................................................................................508 Chapter 19: RMAN Restore and Recovery.........................................................509 Determining Media Recovery Required ......................................................................510 Determining What to Restore......................................................................................511 25. CONTENTS xxiv How the Process Works .....................................................................................................................511 Using Data Recovery Advisor.............................................................................................................512 Using RMAN to Stop/Start Oracle................................................................................515 Shutting Down ...................................................................................................................................515 Starting Up .........................................................................................................................................515 Complete Recovery.....................................................................................................516 Testing Restore and Recovery ...........................................................................................................516 Restoring Entire Database .................................................................................................................518 Restoring Tablespaces.......................................................................................................................519 Restoring Read-Only Tablespaces .....................................................................................................520 Restoring Temporary Tablespaces.....................................................................................................521 Restoring Datafiles.............................................................................................................................521 Restoring Datafiles to Non-Default Locations....................................................................................522 Performing Block Level Recovery ......................................................................................................523 Restoring Archive Redo Log Files ......................................................................................................524 Restoring the Spfile............................................................................................................................526 Restoring a Control File...............................................................................................527 Using a Recovery Catalog ..................................................................................................................527 Using an Autobackup to Restore........................................................................................................528 Specifying a Filename........................................................................................................................528 Incomplete Recovery ..................................................................................................529 Determining the Type of Incomplete Recovery ..................................................................................531 Performing Time-Based Recovery .....................................................................................................532 Performing Log Sequenced-Based Recovery.....................................................................................532 Performing Change/SCN-Based Recovery .........................................................................................533 Restoring to a Restore Point ..............................................................................................................533 Restoring and Recovering to Different Server ............................................................534 Step 1: Create an RMAN Backup on the Originating Database ..........................................................535 Step 2: Copy RMAN Backup to Destination Server.............................................................................536 Step 3: Ensure that Oracle is Installed...............................................................................................536 26. CONTENTS xxv Step 4: Source the Required OS Variables.........................................................................................536 Step 5: Create an init.ora File for the Database to be Restored.........................................................536 Step 6: Create any Required Directories for Datafiles, Control Files, and Dump/Trace Files.............537 Step 7: Startup the Database in NOMOUNT Mode..............................................................................537 Step 8: Restore a Control File from the RMAN Backup......................................................................538 Step 9: Startup Database in Mount Mode ..........................................................................................538 Step 10: Make the Control File Aware of the Location of the RMAN Backups...................................538 Step 11: Rename and restore the datafiles to Reflect New Directory Locations ...............................539 Step 12: Recover the Database..........................................................................................................540 Step 13: Set the New Location for the Online Redo Logs ..................................................................541 Step 14: Open the Database ..............................................................................................................542 Step 15: Add tempfile ........................................................................................................................542 Step 16: Rename the Database..........................................................................................................543 Summary.....................................................................................................................543 Chapter 20: Oracle Secure Backup ...................................................................545 OSB Editions and Features..........................................................................................545 OSB Terminology ........................................................................................................546 OSB Administrative Domain and Servers...........................................................................................546 OSB Interfaces ...................................................................................................................................547 OSB Users and Classes......................................................................................................................548 OSB Daemons ....................................................................................................................................548 Download and Installation ..........................................................................................549 Command-line Access to OSB ....................................................................................551 OSB Configuration.......................................................................................................552 Configuring Users and Classes ..........................................................................................................552 Configuring Media Families ...............................................................................................................554 Configuring Database Backup Storage Selector................................................................................555 Database Backup........................................................................................................556 Database Restore........................................................................................................557 File System Backup ....................................................................................................558 27. CONTENTS xxvi Creating Dataset Files........................................................................................................................559 Configuring Backup Windows............................................................................................................560 Configuring Backup Schedules and Triggers.....................................................................................560 Performing On-Demand File-System Backups ..................................................................................561 File System Restore..............................................................