Pro Oracle Database 11g Administration ■ ■ ■ Darl Kuhn 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 Sales–eBook 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. ■ CONTENTS 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 Oracle’s 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 vi ■ CONTENTS 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 vii ■ CONTENTS 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 Tablespace’s 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 viii ■ CONTENTS 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 ix ■ CONTENTS 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 .......................................................................................................1 46 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 ........................................................................................................1 51 Undropping a Table ....................................................................................................1 52 Removing Data from a Table ......................................................................................1 53 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 .......................................................................................1 59 Creating an Index-Organized Table ............................................................................1 61 Managing Constraints ................................................................................................. 161 Creating Primary-Key Constraints ....................................................................................................... 162 Enforcing Unique Key Values ............................................................................................................... 163 Creating Foreign-key Constraints ....................................................................................................... 164 Checking for Specific Data Conditions ................................................................................................ 165 x
Description: