Oracle Database 10g: Administration Workshop II

Volume 3 - Student Guide

D17092GC10 Edition 1.0 March 2004 D39240

r O

cl a

In e
®

rn te

l& a

O

I A

s U

O e

ly n

Authors Janet Stern James Womack Technical Contributors and Reviewers Christine Jeal Joel Goodman Dairy Chan Martin Jensen Donna Keesling Roman Niehoff Srinivas Putrevu Wolfgang Krueger Dr. Sabine Teuber Gerlinde Frenzen John Watson Lothar Auert Andreas Reinhardt Editor Atanu Raychaudhuri Publisher Jobi Varghese

Copyright © 2004, Oracle. All rights reserved. This documentation contains proprietary information of Oracle Corporation. It is provided under a license agreement containing restrictions on use and disclosure and is also protected by copyright law. Reverse engineering of the software is prohibited. If this documentation is delivered to a U.S. Government Agency of the Department of Defense, then it is delivered with Restricted Rights and the following legend is applicable: Restricted Rights Legend Use, duplication or disclosure by the Government is subject to restrictions for commercial computer software and shall be deemed to be Restricted Rights software under Federal law, as set forth in subparagraph (c)(1)(ii) of DFARS 252.227-7013, Rights in Technical Data and Computer Software (October 1988). This material or any portion of it may not be copied in any form or by any means without the express prior written permission of Oracle Corporation. Any other copying is a violation of copyright law and may result in civil and/or criminal penalties. If this documentation is delivered to a U.S. Government Agency not within the Department of Defense, then it is delivered with “Restricted Rights,” as defined in FAR 52.227-14, Rights in Data-General, including Alternate III (June 1987). The information in this document is subject to change without notice. If you find any problems in the documentation, please report them in writing to Education Products, Oracle Corporation, 500 Oracle Parkway, Redwood Shores, CA 94065. Oracle Corporation does not warrant that this document is error-free. Oracle and all references to Oracle Products are trademarks or registered trademarks of Oracle Corporation. All other products or company names are used for identification purposes only, and may be trademarks of their respective owners.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Contents

1

Introduction Course Objectives 1-2 How DBAs Spend Their Time 1-3 Oracle Database 10g Manageability Goals 1-4 Database Management Challenges 1-5 Oracle Database 10g Solution: Self-Managing Database 1-6 How Oracle Database 10g DBAs Spend Their Time 1-7 Student Preface 1-8 Using Globalization Support Objectives 2-2 Globalization Support Features 2-3 Encoding Schemes 2-4 Database Character Sets and National Character Sets 2-7 Datetimes with Timezones 2-9 Configuring the Database Local Timezone 2-10 Configuring Datetime Formats 2-11 Using Timezones 2-12 Specifying Language-Dependent Behavior 2-13 Specifying Language-Dependent Behavior for the Server 2-14 Language and Territory Dependent Parameters 2-15 Other NLS Server Parameters 2-17 Specifying Language-Dependent Behavior for the Session 2-18 Locale Variants 2-21 Using NLS Parameters in SQL Functions 2-22 Linguistic Sorting 2-25 Using Linguistic Sorting 2-27 Sorts That Are Not Case or Accent Sensitive 2-29 Linguistic Comparisons 2-30 Linguistic Index Support 2-31 Customizing Linguistic Sorting 2-32 Oracle Locale Builder 2-33 Character Set Scanner Utilities 2-34 Data Conversion Between Client and Server Character Sets 2-36 NLS Data Conversion with Oracle Utilities 2-37 NLS Data Conversion with Data Pump 2-39 Obtaining Character Set Information 2-40 Obtaining NLS Parameter Information 2-41 Obtaining NLS Settings Information 2-42 Summary 2-43 Practice 2 Overview: Using Globalization Support Features 2-44

2

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

3

Controlling Access to the Oracle Listener Objectives 3-2 Listener Password Authentication 3-3 Setting Listener Password 3-4 Setting Listener Password with Net Manager 3-5 Set Password with lsnrctl Utility 3-6 Controlling Database Access 3-7 Oracle Net Services External Procedures 3-8 Overview of the EXTPROC Agent 3-9 PL/SQL Calling a C External Procedure 3-10 Default Configuration for External Procedure Calls 3-11 Modifying the Configuration for External Procedure Calls 3-13 Remove Default EXTPROC Entry 3-14 Configure a Dedicated Listener for External Procedure Calls 3-16 Summary 3-20 Practice 3 Overview: Controlling Access to the Listener 3-21 Enabling Distributed Transactions Objectives 4-2 Oracle Net Services Review 4-3 Connecting to an Oracle Database 4-4 Client Application Connectivity to the Oracle Server 4-5 Server-Server Connectivity 4-6 Types of Database Links 4-7 Creating Database Links 4-8 Dropping Links 4-10 Data Dictionary Views 4-11 Remote Query 4-12 Executing a Remote Query 4-13 Distributed Query 4-14 Executing a Distributed Query 4-15 Distributed and Remote Transactions 4-16 In-Doubt Transactions 4-17 Summary 4-19 Configuring Recovery Manager Objectives 5-2 Recovery Manager Features 5-3 Recovery Manager Components 5-5 Media Management 5-7 Using a Flash Recovery Area with RMAN 5-9 Setting Parameters for RMAN 5-10 RMAN Usage Considerations 5-12 Connection Types with RMAN 5-13 Starting RMAN 5-14

4

5

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

ii

Additional RMAN Command Line Arguments 5-15 Configuring Persistent Settings for RMAN 5-16 Configuring RMAN Settings Using EM 5-17 Managing Persistent Settings 5-18 Channel Allocation 5-19 Automatic and Manual Channel Allocation 5-20 Channel Control Options 5-21 Summary 5-23 Practice 5 Overview: Configuring RMAN 5-24 6 Using Recovery Manager Objectives 6-2 Issuing Recovery Manager Commands 6-3 RMAN Command Overview 6-5 RMAN Commands 6-6 Job Command: Example 6-7 The BACKUP Command 6-8 Backup Constraints 6-9 Parallelization of Backup Sets 6-10 Compressed Backups 6-12 Image Copy 6-13 Tags for Backups and Image Copies 6-15 BACKUP Options 6-16 Backing Up Archived Redo Logs 6-18 Copying the Whole Database 6-19 Making Incremental Backups 6-20 Incremental Backup: Example 6-22 Block Change Tracking 6-23 Enabling Block Change Tracking 6-24 Incrementally Updating Backups 6-25 LIST Command Operations 6-26 The REPORT Command 6-27 The REPORT NEED BACKUP Command 6-28 REPORT NEED BACKUP: Examples 6-29 REPORT OBSOLETE and DELETE OBSOLETE 6-30 Managing Backups with EM 6-31 RMAN Dynamic Views 6-32 Monitoring RMAN Backups 6-34 Summary 6-36 Practice 6 Overview: Using RMAN 6-37

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

iii

7

Diagnostic Sources Objectives 7-2 Diagnostic Files 7-3 The Alert Log 7-4 What Is in the alert.log File 7-5 Viewing Recent Alert Log Entries 7-6 Alert Models Architecture 7-7 Server-Generated Alert Types 7-8 Viewing Alerts with Enterprise Manager 7-9 Alerts Notification 7-11 Alert Log Monitoring Configuration 7-12 Editing Thresholds 7-13 Viewing Initialization Parameters 7-14 Trace Files 7-15 Specifying the Location of Trace Files 7-16 Controlling Trace File Size 7-17 Controlling Trace File Writes 7-18 Using Enterprise Manager to Enable and View SQL Tracing 7-19 System Log Files 7-20 Summary 7-21 Practice 7 Overview: Diagnosing Problems 7-22

8

Recovering from Non-Critical Losses Objectives 8-2 Recovery of Non-Critical Files 8-3 Creating New Temporary Tablespace 8-4 Creating a New Control File 8-5 Control File Autobackups 8-7 Recreating Redo Log Files 8-9 Recovering an Index Tablespace 8-12 Recovery Steps 8-13 Server Managed Recovery: RESTORE and RECOVER Commands 8-14 User-Managed Recovery Procedures: RECOVER Command 8-15 Summary 8-16 Practice 8 Overview: Recreating the Control File 8-17

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

iv

9

Incomplete Recovery Objectives 9-2 Incomplete Recovery Overview 9-3 Situations Requiring Incomplete Recovery 9-4 Types of Incomplete Recovery 9-5 Incomplete Recovery Best Practices 9-7 Using RECOVER for Incomplete Recovery 9-9 UNTIL TIME Recovery Example 9-10 UNTIL TIME Recovery Steps 9-11 Cancel-Based Recovery: Example 9-13 Incomplete Recovery and the Alert Log 9-15 Incomplete Recovery of a Database Using RMAN 9-16 RMAN Incomplete Recovery UNTIL TIME: Example 9-17 RMAN Incomplete Recovery UNTIL SEQUENCE: Example 9-19 Recovery Using Enterprise Manager 9-20 Summary 9-26 Practice 9 Overview: Incomplete Recovery 9-27

r O

10 Flashback Database Objectives 10-2 Flashback Any Error 10-3 Flashback Technology Benefits 10-4 When To Use Flashback Technology 10-5 Flashback Database Overview 10-6 Flashback Database Reduces Restore Time 10-7 Flashback Database Architecture 10-8 Configuring Flashback Database 10-9 Configure Flashback Database with EM 10-10 Monitoring Flashback Database 10-12 Monitoring Flashback Database with EM 10-14 Monitoring Flash Recovery Area with EM 10-15 Best Practices for the Database and Flash Recovery Area 10-16 Backing Up the Flash Recovery Area 10-17 Flash Recovery Area Space Usage 10-18 Flashback Database Examples 10-19 Flashback Database with EM 10-20 Flashback Database Using EM 10-22 Excluding Tablespaces from Flashback Database 10-23 Flashback Database Considerations 10-24 Summary 10-25 Practice 10 Overview: Flashback Database 10-26

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

v

11 Recovering from User Errors Objectives 11-2 Flashback Time Navigation 11-3 Flashback Drop Overview 11-4 Recycle Bin 11-5 Querying the Recycle Bin 11-6 Flashback Dropped Tables Using EM 11-8 Restoring Objects from the Recycle Bin 11-9 Recycle Bin Automatic Space Reclamation 11-10 Recycle Bin Manual Space Reclamation 11-12 Bypassing the Recycle Bin 11-14 Querying Dropped Tables 11-15 Flashback Drop Considerations 11-16 Flashback Versions Query Overview 11-17 Flashback Versions Query Using EM 11-18 Flashback Versions Query Syntax 11-19 Flashback Versions Query Example 11-20 Flashback Versions Query Considerations 11-21 Flashback Transaction Query Overview 11-22 Querying FLASHBACK_TRANSACTION_QUERY 11-23 Using Flashback Versions Query and Flashback Transaction Query 11-24 Flashback Transaction Query Using EM 11-25 Flashback Transaction Query Considerations 11-26 Flashback Table Overview 11-27 Using EM to Flashback Tables 11-28 Flashback Table Example 11-29 Rolling Back a Flashback Table Operation 11-30 Flashback Table Considerations 11-31 Guaranteed Undo Retention 11-32 SCN and Time Mapping Enhancements 11-33 Summary 11-34 Practice 11 Overview: Recovering from User Errors 11-35 12 Dealing With Database Corruption Objectives 12-2 What Is Block Corruption? 12-3 Block Corruption Symptoms: ORA-1578 12-4 DBVERIFY Utility 12-5 Interpreting DBVERIFY 12-6 The ANALYZE Command 12-8 Initialization Parameter DB_BLOCK_CHECKING 12-9 How to Handle Corruptions 12-10 The DBMS_REPAIR Package 12-12 Using DBMS_REPAIR 12-13

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

vi

Block Media Recovery (BMR) 12-17 The BLOCKRECOVER Command 12-18 RMAN BMR Interface 12-19 Examples of BLOCKRECOVER 12-20 Which Object Is Corrupted? 12-22 Summary 12-23 Practice 12 Overview: Dealing with Database Corruption 12-24 13 Optimizing Database Performance Objectives 13-2 Advisory Framework Overview 13-3 Database Control and Advisors 13-5 Typical Advisor Tuning Session 13-6 Manually Invoking ADDM 13-7 Application Tuning Challenges 13-8 SQL Tuning Advisor Overview 13-9 SQL Tuning Advisor Options and Recommendations 13-10 Using the SQL Tuning Advisor 13-11 Using the SQL Access Advisor 13-13 Using the Memory Advisor 13-15 Segment Advisor Overview 13-16 Segment Advisor 13-17 Growth Trend Report 13-18 Segment Resource Estimation 13-19 The Undo Management Page 13-20 The Undo Advisor Page 13-21 What Is Automatic Storage Management? 13-22 ASM Key Features and Benefits 13-23 ASM Concepts 13-24 ASM General Architecture 13-25 ASM Instance Creation 13-27 ASM Instance Initialization Parameters 13-28 Accessing an ASM Instance 13-29 ASM Home Page 13-30 ASM Performance Page 13-31 ASM Configuration Page 13-32 Starting Up an ASM Instance 13-33 Shutting Down an ASM Instance 13-34 ASM Disk Groups 13-35 ASM Administration Page 13-36 Create Disk Group Page 13-37 ASM Files 13-38 ASM Filenames 13-39

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

vii

ASM File Name Mapping 13-40 SQL Commands and File Naming 13-41 DBCA and Storage Options 13-42 Migrating Your Database to ASM Storage 13-43 Summary 13-44 Practice 13 Overview: Optimizing Database Performance 13-45 14 Using Materialized Views Objectives 14-2 Materialized Views 14-3 Refreshing Materialized Views 14-4 Materialized View Logs 14-6 Primary Key Materialized Views 14-7 Creating Materialized Views 14-8 Updatable Materialized Views 14-9 Monitoring Materialized View Refresh 14-10 Refresh Job Errors 14-11 Monitoring Refresh Operations 14-12 Additional Distributed Data Technologies 14-13 Summary 14-15 15 Managing Resources Objectives 15-2 Overview 15-3 Database Resource Manager Concepts 15-4 Using Sub-Plans to Limit CPU Utilization 15-5 Limiting CPU Utilization: Example 15-7 Resource Manager Configurations 15-8 Active Session Pool Mechanism 15-10 Setting the Active Session Pool 15-11 Automatic Consumer Group Switching 15-13 Configuring Consumer Group Switching 15-16 Adaptive Consumer Group Mapping 15-17 Creating a Mapping Using DBMS_RESOURCE_MANAGER 15-18 Assigning Priorities Using DBMS_RESOURCE_MANAGER 15-19 The Initial Plan: SYSTEM_PLAN 15-20 Creating a New Resource Plan 15-21 Oracle Enterprise Manager: Resource Manager 15-23 Creating a Simple Plan 15-24 Creating a Complex Plan 15-25 Resource Allocation Methods for Resource Plans 15-26 Comparison of EMPHASIS and RATIO 15-28 Creating Resource Consumer Groups 15-30

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

viii

Assigning Users to Consumer Groups 15-32 Resource Allocation Methods for Consumer Groups 15-33 Administering the Resource Manager 15-34 Assigning Resource Manager Privileges 15-35 Setting the Resource Plan for an Instance 15-36 Viewing Resource Consumer Groups 15-37 Changing a Consumer Group Within a Session 15-38 Changing Consumer Groups for Sessions 15-39 Database Resource Manager Information 15-40 Resource Plan Directives 15-41 Monitoring the Resource Manager 15-43 Summary 15-46 Practice 15 Overview: Using the Resource Manager 15-47 16 Automating Tasks with the Scheduler Objectives 16-2 Scheduling Needs 16-3 Scheduler Concepts 16-4 Privileges for Scheduler Components 16-6 Creating a Scheduler Job 16-8 Creating a Scheduler Job: Example 16-9 Setting the Repeat Interval for a Job 16-10 Calendaring Expressions 16-11 Using Scheduler Programs 16-12 Creating a Program Using EM 16-13 Specifying Schedules for a Job 16-14 Creating and Using Schedules 16-15 Using EM to Create Schedules 16-16 Advanced Scheduler Concepts 16-17 Creating a Job Class 16-18 Job Logging 16-20 Creating a Window 16-21 Prioritizing Jobs Within a Window 16-23 Enabling and Disabling Scheduler Components 16-25 Managing Jobs 16-26 Managing Programs 16-27 Managing Programs with EM 16-28 Managing Schedules 16-29 Managing Windows 16-30 Window Priority 16-32 Managing Attributes of Scheduler Components 16-33 Managing Attributes of the Scheduler 16-35

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

ix

Viewing Job Execution Details 16-36 Viewing Job Logs 16-37 Purging Job Logs 16-38 Data Dictionary Views 16-40 Summary 16-41 Practice 16 Overview: Automating Tasks with the Scheduler 16-42 17 Advanced Tools and Techniques Objectives 17-2 Using SQL to Generate Scripts 17-3 Example: Compiling Invalid Objects 17-4 What Is a Procedure? 17-5 PL/SQL Procedures 17-6 Using IN and OUT Parameters 17-7 Using Native Dynamic SQL 17-9 The EXECUTE IMMEDIATE Statement 17-10 Dynamic SQL Using EXECUTE IMMEDIATE 17-12 Dynamic SQL Example 17-13 External Tables 17-14 External Tables and the Oracle Database 17-15 External Tables: Example 17-16 Retrieving User Context Attributes 17-17 Resumable Statements 17-19 Using Resumable Space Allocation 17-20 Resuming Suspended Statements 17-22 Summary 17-24 Practice 17 Overview: Using Dynamic SQL 17-25 18 Workshop Objectives 18-2 Workshop Methodology 18-3 Business Requirements 18-5 Database Configuration 18-6 Simulated Application 18-7 Method for Resolving Database Issues 18-8 Summary 18-10 Practice 18 Overview: Workshop Setup 18-11 Appendix A: Solutions

Appendix B: Basic Linux and vi Commands

r O

Appendix C: Acronyms and Terms

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

x

___________ Appendix A: Solutions ___________

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Solution for Practice 2: Using Globalization Support Features 1. Start iSQL*Plus by opening your browser and entering the following URL: http://hostname:5560/isqlplus. If there is no response, start the isqlplus instance by running the following command at the OS command prompt:
$ isqlplusctl start

Login in with a username of SYSTEM and a password of ORACLE. 2. Determine the database and the national character set.
SELECT * FROM NLS_DATABASE_PARAMETERS WHERE parameter LIKE '%CHARACTER%';

3. Select the current date. If the year is not displayed using a four-digit year, then alter your session (or database) so four digits appear when you select the date again.
SELECT SYSDATE FROM dual;

ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-YYYY HH:MI:SS'; SELECT SYSDATE FROM dual;

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-2

Solution for Practice 2: Using Globalization Support Features (continued) Change NLS_LANGUAGE to FRENCH and query the current time and date. What string is now displayed for the date?
ALTER SESSION SET NLS_LANGUAGE=FRENCH; SELECT SYSDATE FROM dual;

4. Use different NLS_SORT settings to sort data in the proper linguistic manner. a. Execute the shell script lab_02_04.sh to create a table named LIST in the SYSTEM schema that contains four French words. Use the following command at the OS prompt:
$ ./lab_02_04.sh

b. Display the contents of the table ordered by the value of the WORD column. In what order are the numbers in the NUM column displayed?
SELECT * FROM list ORDER BY word;

The rows displayed by this query may be in one of two linguistic orders: FRENCH or BINARY, depending upon whether you ran the query in the same session as that in which the ALTER SESSION SET NLS_LANGUAGE=FRENCH; command was run, or whether you started a new session after running the shell script. If you started a new session, the rows should be displayed in the same order as shown for step c.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-3

Solution for Practice 2: Using Globalization Support Features (continued) c. Set NLS_SORT to BINARY for your session. Select the table contents and order the results by the WORD column. In what order are the numbers in the NUM column displayed?
ALTER SESSION SET NLS_SORT=BINARY; SELECT * FROM list ORDER BY word;

d. Next, set NLS_SORT to French. Select the table contents and order the results by the WORD column. In what order are the numbers in the NUM column displayed?
ALTER SESSION SET NLS_SORT=FRENCH; SELECT * FROM list ORDER BY word;

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-4

Solution for Practice 2: Using Globalization Support Features (continued) e. Set NLS_SORT to French_M. Select the table contents and order the results by the WORD column. In what order are the numbers in the NUM column displayed?
ALTER SESSION SET NLS_SORT=FRENCH_M; SELECT * FROM list ORDER BY word;

5. Set NLS_SORT to BINARY. Now retrieve the table contents in the same order the last query in Step 3, without using another ALTER SESSION command.
ALTER SESSION SET NLS_SORT=BINARY; SELECT * FROM list ORDER BY NLSSORT(word,'NLS_SORT=FRENCH_M');

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-5

Solution for Practice 3: Controlling Access to the Listener Exercise 1: Password Protecting the Listener This exercise covers the process of password protecting your listener using Enterprise Manager. In your web browser address field, type: http://your_host_name:5500/em. Login as sys/oracle as sysdba unless noted otherwise. If this is your first time running EM, you will need to click I agree on the License Agreement screen. 1. From the Net Services page of Enterprise Manager, set an encrypted password to protect listener operations. a. From the Database Control home page, click on the listener name under the General region of the page.

b.

On the Listener page, click Edit.

c.

Provide your host login credentials (oracle/oracle) and click Login to continue.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-6

Solution for Practice 3: Controlling Access to the Listener (continued) Exercise 1: Password Protecting the Listener (continued) d. On the Edit Listeners, with the target Listener selected, click the Authentication tab.

e.

Click the 'Require a password for listener operations' button. Type your password in the New Password field and then type it again in the Confirm Password field. Click on OK to finish.

f.

The listener must be restarted for the changes to take effect. Select Restart and then click OK to proceed with the restart operation.

2. Login as the user sales with a password of oracle and verify listener password protection is in effect.
$ su – sales password: $ $ lsnrctl stop LSNRCTL for Linux: Version 10.1.0.2.0 - Production on 27-FEB-2004 07:44:36 Copyright (c) 1991, 2004, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=EDRSR13P1)(PORT=1521))) TNS-01190: The user is not authorized to execute the requested listener command Oracle Database 10g: Administration Workshop II A-7

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Solution for Practice 3: Controlling Access to the Listener (continued) Exercise 2: Securing the EXTPROC Service Entry This exercise covers the removal of the default EXTPROC service entry for your listener and the addition of a listener dedicated to external procedure requests. 1. From the Net Services page of Enterprise Manager, remove the default EXTPROC service. a. From the Database Control home page, click the listener name link in the General region of the page. b. On the Listener page, click Edit. Provide your host login credentials (oracle/oracle) and click Login to continue.

c. On the Listeners:/u01… page, with the target Listener selected, click Edit.

d. Click the Other Services tab. Select extproc and then click Remove.

e. Click the General tab next. Select IPC then click Remove. To continue, click OK.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-8

Solution for Practice 3: Controlling Access to the Listener (continued) Exercise 2: Securing the EXTPROC Service Entry (continued) f. The listener must be restarted for the changes to take effect. Select Restart and then click OK to proceed with the restart operation.

2. View the listener.ora file to verify that the entry has been removed.
$ cat /u01/app/oracle/product/10.1.0/db_1/network/admin/listener.ora # listener.ora Network Configuration File: # /u01/app/oracle/product/10.1.0/db_1/network/admin/listener.ora # Generated by Oracle configuration tools. PASSWORDS_LISTENER = 1DF5C2FD0FE9CFA2 LOGGING_LISTENER = OFF

LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = EDRSR13P1)(PORT = 1521)) ) ) ) TRACE_LEVEL_LISTENER = OFF

If you see a line like: (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC) then the operation was not successful.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-9

Solution for Practice 3: Controlling Access to the Listener (continued) Exercise 2: Securing the EXTPROC Service Entry (continued) 3. From the Net Services page of Enterprise Manager, add a new listener dedicated to servicing external procedure requests. a. From the Database Control home page, click on the listener name under the General region of the page. b. On the Listener page, click the Net Services Administration link under Related Links. c. Choose Listeners from the Administration pull down list and click Go.

d. On the Listeners: /u01… page, click Create.

e. Type in LISTENEREXTPROC in the Listener Name field and then click Add to add a listening address.

f. In the Add Address region, choose IPC from the Protocol pull down list and type in extproc in the Key field.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-10

Solution for Practice 3: Controlling Access to the Listener (continued) Exercise 2: Securing the EXTPROC Service Entry (continued) g. The IPC protocol is now visible on the Create Listener page. Click on the Other Services tab to continue.

h. In the Other Services panel, click Add to add a program name.

i. On the Create Other Service page, type extproc in both the Program Name and Service Name fields. Type the location of your ORACLE_HOME in the Oracle Home Directory field and type your SID name in the SID field then click OK.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-11

Solution for Practice 3: Controlling Access to the Listener (continued) Exercise 2: Securing the EXTPROC Service Entry (continued) j. When you are returned to the Create Listener page, click on the OK button.

k. Now, on the Listeners page, your new listener should appear. Select the LISTENEREXTPROC listener and choose Start/Stop from the Actions pull down list, then click Go.

l. Check the status for LISTENEREXTPROC and make sure it is started.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-12

Solution for Practice 5: Configuring Recovery Manager 1. Connect to your database as the target database in the default NOCATALOG mode as the SYSTEM user.
$ rman target system/manager NOCATALOG Recovery Manager: Release 10.1.0.2.0 - Production Copyright (c) 1995, 2004, Oracle. All rights reserved. connected to target database: ORCL (DBID=1045444042) using target database controlfile instead of recovery catalog

2. Use the RMAN SHOW ALL command to generate a listing of the RMAN configuration settings.
RMAN> show all; RMAN configuration parameters are: CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default CONFIGURE BACKUP OPTIMIZATION OFF; # default CONFIGURE DEFAULT DEVICE TYPE TO DISK; CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY PARALLELISM 1; CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE MAXSETSIZE TO UNLIMITED; # default CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/10.1.0/db_1/dbs/snapcf_orcl.f'; # default

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-13

Solution for Practice 5: Configuring Recovery Manager (continued) 3. Use the Enterprise Manager Database Control Console to set the backup retention policy to a recovery window of 2 days. a. b. c. d. e. f. Log in to the Database Control Console as the SYSTEM user. Go to the Maintenance page. Select Configure Backup Settings. Click Policy. Scroll down to the Retention Policy section. Choose "Retain backups that are necessary for a recovery to any time within the specified number of days…" and specify a value of 2. To save the modified details of 'Retention Policy', enter the host credentials of oracle/oracle and click OK.

4. Verify the backup retention policy setting using the RMAN utility and the SHOW command.
RMAN> show retention policy; RMAN configuration parameters are: CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-14

Solution for Practice 6: Using Recovery Manager 1. Using SQL*Plus or the EM Database Control Console, verify the database is in ARCHIVELOG mode. If not, alter the database to enable archiving of the online redo logs. It is not. Correct this problem with the following commands, or use Enterprise Manager.
SQL> CONNECT / AS SYSDBA SQL> ARCHIVE LOG LIST Database log mode Automatic archival Archive destination Oldest online log sequence Current log sequence SQL> SHUTDOWN IMMEDIATE ORACLE instance shut down. SQL> STARTUP MOUNT Database mounted. SQL> ALTER DATABASE ARCHIVELOG; Database altered. SQL> ALTER DATABASE OPEN; Database altered. SQL> ARCHIVE LOG LIST; Database log mode Automatic archival Archive destination Oldest online log sequence Next log sequence to archive Current log sequence Archive Mode Enabled USE_DB_RECOVERY_FILE_DEST 55 57 57 No Archive Mode Disabled USE_DB_RECOVERY_FILE_DEST 54 56

2. Connect to your database as the target database in the default NOCATALOG mode as the SYSTEM user.
$ rman target system/manager NOCATALOG

Recovery Manager: Release 10.1.0.2.0 - Production Copyright (c) 1995, 2004, Oracle. All rights reserved. connected to target database: ORCL (DBID=1045444042) using target database controlfile instead of recovery catalog

3. Use the RMAN REPORT command to generate a listing of your database structure.
RMAN> REPORT SCHEMA;

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-15

Solution for Practice 6: Using Recovery Manager (continued) 4. Obtain a listing of all database backup sets.
RMAN> LIST BACKUP OF DATABASE; List of Backup Sets =================== BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- -------- ----------- ------------ -----------3 Full 66M DISK 00:00:11 19-FEB-04 BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20040219T131750 Piece Name: /home/oracle/DONTTOUCH/df_ORCL_10_1.bak List of Datafiles in backup set 3 File LV Type Ckp SCN Ckp Time ---- -- ---- -------- --------Name -------------------------------4 Full 1027337 19-FEB-04 /u01/app/oracle/oradata/orcl/users01.dbf 5 Full 1027337 19-FEB-04 /u01/app/oracle/oradata/orcl/example01.dbf RMAN> LIST COPY OF DATABASE;

5. Use RMAN to back up the data files belonging to the EXAMPLE and USERS tablespaces. Be sure you also make a copy of the current control file and server parameter file. Your backups should be placed in the $HOME/DONTTOUCH/ directory and should use the format df_%d_%s_%p.bak for the file names.
RMAN> BACKUP AS BACKUPSET 2> FORMAT '$HOME/DONTTOUCH/df_%d_%s_%p.bak' 3> TABLESPACE USERS, EXAMPLE;

Starting backup at 19-FEB-04 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset input datafile fno=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf input datafile fno=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf channel ORA_DISK_1: starting piece 1 at 19-FEB-04 channel ORA_DISK_1: finished piece 1 at 19-FEB-04 piece handle=/home/oracle/DONTTOUCH/df_ORCL_10_1.bak comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15 Finished backup at 19-FEB-04 Starting Control File and SPFILE Autobackup at 19-FEB-04 Piece handle=/u01/app/oracle/flash_recovery_area/ ORCL_EDRSR12P1/autobackup/2004_02_19/o1_mf_s_518534285_03bb0g7l_.bkp comment=NONE Finished Control File and SPFILE Autobackup at 19-FEB-04 Oracle Database 10g: Administration Workshop II A-16

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Solution for Practice 6: Using Recovery Manager (continued) 6. Create an image copy of two data files. Use the following information: –

Copy the SYSTEM tablespace and name the copy sys01.cpy with a tag of SYSTEM01 Copy the SYSAUX tablespace and name the copy sysaux01.cpy with a tag of SYSAUX01 The files should be written to the Flash Recovery Area.

RMAN> BACKUP AS COPY 2> FORMAT 'sys01.cpy' 3> TABLESPACE SYSTEM 4> TAG=SYSTEM01; Starting backup at 19-FEB-04 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy ... RMAN> BACKUP AS COPY 2> FORMAT 'sysaux01.cpy' 3> TABLESPACE SYSAUX 4> TAG=SYSAUX01; Starting backup at 19-FEB-04 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy ...

7. Obtain a listing of all database files that have not been backed up.
RMAN> REPORT NEED BACKUP;

RMAN retention policy will be applied to the command RMAN retention policy is set to recovery window of 2 days Report of files whose recovery needs more than 2 days of archived logs File Days Name ---- ----- ------------------------------------------------

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-17

Solution for Practice 7: Configuring Alerts This practice will familiarize you with the setting thresholds for warning alerts andcritical alerts. 1. Connect as SYSDBA through SQL*Plus, check that you do not have any outstanding alerts for the User Commits Per Sec metric, and look at your alert history. Then run the lab_07_01_02.sql script. This script sets the User Commits Per Sec metric with a warning threshold of 3, and a critical threshold of 6. When done, check that the metrics thresholds have been set correctly.
SQL> connect / as sysdba Connected. SQL> select reason from dba_outstanding_alerts where 2 upper(reason) like'%COMMIT%'; no rows selected
SQL> select reason from dba_alert_history where 2 upper(reason) like'%COMMIT%'; no rows selected

SQL> @lab_07_01_02.sql PL/SQL procedure successfully completed. SQL> col object_name format a20 SQL> col metrics_name format a30 SQL> col warning_value format a10 SQL> col critical_value format a10

SQL> select metrics_name, warning_value, critical_value 2 from dba_thresholds where upper(metrics_name) 3 like'%COMMIT%'; METRICS_NAME WARNING_VA CRITICAL_V ------------------------------ ---------- ---------User Commits Per Sec 3 6

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-18

Solution for Practice 7: Configuring Alerts (continued) 2. Execute the lab_07_01_03.sql script. This script creates a new table and inserts one row. Connect as SYSDBA through the Database Control Console and look at the corresponding metrics graphic rate. Then, execute the lab_07_01_04.sql script. This script generates a commit rate between three and six commits per second for one minute. While the script is executing, observe the metrics graph using the Database Control Console. After a minute or two, look at your outstanding alerts and alert history. What are your conclusions?
SQL> @lab_07_01_03.sql Connected. drop table t purge * ERROR at line 1: (This is OK, script drops table first if it already exists) ORA-00942: table or view does not exist Table created. 1 row created. Commit complete. SQL> @lab_07_01_04.sql

a. b. c. d.

From the Database Control home page, click the All Metrics link under Related Links. On the All Metrics page, expand the Throughput listing. On the All Metrics page, click the User Commits (per second) link.

On the User Commits (per second) page, make sure that the View Data field is set to Real Time: 30 Seconds Refresh.

r O

Answer: Although the commit rate is going above the warning level, you do not get any outstanding alerts. This is because an alert is raised only after two consecutive occurrences of the observation period’s violation. So the rate should be above the warning level for more than one minute

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-19

Solution for Practice 7: Configuring Alerts (continued) 3. While connected as SYSDBA through Database Control, look at the corresponding metrics graphic rate, and execute the lab_07_01_05.sql script. This script generates a commit rate of five commits per second for three minutes on your system. After the script finishes its execution, examine your outstanding alerts and alert history using Database Control. What are your conclusions?

Answer: Because this time the commit rate is maintained above the warning level, and less than the critical level for more than two minutes, you should get a warning alert.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-20

Solution for Practice 7: Configuring Alerts (continued) 4. While connected as SYSDBA through Database Control, look at the corresponding metrics graphic rate, and execute the lab_07_01_06.sql script. This script generates a commit rate of eight commits per second for three minutes on your system. While the script is executing, observe the metrics graph using Database Control. After the script finishes its execution, look at your outstanding alerts and alert history using both SQL*Plus and Database Control. What are your conclusions?

Answer: Because the commit rate is maintained above the warning level, and less than the critical level for more than two minutes, you should get a critical alert. 5. Wait three more minutes and look at your outstanding alerts and the alert history again. What are your conclusions?

Answer: Because the commit rate is now close to zero for more than three minutes, the alert is automatically cleared. 6. Using Database Control, change the 30 second threshold check for the User Commits (per second) metric back to the default value (last 24 hours). Execute the lab_07_cleanup.sql script to clean up your environment.

$ lab_07_cleanup.sql Connected. PL/SQL procedure successfully completed. PL/SQL procedure successfully completed. PL/SQL procedure successfully completed. Oracle Database 10g: Administration Workshop II A-21

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Solution for Practice 8: Recreating the Control File 1. Use the ALTER DATABASE command to back up the control file to trace.
SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE; Database altered.

2. Execute the $HOME/labs/lab08_02.sql script to identify the trace file.
SQL> @$HOME/labs/lab08_02.sql USERNAME -----------------------------SYSTEM SPID --------<process ID>

3. Exit SQL*Plus. At the OS command prompt, copy the trace file to $HOME/DONTTOUCH/cntrl.sql. Using an editor, remove the comment lines from the trace file.
SQL> exit $ cd /u01/app/oracle/admin/ORCL/udump $ cp <sid>_ora_<process ID>.trc $ vi $HOME/DONTTOUCH/cntrl.trc $HOME/DONTTOUCH/cntrl.trc

Remove all unneeded text and commands from the trace file.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-22

Solution for Practice 9: Incomplete Recovery Exercise 1: Point-in-Time Recovery 1. As user system/oracle create the table HR.DEPARTMENTS2 as select * from HR.DEPARTMENTS. Confirm that the table exists, and record the total number of rows in the table. View the active log by querying V$LOG. Perform a log switch when finished.
$ sqlplus /nolog SQL*Plus: Release 10.1.0.2.0 - Production on Thu Feb 19 03:29:16 2004 Copyright (c) 1982, 2004, Oracle. All rights reserved.

SQL> connect system/oracle as sysdba Connected. SQL> create table HR.DEPARTMENTS2 as select * from HR.DEPARTMENTS; Table created. SQL> select count(*) from hr.departments2; COUNT(*) ---------27 SQL> select sequence#, status from v$log; SEQUENCE# ---------65 63 64 STATUS ---------------CURRENT INACTIVE INACTIVE

SQL> alter system switch logfile; System altered.

2. Check and record the system time and date.
SQL> !date Thu Feb 19 03:31:49 PST 2004 SQL>

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-23

Solution for Practice 9: Incomplete Recovery (continued) Exercise 1: Point-in-Time Recovery (continued) 3. Query V$LOG again to confirm the switch and then insert three lines into the DEPARTMENTS2 table and commit. Confirm the number of rows in the table. These inserts represent the introduction of “questionable” data into the table.
SQL> select sequence#, status from v$log; SEQUENCE# ---------65 66 64 SQL> SQL> SQL> SQL> SQL> insert insert insert commit select STATUS ---------------ACTIVE CURRENT INACTIVE into hr.departments2 values (280, 'DUMMY1','',''); into hr.departments2 values (290, 'DUMMY2','',''); into hr.departments2 values (300, 'DUMMY3','',''); count(*) from departments2;

COUNT(*) ---------30

4. Shutdown the database, and restart it in mount mode.
SQL> shutdown immediate; SQL> startup mount; ORACLE instance started. SQL> exit

5. Using RMAN, recover the database to a point in time before the new data was introduced using the information you recorded before the inserts were performed.
$ rman target / Recovery Manager: Release 10.1.0.2.0 - Production Copyright (c) 1995, 2004, Oracle. All rights reserved. connected to target database: ORCL (DBID=1045444042) RMAN> set until time "TO_DATE('04-FEB-19:03:31:49','YY-MONDD:HH24:MI:SS')"; 3> restore database; 4> recover database; 5> } executing command: SET until clause using target database controlfile instead of recovery catalog Starting restore at 19-FEB-04 allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=268 devtype=DISK Oracle Database 10g: Administration Workshop II A-24

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Solution for Practice 9: Incomplete Recovery (continued) Exercise 1: Point-in-Time Recovery (continued)
channel ORA_DISK_1: starting datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf ... media recovery complete Finished recover at 19-FEB-04

6. Open the database with the RESETLOGS option and confirm the recovery. Always perform a backup after opening the database with the RESETLOGS option. Finally, bounce the database.
SQL> connect system/oracle SQL> alter database open resetlogs; SQL> select count(*) from hr.departments2; COUNT(*) ---------27 SQL> exit $ rman target / RMAN> backup database;

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-25

Solution for Practice 9: Incomplete Recovery (continued) Exercise 2:Recovery Using Log Sequence and Enterprise Manager 1. Determine the current log sequence and write it down.
SQL> select sequence#, status from v$log; SEQUENCE# ---------206 207 208 STATUS ---------------INACTIVE INACTIVE CURRENT

2. Verify the row count for the HR.DEPARTMENTS2 table.
SQL> select count(*) from hr.departments2; COUNT(*) ---------27

3. Force a log switch and verify the switch has taken place. Perform several inserts into the HR.DEPARTMENTS2 table and commit the changes. Verify the row count.
SQL> alter system switch logfile; System altered. SQL> select sequence#, status from v$log;

SEQUENCE# STATUS ---------- ---------------209 CURRENT 207 INACTIVE 208 ACTIVE SQL> insert into hr.departments2 values (280, 'DUMMY1','',''); SQL> insert into hr.departments2 values (290, 'DUMMY2','',''); SQL> insert into hr.departments2 values (300, 'DUMMY3','',''); SQL> commit SQL> select count(*) from departments2; COUNT(*) ---------30

4. Using Enterprise Manager, recover the database to the log sequence you wrote down previously. a.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

From the Database Control home page, click on the Maintenance folder tab, and then click on Perform Recovery. Select Whole Database from the Object Type pull down list
Oracle Database 10g: Administration Workshop II A-26

b.

Solution for Practice 9: Incomplete Recovery (continued) Exercise 2:Recovery Using Log Sequence and Enterprise Manager c. d. Select "Recover to the current time … ". Click Next to continue.

e. f.

Click on the Sequence button and type in the sequence number you wrote down previously. Click Next to continue.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-27

Solution for Practice 9: Incomplete Recovery (continued) Exercise 2:Recovery Using Log Sequence and EM (continued) g. h. Review the recovery steps and the RMAN script that will be run. Click Submit.

5. Verify that the recovery was successful. Perform a backup when finished.
SQL> connect system/oracle as sysdba Connected. SQL> select count(*) from hr.departments2; COUNT(*) ---------27 SQL> exit $ rman target / RMAN> backup database;

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-28

Solution for Practice 10: Flashback Database This practice covers the configuration and basic functions of Flashback Database. Unless specified otherwise, you should be logging in as SYS/ORACLE as SYSDBA either through Database Control or SQL*Plus. Exercise 1: Configuring Flashback Database 1. Flashback Database requires that the database be in ARCHIVELOG mode. Use EM to configure this , if needed. a. b. c. From the database home page, click on the Maintenance tab. Click on Configure Recovery Settings. Under Media Recovery, click the ARCHIVELOG mode check box, if not already checked.

2. Configure Flashback Database from the Configure Recovery Settings page. Set the flash recovery area size to 4 GB. Enable Flashback logging and set the DB_FLASHBACK_RETENTION_TARGET parameter to 1 day. a. c. b.

r O

Scroll to the bottom of the Configure Recovery Settings page Accept the default Flash Recovery Area Location. Click the Enable flashback logging … check box.
Oracle Database 10g: Administration Workshop II A-29

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Increase the Flash Recovery Area Size from 2 to 4 GB.

d.

Solution for Practice 10: Flashback Database (continued) Exercise 1: Configuring Flashback Database (continued) e. f. Accept the default value (24 hours) for Flashback Retention Time. Click Apply to continue.

g.

On the Confirmation page, you are notified that the database needs to be restarted. Click the Yes button to accept and continue.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-30

Solution for Practice 10: Flashback Database (continued) Exercise 2: Using the Flashback Database RMAN interface 1. Confirm the row count for the DEPARTMENTS2 table and then record the system time.
SQL> connect system/oracle as sysdba Connected. SQL> select count(*) from HR.DEPARTMENTS2; COUNT(*) ---------27 SQL> !date Thu Feb 19 13:34:59 PST 2004

2. Delete several rows from the DEPARTMENTS2 table.
SQL> delete from hr.departments2 where department_id > 240; 3 rows deleted.

3. Commit the changes and then confirm the row count.
SQL> select count(*) from hr.departments2; COUNT(*) ---------24

4. Using the Flashback Database RMAN interface, flash the database back to reflect its condition before the data was dropped.

Shutdown the database and start it again in mount mode. Then start RMAN and run the RMAN command shown below, being careful to substitute your date in the command.
SQL> connect / as sysdba Connected. SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount; ORACLE instance started. SQL>host $ rman target / RMAN> FLASHBACK DATABASE 2> TO TIME = "TO_DATE('04-FEB-19:13:34:59','YY-MON-DD:HH24:MI:SS')"; Starting flashback at 19-FEB-04 using target database controlfile instead of recovery catalog allocated channel: ORA_DISK_1 ... Finished flashback at 19-FEB-04 RMAN> exit

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-31

Solution for Practice 10: Flashback Database (continued) Exercise 2: Using the Flashback Database RMAN interface (continued) 5. Confirm that the flashback operation was successful. Perform a backup when finished. From a SQL*Plus session, connect as SYS and open the database with the RESETLOGS option. Get a row count from the DEPARTMENTS2 table to confirm that the flashback was successful.
$ sqlplus /nolog SQL> CONNECT / as sysdba Connected. SQL> ALTER DATABASE OPEN RESETLOGS; Database altered. SQL> SELECT COUNT(*) FROM hr.departments2; COUNT(*) ---------27 SQL> exit $ rman target / RMAN> backup database;

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-32

Solution for Practice 10: Flashback Database (continued) Exercise 3: Using the Flashback Database EM Interface 1. Confirm the row count for the HR.DEPARTMENTS2 table and then record the current SCN by querying V$DATABASE. Record this value here: ________________.
SQL> connect system/oracle as sysdba Connected. SQL> SELECT COUNT(*) FROM hr.departments2; COUNT(*) ---------27 SQL> SELECT current_scn FROM v$DATABASE; CURRENT_SCN ----------468296

2. Delete several rows from the HR.DEPARTMENTS2 table. Commit the changes and get another row count.
SQL> DELETE FROM hr.departments2 WHERE department_id > 240; 3 rows deleted. SQL> commit; SQL> SELECT COUNT(*) FROM hr.departments2; COUNT(*) ---------24

3. Query V$DATABASE and be certain the SCN has been incremented.
SQL> select current_scn from v$DATABASE; CURRENT_SCN ----------468518

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-33

Solution for Practice 10: Flashback Database (continued) Exercise 3: Using the Flashback Database EM Interface (continued) 4. Using EM, flashback the database to the SCN recorded before the rows were deleted. Review the RMAN commands used for the flashback operation before submitting your request. a. Select Whole Database from the Object Type pull down list. Select 'Recover to current time or previous point-in-time' for the Operation Type. Provide your host login and password, oracle/oracle, then click Next.

b.

You will be notified that the database is being shut down and restarted in mount mode. Wait a few minutes, then click Refresh to proceed.

c.

You are then notified of the state of the database. Click Perform Recovery.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-34

Solution for Practice 10: Flashback Database (continued) Exercise 3: Using the Flashback Database EM Interface (continued) d. Next, you must provide both host credentials and database credentials so a new session can be initiated and the database can be opened after the flashback operation. Use oracle/oracle for the host login and sys/oracle for the database credentials. Click Continue to proceed. If you are redirected to the Perform Recovery: Type screen, just repeat your responses as provided in step a.

e.

On the next screen, you must supply point-in-time recovery information. Choose 'Recover to a prior point-in-time', then select SCN and enter the SCN value recorded in Step1. Click Next to continue.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-35

Solution for Practice 10: Flashback Database (continued) Exercise 3: Using the Flashback Database EM Interface (continued) f. On this screen, indicate your preference for the flashback method over traditional point-in-time recovery by selecting 'Yes, use flashback …'. Click Next to proceed.

g.

Take some time and review the information here. Make sure everything is correct. You can also review the RMAN commands that will be executed. Click Submit to continue.

h.

If successful, you should see a screen similar to the one shown below. Click OK and return to the Database Control home page.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-36

Solution for Practice 10: Flashback Database (continued) Exercise 3: Using the Flashback Database EM Interface (continued) 5. Verify the flashback operation was successful. Start a SQL*Plus session, connect as system/oracle and get a row count from the HR.DEPARTMENTS2 table to verify that the database has been properly flashed back.
SQL> CONNECT system/oracle as sysdba Connected. SQL> SELECT COUNT(*) FROM hr.departments2; COUNT(*) ---------27

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-37

Solution for Practice 10: Flashback Database (continued) Exercise 4: Managing and Moitoring Flashback Database This exercise will familiarize you with the dictionary views used to manage and monitor Flashback Database. 1. Query the V$FLASHBACK_DATABASE_LOG view and determine the lowest SCN that the database can be flashbacked to. Record your answer here: _____________
SQL> SELECT oldest_flashback_scn, oldest_flashback_time 2 FROM V$FLASHBACK_DATABASE_LOG; OLDEST_FLASHBACK_SCN OLDEST_FL -------------------- --------468299 20-FEB-04

2. View the overhead associated with flashback logging and related operations by querying V$FLASHBACK_DATABASE_STAT.
SELECT * FROM V$FLASHBACK_DATABASE_STAT; BEGIN_TIM --------20-FEB-04 0 20-FEB-04 459202560 END_TIME FLASHBACK_DATA --------- -------------20-FEB-04 20-FEB-04 6561792 21110784 DB_DATA REDO_DATA ESTIMATED_FLASHBACK_SIZE -------- ---------- ----------------------11223040 40321024 5063168 16595456

3. Determine the current size of stored flashback data by querying V$FLASHBACK_DATABASE_LOG. Record your answer here: _____________

SQL> SELECT estimated_flashback_size, flashback_size flashback_size 2 FROM V$FLASHBACK_DATABASE_LOG; ESTIMATED_FLASHBACK_SIZE FLASHBACK_SIZE ------------------------ -------------353648640 32677888

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-38

Solution for Practice 11: Recovering from User Errors Exercise 1: Performing Flashback Drop This exercise will familiarize you with the Flashback Drop feature. 1. Get a row count from the HR.DEPARTMENTS2 table.
SQL> CONNECT system/oracle Connected. SQL> SELECT COUNT(*) FROM hr.departments2; COUNT(*) ---------27

2. Drop the HR.DEPARTMENTS2 table, and verify that it has indeed been dropped.
SQL> DROP TABLE hr.departments2; Table dropped. SQL> SELECT * FROM hr.departments2; SELECT * FROM hr.departments2 * ERROR at line 1: ORA-00942: table or view does not exist

3. Determine the object name, undrop status and other related information by querying DBA_RECYCLEBIN.
SQL> SELECT original_name, object_name, droptime 2 FROM dba_recyclebin WHERE can_undrop = 'YES'; ORIGINAL_NAME OBJECT_NAME ------------------- -----------------------------DEPARTMENTS2 BIN$07xSYSqrEmPgMLmLbSNgjw==$0

4. Use the SQL FLASHBACK TABLE command to restore the table.
SQL> FLASHBACK TABLE hr.departments2 TO BEFORE DROP; Flashback complete.

SQL> SELECT COUNT(*) FROM hr.departments2; COUNT(*) ---------27

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

DROPTIME ------------------2004-02-19:13:33:44

Oracle Database 10g: Administration Workshop II A-39

Solution for Practice 11: Recovering from User Errors Exercise 2: Performing Flashback Versions Queury Using Enterprise Manager 1. Insert 3 rows into the HR.DEPARTMENTS2 table and commit the changes. Confirm that the inserts were successful.
SQL> SQL> SQL> SQL> SQL> SQL> INSERT INTO hr.departments2 VALUES (280, 'DUMMY1','',''); COMMIT; INSERT INTO hr.departments2 VALUES (290, 'DUMMY2','',''); COMMIT; INSERT INTO hr.departments2 VALUES (300, 'DUMMY3','',''); COMMIT;

SQL> SELECT COUNT(*) FROM hr.departments2; COUNT(*) ---------30

2. Use Enterprise Manager to view the row history of the HR.DEPARTMENTS2 table. a. b. From the Database Control home page, click on the Maintenance tab, then click Perform Recovery under the heading Backup/Recovery. Select Tables from the Object Type pull down list. When the screen refreshes, select Flashback Existing Tables. Click Next to proceed.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-40

Solution for Practice 11: Recovering from User Errors (continued) Exercise 2: Performing Flashback Versions Queury Using Enterprise Manager (continued) c. Enter the name of the table and click Next.

d.

Highlight DEPARTMENT_ID under Available Columns and click the Move button to move it under Selected Columns. Enter a where clause that will select the added rows. For example, if you added rows with DEPARTMENT_IDs of 280, 290, and 300 in Step 1, the statement "WHERE department_id > 270" will work nicely. Click Next to continue.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-41

Solution for Practice 11: Recovering from User Errors (continued) Exercise 2: Performing Flashback Versions Queury Using Enterprise Manager (continued) e. You can now review the rows under Flashback Versions Query Result.

3. Use Enterprise Manager to flashback the middle insert. a. Under Flashback Versions Query Result, select the middle transaction from the list to flashback. Click Next to continue.

b.

On the next screen, you are asked to include any tables related or dependant on the table we are flashing back. Since there are none, click Next to continue.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-42

Solution for Practice 11: Recovering from User Errors (continued) Exercise 2: Performing Flashback Versions Queury Using Enterprise Manager (continued) c. Review the information and click Submit.

d.

On the next screen, we find that the operation has failed because row movement is not enabled for the table. If you recall from the lesson, row movement must be enabled for this feature to work.

e. f.

To enable row movement for this table, go to the Database Control home page and click the Administration tab, then click on the Table link in the Schema region. Enter hr in the Schema field and departments2 in the Object Name field, then click Go.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-43

Solution for Practice 11: Recovering from User Errors (continued) Exercise 2: Performing Flashback Versions Queury Using Enterprise Manager (continued) g. One table is displayed in the Results region, and selected by default. Click Edit.

h.

Click the Options tab.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-44

Solution for Practice 11: Recovering from User Errors (continued) Exercise 2: Performing Flashback Versions Queury Using Enterprise Manager (continued) i. From the Enable Row Movement pull down list, select Yes and click Apply.

j.

Click OK on the Confirmation page to continue to the Database Control home page.

k.

Now you can perform the flashback operation. From the Database home page, click the Maintenance tab and select Perform Recovery under the heading Backup/recovery. Select Tables from the Object Type pull down list. When the screen refreshes, select Flashback Existing Tables. Click Next to proceed. Enter the name of the table and click Next.

l. m. n.

Highlight DEPARTMENT_ID under Available Columns and click the Move button to move it under Selected Columns. Enter a WHERE clause that will select the added rows. For example, in Step 1, if you added rows department IDs of 280, 290, and 300, use the clause "where department_id > 270". Click Next to continue.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-45

Solution for Practice 11: Recovering from User Errors (continued) Exercise 2: Performing Flashback Versions Queury Using Enterprise Manager (continued) o. You can now review the rows under Flashback Versions Query Result. Select the middle transaction. Click Next to continue.

p.

Review your selection and click Submit.

q.

On the Confirmation page, click OK to continue.

r.

Get a row count to confirm the flashback operation.

SQL> SELECT COUNT(*) FROM hr.departments2; COUNT(*) ---------28

Question: According to the row count, we have flashed back 2 transactions (30-28=2). Were you expecting just a single transaction to be flashed back? Answer: If you answered yes, remember that the SCN used in the flashback example was 679196, which is greater than the SCN for the record with DEPARTMENT_ID equal to 280 (679194) so rows with DEPARTMENT_IDs of 290 and 280 are both flashed back.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-46

Solution for Practice 12: Dealing with Database Corruption Exercise 1: Detecting Database Corruptions 1. Perform a full backup using Enterprise Manager. From the Database Control home page, select the Maintenance tab and then Schedule Backup under Backup/Recovery. From the Backup Strategy pull down list, select Customized and then click the Whole Database button. Provide oracle/oracle for the host credentials. Click Next to proceed.

Accept the default choices on the Options page and click Next to continue.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-47

Solution for Practice 12: Dealing with Database Corruption (continued) Exercise 1: Detecting Database Corruptions (continued) On the settings page, make sure Disk is selected and click the Next button to continue.

On the Schedule page, make sure Immediately is selected under Start and the backup is performed one time only. Click the Next button to continue.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-48

Solution for Practice 12: Dealing with Database Corruption (continued) Exercise 1: Detecting Database Corruptions (continued) Review the backup details and click on the Submit job button.

2. Introduce a corruption into the block on which the DEPARTMENTS table resides by querying the DBA_EXTENTS table to find the file and block id. Find the file name of the file id returned above. Make sure you have write privileges on the data file. If not, use the chmod command as root to correct this.
SQL> SELECT file_id, block_id FROM dba_extents 2 WHERE segment_name = 'DEPARTMENTS'; FILE_ID BLOCK_ID ---------- ---------5 49 SQL> SELECT file#, name FROM v$datafile; FILE# NAME ---------1 2 3 4 5 SQL> exit $ su – password: # chmod 775 # exit $

-----------------------------------------------------------/u01/app/oracle/oradata/orcl/system01.dbf /u01/app/oracle/oradata/orcl/undotbs01.dbf /u01/app/oracle/oradata/orcl/sysaux01.dbf /u01/app/oracle/oradata/orcl/users01.dbf /u01/app/oracle/oradata/orcl/example01.dbf

/u01/app/oracle/oradata/orcl/example01.dbf

3. Run the lab_12_01_03.sh script using the information gathered above to corrupt the block. This script requires the file name, block number, and database block size as arguments. Shutdown and restart the database to clear the buffer cache.
$ lab_12_01_03.sh /u01/app/oracle/oradata/orcl/example01.dbf 49 8192 0+1 records in 0+1 records out $ exit SQL> shutdown immediate; SQL> startup Oracle Database 10g: Administration Workshop II A-49

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Solution for Practice 12: Dealing with Database Corruption (continued) Exercise 1: Detecting Database Corruptions (continued) 4. Run the dbv command and inspect the output.
$ dbv file=/u01/app/oracle/oradata/orcl/example01.dbf blocksize=8192 DBVERIFY: Release 10.1.0.2.0 - Production on Mon Feb 23 11:00:17 2004 Copyright (c) 1982, 2004, Oracle. All rights reserved. DBVERIFY Verification starting: FILE = /u01/app/oracle/oradata/orcl/example01.dbf Page 49 is marked corrupt Corrupt block relative dba: 0x01400031 (file 5, block 49) Bad header found during dbv: Data in bad block: type: 67 format: 7 rdba: 0x0a545055 last change scn: 0x0000.00057b13 seq: 0x2 flg: 0x04 spare1: 0x52 spare2: 0x52 spare3: 0x0 consistency value in tail: 0x7b132002 check value in block header: 0x676 computed block checksum: 0xe441 Page 51 is marked corrupt Corrupt block relative dba: 0x01400033 (file 5, block 51) Bad header found during dbv: Data in bad block: type: 67 format: 7 rdba: 0x0a545055 last change scn: 0x0000.000724f2 seq: 0x1 flg: 0x04 spare1: 0x52 spare2: 0x52 spare3: 0x0 consistency value in tail: 0x24f22301 check value in block header: 0x6b91 computed block checksum: 0xe440 Page 52 is marked corrupt Corrupt block relative dba: 0x01400034 (file 5, block 52) Bad header found during dbv: Data in bad block: type: 67 format: 7 rdba: 0x0a545055 last change scn: 0x0000.00057b19 seq: 0x1 flg: 0x06 spare1: 0x52 spare2: 0x52 spare3: 0x0 consistency value in tail: 0x7b190601 check value in block header: 0xb133 computed block checksum: 0xe462

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-50

Solution for Practice 12: Dealing with Database Corruption (continued) Exercise 1: Detecting Database Corruptions (continued)
Page 53 is marked corrupt Corrupt block relative dba: 0x01400035 (file 5, block 53) Bad header found during dbv: Data in bad block: type: 67 format: 7 rdba: 0x0a545055 last change scn: 0x0000.00057b13 seq: 0x2 flg: 0x04 spare1: 0x52 spare2: 0x52 spare3: 0x0 consistency value in tail: 0x7b130602 check value in block header: 0xfb9e computed block checksum: 0xe463 DBVERIFY - Verification complete Total Total Total Total Total Total Total Total Total Total Total Pages Pages Pages Pages Pages Pages Pages Pages Pages Pages Pages Examined : Processed (Data) : Failing (Data) : Processed (Index): Failing (Index): Processed (Other): Processed (Seg) : Failing (Seg) : Empty : Marked Corrupt : Influx : 19200 4404 0 1244 0 2680 0 0 10867 4 0

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-51

Solution for Practice 12: Dealing with Database Corruption (continued) Exercise 2: Using RMAN to Repair Corrupt Blocks 1. Query the DEPARTMENTS table using a SELECT command. What is the error that is returned? Before performing this step, be sure that the database has been bounced as required in step 3 in the previous exercise.
SQL> SELECT * FROM hr.departments; select * from hr.departments * ERROR at line 1: ORA-01578: ORACLE data block corrupted (file # 5, block # 51) ORA-01110: data file 5: '/u01/app/oracle/oradata/orcl/example01.dbf'

2. Perform block media recovery using RMAN. Use the DBVERIFY output from the previous exercise to determine the blocks that need recovering.
$ rman blockrecover datafile 5 block 49, 50, 51, 52, 53 Starting blockrecover at 23-FEB-04 using target database controlfile instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=272 devtype=DISK ...

3. Verify that the block recovery is successful.
SQL> SELECT * FROM hr.departments;

DEPARTMENT_ID DEPARTMENT_NAME MANAGER_ID LOCATION_ID ------------- ------------------------------ ---------- ----------10 Administration 200 1700 20 Marketing 201 1800 30 Purchasing 114 1700 40 Human Resources 203 2400 50 Shipping 121 1500 ...

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-52

Solution for Practice 13: Optimizing Database Performance Exercise 1: Proactively Managing Your Database Using ADDM Unless specified otherwise, you should be logging in as SYSDBA either with the Database Control Console or SQL*Plus. 1. Use the Database Control Console to create a new tablespace called TBSADDM. This tablespace should have only one 50 MB file and must be locally managed. Also, make sure that TBSADDM does not use automatic segment space management. a. From the Database Control home page, click on the Administration tab and then click on Tablespaces. On the Tablespaces page, click the Create button.

b.

On the Create Tablespace page, specify TBSADDM in the Name field, and then click the Add button.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-53

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 1: Proactively Managing Your Database Using ADDM (continued) c. On the Create Tablespace: Add Datafile page, specify tbsaddm.dbf in the File Name field and change the File Size to 50 MB. When done, click the Continue button.

d.

After returning to the Create Tablespace page, click the Storage tab. Make sure that Manual is selected for the Segment Space Management region. Click the OK button.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-54

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 1: Proactively Managing Your Database Using ADDM (continued) 2. Using the Database Control Console, create a new user called ADDM identified by ADDM. Make sure that the ADDM user has TBSADDM as its default tablespace, and TEMP as its temporary tablespace. When done, grant the following roles to the ADDM user: CONNECT, RESOURCE, DBA.
a.

From the Database Control home page, click the Administration tab and then click on Users. On the Users page click the Create button.

b.

On the Create User page, specify the following fields: Name, Enter Password, Confirm Password, Default Tablespace, and Temporary Tablespace. When done, click the Roles tab.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-55

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 1: Proactively Managing Your Database Using ADDM (continued) c. Click the Modify button. On the Modify Roles page, select RESOURCE, and DBA from the Available Roles list. Click the Move button to move the roles into the Selected Roles window. Then click the OK button. After being returned to the Create User page, click the OK button.

3. Connect as ADDM in SQL*Plus, execute lab_13_01_01.sql from the labs directory. Connect as user oracle from your terminal emulator and execute the lab_13_01_02.sh script from your labs directory.
$ cd labs $ sqlplus /nolog SQL> connect addm/addm Connected. SQL> @lab_13_01_01.sql Connected. PL/SQL procedure successfully completed. … SQL> exit $ ./lab_13_01_02.sh

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-56

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 1: Proactively Managing Your Database Using ADDM (continued) 4. From the Database Control Console home page, click the Performance tab. On the Performance page, make sure that the View Data field is set to Real Time: 15 Seconds Refresh. After a while, you should see a spike on the Sessions: Waiting and Working graph. After the spike is finished, execute the lab_13_01_03.sql script. This script forces the creation of a new snapshot. Looking at the graph, you can already determine that this instance is suffering concurrency problems.

SQL> CONNECT addm/addm Connected. SQL> @lab_13_01_03.sql Connected. PL/SQL procedure successfully completed.

5. Return to the Database home page. Because the ADDM data is not refreshed too frequently on the console, you may not see the latest ADDM result in the Diagnostic Summary region. Retrieve the latest ADDM findings, and determine the cause of the problem.
a.

From the Database home page click the Advisor Central link. On the Advisor Central page, select ADDM in the Advisory Type drop-down list, and select Last 24 Hours in the Advisor Runs drop-down list. When done, click Go.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-57

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 1: Proactively Managing Your Database Using ADDM (continued)
b.

Select the latest ADDM task completed by the ADDM user. When done, click the View Result button.

c.

This takes you to the Automatic Database Diagnostic Monitor (ADDM) page where you can see the results of the Performance Analysis. Looking at the Performance Analysis region, you can see that the first finding has a 100% impact on the system. So your first instinct is to look at the corresponding recommendation. Click the SQL statements consuming significant database time were found link to investigate further.

d.

This brings you to the Performance Finding Details page where ADDM identifies the high-load SQL statement. Click the Run SQL Tuning Advisor Now button to tune this statement. On the Schedule Advisor page, click OK.

r O

e.

cl a

When the analysis is done, click the View Recommendations button.

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-58

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 1: Proactively Managing Your Database Using ADDM (continued)
f.

You are directed to the Recommendations page. Unfortunately, there is no possible recommendation for this INSERT statement.

g.

The problem must be further below in the stack. Return to the Automatic Database Diagnostic Monitor (ADDM) page to investigate further. Click the Read and write contention on database blocks was consuming significant database time link. This recommendation is related to the schema category.

h.

Here you are advised to use the Automatic Segment Space Management feature for your ADDM table.

6. To fix the problem, create a new tablespace called TBSADDM2, and execute the lab_13_01_05.sql script from your labs directory. This script drops the ADDM table, and re-creates it in the new tablespace. This script also gathers statistics on the table and takes a new snapshot. a.

r O

cl a

To implement the recommendation, you must re-create the objects. First, you need to create a new tablespace that uses the Automatic Space Management feature. Return to the Database home page, and click the Administration tab.

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-59

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 1: Proactively Managing Your Database Using ADDM (continued) b. Click the Tablespaces link, and then click Create. Specify the name of the new tablespace in the Name field. You can call this new tablespace TBSADDM2. Click Add to add a file to this tablespace.

c.

On the Create Tablespace: Add Datafile page, specify the name of the new file, and make sure that its size is set to 50 MB. When done, click the Continue button.

d.

Back to the Create Tablespace page, click the Storage tab, and make sure that Automatic is set in the Segment Space Management region. Then click the OK button to create the new tablespace.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-60

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 1: Proactively Managing Your Database Using ADDM (continued) e. Now, run the lab_13_01_05.sql and recreate table ADDM in the new tablespace:

SQL> @lab_13_01_05.sql Connected. Table dropped. Table created. PL/SQL procedure successfully completed. PL/SQL procedure successfully completed.

7. Connect as user oracle and execute the lab_13_01_02.sh script again from your labs directory. From the Database Control Console home page, go to the Performance page and make sure that the View Data field is set to Real Time: 15 Seconds Refresh. After a while, you should see a spike on the Sessions: Waiting and Working graph. When the spike is finished, execute the lab_13_01_06.sql script. This script forces the creation of a new snapshot. From the Database Control home page, go to Advisor Central and look at the latest snapshot. Has the situation improved?
$ ./lab_13_01_02.sh

Looking at the graph, you can already determine that this instance is not having the same concurrency issues encountered earlier.

Connected. SQL> @lab_13_01_06.sql Connected.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-61

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 1: Proactively Managing Your Database Using ADDM (continued) Looking at the Performance Analysis page, you can determine that the severity of the problems noted earlier have decreased substantially.

8. To clean up your environment, execute the lab_13_01_cleanup.sql script.
SQL> @lab_13_01_cleanup.sql

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-62

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 2: Setting Up an ASM Instance 1. Use DBCA to create the ASM instance on your machine. During the ASM instance creation, DBCA asks you whether you want to change the default values for the ASM initialization parameter. Make sure that the disk discovery string is set to /u02/asmdisks/*. Then DBCA asks you to create new disk groups. Create one disk group called DGROUP1 that is using the following four ASM disks:
– – – /u02/asmdisks/disk0 /u02/asmdisks/disk1 /u02/asmdisks/disk2 /u02/asmdisks/disk3

Make sure to specify that DGROUP1 is using external redundancy. After the ASM instance and the disk group are created, you can exit DBCA. Do not create a database. a.
$ whoami oracle $ dbca

Start dbca as oracle from an OS command line window.

b.

From the DBCA Welcome page, click the Next button to continue.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-63

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 2: Setting Up an ASM Instance (continued) c. On the Operations page, select the Create Database option button and click Next to proceed.

d.

On the Database Templates page, select the General Purpose option button and click the Next button to continue.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-64

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 2: Setting Up an ASM Instance (continued) e. On the Database Identification page, specify a Global Database Name. For example: ASM1.us.oracle.com. Click the Next button.

f.

On the Management Options page, make sure the Configure the Database with Enterprise Manager checkbox is selected. Click the Next button to continue.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-65

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 2: Setting Up an ASM Instance (continued) g. On the Database Credentials page, click the Use the Same Password for All Accounts option button. Use oracle for the password. Click the Next button to continue.

h.

On the Storage Options page, make sure that the Automatic Storage Management (ASM) option button is selected. Click the Next button.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-66

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 2: Setting Up an ASM Instance (continued) i. Because there is currently no ASM instance on your system, DBCA will create one automatically. On the Create ASM Instance page, specify the SYS password for your ASM instance. In this class, oracle is used. Then click the ASM Parameters button. In the ASM Parameters dialog box, make sure that the asm_diskstring field is set to /u02/asmdisks/*. Click the Close button and then Next.

j.

k.

In the Database Configuration Assistant dialog box, click the OK button.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-67

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 2: Setting Up an ASM Instance (continued) l. On the ASM Disk Groups page, click the Create New button.

m.

In the Create Disk Group dialog box, specify DGROUP1 in the Disk Group Name field. Make sure External is selected. Select all CANDIDATE disks from the Select Member Disks array, then click OK to continue.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-68

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 2: Setting Up an ASM Instance (continued) n. Click the Select check box next to DGROUP1 and click Next to continue.

o.

On the Database File Locations page, click the Cancel button.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-69

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 2: Setting Up an ASM Instance (continued) 2. Connect as oracle in your terminal emulator window and start your ASM instance and list the processes associated with it. Look at the ASM processes and query V$ASM_DISKGROUP to view the disk group characteristics. Create a new tablespace called TBSASM that is stored inside the ASM disk group DGROUP1, and that has one 200 MB data file. a. You must set ORACLE_SID to +ASM before starting your ASM instance.

$ ORACLE_SID=+ASM $ export ORACLE_SID $ echo $ORACLE_SID +ASM $ sqlplus / as sysdba Connected to an idle instance. SQL> startup ASM instance started Total System Global Area 100663296 bytes Fixed Size 777616 bytes Variable Size 99885680 bytes Database Buffers 0 bytes Redo Buffers 0 bytes ASM diskgroups mounted SQL> SQL> !ps -ef | grep ASM oracle 21223 1 0 10:42 ? 00:00:00 asm_pmon_+ASM oracle 21225 1 0 10:42 ? 00:00:00 asm_mman_+ASM oracle 21227 1 0 10:42 ? 00:00:00 asm_dbw0_+ASM oracle 21229 1 0 10:42 ? 00:00:00 asm_lgwr_+ASM oracle 21231 1 0 10:42 ? 00:00:00 asm_ckpt_+ASM oracle 21233 1 0 10:42 ? 00:00:00 asm_smon_+ASM oracle 21235 1 0 10:42 ? 00:00:00 asm_rbal_+ASM oracle 21239 1 0 10:42 ? 00:00:00 oracle+ASM (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

SQL> select NAME, STATE, TYPE, TOTAL_MB, FREE_MB from v$asm_diskgroup; NAME STATE TYPE TOTAL_MB FREE_MB -------------------------- ----------- ------ ---------- ---------DGROUP1 MOUNTED NORMAL 800 648

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-70

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 2: Setting Up an ASM Instance (continued) b. Exit from your current shell and log back in as oracle. This is done to reset the ORACLE_SID environment variable overwritten earlier for your ASM instance.

$ exit $ sqlplus / nolog SQL> connect / as sysdba Connected. SQL> create tablespace tbsasm datafile '+DGROUP1' size 200M; Tablespace created.

3. Using SQL*Plus, connect to your database instance as a SYSDBA user and create a new tablespace called TBSASMMIG. This tablespace should contain only one 10 MB file stored in your file system (not using ASM). Create a table called T2 stored in TBSASMMIG. Insert one row inside T2.
SQL> connect / as sysdba Connected. SQL> create tablespace tbsasmmig datafile 'asmmig1.dbf' size 10M; Tablespace created. SQL> select file_name,tablespace_name from dba_data_files; FILE_NAME --------------------------------------------------/u01/app/oracle/oradata/oracle/users01.dbf /u01/app/oracle/oradata/oracle/sysaux01.dbf /u01/app/oracle/oradata/oracle/undotbs01.dbf /u01/app/oracle/oradata/oracle/system01.dbf /u01/app/oracle/oradata/oracle/example01.dbf /u01/app/oracle/product/10.1.0/db_1/dbs/asmmig1.dbf

SQL> create table t2(c number) tablespace tbsasmmig; Table created. SQL> insert into t2 values(1); 1 row created.

r O

cl a

In e

rn te

l& a

O

I A

s U

TABLESPACE_NAME ----------------USERS SYSAUX UNDOTBS1 SYSTEM EXAMPLE TBSASMMIG

O e

ly n

Oracle Database 10g: Administration Workshop II A-71

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 2: Setting Up an ASM Instance (continued) 4. Migrate TBSASMMIG to ASM storage. When done, check that the migration was successful.
SQL> host rman target / nocatalog Recovery Manager: Release 10.1.0.2.0 - Production Copyright (c) 1995, 2004, Oracle. All rights reserved.

connected to target database: ORACLE (DBID=1392029477) using target database controlfile instead of recovery catalog RMAN> SQL "alter tablespace tbsasmmig offline"; RMAN> backup as copy tablespace tbsasmmig format '+DGROUP1'; Starting backup at 25-FEB-04 allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=233 devtype=DISK channel ORA_DISK_1: starting datafile copy input datafile fno=00006 name=/u01/app/oracle/product/10.1.0/db_1/dbs/asmmig1.dbf output filename=+DGROUP1/oracle/datafile/tbsasmmig.257.1 tag=TAG20040225T111512 recid=2 stamp=519045315 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03 Finished backup at 25-FEB-04 RMAN> switch tablespace tbsasmmig to copy;

datafile 6 switched to datafile copy "+DGROUP1/oracle/datafile/tbsasmmig.257.1"

RMAN> SQL "alter tablespace tbsasmmig online"; SQL> select file_name,tablespace_name

from dba_data_files;

FILE_NAME TABLESPACE_NAME ---------------------------------------------- ----------------------/u01/app/oracle/oradata/orcl/users01.dbf USERS /u01/app/oracle/oradata/orcl/sysaux01.dbf SYSAUX /u01/app/oracle/oradata/orcl/undotbs01.dbf UNDOTBS1 /u01/app/oracle/oradata/orcl/system01.dbf SYSTEM +DGROUP1/orcl/datafile/tbsasm.256.1 TBSASM +DGROUP1/orcl/datafile/tbsasmmig.257.1 TBSASMMIG 6 rows selected.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-72

Solution for Practice 13: Optimizing Database Performance (continued) Exercise 2: Setting Up an ASM Instance (continued)
SQL> select * from t2; C ---------1

5. Cleanup your environment by dropping tablespace TBSASMMIG including its contents and data file. Do the same with tablespace TBSASM. Also, remove the standard file system file that was originally created to store TBSASMMIG.
SQL> connect / as sysdba Connected. SQL> DROP TABLESPACE tbsasmmig INCLUDING CONTENTS AND DATAFILES; Tablespace dropped. SQL> DROP TABLESPACE tbsasm INCLUDING CONTENTS AND DATAFILES; Tablespace dropped. SQL> host rm $ORACLE_HOME/dbs/asmmig1.dbf SQL>

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-73

Solution for Practice 15: Using the Resource Manager 1. Login to the EM Database Control Console as the SYSTEM user Invoke Enterprise Manager Database Control by opening your browser and entering the following URL: http://hostname:5500/em Login in with a username of 'system' and a password of 'oracle'. 2. Go to the Administration page. From the Database page, click on the Administration tab. 3. Create the APPUSER resource consumer group using EM. Do not add users to the group. a. b. c. From the Administration page, click on Resource Consumer Groups in the Resource Manager section. On the Resource Consumer Groups page, click Create. For the Consumer Group name, enter APPUSER, then click OK.

4. Add the APPUSER resource consumer group to the SYSTEM_PLAN resource plan. Assign to this group 60% of the CPU resources at level 3. Modify the LOW_GROUP group to receive 40% of the CPU resources at level 3. a. b. c. e. From the Administration page, click on Resource Plans in the Resource Manager section. Select the SYSTEM_PLAN and click Edit. Select the APPUSER group and move it to the Selected Groups list. Click OK. On the Edit Resource Plan: SYSTEM_PLAN page, click Modify. Change the CPU resource allocation percentages at Level 3 to 60 for APPUSER and 40 for LOW_GROUP. Click Apply.
Oracle Database 10g: Administration Workshop II A-74

d.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Solution for Practice 15: Using the Resource Manager (continued) 5. Configure Automatic Consumer Group Mappings as follows: – – – – a. b. c. d. e. A user logged in to the database as the HR user should be assigned to the APPUSER consumer group. A user logged in to the database as the SCOTT user should be assigned to the LOW_GROUP. A user logged in at the operating system as the 'oracle' user should be assigned to the SYS_GROUP. If a user is logged in at the OS level as 'oracle' and at the database level as SCOTT, the user should be placed in the LOW_GROUP. From the database Administration page, in the Resource Manager section, click Resource Consumer Group Mappings. In the Oracle User Map section, click Add Another Row to configure mappings for the HR and SCOTT database users. Change the Consumer Group from DEFAULT_CONSUMER_GROUP to APPUSER and specify HR as the Oracle user. Click Apply. Click Add Another Row to configure mappings for the SCOTT database user. Change the Consumer Group to LOW_GROUP and specify SCOTT as the Oracle user.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-75

Solution for Practice 15: Using the Resource Manager (continued) f. Click the priorities tab. Since ORACLE_USER is listed above CLIENT_OS_USER, no change is needed.

g. h. i.

Click the General tab to return to the Resource Consumer Group Mapping main page. In the Client OS User Map section, click Add Another Row. Change the Consumer Group from DEFAULT_CONSUMER_GROUP to SYS_GROUP and specify oracle as the Client OS User.

j.

Scroll to the top of the page and click Apply.

6. Edit the HR, SCOTT, and PM users to assign them privileges for all resource consumer groups to which they could be assigned. – HR: APPUSER consumer group – SCOTT: LOW_GROUP consumer group – PM: LOW_GROUP, SYS_GROUP, and APPUSER consumer groups a. c. b.

r O

From the Administration page, click Users in the Security section. Select the HR user and click Edit.

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Click the Consumer Groups tab and then click Modify.

Oracle Database 10g: Administration Workshop II A-76

Solution for Practice 15: Using the Resource Manager (continued) d. Move the APPUSER consumer group to the Selected Consumer Groups list and click OK.

e. f. g. h. i. j.

When returned to the Edit User page, click Apply. To edit the user SCOTT, click Users in the breadcrumb listing. Select SCOTT and click Edit. Click the Consumer Groups tab and then click Modify.

Move the LOW_GROUP consumer group to the Selected Consumer Groups list and click OK. When returned to the Edit User page, click Apply.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-77

Solution for Practice 15: Using the Resource Manager (continued) k. l. m. n. o. To edit the user PM, click Users in the breadcrumb listing. Select PM and click Edit. Click the Consumer Groups tab and then click Modify. Move the LOW_GROUP, SYS_GROUP, and APPUSER consumer groups to the Selected Consumer Groups list and click OK. When returned to the Edit User page, click Apply.

7. Activate the SYSTEM_PLAN resource plan. a. b. From the Administration page, click Resource Plans in the Resource Manager section. Select the SYSTEM_PLAN, set the action type to Activate and click Go. Click Yes when asked for confirmation.

8. Run the script lab_15_08.sql to unlock all the accounts and set the passwords to match the username.
SQL> @$HOME/labs/lab_15_08

9. Test the consumer group mappings by opening two SQL*Plus sessions. Connect as the HR user in the first session, and connect as the SYSTEM user in the second session. In the second session, as the SYSTEM user, query the V$SESSION data dictionary view to determine which resource consumer group was assigned to the other session. Filter out those sessions with a SCHEMANAME beginning with SYS%.
% sqlplus hr/hr % sqlplus system/oracle

SQL> SELECT schemaname, resource_consumer_group 2> FROM V$SESSION 3> WHERE schemaname not like 'SYS%';

SCHEMANAME RESOURCE_CONSUMER_GROUP ------------------------------ -------------------------------HR APPUSER DBSNMP

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-78

Solution for Practice 15: Using the Resource Manager (continued) 10. Repeat the test in Step 9 for the SCOTT and PM users. Write down your results in the following table: Database User HR SCOTT PM Resource Consumer Group APPUSER LOW_GROUP SYS_GROUP

SQL> CONNECT scott/scott SQL> CONNECT system/oracle SQL> SELECT schemaname, resource_consumer_group 2> FROM V$SESSION 3> WHERE schemaname not like 'SYS%';

SCHEMANAME RESOURCE_CONSUMER_GROUP ------------------------------ -------------------------------SCOTT LOW_GROUP DBSNMP SQL> CONNECT pm/pm SQL> CONNECT system/oracle

SQL> SELECT schemaname, resource_consumer_group 2> FROM V$SESSION 3> WHERE schemaname not like 'SYS%'; SCHEMANAME RESOURCE_CONSUMER_GROUP ------------------------------ -------------------------------PM SYS_GROUP DBSNMP

11. Deactivate the SYSTEM_PLAN resource plan. a.

b.

r O

From the Administration page, click Resource Plans in the Resource Manager section. Select the SYSTEM_PLAN, set the action type to Deactivate and click Go. Click Yes when asked for confirmation.
Oracle Database 10g: Administration Workshop II A-79

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Solution for Practice 16: Automating Tasks with the Scheduler Exercise 1: Monitoring the Scheduler
In this practice, you will use the Database Control Console to monitor and configure an administrator for the Scheduler.

1. Login to EM Database Control as the SYSTEM user. 2. Grant the following privileges to the to the HR user. – SCHEDULER_ADMIN role – CREATE JOB system privilege – SELECT ANY DICTIONARY – MGMT_USER role a. b. c. d. e. From the Database home page, click the Administration tab. On the Administration page, click on the Users link, under the heading of Security. On the Users page, click on the HR user name to edit the account. On the Edit User page, click on the Roles tab. Then click on the Modify button on the right-hand side of the page. On the Modify Roles page, click on the SCHEDULER_ADMIN role, and then press the > 'Move' button to grant this role to the HR user. Repeat for the MGMT_USER role. Then click on the OK button. When returned to the Edit User page, click on the System Privileges tab, and then click on the Modify button.

f. g.

In the Available System Privileges list, click on the SELECT ANY DICTIONARY privilege and click on the > 'Move' button to grant this privilege to the HR user. Repeat for the CREATE JOB system privilege. Click OK. On the Edit User page, click on Apply.

h.

3. Because you are going to use the HR user to administer jobs through Database Control, you need to make sure that HR is registered as a possible Administrator. a. On the Administration page, click Administrator s in the upper right hand corner. On the Administrator page, click the Create button. b. On the Create Administrators: Properties page, enter HR in the Name, Password, and Confirm Password fields. Do not enter a value for the email address.

r O

c. Click the Finish button. d. On the Create Administrator: Review page, click the Finish button. e. Back to the Administrators page, click the Database tab.

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-80

Solution for Practice 16: Automating Tasks with the Scheduler (continued) Exercise 1: Monitoring the Scheduler (continued) 4. Login to the Database Control Console as the HR user. . If this is your first time running EM as this user, you will need to click I agree on the License Agreement screen. a. b. c. In the upper right corner of the current page, click the Logout link. Click the Login button to log back in. For the username and password enter HR. Then click Login.

5. Click the Administration tab. 6. Click on the Jobs link in the Scheduler section, at the bottom right corner of the page. 7. Are there any existing jobs? No. 8. Are there any existing programs? (Hint: use the browser Back button) a. Go back to the Administration main page, and click the Programs link under the heading Scheduler. There are no existing programs.

9. Are there any existing schedules? a. b. Go back to the Administration main page Click the Schedules link under the heading Scheduler. There is one schedule, called DAILY_PURGE_SCHEDULE.

10. Are there any existing windows? What resource plan is associated with each window? a. b. Go back to the Administration main page

Click the Windows link under the heading Scheduler. There are two windows, named WEEKNIGHT_WINDOW and WEEKEND_WINDOW. The windows do not have any resource plan associated with them.

11. Are there any existing job classes? If so, what resource consumer group is associated with each job class? a. b. Go back to the Administration main page – – Click the Job Classes link under the heading Scheduler. There are two job classes: DEFAULT_JOB_CLASS: no resource consumer group AUTO_TASKS_JOB_CLASS: AUTO_TASK_CONSUMER_GROUP resource consumer group

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-81

Solution for Practice 16: Automating Tasks with the Scheduler (continued) Exercise 2: Creating Scheduler Components
In this exercise, you will create Scheduler objects and use them to automate administrative tasks.

1. Log in to the Database Control Console as the HR user. Click the Administration tab. Under the heading Scheduler, click Jobs. Click the Create button to open the Create Job window. Create a simple job that runs a SQL script: • General: Name: CREATE_LOG_TABLE_JOB Owner: HR Description: Create the SESSION_HISTORY table for the next part of this practice Logging level: RUNS Command type: In-line Program: Executable Executable: /home/oracle/labs/lab_16_02_01.sh • Schedule: Repeating: Do not Repeat Start: Immediately • Options: No special options. a. On the Create Job page, enter CREATE_LOG_TABLE_JOB in the Name field. Make sure that HR is specified in the Owner field. Enter "Create the SESSION_HISTORY table for the next part of this practice" in the Description field. Verify the following: – Enabled is set to Yes – Logging Level is set to Log job runs only (RUNS) – Job Class is set to DEFAULT_JOB_CLASS – Auto Drop is set to FALSE – Restartable is set to FALSE In the Command section, click the Change Command Type button. On the Select Command Option, select In-line Program: Executable and click OK. Back to the Create Job page, enter /home/oracle/labs/lab_16_02_01.sh in the Executable Name field. Click the Schedule tab. On the Schedule page, make sure the Immediately radio button is selected, and the Repeat field is set to Do Not Repeat.

b. c. d. e. f.

2. Click on OK to create the job.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-82

Solution for Practice 16: Automating Tasks with the Scheduler (continued) Exercise 2: Creating Scheduler Components (continued) 3. Click on the Run History tab and verify the job ran successfully. If the job failed, click on the job name, and then scroll down to the Operation Detail section. Click on any of the Log Id entries to find out why the job failed. To start over and recreate the job, you must first delete the job. If it does not show up under Scheduled Jobs, click on the Disabled tab and delete the job from there. 4. Create a program called LOG_SESS_COUNT_PRGM that logs the current number of database sessions into a table. Type in the following code or cut and paste the code into EM from the file lab_16_02_04.sql:
DECLARE sess_count NUMBER; BEGIN SELECT COUNT(*) INTO sess_count FROM V$SESSION; INSERT INTO session_history VALUES (systimestamp, sess_count); COMMIT; END;

There should not be a trailing '/' character for this code. Including it will cause the program to fail during execution. a. b. c. d. e. f. g. From the Administration page, click on the Programs link under the heading Scheduler. Click on Create. Set Enabled to Yes Leave the type set to PL/SQL Block. Click OK. Enter LOG_SESS_COUNT_PRGM for the name of the Program.

Enter the above PL/SQL text into the Source field.

5. Create a schedule named SESS_UPDATE_SCHED owned by HR that executes every 3 seconds. Because the Database Control Console only supports scheduled intervals of one minute or larger, you will use SQL*Plus and the DBMS_SCHEDULER. CREATE_SCHEDULE procedure to create the program. a. Start SQL*Plus and log in as the HR user.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-83

Solution for Practice 16: Automating Tasks with the Scheduler (continued) Exercise 2: Creating Scheduler Components (continued) b. Execute the following code:
BEGIN DBMS_SCHEDULER.CREATE_SCHEDULE ( schedule_name => 'SESS_UPDATE_SCHED', start_date => SYSTIMESTAMP, repeat_interval => 'FREQ=SECONDLY;INTERVAL=3', comments => 'Every three seconds'); END; /

6. Return to the Database Control Console, and verify the schedule was created. Hint: You may have to refresh the page for the schedule to appear. a. Go back to the Administration main page, and click on the Schedules link under the heading Scheduler.

7. Using the Database Control Console, create a job named LOG_SESSIONS_JOB that uses the program LOG_SESS_COUNT_PRGM and the schedule SESS_UPDATE_SCHED. Make sure the job uses FULL logging. a. b. c. d. e. Click Jobs under the heading Scheduler. Click the Create button to open the Create Job window. Enter LOG_SESSIONS_JOB for the name. Change the logging level to FULL.

Click the Change Command Type button. In the Select Command Option window, choose Program Name, and enter HR.LOG_SESS_COUNT_PRGM in the space next to it, or use the lookup button to select the program. Click OK. When resturned to the Create Job window, click the Schedule tab. Change the Schedule Type to 'Use Pre-Defined Schedule'. Select the HR.SESS_UPDATE_SCHED schedule. Click OK to create the job.

f.

g.

8. Check the HR.SESSION_HISTORY table for rows. If there are rows in the table, are the timestamps 3 seconds apart?
SELECT * FROM hr.session_history ORDER BY snap_time; Yes there are rows, and yes the timestamps are 3 seconds apart.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-84

Solution for Practice 16: Automating Tasks with the Scheduler (continued) Exercise 2: Creating Scheduler Components (continued) 9. Use the Database Control Console to alter the SESS_UPDATE_SCHED schedule from every three seconds to every three minutes a. b. c. d. e. f. From the Administration page, click Schedules. Click the SESS_UPDATE_SCHED link. Change the description to 'Every 3 minutes'. Change Repeating from Do Not Repeat to By Minutes. Set the Interval to 3. Click Apply.

10. Using SQL*Plus, query the HR.SESSION_HISTORY table to verify the rows are being added every three minutes now, instead of every three seconds.
CONNECT hr/hr SELECT * FROM SESSION_HISTORY ORDER BY snap_time;

11. Alter the table HR. SESSION_HISTORY to contain a new column, BACKGROUND_COUNT of type NUMBER. Using EM: a. b. c. d. e. f.

From the Administration page, click on Tables under the heading Schema. Enter HR for the Schema and SESSION_HISTORY for the table name, then click Go. Click the table name in the Results list. Click the Add 5 Table Columns button.

In the first empty row (after NUM_SESSIONS) enter BACKGROUND_COUNT for the column name and NUMBER for the data type. Click Apply to alter the table.

Using SQL*PLus:

CONNECT hr/hr ALTER TABLE session_history ADD (BACKGROUND_COUNT NUMBER);

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-85

Solution for Practice 16: Automating Tasks with the Scheduler (continued) Exercise 2: Creating Scheduler Components (continued) 12. Alter the program LOG_SESS_COUNT_PRGM to log new information into the logging table. Modify the code to look like the following text or copy the code from the script lab_16_02_12.sql:
DECLARE sess_count NUMBER; back_count NUMBER; BEGIN SELECT COUNT(*) INTO sess_count FROM V$SESSION; SELECT COUNT(*) INTO back_count FROM V$SESSION WHERE type = ''BACKGROUND''; INSERT INTO session_history VALUES (systimestamp, sess_count, back_count); COMMIT; END;

a. b. c. d.

From the Administration page, click Programs under the heading Scheduler. Click the LOG_SESS_COUNT_PRGM link. Change the Source code to match the above text. Click Apply.

13. Run the job LOG_SESSIONS_JOB immediately, and verify the new information was added to the HR.SESSIONS_HISTORY table. a. b. c. d. From the Administration page, click Jobs under the heading Scheduler. Click the Run History tab to verify the job ran successfully. With the job LOG_SESSIONS_JOB selected, click the Run Now button. Using either SQL*Plus or iSQL*Plus, query the HR.SESSION_HISTORY table to verify the newest rows contain the background session count.

CONNECT hr/hr ALTER TABLE session_history (BACKGROUND_COUNT NUMBER);

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-86

Solution for Practice 16: Automating Tasks with the Scheduler (continued) Exercise 2: Creating Scheduler Components (continued) 14. Drop the job LOG_SESSIONS_JOB, the program LOG_SESS_COUNT_PRGM, and the schedule SESS_UPDATE_SCHED. DO NOT DELETE THE WRONG SCHEDULER COMPONENTS!!!! a. b. c. d. e. f. g. From the Administration page, click Jobs under the heading Scheduler. With the job LOG_SESSIONS_JOB selected, click on the Delete button. Select 'Drop the job and stop any running instance' and then click Yes. Click the database breadcrumb at the left top corner of the page to return to the Administration page. Then click Programs under the heading Scheduler. With the program LOG_SESS_COUNT_PRGM selected, click the Delete button. Click Yes to confirm. Click the database breadcrumb at the left top corner of the page to return to the Administration page. Then click Schedules under the heading Scheduler. With the schedule SESS_UPDATE_SCHED selected, click the Delete button. Select "If there are dependent objects, it will not be dropped. " and click Yes to confirm.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-87

Solution for Practice 17: Using Dynamic SQL Exercise 1: Write a Dynamic SQL Procedure 1. Create a table in the HR schema named EMP2 that is a copy of the HR.EMPLOYEES table. Hint: Use the CREATE TABLE … AS SELECT… command.
SQL> CONNECT hr/hr SQL> CREATE TABLE emp2 AS SELECT * FROM employees;

2. Create a procedure called FIRE_EMP that deletes a row in the EMP2 table. The procedure should: – – –
SQL> 2> 3> 4> 4> 5>

Accept the employee ID of the employee being removed from the table. Use the EXECUTE IMMEDIATE statement to perform the query. Make sure the change is committed.
CREATE OR REPLACE PROCEDURE fire_emp (id NUMBER)AS BEGIN EXECUTE IMMEDIATE 'DELETE FROM emp2 WHERE employee_id = ' || id; COMMIT; END; /

3. Test the FIRE_EMP procedure for various rows in the EMP2 table.

4. Verify the rows have been deleted from the EMP2 table by comparing the data in EMP2 with the data in the original table EMPLOYEES. Use the following query:
SQL> SELECT employee_id FROM employees 2> MINUS 3> SELECT employee_id FROM emp2; EMPLOYEE_ID ----------137 140 154

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-88

Solution for Practice 17: Using Dynamic SQL (continued) Exercise 2: Use SQL to Dynamically Generate a SQL Script Generate a script using a SQL query that disables all the indexes in the HR schema.
SQL> CONNECT system/oracle SQL> SQL> SQL> SQL> SQL> set echo off set heading off set feed off set pages 1000 SPOOL disable_HR_indexes.sql

SQL> SELECT 'ALTER INDEX ' || index_name || 'DISABLE;' 2> FROM DBA_INDEXES 3> WHERE owner = 'HR'; SQL> spool off

Then, edit the resulting file to remove any unneccessary text. Exercise 3: Retrieve the Value of User Context Variables for the Current Session Write a query that retrieves the database name, the instance name, the host name, and the current user for your session.
SQL> SQL> SQL> SQL> CONNECT system/oracle SET echo on SET heading ON SET feedback ON

SQL> SELECT SYS_CONTEXT('USERENV', 'SESSION_USER') username, SQL> SYS_CONTEXT('USERENV', 'INSTANCE_NAME') Instance, SQL> SYS_CONTEXT('USERENV', 'DB_NAME') "DB Name", SQL> SYS_CONTEXT('USERENV', 'HOST') hostname SQL> FROM dual; USERNAME ----------------------------------------------------------------------INSTANCE ----------------------------------------------------------------------DB Name ----------------------------------------------------------------------HOSTNAME ----------------------------------------------------------------------SYSTEM orcl orcl EDRSR12P1

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

1 row selected. Oracle Database 10g: Administration Workshop II A-89

Solution for Practice 18: Workshop Setup 1. Run the script lab_18_01.sql in your labs directory to reset the database to its initial state. This script will also remove all trace files previously generated by the database. It will take several minutes for this script to finish.
SQL> @lab_18_01.sql

2. Start the database, if needed.
SQL> CONNECT / as sysdba SQL> STARTUP

3. Verify the database is in ARCHIVELOG mode. It is not. Correct this problem with the following commands, or use Enterprise Manager.
SQL> CONNECT / AS SYSDBA SQL> ARCHIVE LOG LIST Database log mode Automatic archival Archive destination Oldest online log sequence Current log sequence SQL> SHUTDOWN IMMEDIATE ORACLE instance shut down. SQL> STARTUP MOUNT Database mounted. SQL> ALTER DATABASE ARCHIVELOG; Database altered. SQL> ALTER DATABASE OPEN; Database altered. SQL> ARCHIVE LOG LIST; Database log mode Automatic archival Archive destination Oldest online log sequence Next log sequence to archive Current log sequence

No Archive Mode Disabled USE_DB_RECOVERY_FILE_DEST 54 56

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Archive Mode Enabled USE_DB_RECOVERY_FILE_DEST 55 57 57

Oracle Database 10g: Administration Workshop II A-90

Solution for Practice 18: Workshop Setup (continued) 4. Use Enterprise Manager or connect to the database as SYSDBA. Use the data dictionary views and SQL*Plus commands to complete the Database Configuration Checklist on the next two pages. Tablespace and Data file Information
SQL> CONNECT / AS SYSDBA SQL> SELECT tablespace_name, file_name FROM DBA_DATA_FILES; SQL> SELECT tablespace_name, file_name FROM DBA_TEMP_FILES;

Tablespace Name USERS SYSAUX UNDOTBS1 SYSTEM EXAMPLE TEMP

Data file Name (full path) /u01/app/oracle/oradata/orcl/users01.dbf /u01/app/oracle/oradata/orcl/sysaux01.dbf /u01/app/oracle/oradata/orcl/undotbs01.dbf /u01/app/oracle/oradata/orcl/system01.dbf /u01/app/oracle/oradata/orcl/example01.dbf /u01/app/oracle/oradata/orcl/temp01.dbf

Online Redo Log File Information Online logs should be mirrored.

SQL> SELECT l.group#, member, bytes, lf.status 2> FROM v$logfile lf, v$log l 3> WHERE l.group# = lf.group#;

SQL> ALTER DATABASE ADD LOGFILE 2> MEMBER '/u01/app/oracle/oradata/orcl/redo01b.log' 3> TO GROUP 1; SQL> ALTER DATABASE ADD LOGFILE 2> MEMBER '/u01/app/oracle/oradata/orcl/redo02b.log' 3> TO GROUP 2; SQL> ALTER DATABASE ADD LOGFILE 2> MEMBER '/u01/app/oracle/oradata/orcl/redo03b.log' 3> TO GROUP 3;

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-91

Solution for Practice 18: Workshop Setup (continued) Group # 3 2 1 1 2 3 Redo Log File Name (full path) /u01/app/oracle/oradata/orcl/redo03.log /u01/app/oracle/oradata/orcl/redo02.log /u01/app/oracle/oradata/orcl/redo01.log Size 10M 10M 10M Status

/u01/app/oracle/oradata/orcl/redo01b.log 10M /u01/app/oracle/oradata/orcl/redo02b.log 10M /u01/app/oracle/oradata/orcl/redo03b.log 10M

Control File Information
SQL> SELECT name, status FROM V$CONTROLFILE;

Control files should be mirrored. Control File Name (full path) /u01/app/oracle/oradata/orcl/control01.ctl /u01/app/oracle/oradata/orcl/control02.ctl /u01/app/oracle/oradata/orcl/control03.ctl

r O

cl a

In e

rn te

l& a

O

I A

s U

Status

O e

ly n

Oracle Database 10g: Administration Workshop II A-92

Solution for Practice 18: Workshop Setup (continued) Operational Thresholds a. b. c. From the Database Home page, in the Related Links region at the bottom of the page, click the Manage Metrics link. On the Manage Metrics page you can view the current setting for all thresholds. The default setting for Archive Area Used(%) is Warning at 80%, no critical threshold. The business requirements specify a warning should be issued at 75% full and a critical alert when it is 90% full. To modify these settings, click Edit Thresholds. Select Archive Area Used(%), change the Warning Threshold to 75 and the Critical Threshold to 90. Then click OK. Edit other thresholds as needed, to meet the criteria specified below.

d.

Metric Archive Area Used (%) Broken Job Count CPU Usage (per transaction) Data Block Corruption Alert Log Error Failed Job Count SQL Response Time (%) Scans on Long Tables (per transaction) Sorts in Memory (%)

Warning Threshold > 75 >0 > 60

Critical Threshold >90

>75

CONTAINS ORA>0 > 200 >2 < 80

r O

cl a

In e

rn te

l& a

O

I A

>5

s U

O e

ly n

< 50

Oracle Database 10g: Administration Workshop II A-93

Solution for Practice 18: Workshop Setup (continued) Initialization Parameters
show show show show show show parameter parameter parameter parameter parameter parameter dump size log_archive db format sga

Parameter Name BACKGROUND_DUMP_DEST CORE_DUMP_DEST DB_BLOCK_CHECKING DB_BLOCK_SIZE DB_CACHE_SIZE DB_FILES DB_NAME DB_RECOVERY_FILE_DEST

Value /u01/app/oracle/admin/orcl/bdump /u01/app/oracle/admin/orcl/c dump FALSE 8192 (8K) 24M 200 orcl

/u01/app/oracle/flash_recovery_area

DB_RECOVERY_FILE_DEST_SIZE 2G LOG_ARCHIVE_DEST_n LOG_ARCHIVE_DEST_n_STATE LOG_ARCHIVE_FORMAT SGA_MAX_SIZE

r O

SGA_TARGET

cl a

In e

rn te

l& a
180M 0

O

I A

s U

O e

ly n

ENABLE %t_%s_%r.dbf

USER_DUMP_DEST

/u01/app/oracle/admin/orcl/udump

Oracle Database 10g: Administration Workshop II A-94

Solution for Practice 18: Workshop Setup (continued) RMAN Backup Information
$ rman target / RMAN> list backup of database; using target database controlfile instead of recovery catalog RMAN> list copy of database; RMAN> show all; RMAN configuration parameters are: CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default CONFIGURE BACKUP OPTIMIZATION OFF; # default CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE MAXSETSIZE TO UNLIMITED; # default CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/10.1.0/db_1/dbs/snapcf_orcl.f'; # default

To check the backup schedule, use Enterprise Manager. From the Maintenance page, click Jobs in the Related Links region. There should be a scheduled backup job that executes every morning at 2 a.m.. If one does not exist, use Enterprise Manager to configure scheduled backups, using the recommended settings. Full or Complete database backups

Control files and spfile automatically backed up? Retention policy for backups

To configure RMAN to automatically backup up the control file and SPFILE:
RMAN> configure controlfile autobackup on; Oracle Database 10g: Administration Workshop II A-95

ra O

Backup schedule

cl

In e

rn te

l& a

No backups exist for this database. A full backup should be taken immediately following this lab. No, autobackup set to FALSE. Needs to be altered. Redundancy of 1 Every morning at 2 a.m.

O

I A

s U

O e

ly n

Solution for Practice 18: Workshop Setup (continued) 5. Verify Flashback Database has been enabled.
SQL> SELECT flashback_on FROM v$database;
FLA --NO

SQL> shutdown immediate ORACLE instance shut down. SQL> startup mount ORACLE instance started. SQL> ALTER DATABASE FLASHBACK ON; Database altered. SQL> ALTER DATABASE OPEN; Database altered. SQL> SELECT flashback_on FROM v$database;
FLA --YES

6. Create a user-defined metric as follows:

a. From the Database Home page, in the Related Links region, click the User-Defined Metrics link. b. Click create on the User-Defined Metrics page. c. Specify the following:

Metric name: INVALID REDO LOG FILE COUNT Metric Type: Number SQL Query: SELECT count(*) FROM v$logfile WHERE status = 'INVALID' Database credentials: System / oracle Thresholds: Comparison operator > Critical 1 Schedule: Immediately after creation and then Repeat every 5 Minutes.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-96

Solution for Practice 18: Workshop Setup (continued)

d.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Click OK.
Oracle Database 10g: Administration Workshop II A-97

Solution for Practice 18: Workshop Setup (continued) 7. Execute the $HOME/labs/lab_18_07.sql script.
SQL> @/home/oracle/labs/lab_18_07

8. Use RMAN to make a whole database backup. Instruct RMAN to delete the archived log files after they have been backed up.
$ rman target / RMAN> backup database; RMAN> backup archivelog all delete all input;

9. Verify that a new backup exists and that regular backups are scheduled.
RMAN> list backup of database; RMAN> exit

In Enterprise Manager, from the Maintenance Page, in the Related Links region, click Jobs. If there is not a job listed in the Results region with a name containing the string "BACKUP", then you need to schedule regular backups. From the Maintenance page, click Schedule Backup. Use the Oracle-suggested backup strategy, specify the host credentials (oracle/oracle), and click Next. Review the information on the next page, then click Next. Specify the backup time of the your in Step 2, then click Next. For Step 3, review the RMAN script, then click Submit Job. 10. Ensure that your instance is started and your database is open, then begin the workshop scenarios.
SQL> CONNECT / AS SYSDBA SQL> SELECT status FROM v$instance;
STATUS -----------OPEN

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-98

Solution for Workshop Scenario 1
Observations: After running the wlab_01_01.sh script, connect as SYSDBA through Database Control and navigate to the Performance tab of the Database Control home page. On the Performance page, make sure that the View Data field is set to Real Time: 15 second Refresh.You should see the workload activity going up very quickly. Because the CPU used by the workload is very close to the maximum CPU available on your system, there must be an issue with this workload. Because the most important area corresponding to a wait class is the User I/O wait class, the issue must be associated to that class.

Methodology: First of all, you must determine the problem itself. The fastest way to determine it is by looking at an ADDM report analysis executed during the problematic period. Then, by following its analysis, ADDM should guide you through the process of fixing the problem.

Go to the Advisor Central page and search for the correct ADDM task. This is how you can retrieve the task from the Advisor Central page: From the Database Control home page, click the Advisor Central link. On the Advisor Central page, select ADDM in the Advisory Type drop-down list, and select Last 24 Hours in the Advisor Runs drop-down list. When done, click the Go button. Then, select the ADDM task corresponding to the time of the problematic period. When done, click the View Result button.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-99

Solution for Workshop Scenario 1 (continued) This brings you to the Automatic Database Diagnostic Monitor (ADDM) page where you can see the results of the Performance Analysis in question.

On the corresponding Automatic Database Diagnostic Monitor (ADDM) page, click the finding with the highest impact on the database time. In this case we see that the Host CPU … entry has an impact of 100%. Drilling down you find that it consists of two reccommendations; add a second CPU and tune a SQL statement. Since you cannot add a second CPU, click the Show SQL Tuning check box and click on the Run SQL Tuning Advisor button. When the Schedule Advisor screen appears, click on the OK button.

This starts the execution of a SQL Tuning Advisor task. When the SQL Tuning Window appears, click the View Recommendations button.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-100

Solution for Workshop Scenario 1 (continued) After the task has executed, you are given the details of the corresponding recommendations. The estimated benefit of the suggested solution is 99.97%. Click the Implement button to accept.

From the Database Control home page, click the Performance tab. On the Performance page, you should see a dramatic drop for CPU Used, and all the wait class categories on the Sessions: Waiting and Working graph.

To stop the workload, execute the following command: wlab_01_stop.sh from your terminal emulator window. Next, run the wlab_01_cleanup.sh script to clean up your database and environment.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-101

Solution for Workshop Scenario 2
Observations: Look at the output from the wlab_02_02.sql script. ERROR at line 2:ORA-12853: insufficient memory for PX buffers: current 3776K, max needed208896K ORA-04031: unable to allocate 131084 bytes of shared memory ("largepool","unknown object","large pool","PX msg pool")
What do you suppose the problem is? Because your large pool buffer is too small, and because

Automatic Shared Memory Tuning is not enabled, you get an ORA-04031 error.

Methodology: Using Database Control, it is possible to fix this problem. 1. On the Memory Parameters page, click the Enable button. 2. On the Enable Automatic Shared Memory Management page, make sure that the Total SGA Size for Automatic Shared Memory Management field is set to the same value as the Current Total SGA Size (MB) field. This should be 253 MB. 3. When done, click the OK button. Results: On the server side, the SGA_TARGET initialization parameter was dynamically changed to a non-zero value to enable the Automatic Shared Memory Management feature. The sizes of the automatically tuned buffers are still the same, but their corresponding values in the V$PARAMETER view are modified to their minimum value. This is done automatically by Database Control to allow those buffers to shrink. You can verify this by looking at the ALTER SYSTEM commands that were logged in the alert.log file. Connect as SYSDBA through SQL*Plus and execute the wlab_02_02.sql script again.
Click the Refresh button of the Memory Parameters page. You should see that the large pool buffer has dynamically allocated more memory to satisfy the parallel query execution. You should not get any error, and the script should complete.

Connect as SYSDBA through SQL*Plus and execute the wlab_02_cleanup.sql script to clean up your environment.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-102

Solution for Workshop Scenario 3 Observations: After executing the wlab_03_01.sql script wait a few minutes and go to the Database Control home page. Click on the Alert Log link under Diagnostic Summary.

If there are no recent entries listed, exit Enterprise Manager and examine the alert log file. Look at the ORA-20217 error.
Wed Mar 24 10:25:22 2004 Errors in file /u01/app/oracle/admin/orcl/bdump/orcl_j000_28368.trc: ORA-12012: error on auto execute of job 53315 ORA-20127: ORA-20127: Application Error Expecting 27 rows in DEPARTMENTS table, found 30 ORA-06512: at line 7

After checking with Human Resources, it is found that the DEPARTMENTS table has been updated incorrectly. The number of departments is supposed to be static (27 total) and the new data is not correct. You need to return the DEPARTMENTS table to its original state. Methodology: Using Flashback Table will yield the end result you need. From the Database Control home page, click on the Maintenance tab and click on the Perform Recovery link. From the Object Type pull down list select Tables and click on the Flashback Existing Tables button, then click on the Next button to continue.

r O

Do you know when the table was changed? Probably not. Remember that the ORA-20217 error indicated that there were 3 extra rows in the HR.DEPARTMENTS table. On the Point-intime page, click on the Evaluate row changes and transactions to decide on a point in time button and type in HR.DEPARTMENTS in the Table field. Click Next to continue.

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-103

Solution for Workshop Scenario 3 (continued) The next page requires a simple filter be defined to narrow the search. Create a generic filter by moving DEPARTMENT_ID to the Selected Columns window and specifying WHERE department_id > 0 as the WHERE clause. Click the Show all row history button and then click Next to proceed. On the Choose SCN page, you can see the three inserts. Select the insert with the lowest SCN (if they are different) and click Next to continue. Review the information presented on the next page before continuing. If everything looks correct, click Next to continue. On the Dependancy Options page, click the Cascade … button and then click Next to proceed. On the Perform Recovery: Review page, click the Submit button when you have verified the information. Results: When you have received confirmation of your flashback operation, check the row count in the table to ensure that the operation was indeed successful.
SQL> select count(*) from hr.departments; COUNT(*) ---------27

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-104

Solution for Workshop Scenario 4 Observations: After executing the wlab_04_01.sql wait a few minutes and go to the Database Control home page. Click on the Alert Log link under Diagnostic Summary.

There is a repeating ORA-00942 "Table or view does not exist" error. This bears investigating. How can you determine what table or view has been dropped? The quickest method is to query the DBA_RECYCLY_BIN view.
SQL> select owner, original_name, droptime FROM dba_recyclebin; OWNER -------------------------HR HR HR ORIGINAL_NAME --------------------DEPT_LOCATION_IX DEPT_ID_PK DEPARTMENTS

Try to access the table through SQL*Plus to confirm that the table has been dropped.
SQL> select * from hr.departments; select * from hr.departments * ERROR at line 1: ORA-00942: table or view does not exist

This is the same error that was observed in Enterprise Manager. So the DEPARTMENTS table has been dropped. You must take immediate steps to restore this table.

r O

Methodology: There are several methods that will work in this situation. Flashback Table is probably the most straightforward choice. You can use Flashback Table through Enterprise Manager or through SQL*Plus. The SQL*Plus approach is shown here because of its simplicity.
Oracle Database 10g: Administration Workshop II A-105

cl a

In e

rn te

l& a

O

I A

s U

DROPTIME -----------------2004-03-04:09:39:36 2004-03-04:09:39:36 2004-03-04:09:39:36

O e

ly n

SQL> flashback table hr.departments to before drop; Flashback complete.

Results: Perform a select against the DEPARTMENTS table to confirm the success of the Flashback Table operation.
SQL> select department_name from hr.departments; DEPARTMENT_NAME -----------------------------Administration Marketing Purchasing Human Resources Shipping IT ...

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-106

Solution for Workshop Scenario 5 Observations • • Database is not running. Attempting to start the database via SQL*Plus result in errors: – – • ORA-01157: cannot identify/lock data file 4 - see DBWR trace file ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'.

Attemtping to connect to the database via Enterprise Manager brings up an informational screen indicating "The database status is currently unavailable." You have the option of starting the database or performing recovery.

Methodology Recover the missing datafile. 1. Using Enterprise Manager, click the Perform Recovery button on the page displayed after you attempted to log in. a. Supply the host credentials of oracle/oracle and the database credentials of sys/oracle. b. Change the Object type to Datafiles, and select 'Recover to current time or a previous point-in-time' as the Operation type., then click Next.

c. Select the users01.dbf datafile by checking the box in front of the file name, then click Next. d. Indicate the files should be restored to the default location, then click Next. e. Click Submit to start the recovery. 2. Review the RMAN output, then click OK.

3. Use EM to start the database (or change the database state from MOUNTED to OPEN). Results • • • •

The database is now open and available for users. SQL*Plus and EM connections are now allowed. The USERS tablespace is online

r O

There are no alerts listed in the Database Home page. The only way to prevent this problem from occurring is to determine why the data file went missing in the first place, and prevent the situation from occurring again.

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-107

Solution for Workshop Scenario 6 1. As a DBA user (such as SYSTEM), create the user JONES either through Enterprise Manager, or by using SQL*Plus.
SQL> CONNECT system/oracle SQL> CREATE USER jones IDENTIFIED by jones;

2. Grant the CONNECT and RESOURCE roles to the user JONES.
SQL> GRANT CONNECT, RESOURCE TO jones;

3.

Generate a script that will grant the table privileges to the JONES user.

SQL> CONNECT hr/hr SQL> set head off SQL> set feedback off SQL> spool grant_privs.sql SQL> SELECT 'CONNECT hr/hr' FROM dual; SQL> SELECT 'GRANT SELECT ON HR.' || table_name || ' TO jones;' 2> FROM user_tables; SQL> CONNECT oe/oe SQL> SELECT 'CONNECT oe/oe' FROM dual; 2> FROM user_tables; SQL> spool off SQL> EXIT

SQL> SELECT 'GRANT SELECT ON OE.' || table_name || ' TO jones;'

4. Use a text editor to remove the echoed commands from the generated script and then save the modified script. 5. Run the generated script within SQL*Plus.
$ sqlplus system/oracle SQL> @grant_privs.sql

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-108

Solution for Workshop Scenario 6 (continued) 6. Generate a script that will create the private synonyms for the JONES user.

SQL> CONNECT jones/jones SQL> set head off SQL> set feedback off SQL> spool create_syns.sql SQL> SELECT 'CONNECT jones/jones' FROM dual; SQL> SELECT 'CREATE SYNONYM ' || table_name || ' FOR ' || owner || '.' 2> || table_name || ';' 3> FROM all_tables 4> WHERE owner in ('HR', 'OE'); SQL> spool off SQL> @create_syns.sql

7. Use a text editor to remove the echoed commands from the generated script and then save the modified script. 8. Run the generated script within SQL*Plus.
$ sqlplus system/oracle SQL> @create_syns.sql

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-109

Solution for Workshop Scenario 7 Observations • • • A query of DBA_TEMP_FILES returns the ORA-01157 error, indicating a file cannot ibe idenfitied or locked by the database A DBWR trace file has been created indicating a problem with the temporary tablespace datafile. After minute or two, the Database Home page in Enterprise Manager will show Data Block Corruption Alert Log Error alerts, with the detail information indicating the database was unable to open the datafile TEMP01.DBF If you attempt to view the Tablespaces for the database using Enterprise Manager, the list is empty.

Methodology Create a new TEMP tablespace. 1. Start the instance if necessary. 2. Use Enterprise Manager or SQL*Plus to create a new temporary tablespace and change the default temporary tablespace to point to this new tablespace.
CREATE TEMPORARY TABLESPACE temp2 TEMPFILE '/u01/app/oracle/oradata/orcl/temp2a.dbf' SIZE 2G; ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp2;

4. Drop the tablespace that contains the missing tempfile including its contents and data files.
DROP TABLESPACE temp INCLUDING CONTENTS AND DATAFILES;

Results • • • • The alerts in EM have cleared.

Enterprise Manager displays the list of tablespaces correctly again. Querying DBA_TEMP_FILES does not return any errors. The only way to prevent this problem from occurring is to determine why the temporary file went missing in the first place, and prevent the situation from occurring again.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II A-110

______________

Appendix B: Basic Linux and vi Commands
______________

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

vi Commands
The Visual Interpreter/Editor (vi) is the most widely used text editor available for the UNIX environment. While almost everybody curses its unwieldy command syntax, it is still the only editor almost certain to be included with every version of the UNIX and Linux operating system. The following are a partial list of available vi commands. vi has two modes. Command line (where anything typed is taken as an editing command) and input mode (where everything typed will be treated as part of the file being edited. To enter the input mode, type a, A, i, I, o, O, c, C, s, S, r, or R. To return to the command line mode, use the <ESC> key. To access the vi editor from SQLPlus, enter the following command: SQL>define _editor=vi To edit a file from SQLPlus prompt, edit <filename> (press enter), from the Linux command prompt, vi <filename> (press enter) To MOVE the cursor:
h - move left j - move down k - move up e - end of current word l - move right

w - one word forward b - one word backward

W, B, or E - same as lower case but ignores punctuation 0 (zero) - Move to beginning of current line G - go to last line of file L - go to last line on screen $ - end of current line H - go to top line on the screen M - go to bottom line on the screen

/<string> - Search forward to the next occurrence of <string> ?<string> - Search backward to the next occurrence of <string> n - Repeat previous search <ctrl> f - Scroll forward one page

N - Repeat previous search in opposite direction

To UNDO previous changes:

u - Will undo the most recent change.

:e! - re-edit current file without saving any changes made since last change

To ENTER NEW text:

r O

a - Append text after the current cursor position. A - Append text to the end of a line (jumps to end of line and begin appending). c - Change object C - Change from current cursor position to end of the line

cl a

In e

rn te

l& a

<ctrl> b - Scroll backward one page

O

I A

s U

O e

ly n

U - Will undo the most recently deleted text.

i - Insert text before the current cursor position. I - Insert text at the beginning of a line.

Oracle Database 10g: Administration Workshop II B-2

o - Insert a blank line BELOW the current cursor position. O - Insert a blank line ABOVE the current cursor position. r - Replace character at current cursor position R - Replace all characters until <ESC> is pressed s - substitute text for character under cursor :s/A/B/opt substitutes string B for string A. %s/A/B/opt is global replace options include: g (change all occurences on current line) p (print changed lines) . <period> - repeat last change To leave the input mode, press <ESC> c (confirm prior to each change) S - Substitute entire line to the end n. <integer><period> repeat last change n times

To DELETE existing text:
x - Will delete the character directly under the current cursor location. dd - Will delete the entire line where the cursor is located. dnd (where n is some integer) will delete n lines from current cursor position dw - delete current word D - delete to end of current line

J - Delete return at end of current line. Join this line and the next <int> J - Join the next <int> lines

COPY, CUT, and PASTE: vi uses a single buffer where the last changed or deleted text is stored. This text may be manipulated with the following commands: Y - Yank a copy of the current line yw - Yank a copy of the current word p - Put buffer contents after cursor y <integer> - Yank a copy of next <int> lines yb - Yank a copy of the previous word

Also, see the s and S commands under the input section

To SAVE edited changes to an operating system file:
zz - Will terminate edit mode.

:wq - Write all changes and quit the edit mode

To QUIT without saving changes:
ZZ - Will terminate edit mode. :q! - Will terminate the file without saving changes.

ra O

le c

In

rn te

l& a

P - Put buffer contents before cursor

O

I A

s U

O e

ly n

:w filename - Will save changes to the filename specified.

Oracle Database 10g: Administration Workshop II B-3

Basic Linux Commands This appendix is meant to serve only as a quick reference while you are in class. For more details on these commands, consult the man pages, your Linux documentation, or other Linux command reference books. Files and Directories Command manual Linux Commands
man <command> man –k <string> man man

Description/Comments Find the manual entry for this <command>. Show all the manual entries that contain this <string>. Displays the manual page for
man.

Command information

info <command>

Print to standard out List users Change working directory Copy a file View a file View a file List directory

cat <file> cat /etc/password cd <directory>

Show the information system entry for this command. Using info info shows a tutorial of the info documentation system. Concatenate and print – print the named file to the terminal screen. Change working directory to specified directory cd with no parameters changes to $HOME. Copy a source file to a destination file. View a file a page at a time. This is a GNU version of more, or pg. View a file a page at a time. BSD version. Options –l long listing, -R recursive, -a show hidden files, -t sort by time, -r reverse sort, default directory is current working directory. Make a directory defaults into the current working directory, full path may be specified. Move changes the name of a file or moves it to a different directory.

cp <source_file> <destination_file> less <file> more <file> ls <directory>

Create a directory

ra O

Move or rename a file

cl

In e

mkdir <directory>

rn te

l& a

O

I A

s U

O e

ly n

mv <old_file> <new_file>

Oracle Database 10g: Administration Workshop II B-4

Process List

ps ps -ef

Print working directory Remove or erase a file

pwd rm <file>

Create an empty touch <file> file hostname Name of the machine The IP address host <machine_name> of the machine

Shows the processes report Shows all processes on the system with a full listing. Many option exist see the man page for details. Print to stdout the current working directory. Removing a file on Linux is permanent. Options –r recursive, and –f force (including subdirectories) are very dangerous. Often the rm command is aliased with rm –i The option –i asks ‘Are you sure?’ Create a file. Returns the name of the machine.

Queries the Domain Name Server, and returns the IP address of the machine name. rsh <host> <command> Remote shell Execute a <command> on <host>. Rsh is not secure, use ssh instead. Remote shell ssh <host> Secure shell, has features to replace rsh, rcp, ftp, and telnet. telnet <host> Remote shell Start a terminal session on <host>. Telnet is not secure use ssh instead. grep <option> <pattern> <file> Search a <file> or stream for a Search a file for a pattern regular expression defined by <pattern> and show the line that contains that pattern. A common option is –i for case insensitive. grep can accept input from a file or stdin through a pipe as in: Source a script . <script_file>

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

netstat –a| grep ESTABLISHED

In the bash shell this command ‘.’ forces the script to run in the shell. Normal behavior is for the script to run in a child shell.

Oracle Database 10g: Administration Workshop II B-5

An interpreter

awk

Sort a file

sort

Command line sed editor
vi <file>

Visual editor

Gnu editor

emacs <file>

WSIWIG editor gedit <file> WSIWIG
kate <file>

Terminal output stdout

Terminal input stdin (keyboard)

Alias

r O

Show shell variables

cl a

In e
set

alias <command> <alias>

rn te

l& a

O

I A

A macro language for reformatting or interpreting input. For each line of input, a variety of actions can be taken. May be referred to as nawk – for “new awk.” Sort a file takes input from stdin or a filename argument, many options to sort by a particular column, field, etc. See man page. Sed is a command line editor, with many possible commands and options that are very good for editing from a shell script. Terminal based editor available on every Unix system, Linux provides vim, an improved vi, that is a superset of vi. This is a GPL editor with extensive customizable features available on most UNIX and Linux distributions. A full-screen editor, requiring X. Available under Gnome. A full-screen editor, requires X. Available under KDE Standard out (stdout), is not a command but a concept, most Linux commands write to stdout by default unless redirected. Standard in (stdin), is not a command but a concept, most Linux commands read from stdin by default unless redirected. Make a substitution when a user types <command> substitute and execute <alias>, common alias is alias ‘rm’ ‘rm –i’. These aliases are set in the .bashrc file. Prints all of the variables that are currently defined in the shell.

s U

O e

ly n

Oracle Database 10g: Administration Workshop II B-6

Show environment variables

printenv or env

File Creation mask

umask –S u=rwx,g=rx,o=rx

Clock

xclock

X access control

xhost xhost +<Xclient>

Prints all the environment variables – an environment variable has been ‘exported’ so that it will be inherited by child processes. Set the default permissions for all files created by this shell or its children. The –S option uses the symbolic notation, the numeric notation is obsolete. An X client that shows a clock on the screen. Often used to test the X windows system. Show the current access control in place. Add a Xclient that is allowed to access the local DISPLAY, if no <Xclient> is given all are allowed.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II B-7

System Linux Commands Administration Root file system / Home Directory /home

Description / Comments The root directory for the system directory tree. Typically the directory in which all user home directories placed. For example: /home/oracle. A temporary storage area. Do notput anything here you want to keep. SA often have a cron job to remove everything periodically. A small partition to hold the kernel image(s) and boot loader instructions. The location of most system log files. Configuration files are located per the application. Any configuration file that you change after installation should be included in the backup. The /etc/passwd file holds user information and must be readable by others; even with encrypted passwords this can be a security hole. The /etc/shadow file holds the encrypted passwords and is only readable by root. The /etc/groups file defines the groups on a server and the users that are members of the group; primary group for a user is defined in the /etc/passwd file. The file that sets the X server settings for your video card, monitor, mouse, and keyboard. Usually set up with a vendor supplied tool, such as sax2.

Tmp directory

/tmp

Boot directory Log directory Sample configuration files

/boot

/var/log /etc/inittab

Password files /etc/passwd
/etc/shadow

Groups file

/etc/group

X configuration /etc/X11/XF86Config file

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II B-8

crontab -e Schedule a command to run at a regularly scheduled time /etc/anacrontab Schedule a script to run at a particular frequency at <options> TIME Schedule a command to run at a single specified time batch <options> <TIME> Schedule a command

Use this command to edit the crontab file, to create the specification for the cron daemon to use. Edit the file to specify a script to run at a particular frequency (see man anacrontab for details). Runs a job specified by <options> at a specified TIME parameter.

Run a command when the load average drops below .8, optionally after a set TIME. mount <opt> <dev> <mount_point> Mount a file system on device Mount a file system <dev> at <mount_point> with the options specified by <dev>. umount <dev> Unmount a file Unmount the file system or device. umount <mount_point> system Maximum # of 65535 user ID Recover root {lilo} This is a procedure to recover the control-x password root password if is lost. This linux S requires physical access to the passwd root machine and system console. You start by rebooting the machine, then during the LILO boot press and hold [Ctrl] + [x] to get a {grub} prompt and command LILO to c kernel vmlinuz-2.4.9-13 single boot linux to runlevel S.
ro root=/dev/hda8 initrd /initrd-2.4.9-13.img boot passwd root

Create new user useradd

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

The second procedure uses the grub boot loader. The –D option alone shows the defaults. –D with other options changes the defaults options; without –D override, the default (e.g., –g) sets a primary group.

Oracle Database 10g: Administration Workshop II B-9

Delete user Modify user account Create new group Delete group

userdel usermod groupadd groupdel

Change run levels

init <runlevel>

Synchronize the sync disks Shutdown the Linux system
shutdown <mode> <delay>

Error logs

dmesg

Network IP configuration Hosts IP addresses

r O

Name service switch

cl a

In e

/etc/sysconfig/networkscripts/ /etc/hosts

rn te

l& a

O

I A

Remove a user and optionally all files belonging to the user. Change /etc/password information. –g sets the group id; default is first free value above 500. Remove a group from the system. May not remove a group that is a primary group for a user. Files owned by deleted group must be manually changed with chown. The init command causes the rcN.d scripts to be evaluated, for the change in run level. init 6 forces a reboot. Forces the buffer cache and page cache to write all dirty buffers to disk. Used just before a reboot to prevent disk corruption. Do a graceful shutdown of the system, shut down processes, run all shutdown scripts, and sync disks. The modes are –r, reboot and –h, halt. The delay is a required parameter is a number in seconds or ‘now’. Option shutdown warning message may be sent as well. View boot messages. This log is circular, and limited system errors could overwrite boot information after a time. This directory holds scripts executed as part of the boot up sequence by rc.sysinit. A list of hosts that your machine knows about. Must at minimum include the name of the local machine and loopback IP.

s U

O e

ly n

/etc/nsswitch.conf

Oracle Database 10g: Administration Workshop II B-10

Network parameters Routing daemon NIC Configurations Secondary IP Address Login prompt

sysctl -a | grep net routed ifconfig -a modprobe ip_alias ifconfig eth0:1 IP /etc/issue

View all net parameters that are set for the kernel.

Show all the network devices currently configured.

YP/NIS service /sbin/ypbind binder Module information List modules Load module Unload module Install Software Uninstall software List installed software Verify installed software List all files
modinfo <options> <module>

lsmod insmod rmmod rpm -ivh package rpm -e package rpm -qa rpm -V package rpm -ql package

Package owner rpm -qf file Machine model uname -m uname -r OS Level runlevel Run Level

r O

Kernel Parameters Max # File Descriptors

cl a

In e

rn te

l& a

O

I A

sysctl -a sysctl fs.file-max

Banner message user sees when issued the login prompt. Finds and attaches to a NIS server for name resolution and other services. Display information about kernel modules: –l shows license, –p parameters, –d description. Show currently loaded modules. Load a loadable module. Unload a loadable module. Install –i, verbose –v, with progress hash marks –h. Erase package –e; will not uninstall if dependencies exist. Query –q, All –a, lists all installed packages. Compares installed files with the rpm database information. List all the files that are part of a package. List the package when given the full file name. Shows CPU level (e.g., i686). Shows kernel version. Shows previous and current runlevel. Show settings of all settable kernel parameters. Shows the value of maximum number of file descriptor per process.

s U

O e

ly n

Oracle Database 10g: Administration Workshop II B-11

/etc/sysctl.conf Kernel parameter settings Change Kernel echo <value> > </proc/<file> Parameter echo 2147483648 >/proc/sys/kernel/shmmax

Shared Memory sysctl kernel.shmmax Change Kernel sysctl –w <parameter>=<value> Parameter Set Process limits
ulimit <option> <value>

Show process ulimit limits ipcs <option> Interprocess Communication (Shared Memory and Semaphores) ipcrm shm <shmid> Remove a shared memory segment

Compiled in kernel parameters; may be reset at bootup by setting them in this file. Write the new value of a kernel parameter into the /proc file system. Set the value of the maximum size of a shared memory segment. Show the shmmax parameter. Change a kernel parameter; the –p option reads the setting from a file and sets them. The default file is /etc/sysctl.conf Set limits on a shell and processes started by the shell. Users can make limits more restrictive; generally only root can make limit less restrictive; some options require root privilege. Options: –u sets number of processes, –n number of file handles; many others (see man bash). Without options ulimit show the current limit settings. Options: –m the current usage of shared memory; –s usage of semaphores; –a shows all.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Releases the shared memory segment identified by <shmid>. This is very dangerous. You can corrupt a database that is using the segment that is released.

Oracle Database 10g: Administration Workshop II B-12

System Performance Performance monitor System activity reporter

Linux Commands
top sar –<options> <interval> <count>

Description / Comments View real-time OS and process statistics. Options: –q shows CPU queue, –u CPU utilization, –d device activity, –n DEV network device activity, many more (see man page). Interval is in seconds. Interval is in seconds. Shows instantaneous virtual memory usage. Kernel slab allocator statistics: frequently allocated cache objects such as inode, dentries, and asynchronous IO buffers. Options: –d device activity, –c CPU activity, –x extended disk activity statistics. The interval is in seconds. Return CPU statistics for particular processor or all CPUs in an smp system. Maximum physical RAM requires enterprise kernel (Red Hat Enterprise Linux AS 21 only supports up to 16 GB). Shows devices currently in use for swap. The swap device is arbitrary designated at install. It may be changed or added to. Multiple swap devices may be created; swap size should be at least as large as physical memory.

Virtual Memory vmstat <interval> < count> statistics Virtual Memory cat /proc/meminfo statistics Kernel Cache cat /proc/slabinfo statistics
iostat <option> <interval> <count>

I/O statistics

Multiprocessor mpstat –P <cpu> <count> <interval> Statistics Physical RAM 64 GB(Theoretical)

Swap device

swapon -s

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II B-13

Display swap free size Activate Swap swapon -a Free disk blocks df -k Device listing Disk information

Show the current memory and swap usage. Turn on swap. Measured in KB; use –m for MB units. cat /proc/devices List devices known to the system by major and minor number. cat /proc/scsi/scsi0/sda/model View SCSI disk information.
cat /proc/ide/ide0/hda/model netstat <options>

Print network statistics xosview Graphical system statistics viewer

View IDE disk information. Print a wide variety of network statistics (see man netstat). An X-based display of recent OS statistics.

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II B-14

Misc System Information NFS exported NFS Client mounted directories Max File System Max File Size

Linux Commands
/etc/exports /var/lib/nfs/xtab

Description / Comments Database file are not supported on simple NFS.

2 TB with 4KB block size (on 32 With ext3 and ext2, others vary. kernel) 2 GB {512B block size}

File size can not exceed file system 2 TB

The oracle database can create files up to 64 GB with a 16 KB database block size. The 32-bit kernel limits file and block devices to 2 TB. Dump the file system properties to stdout. Mounts these file systems at boot up.

{4KB block size}

dumpe2fs <device> File System Block size Filesystem table /etc/fstab

Journal Filesystem types Disk Label Extend File system Backup Restore Prepare boot volumes Startup script Kernel Kernel Bits

ext3 reiserfs fdisk -l resize2fs resize_reiserfs tar cvf /dev/rst0 / tar xvf /dev/rst0 /sbin/lilo

fdisk is not available on all

ra O

cl

In e

/etc/rc.d/rc

rn te

l& a

O

I A

distributions. Extending a file system is applicable to only some file system types. Create a backup of the root / file system. Restore the root / file system. Must be run after changing /etc/lilo.conf to push changes to boot loader.

s U

O e

ly n

/boot/vmlinuz getconf WORD_BIT

POSIX call to get kernel information. There are many other variables besides WORD_BIT.

Oracle Database 10g: Administration Workshop II B-15

Boot single user {lilo}

control-x linux S {grub} c kernel vmlinuz-2.4.9-13 single ro root=/dev/hda8 initrd /initrd-2.4.9-13.img boot

Use LILO facility.

Use GRUB Boot Loader.

Time zone Management SW Directory Devices CPU Whole Disk CDROM CDROM file type Floppy drive System information

/etc/sysconfig/clock /var/lib/rpm /dev cat /proc/cpuinfo /dev/sda /dev/cdrom iso9660 /dev/fd0 /proc

Directory where rpm database are kept. This directory holds all the device files. Shows CPU static information. Device name. Usually mounted at /mnt/cdrom.

Compile and link a executable

make –f <file> <command>

r O

cl a

In e

rn te

l& a

O

I A

Usually mounted at /mnt/floppy. The /proc filesystem is a memorybased file system that allows access to process and kernel settings and statistics. Use a make file <file> to determine which parts of a large program need to be recompiled, and issue the commands required to compile, link, and prepare the executable for use.

s U

O e

ly n

Oracle Database 10g: Administration Workshop II B-16

LVM LVM

Linux (UnitedLinux)
Logical Volume Manager

LVM Concepts logical extents
logical volume

volume group

Description / Comments This package is not provided by Red Hat Enterprise Linux AS 2.1 and may not be added without tainting the kernel. Kernel support is provided in United Linux. A Logical volume is made up of logical extents. A set of logical extents taken from a volume group and presented to the OS as a disk volume. These extents may be striped across multiple disks. A set of physical disk partitions created by fdisk or the like, initialized with pvcreate, then grouped into a physical volume with vgcreate.

Display volume vgdisplay -v group Modify physical pvchange volume Prepare physical pvcreate disk pvdisplay List physical volume vgreduce Remove disk from volume group pvmove Move logical volumes to another physical volumes Create volume vgcreate group Remove volume vgremove group Volume group vgchange availability Restore volume vgcfgrestore group

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II B-17

Exports volume group Imports volume group Volume group listing Change logical volume characteristics List logical volume Make logical volume Extend logical volume Reduce logical volume Remove logical volume Create striped volumes

vgexport vgimport vgscan lvchange

lvdisplay lvcreate lvextend lvreduce lvremove lvcreate -i 3 -I 64

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Oracle Database 10g: Administration Workshop II B-18

_________________

Appendix C: Acronyms and Terms
_________________

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n

Term active session pool ADDM ASM ATO Automated Storage Management Automatic Database Diagnostic Management Automatic Tuning Optimizer Automatic Workload Repository auxiliary database AWR backup piece backup set block change tracking CFS change tracking file channel CLI control file data block

Definition Number of current active sessions allowed for a resource group or subplan Automatic Database Diagnostic Management Automated Storage Management Automatic Tuning Optimizer Provides a vertical integration of the file system and the volume manager specifically built for the Oracle database files A utility that does a top-down instance analysis, identifies problems and potential causes, and gives recommendations for fixing the problems A database feature that performs various analysis of SQL performance within the database Collects, processes, and maintains performance statistics for problem detection and self-tuning purposes. Used when creating a duplicate database or performing tablespace point-in-time recovery Automatic Workload Repository An individual file that is part of a backup set. Copy of one or more data or archived log files. Differs from image copies in that empty blocks are not stored. Uses the change tracking writer (CTWR) background process to record the physical location of all database changes in a separate file. Cluster File Storage File used to store the physical location of database changes made since the last backup. A link or connection to a target database. command-line interpreter Contains information about the physical structure of the database including the locations of all data and redo log files. The smallest unit of physical storage within the database. Data Blocks contain rows of data, index information, etc. Contains the data for the database A utility that assesses the feasibility of migrating an Oracle database to a new database character set. Database Administrator data block address, used to uniquely identify a data block within the database

Page 15-8 13-3 13-22 to 13-43 13-9 5-9,13-22 to 13-43 13-3 13-9 13-7 5-5

data file Database Character Set Scanner DBA DBA

r O

cl a

I e

er nt

na

l&

O

I A

s U

O e

ly n
13-7 6-8 6-8 6-23 5-9 6-23 5-6 8-5, 8-7 12-3

2-34 12-3

Oracle Database 10g: Administration Workshop II C-2

Term DBCA DBVERIFY DDL DML Dynamic SQL EM emctl encoded character set

Enterprise Manager Database Control Console external table Tables used to access data in external sources, such as flat files, as if it were in a table in the database flash recovery area A unified storage location for all recovery related files and activities in an Oracle database flashback buffer Flashback Database Flashback Drop Flashback Table Flashback Transaction Query Flashback Versions Query format mask elements growth trend report

Definition Database Configuration Assistant An external command-line utility that performs a physical data structure integrity check on an offline database Data Definition Language. The class of SQL statements that define and manipulate database objects. Data Manipulation Language. The class of SQL statements that query and manipulate data. SQL statements that can be created dynamically at run time by using variables Enterprise Manager Enterprise Manager Control. Utility for starting, stopping, and checking the status of Database Control, the Oracle Agent, and Oracle Management Servers. An encoded character set maps numeric codes to characters that a computer or terminal can display and receive. A graphical interface used to manage the database.

Page 2-7, 13-42 12-5 2-37

17-9

2-4

Globalization support

ra O

le c

In

An area in memory that stores Flashback Database data. A new recovery method that uses Undo data to recover the database instead of Redo data. A feature that allows you to undo the effects of a DROP TABLE statement without resorting to traditional point-in-time recovery A command that allows you to recover a table and all of its dependent objects from the recycle bin A diagnostic tool you can use to view changes made to the database at the transaction level Provides a history of changes made to a row along with the corresponding identifier of the transaction that made the change A character literal that describes the format of datetime or numeric data stored in a character string. Analysis of the growth of database segments

rn te

l& a

O

I A

s U

O e

ly n

17-14

5-9, 10-11, 10-16,to 10-18 10-8 10-6 to 108 11-4 11-9 11-22 11-24 2-24

Ensures that utilities and error messages, sort order, date, time, monetary, numeric, and calendar

13-16, 1318 2-3

Oracle Database 10g: Administration Workshop II C-3

Term image copy incarnation

init.ora or init<sid>.ora instance isqlplusctl jnnn Language and Character Set File Scanner LCSSCAN LEGATO® NetWorker, Single-Server Version linguistic sort listener locale locale variants LSSV media management library metric MML MMON

Definition conventions automatically adapt to the native language. A bit-for-bit identical copy of a database file. A separate version of a physical database. The incarnation of the database changes when you open it with the RESETLOGS option, but you can recover backups from a prior incarnation so long as the necessary redo is available. Same as parameter file The collection of shared memory and processes used to access the Oracle Database Control utility for starting and stopping iSQL*Plus listener processes Job Queue Processes. Execute scheduled jobs A statistic-based utility for determining the language and character set for unknown file text. Language and Character Set File Scanner Software included with Oracle Database 10g the enables the Recovery Manager utility to write to tape drives Produces a sort sequence that matches the alphabetic sequence of characters, not their numeric values in the character encoding scheme The gateway to the Oracle instance for all non-local user connections. A collection of information about the linguistic and cultural preferences from a particular region A language-dependent territory definition LEGATO® NetWorker, Single-Server Version Used by RMAN when writing to or reading from tapes

Page 6-8 9-8

2-45 16-5 2-34 2-34 5-8

National Language Support NLS NLS Runtime Library

ra O

cl

In e

A measurement of some database or instance characteristic. Media Management Library Management Monitor Process. Issues alerts whenever a metric violates its threshold value. Captures statistics for SQL objects which have been recently modified. Parameters and files that determine the locale-specific behavior of the database client and the database server National Language Support A comprehensive suite of language-independent functions that allow proper text and character processing and language convention manipulations

rn te

l& a

O

I A

s U

O e

ly n
2-25 3-3, 4-3 2-21 2-21 5-8 5-6 7-7, 13-30, 13-31 5-6 7-7 2-13 2-13 2-19

Oracle Database 10g: Administration Workshop II C-4

Term NLS_LANG NLSRTL Non-critical files OMF Oracle Locale Builder Oracle Managed Files Oracle Net ORACLE_BASE ORACLE_HOME ORACLE_SID package parallelization PGA PGA Advisor

Definition Environment variable used to specify the language, territory and characterset used by a database. National Language Support Runtime Library Files that the database and most applications can operate without Oracle Managed Files Provides a graphical user interface through which you can easily view, modify, and define locale-specific data. A feature of the Oracle database which manages the creation, naming and deletion of Oracle database files within dedicated areas of disk Enables network connections between the Oracle Database 10g and client or middle tier applications Environment variable used to point to the base of the OFA structure Environment variable used to identify a directory containing Oracle software Environment variable used to specify the default database instance name A collection of procedures and function definitions that are logically related. The procedures and functions are implemented by the package body. Allocating multiple channels for RMAN backup and recovery operations. Program Global Area. Private memory area for use by a process. Gives detailed statistics for the work areas, and provides recommendations about optimal usage of Program Global Area (PGA) memory based on workload characteristics. An area of memory used by one process to pass information to another. Procedural Language/Structured Query Language. Adds structured programming capability to SQL. The right to execute a particular type of SQL statement. There are two basic forms of privileges, object and system. A PL/SQL program that performs a specific action. Recoverer Process. Automatically resolves failures in distributed transactions (transactions distributed across multiple databases) A separate database that keeps historical data concerning backup activities

Page 2-18 2-19 8-3 5-9, 8-10, 13-43 2-33 5-9 4-3

5-14

pipe PL/SQL privilege procedure RECO

recovery catalog

ra O

le c

In

rn te

l& a

O

I A

s U

O e

ly n
5-4 13-3, 13-3, 1315 6-3 17-6 16-6 17-5 4-17 5-6

Oracle Database 10g: Administration Workshop II C-5

Term Recovery Manager Resource Manager resumable space allocation RMAN RMAN Repository Scheduler

Definition Page The Oracle utility used to back up and restore database 5-5 files. A means for suspending, and later resuming, the execution of large database operations in the event of space allocation failures Recovery Manager A storage structure that maintains metadata about a database's backup and recovery operations. A new database feature that enables database administrators and application developers to control when and where various tasks take place in the database environment System Change Number Monitors object space issues and analyzes growth trends The server processes (UNIX) or threads (Windows NT/2000) invoked by a client utility to connect to the target database System Global Area. Memory area shared by all server and background processes Gives recommendatations for SGA parameter settings System Identifier. Defaults to the database name and uniquely identifies the instance on a given server. Structured Query Language Determines optimal data access paths like indexes and materialized views Provides tuning advice for SQL statements A logical grouping of datafiles The database you are attempting to connect to. A boundary value against which metric values are compared. A feature of Enterprise Manager that suggests parameter values and the amount of additional space that is needed to support flashback for a specified time. A copy of original data stored whenever a DML transaction will change data. Undo data is used to rollback a transaction and to provide read consistent views of changing data. See AWR. 17-19 5-5 5-6 16-3

SCN Segment Advisor server sessions SGA SGA Advisor SID SQL SQL Access Advisor SQL Tuning Advisor tablespace target database threshold Undo Advisor

13-3, 1316, 13-17 5-5

undo data

workload repository

r O

cl a

In e

rn te

l& a

O

I A

s U

O e

ly n
13-15 13-3, 1312, 13, 14 13-3, 139,10,11 5-16 4-3 7-8 13-3, 1320, 13-21

Oracle Database 10g: Administration Workshop II C-6

Sign up to vote on this title
UsefulNot useful