Sei sulla pagina 1di 146

Oracle Database 10g:

Administration Workshop II
Volume 3 - Student Guide

n l y
e O
U s
A I
O
l &
D17092GC10
na
Edition 1.0

te r
March 2004
D39240 I n
c le
r a ®

O
Authors Copyright © 2004, Oracle. All rights reserved.

Janet Stern This documentation contains proprietary information of Oracle Corporation. It is


provided under a license agreement containing restrictions on use and disclosure and
James Womack 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
Technical Contributors applicable:
and Reviewers
Restricted Rights Legend
Christine Jeal
Use, duplication or disclosure by the Government is subject to restrictions for
Joel Goodman commercial computer software and shall be deemed to be Restricted Rights software
Dairy Chan 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).
Martin Jensen
Donna Keesling 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
Roman Niehoff is a violation of copyright law and may result in civil and/or criminal penalties.
Srinivas Putrevu If this documentation is delivered to a U.S. Government Agency not within the
Wolfgang Krueger 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).
Dr. Sabine Teuber
Gerlinde Frenzen 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,
John Watson Oracle Corporation, 500 Oracle Parkway, Redwood Shores, CA 94065. Oracle
Lothar Auert Corporation does not warrant that this document is error-free.
Andreas Reinhardt Oracle and all references to Oracle Products are trademarks or registered trademarks
of Oracle Corporation.
Editor All other products or company names are used for identification purposes only, and
may be trademarks of their respective owners.
Atanu Raychaudhuri

Publisher
n l y
Jobi Varghese

e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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

2 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
n l y
Other NLS Server Parameters 2-17
Specifying Language-Dependent Behavior for the Session 2-18
e O
Locale Variants 2-21
Using NLS Parameters in SQL Functions 2-22
U s
Linguistic Sorting 2-25
Using Linguistic Sorting 2-27
A I
O
Sorts That Are Not Case or Accent Sensitive 2-29
Linguistic Comparisons 2-30
Linguistic Index Support 2-31
l &
a
Customizing Linguistic Sorting 2-32

n
te r
Oracle Locale Builder 2-33
Character Set Scanner Utilities 2-34

I n
Data Conversion Between Client and Server Character Sets 2-36
NLS Data Conversion with Oracle Utilities 2-37

l e
NLS Data Conversion with Data Pump 2-39

c
Obtaining Character Set Information 2-40

r a
Obtaining NLS Parameter Information 2-41
Obtaining NLS Settings Information 2-42
O Summary 2-43
Practice 2 Overview: Using Globalization Support Features 2-44
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
4 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
n l y
Types of Database Links 4-7
Creating Database Links 4-8
e O
Dropping Links 4-10
Data Dictionary Views 4-11
U s
Remote Query 4-12
Executing a Remote Query 4-13
Distributed Query 4-14 A I
Executing a Distributed Query 4-15
O
In-Doubt Transactions 4-17
l &
Distributed and Remote Transactions 4-16

Summary 4-19

n a
5
r
Configuring Recovery Manager
Objectives 5-2
te
I n
Recovery Manager Features 5-3
Recovery Manager Components 5-5

l e
Media Management 5-7

c
Using a Flash Recovery Area with RMAN 5-9

r a
Setting Parameters for RMAN 5-10
RMAN Usage Considerations 5-12
O Connection Types with RMAN 5-13
Starting RMAN 5-14

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
n l y
Tags for Backups and Image Copies 6-15
BACKUP Options 6-16
e O
Backing Up Archived Redo Logs 6-18
Copying the Whole Database 6-19
U s
Making Incremental Backups 6-20
Incremental Backup: Example 6-22
A I
Block Change Tracking 6-23
O
l &
Enabling Block Change Tracking 6-24
Incrementally Updating Backups 6-25
LIST Command Operations 6-26

n a
te r
The REPORT Command 6-27
The REPORT NEED BACKUP Command 6-28

I n
REPORT NEED BACKUP: Examples 6-29
REPORT OBSOLETE and DELETE OBSOLETE 6-30

l e
Managing Backups with EM 6-31

c
RMAN Dynamic Views 6-32

r a
Monitoring RMAN Backups 6-34
Summary 6-36
O Practice 6 Overview: Using RMAN 6-37

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 n l y
8 Recovering from Non-Critical Losses
e O
Objectives 8-2
Recovery of Non-Critical Files 8-3
U s
Creating New Temporary Tablespace 8-4
Creating a New Control File 8-5
A I
Control File Autobackups 8-7
O
Recreating Redo Log Files 8-9

l &
Recovering an Index Tablespace 8-12
Recovery Steps 8-13
n a
te r
Server Managed Recovery: RESTORE and RECOVER Commands 8-14
User-Managed Recovery Procedures: RECOVER Command 8-15
Summary 8-16
I n
Practice 8 Overview: Recreating the Control File 8-17

c l e
r a
O
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
10 Flashback Database
Objectives 10-2
Flashback Any Error 10-3
Flashback Technology Benefits 10-4
When To Use Flashback Technology 10-5
n l y
Flashback Database Overview 10-6
Flashback Database Reduces Restore Time 10-7
e O
Flashback Database Architecture 10-8
Configuring Flashback Database 10-9
U s
Configure Flashback Database with EM 10-10
Monitoring Flashback Database 10-12
Monitoring Flashback Database with EM 10-14 A I
O
Monitoring Flash Recovery Area with EM 10-15

l &
Best Practices for the Database and Flash Recovery Area 10-16
Backing Up the Flash Recovery Area 10-17

a
Flash Recovery Area Space Usage 10-18

n
te r
Flashback Database Examples 10-19
Flashback Database with EM 10-20
Flashback Database Using EM 10-22

I n
Excluding Tablespaces from Flashback Database 10-23
Flashback Database Considerations 10-24

l e
Summary 10-25
c
Practice 10 Overview: Flashback Database 10-26

r a
O
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 n l y
Flashback Table Overview 11-27
Using EM to Flashback Tables 11-28
e O
Flashback Table Example 11-29
Rolling Back a Flashback Table Operation 11-30
U s
Flashback Table Considerations 11-31
Guaranteed Undo Retention 11-32
A I
SCN and Time Mapping Enhancements 11-33
Summary 11-34 O
&
Practice 11 Overview: Recovering from User Errors 11-35
l
Objectives 12-2
n a
12 Dealing With Database Corruption

te r
What Is Block Corruption? 12-3
Block Corruption Symptoms: ORA-1578 12-4

I n
DBVERIFY Utility 12-5
Interpreting DBVERIFY 12-6

l e
The ANALYZE Command 12-8

c
Initialization Parameter DB_BLOCK_CHECKING 12-9

r a
How to Handle Corruptions 12-10
The DBMS_REPAIR Package 12-12
O Using DBMS_REPAIR 12-13

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
n l y
Segment Resource Estimation 13-19
The Undo Management Page 13-20
e O
The Undo Advisor Page 13-21
What Is Automatic Storage Management? 13-22
U s
ASM Key Features and Benefits 13-23
ASM Concepts 13-24
ASM General Architecture 13-25 A I
ASM Instance Creation 13-27
O
Accessing an ASM Instance 13-29
l &
ASM Instance Initialization Parameters 13-28

ASM Home Page 13-30

n
ASM Performance Page 13-31 a
te r
ASM Configuration Page 13-32
Starting Up an ASM Instance 13-33

I n
Shutting Down an ASM Instance 13-34
ASM Disk Groups 13-35

l e
ASM Administration Page 13-36
c
Create Disk Group Page 13-37

r a
ASM Files 13-38
ASM Filenames 13-39
O
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
n l y
Overview 15-3
Database Resource Manager Concepts 15-4
Using Sub-Plans to Limit CPU Utilization 15-5
e O
Limiting CPU Utilization: Example 15-7
Resource Manager Configurations 15-8
U s
Active Session Pool Mechanism 15-10
Setting the Active Session Pool 15-11
A I
Automatic Consumer Group Switching 15-13
Configuring Consumer Group Switching 15-16 O
&
Adaptive Consumer Group Mapping 15-17
l
n a
Creating a Mapping Using DBMS_RESOURCE_MANAGER 15-18
Assigning Priorities Using DBMS_RESOURCE_MANAGER 15-19

te r
The Initial Plan: SYSTEM_PLAN 15-20
Creating a New Resource Plan 15-21

I n
Oracle Enterprise Manager: Resource Manager 15-23
Creating a Simple Plan 15-24

l e
Creating a Complex Plan 15-25

c
Resource Allocation Methods for Resource Plans 15-26

r a
Comparison of EMPHASIS and RATIO 15-28
Creating Resource Consumer Groups 15-30

O
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
n l y
Using Scheduler Programs 16-12
Creating a Program Using EM 16-13
e O
Specifying Schedules for a Job 16-14
Creating and Using Schedules 16-15
U s
Using EM to Create Schedules 16-16
Advanced Scheduler Concepts 16-17
Creating a Job Class 16-18 A I
Job Logging 16-20
O
Creating a Window 16-21

l &
Prioritizing Jobs Within a Window 16-23

Managing Jobs 16-26


n a
Enabling and Disabling Scheduler Components 16-25

te
Managing Programs 16-27r
Managing Programs with EM 16-28

I n
Managing Schedules 16-29
Managing Windows 16-30

l e
Window Priority 16-32
c
Managing Attributes of Scheduler Components 16-33

r a
Managing Attributes of the Scheduler 16-35

O
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
n l y
Using Resumable Space Allocation 17-20
Resuming Suspended Statements 17-22
e O
Summary 17-24
Practice 17 Overview: Using Dynamic SQL 17-25
U s
18 Workshop
Objectives 18-2
A I
Workshop Methodology 18-3
Business Requirements 18-5 O
Database Configuration 18-6
l &
Simulated Application 18-7

n a
Method for Resolving Database Issues 18-8
Summary 18-10

te r
Practice 18 Overview: Workshop Setup 18-11

I n
Appendix A: Solutions

l e
Appendix B: Basic Linux and vi Commands

c
a
Appendix C: Acronyms and Terms
r
O
x
___________
Appendix A:
Solutions
___________

n l y
e O
U s
A I
O
l &
na
te r
I n
c le
ra
O
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;
n l y
e O
U s
A I
O
ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-YYYY HH:MI:SS';
SELECT SYSDATE FROM dual;

l &
n a
te r
I n
c l e
r a
O
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?
n l y
SELECT * FROM list
ORDER BY word;
e O
U s
The rows displayed by this query may be in one of two linguistic orders: FRENCH or BINARY,

A I
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

O
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.

l &
n a
te r
I n
c l e
r a
O
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; n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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');
n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.


n l y
e O
U s
A I
O
l &
n a
c. r
Provide your host login credentials (oracle/oracle) and click Login to continue.
te
I n
c l e
r a
O
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. n l y
The listener must be restarted for the changes to take effect. Select Restart and then
click OK to proceed with the restart operation.
e O
U s
A I
O
l &
2. Login as the user sales with a password of oracle and verify listener password
protection is in effect.
n a
$ su – sales
password:
te r
$
$ lsnrctl stop I n
l e
LSNRCTL for Linux: Version 10.1.0.2.0 - Production on 27-FEB-2004
07:44:36
c
a
Copyright (c) 1991, 2004, Oracle. All rights reserved.
r
O
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


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.

n l y
e O
U s
d. Click the Other Services tab. Select extproc and then click Remove.

A I
O
l &
n a
te r
I n
e. Click the General tab next. Select IPC then click Remove. To continue, click OK.

c l e
r a
O
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 = n l y
(DESCRIPTION =
(ADDRESS_LIST =
e O
)
U s
(ADDRESS = (PROTOCOL = TCP)(HOST = EDRSR13P1)(PORT = 1521))

)
)

A I
TRACE_LEVEL_LISTENER = OFF
O
l &
If you see a line like: (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC) then the
operation was not successful.
n a
te r
I n
c l e
r a
O
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.

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

U s
A I
O
l &
n a
te
extproc in the Key field. r
f. In the Add Address region, choose IPC from the Protocol pull down list and type in

I n
c l e
r a
O
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.

n l y
O
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
e
Home Directory field and type your SID name in the SID field then click OK.

U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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 n l y
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME
e O
s
TO '/u01/app/oracle/product/10.1.0/db_1/dbs/snapcf_orcl.f'; # default

U
A I
O
l &
n a
te r
I n
c l e
r a
O
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. Log in to the Database Control Console as the SYSTEM user.
b. Go to the Maintenance page.
c. Select Configure Backup Settings.
d. Click Policy.
e. Scroll down to the Retention Policy section.
f. 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.

n l y
e O
4. Verify the backup retention policy setting using the RMAN utility and the SHOW command.
RMAN> show retention policy;
U s
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;
A I
O
l &
n a
te r
I n
c l e
r a
O
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 No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 54
Current log sequence 56

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 Archive Mode
n l y
Automatic archival
Archive destination
Enabled
USE_DB_RECOVERY_FILE_DEST
e O
Oldest online log sequence
Next log sequence to archive
Current log sequence
55
57
57
U s
A I
2. Connect to your database as the target database in the default NOCATALOG mode as the
SYSTEM user.
O
$ rman target system/manager NOCATALOG
l &
a
Recovery Manager: Release 10.1.0.2.0 - Production
n
te r
Copyright (c) 1995, 2004, Oracle. All rights reserved.

connected to target database: ORCL (DBID=1045444042)

I n
using target database controlfile instead of recovery catalog

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

O
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;

n l
5. Use RMAN to back up the data files belonging to the EXAMPLE and USERS tablespaces. Be
y
e O
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.
U s
RMAN> BACKUP AS BACKUPSET
2> FORMAT '$HOME/DONTTOUCH/df_%d_%s_%p.bak'
3> TABLESPACE USERS, EXAMPLE; A I
O
l &
Starting backup at 19-FEB-04 using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset

n a
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf

te r
input datafile fno=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 19-FEB-04

I n
channel ORA_DISK_1: finished piece 1 at 19-FEB-04
piece handle=/home/oracle/DONTTOUCH/df_ORCL_10_1.bak comment=NONE

l e
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15

c
Finished backup at 19-FEB-04

r a
Starting Control File and SPFILE Autobackup at 19-FEB-04

O
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


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 n l y
...

e O
U s
7. Obtain a listing of all database files that have not been backed up.

RMAN> REPORT NEED BACKUP; A I


O
l &
RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 2 days

File Days Name


n a
Report of files whose recovery needs more than 2 days of archived logs

r
---- ----- ------------------------------------------------

te
I n
c l e
r a
O
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
n l y
SQL> col critical_value format a10

e O
SQL> select metrics_name, warning_value, critical_value
2 from dba_thresholds where upper(metrics_name)
3 like'%COMMIT%';
U s
METRICS_NAME WARNING_VA CRITICAL_V
A I
------------------------------ ---------- ----------
User Commits Per Sec 3 6 O
l &
n a
te r
I n
c l e
r a
O
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. From the Database Control home page, click the All Metrics link under Related
Links.
n l y
b. On the All Metrics page, expand the Throughput listing.

e O
c.
d.
U s
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.
A I
O
l &
n a
te r
I n
c l e
Answer: Although the commit rate is going above the warning level, you do not get any

r a
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
O than one minute

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?

n l y
O
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.
e
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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?

n l y
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.

e O
5. Wait three more minutes and look at your outstanding alerts and the alert history again. What
are your conclusions?
U s
A I
O
Answer: Because the commit rate is now close to zero for more than three minutes, the alert
is automatically cleared.
l &
n a
6. Using Database Control, change the 30 second threshold check for the User Commits (per

te r
second) metric back to the default value (last 24 hours). Execute the
lab_07_cleanup.sql script to clean up your environment.

I n
c l e
r a
$ lab_07_cleanup.sql

O
Connected.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.

Oracle Database 10g: Administration Workshop II A-21


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 SPID
------------------------------ ---------
SYSTEM <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 $HOME/DONTTOUCH/cntrl.trc

$ vi $HOME/DONTTOUCH/cntrl.trc
n l y
Remove all unneeded text and commands from the trace file.

e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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;

n l y
SEQUENCE#
----------
65
STATUS
----------------
CURRENT
e O
63
64
INACTIVE
INACTIVE
U s
SQL> alter system switch logfile;
System altered. A I
O
l &
2. Check and record the system time and date.

n a
SQL> !date
Thu Feb 19 03:31:49 PST 2004
te r
SQL>
I n
c l e
r a
O
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# STATUS
---------- ----------------
65 ACTIVE
66 CURRENT
64 INACTIVE

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. Shutdown the database, and restart it in mount mode.


n l y
SQL> shutdown immediate;
SQL> startup mount;
e O
ORACLE instance started.
SQL> exit
U s
A I
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.
O
$ rman target /

l &
Recovery Manager: Release 10.1.0.2.0 - Production

n a
Copyright (c) 1995, 2004, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1045444042)

te r
RMAN> set until time "TO_DATE('04-FEB-19:03:31:49','YY-MON-
DD:HH24:MI:SS')";
3> restore database;
I n
5> }
c l e
4> recover database;

r a
executing command: SET until clause
using target database controlfile instead of recovery catalog

O
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


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;

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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# STATUS
---------- ----------------
206 INACTIVE
207 INACTIVE
208 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.
n l y
SQL> select sequence#, status from v$log;

e O
SEQUENCE# STATUS
---------- ----------------
U s
209 CURRENT
207 INACTIVE
208 ACTIVE A I
O
SQL> insert into hr.departments2 values (280, 'DUMMY1','','');

l &
SQL> insert into hr.departments2 values (290, 'DUMMY2','','');
SQL> insert into hr.departments2 values (300, 'DUMMY3','','');
SQL> commit

n a
r
SQL> select count(*) from departments2;

te
COUNT(*)
----------
I n
30

c l e
r a
4. Using Enterprise Manager, recover the database to the log sequence you wrote down
previously.
a.O From the Database Control home page, click on the Maintenance folder tab, and
then click on Perform Recovery.
b. Select Whole Database from the Object Type pull down list
Oracle Database 10g: Administration Workshop II A-26
Solution for Practice 9: Incomplete Recovery (continued)

Exercise 2:Recovery Using Log Sequence and Enterprise Manager


c. Select "Recover to the current time … ".
d. Click Next to continue.

n l y
e. O
Click on the Sequence button and type in the sequence number you wrote down
previously.
e
f. Click Next to continue.
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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. Review the recovery steps and the RMAN script that will be run.
h. 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;
n l y
COUNT(*)
----------
e O
27
SQL> exit
U s
$ rman target /
RMAN> backup database; A I
O
l &
n a
te r
I n
c l e
r a
O
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. From the database home page, click on the Maintenance tab.
b. Click on Configure Recovery Settings.
c. Under Media Recovery, click the ARCHIVELOG mode check box, if not already
checked.

n l y
e O
U s
A I
O
l &
n a
te r
I n
2. Configure Flashback Database from the Configure Recovery Settings page. Set the flash

l e
recovery area size to 4 GB. Enable Flashback logging and set the
c
DB_FLASHBACK_RETENTION_TARGET parameter to 1 day.
a.
r a
Scroll to the bottom of the Configure Recovery Settings page
b.
c.
O Accept the default Flash Recovery Area Location.
Increase the Flash Recovery Area Size from 2 to 4 GB.
d. Click the Enable flashback logging … check box.
Oracle Database 10g: Administration Workshop II A-29
Solution for Practice 10: Flashback Database (continued)

Exercise 1: Configuring Flashback Database (continued)


e. Accept the default value (24 hours) for Flashback Retention Time.
f. 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.

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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

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

U s
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. A I
SQL> shutdown immediate;
O
Database closed.
Database dismounted.
l &
ORACLE instance shut down.
SQL> startup mount;
n a
ORACLE instance started.
SQL>host
te r
$ rman target /
I n
RMAN> FLASHBACK DATABASE

l e
2> TO TIME = "TO_DATE('04-FEB-19:13:34:59','YY-MON-DD:HH24:MI:SS')";

c
r a
Starting flashback at 19-FEB-04
using target database controlfile instead of recovery catalog

...O
allocated channel: ORA_DISK_1

Finished flashback at 19-FEB-04


RMAN> exit

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 /
n l y
RMAN> backup database;

e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.
n l y
SQL> commit;

e O
SQL> SELECT COUNT(*) FROM hr.departments2;

U s
COUNT(*)
----------
24
A I
O
l
SQL> select current_scn from v$DATABASE;&
3. Query V$DATABASE and be certain the SCN has been incremented.

n a
CURRENT_SCN
-----------
468518
te r
I n
c l e
r a
O
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.

n l y
e O
U s
b.
A I
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.
O
l &
n a
te r
c.
n
You are then notified of the state of the database. Click Perform Recovery.
I
c l e
r a
O
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.
l y
On the next screen, you must supply point-in-time recovery information. Choose

n
'Recover to a prior point-in-time', then select SCN and enter the SCN value
recorded in Step1. Click Next to continue.

e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.

n l y
e O
h. U s
If successful, you should see a screen similar to the one shown below. Click OK and
return to the Database Control home page.
A I
O
l &
n a
te r
I n
c l e
r a
O
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

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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 END_TIME FLASHBACK_DATA DB_DATA REDO_DATA ESTIMATED_FLASHBACK_SIZE


--------- --------- -------------- -------- ---------- -----------------------
-
20-FEB-04
0
20-FEB-04 6561792 11223040 5063168

n l y
20-FEB-04
459202560
20-FEB-04 21110784 40321024 16595456

e O
3. Determine the current size of stored flashback data by querying
U
V$FLASHBACK_DATABASE_LOG. Record your answer here: _____________
s
A I
SQL> SELECT estimated_flashback_size, flashback_size flashback_size
2 FROM V$FLASHBACK_DATABASE_LOG;
O
ESTIMATED_FLASHBACK_SIZE FLASHBACK_SIZE
------------------------ --------------
l &
353648640 32677888

n a
te r
I n
c l e
r a
O
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 n l y


e O
3. Determine the object name, undrop status and other related information by querying
DBA_RECYCLEBIN.
U s
SQL> SELECT original_name, object_name, droptime
2 FROM dba_recyclebin WHERE can_undrop = 'YES';
A I
ORIGINAL_NAME OBJECT_NAME
O DROPTIME

DEPARTMENTS2
l &
------------------- ------------------------------
BIN$07xSYSqrEmPgMLmLbSNgjw==$0
-------------------
2004-02-19:13:33:44

n a
4. Use the SQL FLASHBACK TABLE command to restore the table.

te r
SQL> FLASHBACK TABLE hr.departments2 TO BEFORE DROP;

Flashback complete.
I n
c l e
SQL> SELECT COUNT(*) FROM hr.departments2;

r
COUNT(*)a
O
----------
27

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> INSERT INTO hr.departments2 VALUES (280, 'DUMMY1','','');
SQL> COMMIT;
SQL> INSERT INTO hr.departments2 VALUES (290, 'DUMMY2','','');
SQL> COMMIT;
SQL> INSERT INTO hr.departments2 VALUES (300, 'DUMMY3','','');
SQL> COMMIT;

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

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

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

e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.

n l y
e O
U s
A I
b.
O
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.

l
n a
te r
I n
c l e
r a
O
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.

n l y
e O
U s
e.
I
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.
A
f.
O
Enter hr in the Schema field and departments2 in the Object Name field, then click
Go.

l &
n a
te r
I n
c l e
r a
O
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.

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.

n l y
k. O
Now you can perform the flashback operation. From the Database home page, click
e
the Maintenance tab and select Perform Recovery under the heading
Backup/recovery.
U s
l.
I
Select Tables from the Object Type pull down list. When the screen refreshes, select
A
Flashback Existing Tables. Click Next to proceed.

m. Enter the name of the table and click Next. O


n.
l &
Highlight DEPARTMENT_ID under Available Columns and click the Move button to

n a
move it under Selected Columns. Enter a WHERE clause that will select the added

te r
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.

I n
c l e
r a
O
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.

n l y
e O
q. On the Confirmation page, click OK to continue.

U s
A I
O
r.
l &
Get a row count to confirm the flashback operation.

n a
COUNT(*)
te r
SQL> SELECT COUNT(*) FROM hr.departments2;

----------
28 I n
c l e
Question: According to the row count, we have flashed back 2 transactions (30-28=2). Were you

r a
expecting just a single transaction to be flashed back?

O
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.

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.

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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 n l y
----------
1 /u01/app/oracle/oradata/orcl/system01.dbf
e O
------------------------------------------------------------

2
3
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
U s
SQL> exit
4
5
/u01/app/oracle/oradata/orcl/users01.dbf
/u01/app/oracle/oradata/orcl/example01.dbf
A I
$ su –
O
password:
# chmod 775
l &
/u01/app/oracle/oradata/orcl/example01.dbf
# exit
$
n a
te r
3. Run the lab_12_01_03.sh script using the information gathered above to corrupt the

I n
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.

c l e
$ lab_12_01_03.sh /u01/app/oracle/oradata/orcl/example01.dbf 49 8192

r a
0+1 records in
0+1 records out

O
$ exit

SQL> shutdown immediate;


SQL> startup

Oracle Database 10g: Administration Workshop II A-49


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 n l y
last change scn: 0x0000.000724f2 seq: 0x1 flg: 0x04
spare1: 0x52 spare2: 0x52 spare3: 0x0
e O
consistency value in tail: 0x24f22301
check value in block header: 0x6b91
U s
computed block checksum: 0xe440

Page 52 is marked corrupt


A I
O
Corrupt block relative dba: 0x01400034 (file 5, block 52)
Bad header found during dbv:
Data in bad block:
l &
type: 67 format: 7 rdba: 0x0a545055

n a
last change scn: 0x0000.00057b19 seq: 0x1 flg: 0x06

te r
spare1: 0x52 spare2: 0x52 spare3: 0x0
consistency value in tail: 0x7b190601

I n
check value in block header: 0xb133
computed block checksum: 0xe462

c l e
r a
O
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 Pages Examined : 19200


Total Pages Processed (Data) : 4404
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 1244
Total Pages Failing (Index): 0
Total Pages Processed (Other): 2680
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total
Total
Total
Pages
Pages
Pages
Empty
Marked Corrupt
Influx
:
:
:
10867
4
0
n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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
...

n l y
3. Verify that the block recovery is successful.
SQL> SELECT * FROM hr.departments;
e O
DEPARTMENT_ID DEPARTMENT_NAME
U
MANAGER_ID LOCATION_ID s
10 Administration
20 Marketing
200
201 A I
------------- ------------------------------ ---------- -----------
1700
1800
30 Purchasing
O
114 1700
40 Human Resources
50 Shipping
l & 203
121
2400
1500
...

n a
te r
I n
c l e
r a
O
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.

n l y
b.
e O
On the Create Tablespace page, specify TBSADDM in the Name field, and then
click the Add button.

U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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. n l y
On the Create User page, specify the following fields: Name, Enter Password,

done, click the Roles tab.


e O
Confirm Password, Default Tablespace, and Temporary Tablespace. When

U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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
n l y
SQL> connect addm/addm
Connected.
e O
SQL> @lab_13_01_01.sql
Connected.
U s
PL/SQL procedure successfully completed.
A I

SQL> exit O
$ ./lab_13_01_02.sh

l &
n a
te r
I n
c l e
r a
O
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.

n l y
e O
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.

a.
U s
Retrieve the latest ADDM findings, and determine the cause of the problem.
From the Database home page click the Advisor Central link. On the Advisor

A I
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.

O
l &
n a
te r
I n
c l e
r a
O
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.

n l y
e O
d.

U s
This brings you to the Performance Finding Details page where ADDM
identifies the high-load SQL statement. Click the Run SQL Tuning Advisor Now
I
button to tune this statement. On the Schedule Advisor page, click OK.
A
O
l &
n a
te r
I n
e.
c l e
When the analysis is done, click the View Recommendations button.

r a
O
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 n l y
for your ADDM table.

e O
U s
A I
O
l &
n a
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,

te r
and re-creates it in the new tablespace. This script also gathers statistics on the table and
takes a new snapshot.
a.
I n
To implement the recommendation, you must re-create the objects. First, you

l e
need to create a new tablespace that uses the Automatic Space Management

c
feature. Return to the Database home page, and click the Administration tab.

r a
O
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.

n l y
e O
U s
A I
O
d.
l &
Back to the Create Tablespace page, click the Storage tab, and make sure that

n a
Automatic is set in the Segment Space Management region. Then click the OK
button to create the new tablespace.

te r
I n
c l e
r a
O
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.

n l y
e O
U s
A I
O
Connected.
l &
SQL> @lab_13_01_06.sql
Connected.
n a
te r
I n
c l e
r a
O
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

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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. Start dbca as oracle from an OS command line window.
$ whoami
oracle
$ dbca

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

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.

n l y
d.
click the Next button to continue.
e O
On the Database Templates page, select the General Purpose option button and

U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.

n l y
f. O
On the Management Options page, make sure the Configure the Database with
e
Enterprise Manager checkbox is selected. Click the Next button to continue.

U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.

n l y
h.
O
On the Storage Options page, make sure that the Automatic Storage

e
Management (ASM) option button is selected. Click the Next button.

U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.
j. 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.

n l y
e O
U s
k.
A I
In the Database Configuration Assistant dialog box, click the OK button.

O
l &
n a
te r
I n
c l e
r a
O
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.

n l y
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.

e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.

n l y
o. On the Database File Locations page, click the Cancel button.

e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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
Redo Buffers
ASM diskgroups mounted
0 bytes
0 bytes
n l y
SQL>
SQL> !ps -ef | grep ASM
e O
oracle
oracle
21223
21225
1 0 10:42 ?
1 0 10:42 ?
00:00:00 asm_pmon_+ASM
00:00:00 asm_mman_+ASM
U s
oracle
oracle
oracle
21227
21229
21231
1 0 10:42 ?
1 0 10:42 ?
1 0 10:42 ?
I
00:00:00 asm_dbw0_+ASM

A
00:00:00 asm_lgwr_+ASM
00:00:00 asm_ckpt_+ASM
oracle 21233 1 0 10:42 ?
O
00:00:00 asm_smon_+ASM
oracle
oracle
21235
21239
1 0 10:42 ?
1 0 10:42 ?
l &
00:00:00 asm_rbal_+ASM
00:00:00 oracle+ASM

a
(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

n
r
SQL> select NAME, STATE, TYPE, TOTAL_MB, FREE_MB from v$asm_diskgroup;

te
NAME
I n STATE TYPE TOTAL_MB FREE_MB
-------------------------- ----------- ------ ---------- ----------
DGROUP1

c l e MOUNTED NORMAL 800 648

r a
O
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;


n l y
FILE_NAME
---------------------------------------------------
e O
TABLESPACE_NAME
-----------------
/u01/app/oracle/oradata/oracle/users01.dbf
/u01/app/oracle/oradata/oracle/sysaux01.dbf
U s USERS
SYSAUX
/u01/app/oracle/oradata/oracle/undotbs01.dbf
/u01/app/oracle/oradata/oracle/system01.dbf
/u01/app/oracle/oradata/oracle/example01.dbf A I UNDOTBS1
SYSTEM
EXAMPLE
/u01/app/oracle/product/10.1.0/db_1/dbs/asmmig1.dbf
O TBSASMMIG

l &
SQL> create table t2(c number) tablespace tbsasmmig;
Table created.

n a
SQL> insert into t2 values(1);
1 row created.
te r
I n
c l e
r a
O
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 n l y
RMAN> switch tablespace tbsasmmig to copy;
e O
U s
datafile 6 switched to datafile copy "+DGROUP1/oracle/datafile/tbsasmmig.257.1"

RMAN> SQL "alter tablespace tbsasmmig online";


A I
SQL> select file_name,tablespace_name
O
from dba_data_files;

FILE_NAME
l & TABLESPACE_NAME

n a
---------------------------------------------- -----------------------
/u01/app/oracle/oradata/orcl/users01.dbf USERS

te r
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
SYSAUX
UNDOTBS1

I n
/u01/app/oracle/oradata/orcl/system01.dbf
+DGROUP1/orcl/datafile/tbsasm.256.1
SYSTEM
TBSASM

c l
6 rows selected.
e
+DGROUP1/orcl/datafile/tbsasmmig.257.1 TBSASMMIG

r a
O
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> n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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. From the Administration page, click on Resource Consumer Groups in the
Resource Manager section.
b. On the Resource Consumer Groups page, click Create.
c. For the Consumer Group name, enter APPUSER, then click OK.

n l y
e O
U s
A I
O
l &
n a
4. Add the APPUSER resource consumer group to the SYSTEM_PLAN resource plan. Assign

te r
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.
I n
From the Administration page, click on Resource Plans in the Resource Manager

b.
section.

c l e
Select the SYSTEM_PLAN and click Edit.
c.
r a
On the Edit Resource Plan: SYSTEM_PLAN page, click Modify.
d.
e.
O Select the APPUSER group and move it to the Selected Groups list. Click OK.
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
Solution for Practice 15: Using the Resource Manager (continued)

5. Configure Automatic Consumer Group Mappings as follows:


– 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.
a. From the database Administration page, in the Resource Manager section, click
Resource Consumer Group Mappings.
b. In the Oracle User Map section, click Add Another Row to configure mappings for
the HR and SCOTT database users.
c. Change the Consumer Group from DEFAULT_CONSUMER_GROUP to
APPUSER and specify HR as the Oracle user. Click Apply.
d. Click Add Another Row to configure mappings for the SCOTT database user.
e. Change the Consumer Group to LOW_GROUP and specify SCOTT as the Oracle
user.

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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. Click the General tab to return to the Resource Consumer Group Mapping main
page.
h. In the Client OS User Map section, click Add Another Row.
i. Change the Consumer Group from DEFAULT_CONSUMER_GROUP to
SYS_GROUP and specify oracle as the Client OS User. n l y
e O
U s
A I
O
l &
j.
a
Scroll to the top of the page and click Apply.

n
te r
6. Edit the HR, SCOTT, and PM users to assign them privileges for all resource consumer
groups to which they could be assigned.

I n
– HR: APPUSER consumer group

l e
– SCOTT: LOW_GROUP consumer group
– PM: LOW_GROUP, SYS_GROUP, and APPUSER consumer groups
c
a.
r a
From the Administration page, click Users in the Security section.
b.
c.O Select the HR user and click Edit.
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. When returned to the Edit User page, click Apply.


f. To edit the user SCOTT, click Users in the breadcrumb listing.
g.
h.
Select SCOTT and click Edit.
Click the Consumer Groups tab and then click Modify. n l y
i. O
Move the LOW_GROUP consumer group to the Selected Consumer Groups list and
e
j.
click OK.
When returned to the Edit User page, click Apply.
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
Oracle Database 10g: Administration Workshop II A-77
Solution for Practice 15: Using the Resource Manager (continued)

k. To edit the user PM, click Users in the breadcrumb listing.


l. Select PM and click Edit.
m. Click the Consumer Groups tab and then click Modify.
n. Move the LOW_GROUP, SYS_GROUP, and APPUSER consumer groups to the
Selected Consumer Groups list and click OK.
o. When returned to the Edit User page, click Apply.

7. Activate the SYSTEM_PLAN resource plan.


a. From the Administration page, click Resource Plans in the Resource Manager
section.
b. 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.

n l y
In the second session, as the SYSTEM user, query the V$SESSION data dictionary view to

sessions with a SCHEMANAME beginning with SYS%.


e O
determine which resource consumer group was assigned to the other session. Filter out those

% sqlplus hr/hr
U s
% sqlplus system/oracle
A I
SQL> SELECT schemaname, resource_consumer_group O
2> FROM V$SESSION
3> WHERE schemaname not like 'SYS%';
l &
n a
SCHEMANAME

HR
te r
RESOURCE_CONSUMER_GROUP
------------------------------ --------------------------------
APPUSER
DBSNMP
I n
c l e
r a
O
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 Resource Consumer Group

HR APPUSER

SCOTT LOW_GROUP

PM 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
n l y
------------------------------ --------------------------------
SCOTT LOW_GROUP
e O
DBSNMP

SQL> CONNECT pm/pm


U s
A I
SQL> CONNECT system/oracle
O
2> FROM V$SESSION
l &
SQL> SELECT schemaname, resource_consumer_group

3> WHERE schemaname not like 'SYS%';


n a
SCHEMANAME
te r
RESOURCE_CONSUMER_GROUP
------------------------------ --------------------------------
PM
DBSNMP I n SYS_GROUP

c l e
11. Deactivate the SYSTEM_PLAN resource plan.
a.
r a
From the Administration page, click Resource Plans in the Resource Manager

b.
O 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


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. From the Database home page, click the Administration tab.
b. On the Administration page, click on the Users link, under the heading of Security.
c. On the Users page, click on the HR user name to edit the account.
d. On the Edit User page, click on the Roles tab. Then click on the Modify button on the
right-hand side of the page.
e. 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.
n l y
f.
O
When returned to the Edit User page, click on the System Privileges tab, and then
click on the Modify button.
e
g.
s
In the Available System Privileges list, click on the SELECT ANY DICTIONARY

U
privilege and click on the > 'Move' button to grant this privilege to the HR user.

h.
Repeat for the CREATE JOB system privilege. Click OK.
On the Edit User page, click on Apply. A I
O
l &
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.

n a
a. On the Administration page, click Administrator s in the upper right hand corner. On the
r
Administrator page, click the Create button.
te
I n
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.

c l e
c. Click the Finish button.

r a
d. On the Create Administrator: Review page, click the Finish button.
O
e. Back to the Administrators page, click the Database tab.

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. In the upper right corner of the current page, click the Logout link.
b. Click the Login button to log back in.
c. 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. Go back to the Administration main page
b.
l
Click the Schedules link under the heading Scheduler. There is one schedule, called
DAILY_PURGE_SCHEDULE.
n y
O
10. Are there any existing windows? What resource plan is associated with each window?
e
a.
b.
Go back to the Administration main page

U s
Click the Windows link under the heading Scheduler. There are two windows,

not have any resource plan associated with them.


A I
named WEEKNIGHT_WINDOW and WEEKEND_WINDOW. The windows do

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

l e
consumer group
c
r a
O
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
n l y
– Logging Level is set to Log job runs only (RUNS)
– Job Class is set to DEFAULT_JOB_CLASS
e O
– Auto Drop is set to FALSE
– Restartable is set to FALSE
U s
b.
c. A I
In the Command section, click the Change Command Type button.
On the Select Command Option, select In-line Program: Executable and click OK.
d. O
Back to the Create Job page, enter /home/oracle/labs/lab_16_02_01.sh in the
Executable Name field.
l &
e. Click the Schedule tab.
n a
f.
r
On the Schedule page, make sure the Immediately radio button is selected, and the

te
Repeat field is set to Do Not Repeat.

I n
2. Click on OK to create the job.

c l e
r a
O
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. From the Administration page, click on the Programs link under the heading
Scheduler. n l y
b. Click on Create.
e O
c. Enter LOG_SESS_COUNT_PRGM for the name of the Program.

U s
d.
e.
Set Enabled to Yes
Leave the type set to PL/SQL Block.
A I
f.
O
Enter the above PL/SQL text into the Source field.
g. Click OK.
l &
a
5. Create a schedule named SESS_UPDATE_SCHED owned by HR that executes every 3
n
te r
seconds. Because the Database Control Console only supports scheduled intervals of one
minute or larger, you will use SQL*Plus and the DBMS_SCHEDULER.

a. I n
CREATE_SCHEDULE procedure to create the program.
Start SQL*Plus and log in as the HR user.

c l e
r a
O
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.
Click Jobs under the heading Scheduler.
Click the Create button to open the Create Job window.
n l y
c.
d.
Enter LOG_SESSIONS_JOB for the name.
Change the logging level to FULL.
e O
e.
U s
Click the Change Command Type button. In the Select Command Option window,

A I
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.
f.
O
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.
l &
g. Click OK to create the job.
n a
te r
8. Check the HR.SESSION_HISTORY table for rows. If there are rows in the table, are the
timestamps 3 seconds apart?
I n
SELECT * FROM hr.session_history

l e
ORDER BY snap_time;

c
Yes there are rows, and yes the timestamps are 3 seconds apart.

r a
O
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. From the Administration page, click Schedules.
b. Click the SESS_UPDATE_SCHED link.
c. Change the description to 'Every 3 minutes'.
d. Change Repeating from Do Not Repeat to By Minutes.
e. Set the Interval to 3.
f. 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.
n l y
Using EM:
a. e O
From the Administration page, click on Tables under the heading Schema.
b.
U s
Enter HR for the Schema and SESSION_HISTORY for the table name, then

c.
click Go.
Click the table name in the Results list. A I
d. Click the Add 5 Table Columns button. O
e.
l &
In the first empty row (after NUM_SESSIONS) enter BACKGROUND_COUNT

a
for the column name and NUMBER for the data type.

n
f.
r
Click Apply to alter the table.

Using SQL*PLus: te
CONNECT hr/hr I n
l e
ALTER TABLE session_history ADD (BACKGROUND_COUNT NUMBER);

c
r a
O
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. From the Administration page, click Programs under the heading Scheduler.
b. Click the LOG_SESS_COUNT_PRGM link.
c. Change the Source code to match the above text.
d. Click Apply.
n l y
to the HR.SESSIONS_HISTORY table.
e O
13. Run the job LOG_SESSIONS_JOB immediately, and verify the new information was added

a.
s
From the Administration page, click Jobs under the heading Scheduler.
U
b.
c.
A I
With the job LOG_SESSIONS_JOB selected, click the Run Now button.
Click the Run History tab to verify the job ran successfully.
d.
O
Using either SQL*Plus or iSQL*Plus, query the HR.SESSION_HISTORY table to

CONNECT hr/hr
l &
verify the newest rows contain the background session count.

a
ALTER TABLE session_history (BACKGROUND_COUNT NUMBER);

n
te r
I n
c l e
r a
O
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. From the Administration page, click Jobs under the heading Scheduler.
b. 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.
c. 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.
d. With the program LOG_SESS_COUNT_PRGM selected, click the Delete button.
Click Yes to confirm.
e. 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.
f. With the schedule SESS_UPDATE_SCHED selected, click the Delete button.
g. Select "If there are dependent objects, it will not be dropped. " and click Yes to
confirm.

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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:

– 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.


SQL> CREATE OR REPLACE PROCEDURE fire_emp (id NUMBER)AS
2> BEGIN
3> EXECUTE IMMEDIATE 'DELETE FROM emp2 WHERE employee_id = ' || id;
4> COMMIT;
4>
5>
END;
/
n l y
3. Test the FIRE_EMP procedure for various rows in the EMP2 table.
e O
U s
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 A I
3> SELECT employee_id FROM emp2;
O
EMPLOYEE_ID
l &
-----------
137
n a
140
154
te r
I n
c l e
r a
O
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> set echo off


SQL> set heading off
SQL> set feed off
SQL> set pages 1000
SQL> 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> CONNECT system/oracle n l y
SQL>
SQL>
SET echo on
SET heading ON
e O
SQL> SET feedback ON

U s
SQL> SELECT SYS_CONTEXT('USERENV', 'SESSION_USER') username,
SQL>
SQL> A I
SYS_CONTEXT('USERENV', 'INSTANCE_NAME') Instance,
SYS_CONTEXT('USERENV', 'DB_NAME') "DB Name",
SQL> SYS_CONTEXT('USERENV', 'HOST') hostname
O
SQL> FROM dual;

l &
USERNAME

n a
-----------------------------------------------------------------------
INSTANCE

te r
-----------------------------------------------------------------------
DB Name
I n
-----------------------------------------------------------------------
HOSTNAME
l e
-----------------------------------------------------------------------
c
SYSTEM
orcl
r a
O
orcl
EDRSR12P1

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 No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 54
Current log sequence 56

SQL> SHUTDOWN IMMEDIATE


ORACLE instance shut down.
n l y
SQL> STARTUP MOUNT
Database mounted.
e O
SQL> ALTER DATABASE ARCHIVELOG;
U s
Database altered.

A I
SQL> ALTER DATABASE OPEN;
Database altered. O
SQL> ARCHIVE LOG LIST;
l &
Database log mode
n a Archive Mode
Automatic archival
Archive destination
Oldest online log sequence
te r Enabled
USE_DB_RECOVERY_FILE_DEST
55

Current log sequence I n


Next log sequence to archive 57
57

c l e
r a
O
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 Data file Name (full path)

USERS /u01/app/oracle/oradata/orcl/users01.dbf

SYSAUX /u01/app/oracle/oradata/orcl/sysaux01.dbf

UNDOTBS1 /u01/app/oracle/oradata/orcl/undotbs01.dbf

SYSTEM /u01/app/oracle/oradata/orcl/system01.dbf

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

n l y
TEMP /u01/app/oracle/oradata/orcl/temp01.dbf

e O
Online Redo Log File Information

U s
Online logs should be mirrored.
SQL> SELECT l.group#, member, bytes, lf.status
A I
2> FROM v$logfile lf, v$log l
3> WHERE l.group# = lf.group#; O
SQL> ALTER DATABASE ADD LOGFILE
l &
a
2> MEMBER '/u01/app/oracle/oradata/orcl/redo01b.log'
n
3> TO GROUP 1;

te
SQL> ALTER DATABASE ADD LOGFILE
r
I n
2> MEMBER '/u01/app/oracle/oradata/orcl/redo02b.log'
3> TO GROUP 2;

c l e
SQL> ALTER DATABASE ADD LOGFILE

r a
2> MEMBER '/u01/app/oracle/oradata/orcl/redo03b.log'
3> TO GROUP 3;
O
Oracle Database 10g: Administration Workshop II A-91
Solution for Practice 18: Workshop Setup (continued)

Group Redo Log File Name (full path) Size Status


#

3 /u01/app/oracle/oradata/orcl/redo03.log 10M

2 /u01/app/oracle/oradata/orcl/redo02.log 10M

1 /u01/app/oracle/oradata/orcl/redo01.log 10M

1 /u01/app/oracle/oradata/orcl/redo01b.log 10M

2 /u01/app/oracle/oradata/orcl/redo02b.log 10M

3 /u01/app/oracle/oradata/orcl/redo03b.log 10M

Control File Information


SQL> SELECT name, status FROM V$CONTROLFILE;

n l y
Control files should be mirrored.

e O
Control File Name (full path)

U s
Status

/u01/app/oracle/oradata/orcl/control01.ctl

A I
/u01/app/oracle/oradata/orcl/control02.ctl
O
l &
/u01/app/oracle/oradata/orcl/control03.ctl

n a
te r
I n
c l e
r a
O
Oracle Database 10g: Administration Workshop II A-92
Solution for Practice 18: Workshop Setup (continued)

Operational Thresholds
a. From the Database Home page, in the Related Links region at the bottom of the
page, click the Manage Metrics link.
b. On the Manage Metrics page you can view the current setting for all thresholds.
c. 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.
d. Edit other thresholds as needed, to meet the criteria specified below.

Metric Warning Threshold Critical Threshold

Archive Area Used (%) > 75 >90

Broken Job Count >0

CPU Usage (per transaction) > 60 >75


n l y
Data Block Corruption Alert
Log Error O
CONTAINS ORA-
e
Failed Job Count >0
U
>5 s
SQL Response Time (%) > 200
A I
Scans on Long Tables (per O
transaction) >2

l &
Sorts in Memory (%)
n
< 80 a < 50

te r
I n
c l e
r a
O
Oracle Database 10g: Administration Workshop II A-93
Solution for Practice 18: Workshop Setup (continued)

Initialization Parameters
show parameter dump
show parameter size
show parameter log_archive
show parameter db
show parameter format
show parameter sga

Parameter Name Value


BACKGROUND_DUMP_DEST /u01/app/oracle/admin/orcl/bdump

CORE_DUMP_DEST /u01/app/oracle/admin/orcl/c dump

DB_BLOCK_CHECKING FALSE

DB_BLOCK_SIZE 8192 (8K)

DB_CACHE_SIZE 24M

n l y
DB_FILES 200

e O
DB_NAME orcl

U s
DB_RECOVERY_FILE_DEST
I
/u01/app/oracle/flash_recovery_area
A
DB_RECOVERY_FILE_DEST_SIZE 2G
O
LOG_ARCHIVE_DEST_n
l &
n a
LOG_ARCHIVE_DEST_n_STATE

te r ENABLE

I
LOG_ARCHIVE_FORMAT
n %t_%s_%r.dbf

c l
SGA_MAX_SIZE e 180M

r a
SGA_TARGET
O
USER_DUMP_DEST
0

/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
n l y
e O
U s
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

scheduled backups, using the recommended settings.


A I
every morning at 2 a.m.. If one does not exist, use Enterprise Manager to configure

O
Full or Complete database backups
l & No backups exist for this database. A full
backup should be taken immediately

n a following this lab.

te r
Control files and spfile automatically backed No, autobackup set to FALSE. Needs to be
up?
I n altered.

cl e
Retention policy for backups Redundancy of 1

r a
Backup schedule Every morning at 2 a.m.
O
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
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: n l y


O
a. From the Database Home page, in the Related Links region, click the User-Defined Metrics
e
link.
b. Click create on the User-Defined Metrics page.
U s
c. Specify the following:
A I
Metric name: INVALID REDO LOG FILE COUNT
Metric Type: Number O
&
SQL Query: SELECT count(*) FROM v$logfile
l
WHERE status = 'INVALID'

n a
Database credentials: System / oracle

Critical 1
te r
Thresholds: Comparison operator >

n
Schedule: Immediately after creation and then Repeat every 5 Minutes.
I
c l e
r a
O
Oracle Database 10g: Administration Workshop II A-96
Solution for Practice 18: Workshop Setup (continued)

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
ra
d.
OClick 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.

n l y
10. Ensure that your instance is started and your database is open, then begin the workshop
scenarios.
SQL> CONNECT / AS SYSDBA
e O
SQL> SELECT status FROM v$instance;

U s
STATUS
------------
OPEN
A I
O
l &
n a
te r
I n
c l e
r a
O
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
n l y
fixing the problem.
e O
period. Then, by following its analysis, ADDM should guide you through the process of

retrieve the task from the Advisor Central page:


U s
Go to the Advisor Central page and search for the correct ADDM task. This is how you can

A I
From the Database Control home page, click the Advisor Central link.

O
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.
l &
n a
Then, select the ADDM task corresponding to the time of the problematic period.

te r
When done, click the View Result button.

I n
c l e
r a
O
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.

n l y
e O
U s
A I
O
l &
This starts the execution of a SQL Tuning Advisor task. When the SQL Tuning Window
a
appears, click the View Recommendations button.
n
te r
I n
c l e
r a
O
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.

n l y
e O
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.
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.

n l y
The sizes of the automatically tuned buffers are still the same, but their corresponding values

O
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
e
ALTER SYSTEM commands that were logged in the alert.log file.

U s
Connect as SYSDBA through SQL*Plus and execute the wlab_02_02.sql script again.

A I
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
O
should not get any error, and the script should complete.

l &
Connect as SYSDBA through SQL*Plus and execute the wlab_02_cleanup.sql script to
clean up your environment.
n a
te r
I n
c l e
r a
O
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

n l y
e O
U s
A I
O
After checking with Human Resources, it is found that the DEPARTMENTS table has been

l &
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.

n a
te r
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.

I n
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.

c l e
Do you know when the table was changed? Probably not. Remember that the ORA-20217

r a
error indicated that there were 3 extra rows in the HR.DEPARTMENTS table. On the Point-in-
time page, click on the Evaluate row changes and transactions to decide on a point in
O
time button and type in HR.DEPARTMENTS in the Table field. Click Next to continue.

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

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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 ORIGINAL_NAME DROPTIME


n l y
--------------------------
HR
HR
---------------------
DEPT_LOCATION_IX
DEPT_ID_PK
O
------------------
2004-03-04:09:39:36
e
2004-03-04:09:39:36
HR DEPARTMENTS
U s2004-03-04:09:39:36

A I
Try to access the table through SQL*Plus to confirm that the table has been dropped.

O
SQL> select * from hr.departments;
select * from hr.departments
l &
*

n a
ERROR at line 1:

te r
ORA-00942: table or view does not exist

I n
This is the same error that was observed in Enterprise Manager. So the DEPARTMENTS table

l e
has been dropped. You must take immediate steps to restore this table.

c
r a
Methodology: There are several methods that will work in this situation. Flashback Table is
O
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


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
...

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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.

l
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. n y
Next.
e O
c. Select the users01.dbf datafile by checking the box in front of the file name, then click

U s
d. Indicate the files should be restored to the default location, then click Next.
e. Click Submit to start the recovery.
A I
2. Review the RMAN output, then click OK.
O
&
3. Use EM to start the database (or change the database state from MOUNTED to OPEN).
l
Results
n a

te r
The database is now open and available for users. SQL*Plus and EM connections are now
allowed.
I n

l e
The USERS tablespace is online

c

a
There are no alerts listed in the Database Home page.
r

O
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.

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;
SQL> SELECT 'GRANT SELECT ON OE.' || table_name || ' TO jones;' n l y
2> FROM user_tables;
e O
SQL> spool off
SQL> EXIT
U s
A I
4. Use a text editor to remove the echoed commands from the generated script and then save the
modified script. O
5. Run the generated script within SQL*Plus.
l &
$ sqlplus system/oracle
n a
SQL> @grant_privs.sql
te r
I n
c l e
r a
O
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
n l y
SQL> @create_syns.sql

e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
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
n l y
TEMPFILE '/u01/app/oracle/oradata/orcl/temp2a.dbf' SIZE 2G;

e O
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp2;

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

Results O
• l &
The alerts in EM have cleared.

n a

r
Enterprise Manager displays the list of tablespaces correctly again.

te

n
Querying DBA_TEMP_FILES does not return any errors.
I

l e
The only way to prevent this problem from occurring is to determine why the temporary file

c
went missing in the first place, and prevent the situation from occurring again.

r a
O
Oracle Database 10g: Administration Workshop II A-110
______________
Appendix B:
Basic Linux and
vi Commands
______________

n l y
e O
U s
A I
O
l &
na
te r
I n
c le
ra
O
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 l - move right

w - one word forward b - one word backward e - end of current word

W, B, or E - same as lower case but ignores punctuation

0 (zero) - Move to beginning of current line $ - end of current line

n l y
G - go to last line of file

L - go to last line on screen


H - go to top line on the screen

M - go to bottom line on the screen


e O
/<string> - Search forward to the next occurrence of <string>
U s
?<string> - Search backward to the next occurrence of <string>

A I
n - Repeat previous search
O
N - Repeat previous search in opposite direction

<ctrl> f - Scroll forward one page

l & <ctrl> b - Scroll backward one page

To UNDO previous changes:

n a
te r
u - Will undo the most recent change. U - Will undo the most recently deleted text.

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

I
To ENTER NEW text:

c l e
a - Append text after the current cursor position.

r a
A - Append text to the end of a line (jumps to end of line and begin appending).

O
c - Change object C - Change from current cursor position to end of the line

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) c (confirm prior to each change)

p (print changed lines) S - Substitute entire line to the end

. <period> - repeat last change n. <integer><period> repeat last change n times

To leave the input mode, press <ESC>

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
n l y
<int> J - Join the next <int> lines

e O
be manipulated with the following commands:
U s
COPY, CUT, and PASTE: vi uses a single buffer where the last changed or deleted text is stored. This text may

Y - Yank a copy of the current line


A I
y <integer> - Yank a copy of next <int> lines

yw - Yank a copy of the current word


O
yb - Yank a copy of the previous word

p - Put buffer contents after cursor


l &
P - Put buffer contents before cursor

a
Also, see the s and S commands under the input section
n
te r
To SAVE edited changes to an operating system file:

e In
zz - Will terminate edit mode. :w filename - Will save changes to the filename specified.

l
:wq - Write all changes and quit the edit mode

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

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 Linux Commands Description/Comments
Directories
Command man <command> Find the manual entry for this
manual <command>.
man –k <string> Show all the manual entries that
contain this <string>.
man man Displays the manual page for
man.
Command info <command> Show the information system entry
information for this command. Using info
info shows a tutorial of the info
documentation system.
Print to cat <file> Concatenate and print – print the
standard out named file to the terminal screen.
List users cat /etc/password
Change cd <directory> Change working directory to
working
directory
specified directory

n l y
cd with no parameters changes to

Copy a file cp <source_file>


<destination_file>
$HOME.
O
Copy a source file to a destination
e
View a file less <file>
file.

U s
View a file a page at a time. This

View a file more <file>


A I
is a GNU version of more, or pg.
View a file a page at a time. BSD

List directory ls <directory> O version.


Options –l long listing, -R

l & recursive, -a show hidden files, -t

n a sort by time, -r reverse sort,


default directory is current

Create a
te r
mkdir <directory>
working directory.
Make a directory defaults into the
directory
I n current working directory, full
path may be specified.
Move or
cl emv <old_file> <new_file> Move changes the name of a file

r a
rename a file or moves it to a different directory.

O
Oracle Database 10g: Administration Workshop II B-4
Process List ps Shows the processes report
ps -ef Shows all processes on the system
with a full listing. Many option
exist see the man page for details.
Print working pwd Print to stdout the current working
directory directory.
Remove or rm <file> Removing a file on Linux is
erase a file 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 an empty touch <file> Create a file.
file
Name of the hostname Returns the name of the machine.
machine
The IP address host <machine_name> Queries the Domain Name Server,
of the machine

Remote shell rsh <host> <command>


and returns the IP address of the
machine name.
Execute a <command> on <host>.n l y
Remote shell ssh <host>
e O
Rsh is not secure, use ssh instead.
Secure shell, has features to

Remote shell telnet <host>


s
replace rsh, rcp, ftp, and telnet.
U
Start a terminal session on <host>.

A I
Telnet is not secure use ssh
instead.
Search a file for grep <option> <pattern>
O
<file> Search a <file> or stream for a
a pattern
l & regular expression defined by
<pattern> and show the line that

n a contains that pattern. A common

te r option is –i for case insensitive.


grep can accept input from a file

I n or stdin through a pipe as in:


netstat –a| grep ESTABLISHED

c e
Source a script . <script_file>
l In the bash shell this command ‘.’
forces the script to run in the shell.

r a Normal behavior is for the script


to run in a child shell.
O
Oracle Database 10g: Administration Workshop II B-5
An interpreter awk 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 sort Sort a file takes input from stdin or
a filename argument, many
options to sort by a particular
column, field, etc. See man page.
Command line sed Sed is a command line editor, with
editor many possible commands and
options that are very good for
editing from a shell script.
Visual editor vi <file> Terminal based editor available on
every Unix system, Linux provides
vim, an improved vi, that is a
superset of vi.
Gnu editor emacs <file> This is a GPL editor with
extensive customizable features
available on most UNIX and
Linux distributions.
n l y
WSIWIG editor gedit <file>
O
A full-screen editor, requiring X.

e
Available under Gnome.
WSIWIG kate <file>
s
A full-screen editor, requires X.

U
Available under KDE
Terminal output stdout
A I
Standard out (stdout), is not a
command but a concept, most

O Linux commands write to stdout


by default unless redirected.
Terminal input stdin
l & Standard in (stdin), is not a
(keyboard)

n a command but a concept, most


Linux commands read from stdin

Alias
te r
alias <command> <alias>
by default unless redirected.
Make a substitution when a user

I n types <command> substitute and

c l e execute <alias>, common alias is


alias ‘rm’ ‘rm –i’. These aliases

r a
Show shell set
are set in the .bashrc file.
Prints all of the variables that are

O
variables currently defined in the shell.

Oracle Database 10g: Administration Workshop II B-6


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

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
Oracle Database 10g: Administration Workshop II B-7
System Linux Commands Description / Comments
Administration
Root file system / The root directory for the system
directory tree.
Home Directory /home Typically the directory in which
all user home directories placed.
For example: /home/oracle.
Tmp directory /tmp A temporary storage area. Do
notput anything here you want to
keep. SA often have a cron job to
remove everything periodically.
Boot directory /boot A small partition to hold the kernel
image(s) and boot loader
instructions.
Log directory /var/log The location of most system log
files.
Sample /etc/inittab Configuration files are located per
configuration the application. Any configuration
files file that you change after

the backup. n l y
installation should be included in

Password files /etc/passwd


/etc/shadow
e O
The /etc/passwd file holds
user information and must be

U s
readable by others; even with
encrypted passwords this can be a

A I
security hole. The /etc/shadow
file holds the encrypted passwords
O and is only readable by root.
Groups file /etc/group

l & The /etc/groups file defines


the groups on a server and the

n a users that are members of the

te r group; primary group for a user is


defined in the /etc/passwd

I n
X configuration /etc/X11/XF86Config
file.
The file that sets the X server
file

c l e settings for your video card,


monitor, mouse, and keyboard.

r a Usually set up with a vendor


supplied tool, such as sax2.
O
Oracle Database 10g: Administration Workshop II B-8
Schedule a crontab -e Use this command to edit the
command to run crontab file, to create the
at a regularly specification for the cron daemon
scheduled time to use.
Schedule a /etc/anacrontab Edit the file to specify a script to
script to run at a run at a particular frequency (see
particular man anacrontab for details).
frequency
Schedule a at <options> TIME Runs a job specified by <options>
command to run at a specified TIME parameter.
at a single
specified time
Schedule a batch <options> <TIME> Run a command when the load
command average drops below .8, optionally
after a set TIME.
Mount a file mount <opt> <dev> <mount_point> Mount a file system on device
system <dev> at <mount_point> with the
options specified by <dev>.
Unmount a file umount <dev> Unmount the file system or device.
system umount

Maximum # of 65535
<mount_point>

n l y
user ID
Recover root {lilo}
e O
This is a procedure to recover the
password control-x
linux S s
root password if is lost. This
U
requires physical access to the
passwd root
I
machine and system console. You
A
start by rebooting the machine,

O then during the LILO boot press


and hold [Ctrl] + [x] to get a
{grub}
c
l & prompt and command LILO to

n
ro root=/dev/hda8 a
kernel vmlinuz-2.4.9-13 single boot linux to runlevel S.

boot
te r
initrd /initrd-2.4.9-13.img The second procedure uses the
grub boot loader.

I n
passwd root

Create new user useradd The –D option alone shows the

c l e defaults.
–D with other options changes the

r a defaults options; without –D

O override, the default (e.g., –g) sets


a primary group.

Oracle Database 10g: Administration Workshop II B-9


Delete user userdel Remove a user and optionally all
files belonging to the user.
Modify user usermod Change /etc/password
account information.
Create new groupadd –g sets the group id; default is first
group free value above 500.
Delete group groupdel 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.
Change run init <runlevel> The init command causes the
levels rcN.d scripts to be evaluated, for
the change in run level. init 6
forces a reboot.
Synchronize the sync Forces the buffer cache and page
disks cache to write all dirty buffers to
disk. Used just before a reboot to

Shutdown the
Linux system
shutdown <mode> <delay>
prevent disk corruption.
Do a graceful shutdown of the
n l y
system, shut down processes, run

e O
all shutdown scripts, and sync
disks. The modes are –r, reboot

U s
and –h, halt. The delay is a
required parameter is a number in

A I
seconds or ‘now’. Option
shutdown warning message may

dmesg O be sent as well.


Error logs

l & View boot messages. This log is


circular, and limited system errors

n a could overwrite boot information


after a time.
Network IP
configuration scripts/
te r
/etc/sysconfig/network- This directory holds scripts
executed as part of the boot up

I n sequence by rc.sysinit.
Hosts IP

c
addresses l e/etc/hosts A list of hosts that your machine
knows about. Must at minimum

r a include the name of the local


machine and loopback IP.
O
Name service
switch
/etc/nsswitch.conf

Oracle Database 10g: Administration Workshop II B-10


Network sysctl -a | grep net View all net parameters that are
parameters set for the kernel.
Routing routed
daemon
NIC ifconfig -a Show all the network devices
Configurations currently configured.
Secondary IP modprobe ip_alias
Address ifconfig eth0:1 IP
Login prompt /etc/issue Banner message user sees when
issued the login prompt.
YP/NIS service /sbin/ypbind Finds and attaches to a NIS server
binder for name resolution and other
services.
Module modinfo <options> <module> Display information about kernel
information modules: –l shows license, –p
parameters, –d description.
List modules lsmod Show currently loaded modules.
Load module insmod Load a loadable module.
Unload module
Install Software
rmmod
rpm -ivh package
Unload a loadable module.
n
Install –i, verbose –v, with
l y
Uninstall rpm -e package
O
progress hash marks –h.

e
Erase package –e; will not
software
List installed rpm -qa
U s
uninstall if dependencies exist.
Query –q, All –a, lists all installed
software
Verify installed rpm -V package
A Ipackages.
Compares installed files with the
software
O rpm database information.
List all files rpm -ql package

l & List all the files that are part of a


package.
Package owner rpm -qf file
n a List the package when given the

Machine model uname -m


te r full file name.
Shows CPU level (e.g., i686).
OS Level
I n
uname -r Shows kernel version.
Run Level

c l e
runlevel Shows previous and current
runlevel.
Kernel
r a
Parameters
sysctl -a Show settings of all settable kernel
parameters.

O
Max # File
Descriptors
sysctl fs.file-max Shows the value of maximum
number of file descriptor per
process.

Oracle Database 10g: Administration Workshop II B-11


Kernel /etc/sysctl.conf Compiled in kernel parameters;
parameter may be reset at bootup by setting
settings them in this file.
Change Kernel echo <value> > </proc/<file> Write the new value of a kernel
Parameter parameter into the /proc file
system.
echo 2147483648 Set the value of the maximum size
>/proc/sys/kernel/shmmax
of a shared memory segment.
Shared Memory sysctl kernel.shmmax Show the shmmax parameter.
Change Kernel sysctl –w <parameter>=<value> Change a kernel parameter; the –p
Parameter option reads the setting from a file
and sets them. The default file is
/etc/sysctl.conf
Set Process ulimit <option> <value> Set limits on a shell and processes
limits 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

Show process ulimit


limits
others (see man bash).

n l y
Without options ulimit show the
current limit settings.
Interprocess
Communication
ipcs <option> O
Options: –m the current usage of
e
shared memory; –s usage of
(Shared
Memory and
s
semaphores; –a shows all.
U
Semaphores)
Remove a ipcrm shm <shmid>
A I
Releases the shared memory
shared memory
O segment identified by <shmid>.
segment
l & This is very dangerous. You can
corrupt a database that is using the

n a segment that is released.

te r
I n
c l e
r a
O
Oracle Database 10g: Administration Workshop II B-12
System Linux Commands Description / Comments
Performance
Performance top View real-time OS and process
monitor statistics.
System activity sar –<options> <interval> Options: –q shows CPU queue, –u
reporter <count> CPU utilization, –d device
activity, –n DEV network device
activity, many more (see man
page). Interval is in seconds.
Virtual Memory vmstat <interval> < count> Interval is in seconds.
statistics
Virtual Memory cat /proc/meminfo Shows instantaneous virtual
statistics memory usage.
Kernel Cache cat /proc/slabinfo Kernel slab allocator statistics:
statistics frequently allocated cache objects
such as inode, dentries, and
asynchronous IO buffers.
I/O statistics iostat <option> <interval> Options: –d device activity, –c
<count> CPU activity, –x extended disk
l y
activity statistics. The interval is in
seconds. n
Multiprocessor mpstat –P <cpu> <count>
Statistics <interval>
e O
Return CPU statistics for
particular processor or all CPUs in

Physical RAM 64 GB(Theoretical)


U s
an smp system.
Maximum physical RAM requires

A I
enterprise kernel (Red Hat
Enterprise Linux AS 21 only
O supports up to 16 GB).
Swap device swapon -s

l & Shows devices currently in use for


swap. The swap device is arbitrary

n a designated at install. It may be

te r changed or added to. Multiple


swap devices may be created;
swap size should be at least as
I n large as physical memory.

c l e
r a
O
Oracle Database 10g: Administration Workshop II B-13
Display swap free Show the current memory and
size swap usage.
Activate Swap swapon -a Turn on swap.
Free disk blocks df -k Measured in KB; use –m for MB
units.
Device listing cat /proc/devices List devices known to the system
by major and minor number.
Disk cat /proc/scsi/scsi0/sda/model View SCSI disk information.
information
cat /proc/ide/ide0/hda/model View IDE disk information.
Print network netstat <options> Print a wide variety of network
statistics statistics (see man netstat).
Graphical xosview An X-based display of recent OS
system statistics statistics.
viewer

n l y
e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
Oracle Database 10g: Administration Workshop II B-14
Misc System Linux Commands Description / Comments
Information
NFS exported /etc/exports Database file are not supported on
simple NFS.
NFS Client /var/lib/nfs/xtab
mounted
directories
Max File 2 TB with 4KB block size (on 32 With ext3 and ext2, others vary.
System kernel)

Max File Size 2 GB {512B block size} The oracle database can create
files up to 64 GB with a 16 KB
File size can not database block size.
exceed file
system 2 TB {4KB block size} The 32-bit kernel limits file and
block devices to 2 TB.
File System dumpe2fs <device> Dump the file system properties to
Block size stdout.
Filesystem table /etc/fstab Mounts these file systems at boot

Journal
Filesystem
ext3
up.

n l y
types
Disk Label
reiserfs
fdisk -l
e O
fdisk is not available on all

Extend File resize2fs


s
distributions.
U
Extending a file system is
system resize_reiserfs
A I
applicable to only some file
system types.
Backup tar cvf /dev/rst0 /
O Create a backup of the root / file

Restore tar xvf /dev/rst0


l & system.
Restore the root / file system.
Prepare boot /sbin/lilo
n a Must be run after changing
volumes

te r /etc/lilo.conf to push
changes to boot loader.
Startup script
I n
/etc/rc.d/rc
Kernel

cl
Kernel Bits e/boot/vmlinuz
getconf WORD_BIT POSIX call to get kernel

r a information. There are many other


variables besides WORD_BIT.
O
Oracle Database 10g: Administration Workshop II B-15
Boot single user {lilo} Use LILO facility.
control-x
linux S

{grub}
c Use GRUB Boot Loader.
kernel vmlinuz-2.4.9-13 single
ro root=/dev/hda8
initrd /initrd-2.4.9-13.img
boot

Time zone /etc/sysconfig/clock


Management
SW Directory /var/lib/rpm Directory where rpm database are
kept.
Devices /dev This directory holds all the device
files.
CPU cat /proc/cpuinfo Shows CPU static information.
Whole Disk /dev/sda Device name.
CDROM /dev/cdrom Usually mounted at
/mnt/cdrom.
CDROM file iso9660
type
Floppy drive /dev/fd0 Usually mounted at
/mnt/floppy.
n l y
System
information
/proc
O
The /proc filesystem is a memory-

e
based file system that allows

U s
access to process and kernel
settings and statistics.
Compile and
link a
make –f <file> <command>

A I
Use a make file <file> to
determine which parts of a large
executable
O program need to be recompiled,
and issue the commands required

l & to compile, link, and prepare the


executable for use.

n a
te r
I n
c l e
r a
O
Oracle Database 10g: Administration Workshop II B-16
LVM Linux (UnitedLinux) Description / Comments
LVM Logical Volume Manager 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.
LVM Concepts logical extents A Logical volume is made up of logical
extents.
logical volume 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.
volume group 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
List physical pvdisplay
n l y
volume
Remove disk vgreduce
e O
from volume
group
U s
Move logical
volumes to
pvmove

A I
another physical
volumes O
Create volume vgcreate
l &
group
Remove volume vgremove
n a
group
Volume group vgchange
te r
availability
I n
group
c l e
Restore volume vgcfgrestore

r a
O
Oracle Database 10g: Administration Workshop II B-17
Exports volume vgexport
group
Imports volume vgimport
group
Volume group vgscan
listing
Change logical lvchange
volume
characteristics
List logical lvdisplay
volume
Make logical lvcreate
volume
Extend logical lvextend
volume
Reduce logical lvreduce
volume
Remove logical lvremove
volume
Create striped lvcreate -i 3 -I 64
n l y
volumes

e O
U s
A I
O
l &
n a
te r
I n
c l e
r a
O
Oracle Database 10g: Administration Workshop II B-18
_________________
Appendix C:
Acronyms and
Terms
_________________

n l y
e O
U s
A I
O
l &
na
te r
I n
c le
ra
O
Term Definition Page
active session pool Number of current active sessions allowed for a 15-8
resource group or subplan
ADDM Automatic Database Diagnostic Management 13-3
ASM Automated Storage Management 13-22 to
13-43
ATO Automatic Tuning Optimizer 13-9
Automated Storage Provides a vertical integration of the file system and 5-9,13-22
Management the volume manager specifically built for the Oracle to 13-43
database files
Automatic Database A utility that does a top-down instance analysis, 13-3
Diagnostic Management identifies problems and potential causes, and gives
recommendations for fixing the problems
Automatic Tuning A database feature that performs various analysis of 13-9
Optimizer SQL performance within the database
Automatic Workload Collects, processes, and maintains performance 13-7
Repository statistics for problem detection and self-tuning
purposes.
auxiliary database Used when creating a duplicate database or performing 5-5
tablespace point-in-time recovery
AWR
backup piece
Automatic Workload Repository
An individual file that is part of a backup set. l
13-7

n
6-8
y
backup set
O
Copy of one or more data or archived log files. Differs
from image copies in that empty blocks are not stored.
e
6-8

block change tracking

U s
Uses the change tracking writer (CTWR) background
process to record the physical location of all database
6-23

CFS
change tracking file
changes in a separate file.
Cluster File Storage
A I
File used to store the physical location of database
5-9
6-23
O
changes made since the last backup.

l&
channel A link or connection to a target database. 5-6
CLI command-line interpreter
control file
r na
Contains information about the physical structure of
the database including the locations of all data and
8-5, 8-7

data block
nt e
redo log files.
The smallest unit of physical storage within the 12-3

e I database. Data Blocks contain rows of data, index

data file
c l information, etc.
Contains the data for the database

r
Scanner
a
Database Character Set A utility that assesses the feasibility of migrating an
Oracle database to a new database character set.
2-34

DBA
DBA
O Database Administrator
data block address, used to uniquely identify a data 12-3
block within the database

Oracle Database 10g: Administration Workshop II C-2


Term Definition Page
DBCA Database Configuration Assistant 2-7, 13-42
DBVERIFY An external command-line utility that performs a 12-5
physical data structure integrity check on an offline
database
DDL Data Definition Language. The class of SQL 2-37
statements that define and manipulate database
objects.
DML Data Manipulation Language. The class of SQL
statements that query and manipulate data.
Dynamic SQL SQL statements that can be created dynamically at run 17-9
time by using variables
EM Enterprise Manager
emctl Enterprise Manager Control. Utility for starting,
stopping, and checking the status of Database Control,
the Oracle Agent, and Oracle Management Servers.
encoded character set An encoded character set maps numeric codes to 2-4
characters that a computer or terminal can display and
receive.
Enterprise Manager A graphical interface used to manage the database.
Database Control Console
external table Tables used to access data in external sources, such as 17-14

flash recovery area


flat files, as if it were in a table in the database
A unified storage location for all recovery related files
n l y
5-9, 10-11,
and activities in an Oracle database

e O 10-16,to
10-18
flashback buffer
data.
U s
An area in memory that stores Flashback Database 10-8

Flashback Database

Flashback Drop
I
A new recovery method that uses Undo data to recover

A
the database instead of Redo data.
A feature that allows you to undo the effects of a
10-6 to 10-
8
11-4
O
DROP TABLE statement without resorting to

Flashback Table &


traditional point-in-time recovery
l
A command that allows you to recover a table and all 11-9
a
of its dependent objects from the recycle bin
n
Flashback Transaction
Query
te r
A diagnostic tool you can use to view changes made to
the database at the transaction level
11-22

Flashback Versions
Query
e In Provides a history of changes made to a row along
with the corresponding identifier of the transaction that
11-24

c l
format mask elements
made the change
A character literal that describes the format of 2-24

r a
growth trend report
datetime or numeric data stored in a character string.
Analysis of the growth of database segments 13-16, 13-
O
Globalization support Ensures that utilities and error messages, sort order,
18
2-3
date, time, monetary, numeric, and calendar

Oracle Database 10g: Administration Workshop II C-3


Term Definition Page
conventions automatically adapt to the native
language.
image copy A bit-for-bit identical copy of a database file. 6-8
incarnation A separate version of a physical database. The 9-8
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.
init.ora or init<sid>.ora Same as parameter file

instance The collection of shared memory and processes used


to access the Oracle Database
isqlplusctl Control utility for starting and stopping iSQL*Plus 2-45
listener processes
jnnn Job Queue Processes. Execute scheduled jobs 16-5
Language and Character A statistic-based utility for determining the language 2-34
Set File Scanner and character set for unknown file text.
LCSSCAN Language and Character Set File Scanner 2-34
LEGATO® NetWorker, Software included with Oracle Database 10g the 5-8
Single-Server Version enables the Recovery Manager utility to write to tape
drives
linguistic sort Produces a sort sequence that matches the alphabetic
sequence of characters, not their numeric values in the l
2-25
n y
listener
character encoding scheme

e O
The gateway to the Oracle instance for all non-local 3-3, 4-3

locale
user connections.

U s
A collection of information about the linguistic and 2-21

locale variants I
cultural preferences from a particular region

A
A language-dependent territory definition 2-21
LSSV
media management O
LEGATO® NetWorker, Single-Server Version
Used by RMAN when writing to or reading from tapes
5-8
5-6
library
metric l &
A measurement of some database or instance 7-7, 13-30,

n a
characteristic. 13-31
MML
MMON
te r
Media Management Library
Management Monitor Process. Issues alerts whenever
5-6
7-7

I n a metric violates its threshold value. Captures statistics


for SQL objects which have been recently modified.
National Language
Support
cle Parameters and files that determine the locale-specific
behavior of the database client and the database server
2-13

NLS
r a National Language Support 2-13

O
NLS Runtime Library A comprehensive suite of language-independent
functions that allow proper text and character
processing and language convention manipulations
2-19

Oracle Database 10g: Administration Workshop II C-4


Term Definition Page
NLS_LANG Environment variable used to specify the language, 2-18
territory and characterset used by a database.
NLSRTL National Language Support Runtime Library 2-19
Non-critical files Files that the database and most applications can 8-3
operate without
OMF Oracle Managed Files 5-9, 8-10,
13-43
Oracle Locale Builder Provides a graphical user interface through which you 2-33
can easily view, modify, and define locale-specific
data.
Oracle Managed Files A feature of the Oracle database which manages the 5-9
creation, naming and deletion of Oracle database files
within dedicated areas of disk
Oracle Net Enables network connections between the Oracle 4-3
Database 10g and client or middle tier applications
ORACLE_BASE Environment variable used to point to the base of the
OFA structure
ORACLE_HOME Environment variable used to identify a directory
containing Oracle software
ORACLE_SID Environment variable used to specify the default 5-14
database instance name
package A collection of procedures and function definitions
that are logically related. The procedures and functions
n l y
parallelization
are implemented by the package body.
Allocating multiple channels for RMAN backup and
e O 5-4

PGA
recovery operations.

U s
Program Global Area. Private memory area for use by 13-3,

PGA Advisor
a process.

A I
Gives detailed statistics for the work areas, and
provides recommendations about optimal usage of
13-3, 13-
15
O
Program Global Area (PGA) memory based on

pipe &
workload characteristics.
l
An area of memory used by one process to pass 6-3
a
information to another.
n
PL/SQL

te r
Procedural Language/Structured Query Language.
Adds structured programming capability to SQL.
17-6

privilege

e In The right to execute a particular type of SQL


statement. There are two basic forms of privileges,
16-6

procedure
c l object and system.
A PL/SQL program that performs a specific action. 17-5
RECO
r a Recoverer Process. Automatically resolves failures in
distributed transactions (transactions distributed across
4-17

O
recovery catalog
multiple databases)
A separate database that keeps historical data 5-6
concerning backup activities

Oracle Database 10g: Administration Workshop II C-5


Term Definition Page
Recovery Manager The Oracle utility used to back up and restore database 5-5
files.
Resource Manager
resumable space A means for suspending, and later resuming, the 17-19
allocation execution of large database operations in the event of
space allocation failures
RMAN Recovery Manager 5-5
RMAN Repository A storage structure that maintains metadata about a 5-6
database's backup and recovery operations.
Scheduler A new database feature that enables database 16-3
administrators and application developers to control
when and where various tasks take place in the
database environment
SCN System Change Number
Segment Advisor Monitors object space issues and analyzes growth 13-3, 13-
trends 16, 13-17
server sessions The server processes (UNIX) or threads (Windows 5-5
NT/2000) invoked by a client utility to connect to the
target database
SGA System Global Area. Memory area shared by all server
and background processes
SGA Advisor
SID
Gives recommendatations for SGA parameter settings
System Identifier. Defaults to the database name and l y
13-15
n
SQL Structured Query Language
e O
uniquely identifies the instance on a given server.

SQL Access Advisor


materialized views
U s
Determines optimal data access paths like indexes and 13-3, 13-
12, 13, 14
SQL Tuning Advisor

A I
Provides tuning advice for SQL statements 13-3, 13-
9,10,11
tablespace
target database O
A logical grouping of datafiles
The database you are attempting to connect to.
5-16
4-3
threshold
compared. l &
A boundary value against which metric values are 7-8

Undo Advisor
n a
A feature of Enterprise Manager that suggests 13-3, 13-

te r
parameter values and the amount of additional space
that is needed to support flashback for a specified
20, 13-21

undo data I n time.


A copy of original data stored whenever a DML

c l e transaction will change data. Undo data is used to


rollback a transaction and to provide read consistent

r a
workload repository
views of changing data.
See AWR.
O
Oracle Database 10g: Administration Workshop II C-6

Potrebbero piacerti anche