Lab Guide D62545
Lab Guide D62545
Lab Guide D62545
Administration Workshop II
Volume III Student Guide
e
d
a
D50079GC20
Edition 2.0
September 2010
D62545
a
r
O
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
c
A
Author
Maria Billings
Disclaimer
Technical Contributors
and Reviewers
Christian Bauwens
Yanti Chang
Timothy Chien
Joe Fong
Andy Fortunak
Gerlinde Frenzen
Mark Fuller
Peter Fusek
Joel Goodman
Vimala Jacob
Dominique Jeunot
Pete Jones
Fukue Kawabe
Donna Keesling
Sean Kim
Achiel Langers
y
m
Gwen Lazenby
e
d
a
Jerry Lee
Deidre Matishak
Bill Millar
Lakshmi Naraparreddi
Ira Singer
Ranbir Singh
James Spiller
Matt Taylor
Branislav Valny
Jean-Francois Verrier
Editors
Nita Pavitran
Raj Kumar
Graphic Designer
e
l
c
Satish Bettegowda
Publisher
a
r
O
Jayanthy Keshavamurthy
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
Contents
Introduction
Course Objectives I-2
Suggested Schedule I-3
Oracle Database 11g: g Stands for Grid I-4
Grid Infrastructure for Single-Instance I-6
Course Examples: HR Sample Schema I-8
e
d
a
y
m
e
l
c
a
r
O
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
iii
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
c
A
e
l
c
a
r
O
iv
e
d
a
e
d
a
y
m
e
l
c
a
r
O
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
v
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
vi
c
A
e
d
a
y
m
Quiz 6-24
Summary 6-26
7
y
m
e
d
a
e
l
c
a
r
O
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
vii
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
viii
y
m
c
A
e
d
a
e
d
a
y
m
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
ix
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
c
A
e
d
a
13 Managing Memory
Objectives 13-2
Memory Management: Overview 13-3
Reviewing Oracle Database Memory Structures 13-4
Buffer Cache 13-6
Using Multiple Buffer Pools 13-8
Shared Pool 13-10
Large Pool 13-11
Java Pool and Streams Pool 13-12
Redo Log Buffer 13-13
Automatic Memory Management: Overview 13-14
Oracle Database Memory Parameters 13-15
Monitoring Automatic Memory Management 13-16
Efficient Memory Usage: Guidelines 13-18
Memory Tuning Guidelines for the Library Cache 13-20
Automatic Shared Memory Management: Overview 13-22
How ASMM Works 13-23
Enabling Automatic Shared Memory Management 13-24
Disabling ASMM 13-25
Program Global Area (PGA) 13-26
Using the V$PARAMETER View 13-28
Quiz 13-29
Summary 13-30
Practice 13 Overview: Using AMM to Correct a Memory Allocation Problem 13-31
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
xi
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
16 Managing Resources
Objectives 16-2
Database Resource Manager: Overview 16-3
Database Resource Manager: Concepts 16-4
Why Use Resource Manager 16-5
Default Maintenance Resource Manager Plan 16-7
e
l
c
a
r
O
xii
c
A
e
d
a
y
m
16-22
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
xiii
c
A
e
d
a
y
m
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
xiv
y
m
c
A
e
d
a
e
d
a
y
m
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
xv
c
A
20 Duplicating a Database
Objectives 20-2
Using a Duplicate Database 20-3
Choosing Database Duplication Techniques 20-4
Duplicating an Active Database 20-5
Duplicating a Database with a Target Connection 20-6
Duplicating a Database with Recovery Catalog Without Target Connection 20-7
Duplicating a Database Without Recovery Catalog or Target Connection 20-8
Creating a Backup-Based Duplicate Database 20-9
Creating an Initialization Parameter File for the Auxiliary Instance 20-10
Specifying New Names for Your Destination 20-11
Using the SET NEWNAME Clauses 20-12
Substitution Variables for SET NEWNAME 20-13
Specifying Parameters for File Naming 20-14
Starting the Instance in NOMOUNT Mode 20-16
Ensuring That Backups and Archived Redo Log Files Are Available 20-17
Allocating Auxiliary Channels 20-18
Understanding the RMAN Duplication Operation 20-19
Specifying Options for the DUPLICATE Command 20-21
Using Additional DUPLICATE Command Options 20-22
Using EM to Clone a Database 20-23
Quiz 20-24
Summary 20-25
Practice 20 Overview: Duplicating a Database 20-26
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
xvi
e
d
a
y
m
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
xvii
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
xviii
y
m
c
A
e
d
a
Appendix A
Practices and Solutions
y
m
e
d
a
a
r
O
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
Table of Contents
Practices for Lesson 1 ......................................................................................................... 4
Practice 1-2: Reviewing the Database Architecture ............................................... 5
Practices for Lesson 2 ......................................................................................................... 6
Practice 2-1: Configuring ARCHIVELOG Mode .................................................. 6
Practice 2-2: Resizing the Flash Recovery Area..................................................... 8
Practice 2-3: Verifying the Backup Destination ................................................... 12
Practice 2-4: Configuring the Retention Policy .................................................... 15
Practices for Lesson 3 ....................................................................................................... 16
Practice 3-1: Creating a Recovery Catalog ........................................................... 16
Practice 3-2: Creating the Recovery Catalog Owner ............................................ 24
Practice 3-3: Creating the Recovery Catalog ........................................................ 25
Practice 3-4: Registering a Database in the Recovery Catalog............................. 26
Practice 3-5: Backing up the Recovery Catalog ................................................... 29
Practices for Lesson 4 ....................................................................................................... 33
Practice 4-1: Setting the Date and Time Format for RMAN ................................ 33
Practice 4-2: Enabling Control File Autobackup .................................................. 35
Practice 4-3: Configuring Devices for Backup ..................................................... 37
Practices for Lesson 5 ....................................................................................................... 39
Practice 5-1: Creating Fast Incremental Backups ................................................. 39
Practice 5-2: Cross-Checking Backups ................................................................. 42
Practice 5-3: Listing Backup Files and Creating Archival Backup ...................... 47
Practices for Lesson 6 ....................................................................................................... 58
Practice 6-1: Backing up the Database ................................................................. 58
Practice 6-2: Recovering from the Loss of a Data File ......................................... 61
Practice 6-3: Recovering from the Loss of all Control Files ................................ 66
Practice 6-4: Recovering from the Loss of a Redo Log Group ............................ 71
Practices for Lesson 7 ....................................................................................................... 75
Practice 7-1: Recovering Image Copies ................................................................ 75
Practice 7-2: Performing Fast Recovery ............................................................... 83
Practices for Lesson 8 ....................................................................................................... 90
Practice 8-1: Monitoring RMAN Jobs .................................................................. 90
Practices for Lesson 9 ....................................................................................................... 93
Practice 9-1: Diagnostic Scenario ......................................................................... 94
Practice 9-2: Repairing Block Corruption .......................................................... 109
Practices for Lesson 10 ................................................................................................... 116
Practice 10-1: Flashback Transaction Backout ................................................... 117
Practices for Lesson 11 ................................................................................................... 118
Practice 11-1: Using Flashback Data Archive .................................................... 119
Practice 11-2: Using the Recycle Bin ................................................................. 133
Practices for Lesson 12 ................................................................................................... 138
Practice 12-1: Flashback Database ..................................................................... 139
Practices for Lesson 13 ................................................................................................... 146
Practice 13-1: Using Automatic Memory Management ..................................... 147
Practices for Lesson 14 ................................................................................................... 166
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
The paper practices for this lesson are embedded in the lesson itself, to facilitate
reviewing the database architecture for yourself and in class. Below are possible answers.
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
Shared pool
Large pool
Java pool
Streams pool
nK buffer pool
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
e
d
a
c
A
3) The graphic on slide 1-8 is the answer to the task on slide 1-7.
For page 1-14: Adding Process Names
1) The DBWn process writes the dirty buffers to the data files.
2) The LGWR process writes the redo entries to the online redo log files.
3) The CKPT process writes checkpoint information in the control file and each data file
header.
4) The SMON process performs recovery on instance startup.
5) The PMON process performs process recovery when a user process fails.
e
l
c
a
r
O
7) The ARCn processes copy redo log files to a designated storage device.
y
m
2) Use labs as your working directory. Unless otherwise indicated, always work from
that directory.
e
d
a
$ cd ~/labs
c
A
$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Tue Jul 21 14:32:29
2009
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> archive log list
Database log mode
Automatic archival
Archive destination
Oldest online log sequence
Current log sequence
SQL>
a
r
O
e
l
c
No Archive Mode
Disabled
USE_DB_RECOVERY_FILE_DEST
6
8
4) Because you can change the ARCHIVELOG mode only when the database is
mounted, shut down the database.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
481259520
1337324
339740692
134217728
5963776
bytes
bytes
bytes
bytes
bytes
y
m
Database altered.
e
d
a
SQL>
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
Database altered.
SQL>
e
l
c
c
A
a
r
O
TYPE
----------string
big integer
VALUE
------------+FRA
4062
Note that the Flash Recovery Area is in the FRA disk group.
y
m
e
d
a
c
A
Note: The first time that you are using a newly configured machine, you may be asked to
add a security exception. The exact formulation and number of pages depends on your
web browser. Follow the prompts and add the exception in the training environment.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
Note 2: Also if Enterprise Manager shows, that the database is down, wait a minute and
refresh the page. (This can occur due to the time intervals in which the database agent
works.)
4) On the database home page, click the +ASM_<hostname> link.
e
l
c
a
r
O
6) If prompted for ASM login credentials, enter sys as username and oracle_4U as
password. Connect as SYSASM, click Save as Preferred Credential, and then click
Login.
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
7) When the disk group list appears, note the Usable Free column for the FRA disk
group.
e
l
c
a
r
O
Note that the FRA disk group has enough usable free space to enlarge the Flash
Recovery Area considerably, although your displayed values may be a little different.
8) Change the Flash Recovery Area size to 6 GB.
a) Navigate to Database > Availability > Recovery Settings and change the Flash
Recovery Area Size to 6 GB.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
b) Click Show SQL, and note the SQL that will be run. This is important to know
because if the Flash Recovery Area is having sizing problems, you may not be
able to run Enterprise Manager to change it.
ALTER SYSTEM SET db_recovery_file_dest_size = 6442450944 SCOPE=BOTH
e
l
c
a
r
O
9) Verify the size of the Flash Recovery Area by using SQL*Plus. Then exit your
SQL*Plus session.
SQL> show parameter recovery_file_dest_size
NAME
TYPE
VALUE
------------------------------------ ----------- ------------db_recovery_file_dest_size
big integer 6G
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining
and Real Application Testing options
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
In this practice, you test the backup destination to see where backups are written.
Use the oraenv script to ensure you are still using the orcl instance in your terminal
session.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
1) Start RMAN.
$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Jul
21 14:52:20 2009
Copyright (c) 1982, 2009, Oracle and/or its affiliates.
rights reserved.
All
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
3) Configure RMAN to automatically back up the control file when any backups are
done.
RMAN> configure controlfile autobackup on;
4) List the database files in your schema, to understand which file you back up in the
next task.
e
l
c
ra
y
m
Note: If you are not connected to the recovery catalog, the RB segs column contains
*** as a value. It contains the YES and NO values when you are connected to the
recovery catalog.
e
d
a
c
A
6) Take a backup of data file 5, and note where the backup is written, then exit.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
2) Return to the RMAN session (or if you closed it, start a new one) and show the
current retention policy setting.
$ rman target /
RMAN> show retention policy;
RMAN configuration parameters for database with db_unique_name
ORCL are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
RMAN>
3) If your redundancy is 1, go to step 5 and exit. If your redundancy had another value,
change it to ensure that one copy of each file is backed up.
RMAN> configure retention policy to redundancy 1;
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
c
A
5) Exit RMAN.
RMAN> exit
e
l
c
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
6) On the Management Options page, deselect the Configure Enterprise Manager option,
and then click the Automatic Maintenance Tasks tab.
e
l
c
a
r
O
8) On the Database Credentials page, select the option Use the Same Administrative
Password for All Accounts. Then enter oracle_4U in the password fields and click
Next.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
e
d
a
y
m
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
12) On the Database Content page, confirm that the Sample Schemas option is not
selected, and then click Next.
a
r
O
e
d
a
y
m
13) On the Initialization Parameter page, set the memory size to 303 MB, click Use
Automatic Memory Management, and then click the Character Sets tab.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
y
m
e
d
a
c
A
15) If the Security Settings page appears, keep the defaults, and then click Next.
16) On the Database Storage page, review the configuration, and then click Next.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
17) On the Creation Options page, make sure that Create Database is the only option
selected, and then click Finish.
e
l
c
a
r
O
18) Review the Confirmation page, and then click OK to start the database creation
process.
e
d
a
y
m
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
y
m
20) When the Database Configuration Assistant finishes running, view the final page, and
then click Exit.
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
In this practice, you configure the recovery catalog database with a user ID and
appropriate privileges, and register a database.
1) Use SQL*Plus to configure the recovery catalog database. Connect to it as SYS to the
RCAT database.
$ sqlplus sys as sysdba
Enter password: oracle_4U@rcat
<<<not displayed
SQL>
2) Create a tablespace named RCAT to hold the repository data. Make it 15 MB in size.
SQL> CREATE TABLESPACE rcat DATAFILE '+DATA/rcat01.dbf' SIZE 15M;
Tablespace created.
SQL>
3) Create a user who will own the recovery catalog data. Name the user RCATOWNER.
The default tablespace should be the RCAT tablespace, and the user should have
unlimited quota on that tablespace.
SQL> CREATE USER rcatowner IDENTIFIED BY "oracle_4U"
2 DEFAULT TABLESPACE rcat QUOTA unlimited on rcat;
User created.
SQL>
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
e
d
a
a
r
O
y
m
In this practice, you create the recovery catalog inside the recovery catalog database you
have prepared.
1) Connect to the recovery catalog database using RMAN. Log in as the recovery
catalog owner you just created.
$ rman catalog rcatowner@rcat
Recovery Manager: Release 11.2.0.1.0 - Production on Fri Jul
10 19:54:04 2009
Copyright (c) 1982, 2009, Oracle and/or its affiliates.
rights reserved.
All
2) Create the recovery catalog. This command may take several minutes to complete.
RMAN> create catalog;
y
m
e
d
a
RMAN> exit
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
In this practice, you register the ORCL database in the recovery catalog that you have just
created.
1) Set up the environment for the ORCL database.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
2) Connect to the target database (to be registered) and the recovery catalog database
using RMAN.
$ rman target / catalog rcatowner@rcat
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Jul
21 15:30:32 2009
Copyright (c) 1982, 2009, Oracle and/or its affiliates.
rights reserved.
All
y
m
RMAN>
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
RMAN> exit
e
l
c
e
d
a
a
r
O
<your_hostname>
1521
rcat
rcatowner
oracle_4U
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e) Back on the Recovery Catalog Settings page, select Use Recovery Catalog. Make
sure that the recovery catalog you just registered is selected in the drop-down list,
and enter the following values:
Recovery Catalog Username:
Recovery Catalog Password:
a
r
O
e
l
c
Username:
Password:
rcatowner
oracle_4U
oracle
oracle
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
In this practice, you configure the retention policy for the recovery catalog and back up
your recovery catalog itself.
1) Set up the environment for the ORCL database.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
2) Start RMAN, use the recovery catalog database as the target, with no catalog
specified.
$ rman target sys@rcat
target database Password: oracle_4U <<< not displayed
connected to target database: RCAT (DBID= 464959795)
RMAN>
3) Make sure that the retention policy for the recovery catalog is set to redundancy
greater than 1. If it is not, set it to at least 2.
RMAN> show retention policy;
y
m
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
e
l
c
a
r
O
Note that you cannot back up an open database that is not in ARCHIVELOG mode.
The recovery catalog database should be run in ARCHIVELOG mode for maximum
availability.
5) Exit RMAN.
e
d
a
RMAN> exit
6) First, set up the environment for the RCAT database and then run the
rcat_to_archivelog.sh script to change the recovery catalog database to
run in ARCHIVELOG mode.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
$ . oraenv
ORACLE_SID = [orcl] ? rcat
c
A
$ cd ~/labs
$ ./rcat_to_archivelog.sh
Database closed.
Database dismounted.
ORACLE instance shut down.
ORACLE instance started.
Total System Global Area
Fixed Size
Variable Size
Database Buffers
Redo Buffers
Database mounted.
e
l
c
y
m
263639040
1299164
230690084
25165824
6483968
bytes
bytes
bytes
bytes
bytes
a
r
O
Database altered.
Database altered.
$
Oracle Database 11g: Administration Workshop II A - 30
9) Back up the recovery catalog database. This time the operation should be
successful.
RMAN> backup database;
Starting backup at 21-JUL-09
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=40 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DATA/rcat/system01.dbf
input datafile file number=00002 name=+DATA/rcat/sysaux01.dbf
input datafile file number=00003 name=+DATA/rcat/undotbs01.dbf
input datafile file number=00005 name=+DATA/rcat01.dbf
input datafile file number=00004 name=+DATA/rcat/users01.dbf
channel ORA_DISK_1: starting piece 1 at 21-JUL-09
channel ORA_DISK_1: finished piece 1 at 21-JUL-09
piece
handle=+FRA/rcat/backupset/2009_07_21/nnndf0_tag20090721t15532
5_0.263.692812405 tag=TAG20090721T155325 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time:
00:02:37
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 21-JUL-09
channel ORA_DISK_1: finished piece 1 at 21-JUL-09
piece
handle=+FRA/rcat/backupset/2009_07_21/ncsnf0_tag20090721t15532
5_0.264.692812569 tag=TAG20090721T155325 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time:
00:00:03
Finished backup at 21-JUL-09
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
RMAN> exit
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining
and Real Application Testing options
SQL>
System altered.
SQL>
System altered.
SQL> Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> ORACLE instance started.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
e
l
c
a
r
O
y
m
In this practice, you set the date/time format that RMAN uses for displaying timestamps.
1) Set the NLS_LANG and NLS_DATE_FORMAT variables such that RMAN includes
time information in any timestamp values. Add the following two lines to the
~oracle/.bashrc file. Then exit all of your terminal windows. This ensures that
when you create new ones, these settings will be in effect.
export NLS_LANG=american_america.al32utf8
export NLS_DATE_FORMAT="yyyy-mm-dd:hh24:mi:ss"
2) Start a new terminal window, and verify the settings by starting RMAN and listing
the backups of the recovery catalog database.
a) Set up the environment for the ORCL database.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
b) Log in to RMAN.
$ rman target sys@rcat
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
c
A
e
l
c
a
r
O
Practice 4-1: Setting the Date and Time Format for RMAN
(continued)
Control File Included: Ckp SCN: 803770
07-21:15:41:59
.
.
.
RMAN>
Note: Because the output of the RMAN commands can be quite long, consider using the
RMAN SPOOL LOG command to direct the output to your specified file.
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
In this practice, you configure RMAN to back up the control file and SPFILE each time it
takes a backup of anything in the RCAT database.
1) In the same recovery catalog RMAN session, make sure that control file autobackup
is enabled.
RMAN> show controlfile autobackup;
RMAN configuration parameters for database with db_unique_name
RCAT are:
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
RMAN>
y
m
3) Verify that it is enabled by backing up the archive logs for the recovery catalog. Then
exit RMAN.
RMAN> backup archivelog all;
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
Note that the control file and SPFILE are automatically backed up now.
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
In this practice, you configure a tape device for use in making backups.
Note: This channel definition is used in the RMAN monitoring and tuning practice.
Therefore, steps 1-4 are mandatory; step 5 (performing a backup) is recommended, but
optional.
1) Make sure the SID variable is set to ORCL.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
2) Start RMAN by connecting to the ORCL as the target database and using the recovery
catalog database.
$ rman target / catalog rcatowner@rcat
recovery catalog database Password: oracle_4U <<<not displayed
RMAN>
3) Show all configuration settings to see whether there are any tape devices defined.
RMAN> show all;
RMAN configuration parameters for database with db_unique_name
ORCL are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
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 ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE
'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO
'/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f'; #
default
y
m
e
d
a
e
l
c
RMAN>
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
4) Define a channel for a tape device that uses the test interface. This actually writes to
disk in the /tape directory.
Oracle Database 11g: Administration Workshop II A - 37
5) Perform a backup to the tape device to make sure it works. Back up the USERS
tablespace. Then exit RMAN.
RMAN> backup device type sbt tablespace users;
Starting backup at 2009-07-21:16:32:09
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: SID=53 device type=SBT_TAPE
channel ORA_SBT_TAPE_1: WARNING: Oracle Test Disk API
channel ORA_SBT_TAPE_1: starting full datafile backup set
channel ORA_SBT_TAPE_1: specifying datafile(s) in backup set
input datafile file number=00004
name=+DATA/orcl/datafile/users.259.692754561
channel ORA_SBT_TAPE_1: starting piece 1 at 2009-0721:16:32:10
channel ORA_SBT_TAPE_1: finished piece 1 at 2009-0721:16:32:11
piece handle=05kkn0sa_1_1 tag=TAG20090721T163210 comment=API
Version 2.0,MMS Version 8.1.3.0
channel ORA_SBT_TAPE_1: backup set complete, elapsed time:
00:00:01
Finished backup at 2009-07-21:16:32:11
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
In this practice, you enable block change tracking so that you can make incremental
backups more quickly.
1) Use Enterprise Manager Database Control to configure backup optimization and
enable block change tracking. Allow a default block change tracking file to be used.
a) From the Database home page of EM, navigate to Availability > Backup Settings
> Policy, and enable backup optimization and block change tracking.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
b) Click OK.
c) If you see the following error, you have not entered the operating system
credentials. Continue with the following steps if that is the case.
d) Scroll to the bottom of the page, and enter oracle as username and oracle as
password. Also, select the option to save this as the preferred credential.
e
l
c
a
r
O
e) Click OK.
2) Make sure that the ORACLE_SID variable is set to ORCL.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
4) Now that you have a level 0 incremental backup, you can take advantage of block
change tracking to make fast incremental backups. Take a level 1 incremental backup.
RMAN> backup incremental level 1 database plus archivelog;
e
l
c
a
r
O
5) In another terminal window, make sure you are at the ~/labs directory.
$ cd ~/labs
y
m
e
d
a
c
A
2
3
4
5
6
7
8
FILE# AVG(DATAFILE_BLOCKS) AVG(BLOCKS_READ)
PCT_READ_FOR_BACKUP AVG(BLOCKS)
---------- -------------------- ---------------- ------------------ ----------1
87040
173
.198759191
34
2
75520
957
1.26721398
344
5
12800
1
.0078125
1
4
640
1
.15625
1
3
12800
311
2.4296875
96
$
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
Note that the percentage of blocks read for making the backup is very low in most cases,
and sometimes very close to zero.
a
r
O
In this practice, you cross-check backups against the recovery catalog, identifying and
deleting any backups that are obsolete.
1) Make sure that you are at the ~/labs directory, and that the ORACLE_SID variable
is set to ORCL.
$ cd ~/labs
$ . oraenv
ORACLE_SID = [orcl] ? orcl
2) Use the RMAN session from the previous practice or start RMAN. Make sure that
you connect to both your target database and the recovery catalog database.
$ rman target / catalog rcatowner@rcat
connected to target database: ORCL (DBID=1220535480)
recovery catalog database Password: oracle_4U <<<not displayed
connected to recovery catalog database
RMAN>
3) List backups of data file 5, noting the entry corresponding to the example data file.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
ra
Take note of the only backup that is a full backup of data file 5. Also note that the
Piece Name is the name of the ASM file where the backup file resides.
4) In an OS terminal window, delete the backup set file. Start a separate terminal
session, so the RMAN session can stay connected. Use the +ASM environment
variables, review and execute the rm_asm_file.sh script to do this. Supply
YOUR full Piece Name as an argument to the script.
$ . oraenv
ORACLE_SID = [orcl] ? +ASM
$ cat rm_asm_file.sh
export ORACLE_SID=+ASM
asmcmd <<-EOI
rm -f $1
exit
EOI
Exit
./rm_asm_file.sh \
y
m
e
d
a
c
A
> +FRA/orcl/backupset/2009_07_21/nnndf0_tag20090721t145358_0.260.692808839
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
ASMCMD> ASMCMD> $
$
5) In your still connected RMAN session, list the backups again, and look for the backup
that corresponds to the example data file.
RMAN> list backup of datafile 5;
List of Backup Sets
===================
e
l
c
a
r
O
y
m
e
d
a
RMAN>
Note that the backups are still listed as before. That is because the repository is not
aware of the fact that the file for the backup piece is missing.
c
A
6) Cross-check the backup sets to make the recovery catalog aware of the missing
backup file.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
RMAN>
y
m
8) List the backup sets again. See that the backup you just deleted is no longer listed.
RMAN> list backup of datafile 5;
List of Backup Sets
===================
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
a
r
O
e
l
c
BS Key
Time
Type LV Size
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
1) Continue to use the RMAN session from the previous practice, and generate a report
of all the obsolete backup files.
RMAN> report obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of obsolete backups and copies
Type
Key
Completion Time
Filename/Handle
-------------------- ------ ------------------ ------------------Backup Set
38
2009-07-21:14:54:16
Backup Piece
41
2009-07-21:14:54:16
+FRA/orcl/autobackup/2009_07_21/s_692808854.261.692808857
Backup Set
68
2009-07-21:16:29:17
Backup Piece
71
2009-07-21:16:29:17 03kkn0mt_1_1
Backup Set
77
2009-07-21:16:29:22
Backup Piece
79
2009-07-21:16:29:22 c-122053548020090721-01
Backup Set
93
2009-07-21:16:32:10
Backup Piece
96
2009-07-21:16:32:10 05kkn0sa_1_1
Archive Log
151
2009-07-21:17:49:04
+FRA/orcl/archivelog/2009_07_21/thread_1_seq_9.268.692819337
Backup Set
105
2009-07-21:16:32:14
Backup Piece
107
2009-07-21:16:32:14 c-122053548020090721-02
Archive Log
163
2009-07-21:19:02:49
+FRA/orcl/archivelog/2009_07_21/thread_1_seq_10.269.692823767
Backup Set
171
2009-07-21:19:02:53
Backup Piece
175
2009-07-21:19:02:53
+FRA/orcl/backupset/2009_07_21/annnf0_tag20090721t190251_0.270
.692823773
Backup Set
205
2009-07-21:19:06:06
Backup Piece
207
2009-07-21:19:06:06
+FRA/orcl/autobackup/2009_07_21/s_692823962.274.692823965
RMAN>
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
Your list of files might look different. - What can you deduce about these backup
files, given that the retention policy is set to REDUNDANCY 1?
2) Which backups would be considered obsolete if the retention policy were set to
redundancy of 2, instead of 1? Answer this without changing the retention policy.
RMAN> report obsolete redundancy 2;
e
l
c
a
r
O
Note that far fewer backups are obsolete in this hypothetical report. That is because
with an increased redundancy, more of the backups are required. This command is
run without affecting the retention policy.
3) Delete all obsolete backups.
RMAN> delete noprompt obsolete;
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
RMAN>
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
BS Key Size
Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -----------------236
277.00K
DISK
00:00:01
2009-0721:19:10:29
BP Key: 240
Status: AVAILABLE Compressed: NO Tag:
TAG20090721T191028
Piece Name:
+FRA/orcl/backupset/2009_07_21/annnf0_tag20090721t191028_0.276
.692824229
e
l
c
ra
Next SCN
Next
y
m
e
d
a
RMAN>
c
A
5) List the image copies of the single data file in the USERS tablespace.
a) Report on the schema to find out which data file number belongs to the USERS
tablespace.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
Key
File S Completion Time
Ckp SCN
Ckp Time
------- ---- - ------------------- ---------- -----------------115
4
A 2009-05-27:21:08:45 1917108
2009-0527:20:50:57
Name: /tmp/users_copy.dat
Do you really want to delete the above objects (enter YES or
NO)? yes
e
l
c
a
r
O
RMAN>
7) To simplify your training environment, disable control file autobackup for the next
few steps.
RMAN> configure controlfile autobackup off;
old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
RMAN>
e
d
a
y
m
RMAN>
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
9) Make another image copy of the data file, but make this one an archival backup.
RMAN> backup as copy datafile 4 keep forever;
Starting backup at 2009-07-21:20:28:30
current log archived
e
l
c
a
r
O
Note that the backup command failed. This is because a backup with the KEEP
attribute (an archival backup) cannot be written to the Flash Recovery Area. Allowing
this has the potential of causing the Flash Recovery Area to quickly run out of space,
forcing you to specify a different location.
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
e
d
a
y
m
RMAN>
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
11) See if there are any obsolete backups. (If you repeat practice steps you might have
obsolete ones.)
RMAN> report obsolete;
e
l
c
a
r
O
y
m
RMAN>
e
d
a
14) For an alternate view of the backups, in EM, navigate to Availability > Manage
Current Backups > Image Copies.
c
A
15) Ensure that the username and password of oracle/oracle are in the host
credentials section at the bottom of the page, and then at the upper-right corner of the
page, click Delete All Obsolete.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
16) When the Specify Job Parameters page appears, click Show RMAN Script.
e
l
c
Note that the script issues the DELETE NOPROMPT OBSOLETE command. Click OK.
17) Click Submit Job.
a
r
O
19) When the job status is Running, use your browsers Reload button until the job status
appears as Succeeded. Then navigate back to the backup listing page for image copies
(Database > Availability > Manage Current Backups > Image Copies).
20) Note that there are now only two backups of data file 4. The obsolete one has been
deleted because it was the third of three, and the retention policy is set to 1, meaning
there need only be two backups of any given file. (Remember the archival backup is
not counted.)
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
21) Click the Backup Sets tab on this page. What archival backup sets appear there? Why
are they there?
e
l
c
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
$ pwd
/home/oracle
e
d
a
$ mkdir BACKUP
c
A
$. oraenv
ORACLE_SID = [+ASM] ? rcat
The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 is
/u01/app/oracle
$
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
3) Shut down the database with the IMMEDIATE option, then mount it.
$ sqlplus / as sysdba
e
l
c
a
r
O
318046208
1336244
251661388
58720256
6328320
bytes
bytes
bytes
bytes
bytes
4) Make a whole database image copy backup into the $HOME/BACKUP directory
using RMAN commands.
$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Jul 21
22:26:33 2009
Copyright (c) 1982, 2009, Oracle and/or its affiliates.
reserved.
All rights
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
$ . oraenv
ORACLE_SID = [rcat] ? rcat
sqlplus / as sysdba
e
l
c
a
r
O
6) Use the ALTER DATABASE command to back up the control file as a trace file.
SQL> alter database backup controlfile to trace as
'/home/oracle/BACKUP/trace_control.bck';
Database altered.
SQL> exit
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
c
A
3) Find out the number of your new data file and back up the data files to the
/home/oracle/BACKUP directory. (You might find it useful to keep the SQL*Plus
window open and start the RMAN session in another terminal window, but it is not
mandatory.)
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
$ . oraenv
ORACLE_SID = [+ASM] ? orcl
a
r
O
e
l
c
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
4) To simulate the passage of time, and to make sure that this data is not cached in the
buffer cache, perform the following steps and exit from SQL*Plus.
a
r
O
5) Delete the data file belonging to the BR_TBS tablespace (not the backup).
$ cd ~/BACKUP
$ ls l br*
6) Now log back in to the database, flush the buffer cache and try to access the data in
the CUSTOMERS table.
y
m
$ sqlplus / as sysdba
SQL> alter system flush buffer_cache;
System altered.
SQL> select count(*) from sys.customers;
select count(*) from sys.customers
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
ERROR at line 1:
ORA-01116: error in opening database file 6
ORA-01110: data file 6: '/home/oracle/BACKUP/br01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
7) Knowing you are going to have to restore this file, you now take it offline, and exit
from SQL*Plus.
SQL> alter database datafile 6 offline;
Database altered.
e
l
c
SQL> exit
a
r
O
oracle
oracle
oracle
oracle
oracle
oinstall
4096 Jul
oinstall
4096 Jul
dba
26222592 Jul
dba
1125867520 Jul
dba
6601 Jul
$ cp br_ORCL_22_1.dbf br01.dbf
$ ls l
-rw-r----- 1 oracle oinstall
26222592
-rw-r----- 1 oracle dba
26222592
-rw-r----- 1 oracle dba
1125867520
-rw-r--r-- 1 oracle dba
6601
Jul
Jul
Jul
Jul
29
29
29
29
29
08:42
08:02
08:38
08:12
08:18
.
..
br_ORCL_22_1.dbf
cold_0fklb6h1_1_1
trace_control.bck
29
29
29
29
08:38
08:38
08:12
08:18
br01.dbf
br_ORCL_22_1.dbf
cold_0fklb6h1_1_1
trace_control.bck
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
d
a
10) The data file cannot be brought online as it is too old and, therefore, you need to
perform media recovery to roll it forward.
SQL> recover datafile 6;
Media recovery complete.
SQL>
e
l
c
12) Try again to access the sys.customers table, and then exit SQL*Plus.
a
r
O
y
m
13) For the ORCL database, confirm that the control file is automatically backed up and
that the backup rentention is set to 1 (if not, modify it), take a database backup and
delete obsolete files (in preparation for the following practices).
$ . oraenv
ORACLE_SID = [orcl] ? orcl
$ rman target / catalog rcatowner@rcat
connected to target database: ORCL (DBID=1220535480)
recovery catalog database Password: oracle_4U <<<not displayed
connected to recovery catalog database
RMAN> show retention policy;
RMAN configuration parameters for database with db_unique_name
ORCL are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
RMAN>
RMAN> backup database;
Starting backup
.
.
.
y
m
e
d
a
RMAN>
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
2) Identify the current control files for the ORCL database. You need to know them in
one of the following tasks. Then shutdown the ORCL database to allow the control
files to be deleted and exit SQL*Plus.
SQL> select name from v$controlfile;
NAME
---------------------------------------------+DATA/orcl/controlfile/current.260.692879691
+FRA/orcl/controlfile/current.256.692879691
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
e
d
a
c
A
3) Set the environment to the ASM instance and run the asmcmd utility to delete the two
control files identified above.
Note: The names of your control files may be different. Delete YOUR control files.
$ . oraenv
ORACLE_SID = [orcl] ? +ASM
The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid is
/u01/app/oracle
$ asmcmd rm +DATA/orcl/controlfile/current.260.692879691
$ asmcmd rm +FRA/orcl/controlfile/current.256.692879691
e
l
c
a
r
O
4) Set the environment back to the ORCL database and attempt to start up the database.
$ . oraenv
ORACLE_SID = [+ASM] ? orcl
e
d
a
5) Using RMAN, connect to the ORCL target database, to the RCAT catalog database,
and restore the control file from the autobackup.
$ rman target / catalog rcatowner@rcat
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
All
e
l
c
a
r
O
y
m
6) Mount the restored control file and attempt to open the database.
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
RMAN> alter database open resetlogs;
RMAN-00571:
===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS
===============
RMAN-00571:
===========================================================
RMAN-03002: failure of alter db command at 07/29/2009 10:08:45
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1:
'+DATA/orcl/datafile/system.256.692879503'
y
m
e
d
a
c
A
7) Because the control files have been restored, the database must be recovered.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
8) Attempt to open the database with the RESETLOGS option after recovery.
RMAN> alter database open resetlogs;
database opened
new incarnation of database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
9) Perform a full database backup and delete obsolete files to be prepared for future labs.
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
RMAN> exit
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
@redo_view.sql
set linesize 120
col member format a43
col status format a10
select l.group#, l.sequence#, l.archived,
l.status, f.member
from v$log l, v$logfile f
where l.group#=f.group#;
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
6 rows selected.
SQL>
2) From this it can be seen in our example that log group 1 is the current log group.
Your current redo log group may be different from the one shown. Note the exact
group names of your current group. You need the names during the next step.
Determine the current redo log group for your database, and then delete its member files
with the asmcmd utility. You must shutdown the database in order to delete files that are
in use in an ASM disk group.
e
l
c
a
r
O
3) Attempt to start the ORCL database and observe what happens. Then exit your
SQL*Plus session.
$ . oraenv
ORACLE_SID = [+ASM] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 is
/u01/app/oracle
$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Tue Aug 4 03:07:48
2009
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 481259520 bytes
Fixed Size
1337352 bytes
Variable Size
411043832 bytes
Database Buffers
62914560 bytes
Redo Buffers
5963776 bytes
Database mounted.
ORA-03113: end-of-file on communication channel
Process ID: 29445
Session ID: 1 Serial number: 5
SQL> exit
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
e
d
a
c
A
4) Display the last section of the alert log to find out more details related to the failure in
starting the ORCL instance.
$ tail /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log
ORA-15012: ASM file '+FRA/orcl/onlinelog/group_1.257.692879701'
does not exist
ORA-00312: online log 1 thread 1:
'+DATA/orcl/onlinelog/group_1.261.692879693'
ORA-17503: ksfdopn:2 Failed to open file
+DATA/orcl/onlinelog/group_1.261.692879693
e
l
c
a
r
O
As you can observe, the instance terminates due to missing all the members of your log
group.
5) Log into SQL*Plus as SYSDBA, start up and mount the ORCL instance. Query the
V$LOG view to determine which log group is the current group and whether its files
have been archived already.
$ sqlplus / as sysdba
SQL> startup mount
ORACLE instance started.
Total System Global Area
Fixed Size
Variable Size
Database Buffers
Redo Buffers
Database mounted.
481259520
1337352
411043832
62914560
5963776
bytes
bytes
bytes
bytes
bytes
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
e
d
a
c
A
STATUS
---------------CURRENT
UNUSED
UNUSED
ARC
--NO
YES
YES
6) If you clear YOUR missing log file group, then this will re-create the missing log
files.
SQL> alter database clear logfile group 1;
alter database clear logfile group 1
*
ERROR at line 1:
ORA-00350: log 1 of instance orcl (thread 1) needs to be archived
ORA-00312: online log 1 thread 1:
'+DATA/orcl/onlinelog/group_1.261.693969247'
e
l
c
a
r
O
This is because the logfile has been deleted, and therefore cannot be archived. Because
the log file has not been archived, lgwr is not allowed to overwrite it, even if the file no
longer exists.
7) Because the logfile group has not been archived, you must use the keyword
unarchived in the command. Open the database and exit SQL*Plus.
SQL> alter database clear unarchived logfile group 1;
Database altered.
SQL> alter database open;
Database altered.
SQL> exit
8) Perform a backup of the ORCL database including archive logs to be ready for future
labs.
$ rman target / catalog rcatowner@rcat
Recovery Manager: Release 11.2.0.1.0 - Production on Wed Jul 29
10:49:07 2009
Copyright (c) 1982, 2009, Oracle and/or its affiliates.
rights reserved.
y
m
c
A
e
d
a
All
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
Deleted 2 objects
a
r
O
RMAN> exit
In this practice, you recover an image copy of a file to the current SCN, to allow faster
recovery time later. You create a new tablespace called APPRAISAL, which has one
table in it. After creating it initially with a small amount of data, you take an incremental
backup of it. Then you add many rows and take another incremental backup. At that
point, you have an image copy of the APPRAISAL tablespace and also an incremental
backup of it. Because you need to recover the tablespace later, you recover the image
copy so that it is as up-to-date as the last incremental backup. This is done without going
to the expense of creating a new image copy.
1) Make sure you are at the ~/labs directory and run the
create_appraisal_ts.sh script to create a new tablespace called
APPRAISAL.
$ cd ~/labs
$ ./create_appraisal_ts.sh
Tablespace created.
Table created.
$
e
d
a
2) Make a level 1 backup of the tablespace, to be used for image copy recovery. If no
level 1 exists yet, it will actually create a level 0 incremental backup. This takes
several minutes.
$ rman target / catalog rcatowner@rcat
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
All rights
e
l
c
y
m
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
RMAN>
a
r
O
3) In a separate terminal window, perform some DML on the table in the APPRAISAL
tablespace. Use the emp_inserts.sh script.
y
m
e
d
a
c
A
5) Run the script to perform more transactions on the table that resides in the
APPRAISAL tablespace.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
$ ./emp_inserts.sh
428 rows created.
Commit complete.
6) Perform another level 1 backup. This one will indeed be a level 1 because you already
have a level 0.
e
l
c
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
7) List and note the SCN of the APPRAISAL tablespace incremental backup (not the
image copy).
RMAN> list backup of tablespace appraisal;
List of Backup Sets
===================
BS Key Type LV Size
Device Type Elapsed Time Completion
Time
------- ---- -- ---------- ----------- ------------ -----------------2036
Incr 1 2.24M
DISK
00:00:00
2009-0805:03:25:54
BP Key: 2041
Status: AVAILABLE Compressed: NO Tag:
APP_INCR
Piece Name:
+FRA/orcl/backupset/2009_08_05/nnndn1_app_incr_0.277.694063555
List of Datafiles in backup set 2036
File LV Type Ckp SCN
Ckp Time
Name
---- -- ---- ---------- ------------------- ---7
1 Incr 855661
2009-08-05:03:25:54
+DATA/orcl/datafile/appraisal.256.694061937
RMAN>
y
m
e
d
a
c
A
8) Use the incremental backup to recover the APPRAISAL tablespace image copy.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
9) List the SCN for the APPRAISAL tablespace image copy. What is it now?
RMAN> list copy of tablespace appraisal;
List of Datafile Copies
=======================
Key
File S Completion Time
Ckp SCN
Ckp Time
------- ---- - ------------------- ---------- -----------------2090
7
A 2009-08-05:03:29:20 855661
2009-0805:03:25:54
Name: +FRA/orcl/datafile/appraisal.288.694063519
Tag: APP_INCR
RMAN>
Note that it is now equal to the SCN of the last incremental backup.
10) Recover all the data file image copies in the database based on the most recent
incremental backup.
RMAN> recover copy of database with tag 'app_incr';
e
d
a
y
m
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
11) View the SCNs of all the image copies now. They should all be, at the most, equal to
the latest incremental backup.
RMAN> list copy;
e
l
c
a
r
O
e
d
a
y
m
2146
5
A 2009-08-05:03:33:32 855661
2009-0805:03:25:54
Name: +FRA/orcl/datafile/example.307.694063477
Tag: APP_INCR
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
2147
6
A 2009-08-05:03:33:32 855661
2009-0805:03:25:54
Name: +FRA/orcl/datafile/br_tbs.289.694063517
Tag: APP_INCR
1641
6
A 2009-08-05:02:24:21 848546
2009-0805:02:24:20
Name: /home/oracle/BACKUP/br_ORCL_23_1.dbf
Tag: TAG20090805T022420
2090
7
A 2009-08-05:03:29:20 855661
2009-0805:03:25:54
Name: +FRA/orcl/datafile/appraisal.288.694063519
Tag: APP_INCR
e
l
c
RMAN>
a
r
O
In this practice, you take advantage of the Flash Recovery Area to perform a fast
recovery of a data file.
Note: The data file numbers in your database may differ from what is shown here.
1) Use the RMAN session from the previous practice and take the APPRAISAL data file
offline.
RMAN> sql "alter tablespace appraisal offline";
sql statement: alter tablespace appraisal offline
starting full resync of recovery catalog
full resync complete
RMAN>
2) Use the SWITCH command to replace the data file from the flash recovery area.
a) Determine the name of the data file that is currently associated with the
APPRAISAL tablespace.
RMAN> report schema;
Report of database schema for database with db_unique_name
ORCL
e
d
a
y
m
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
Note that there is only one data file for the tablespace. In this case, it is data file
number 7. You can use that data file number, instead of the tablespace name, in the
upcoming set of commands.
b) Confirm that you have an image copy for data file 7 that you can switch to.
RMAN> list copy of datafile 7;
List of Datafile Copies
=======================
Key
File S Completion Time
Ckp SCN
Ckp Time
------- ---- - ------------------- ---------- -----------------2090
7
A 2009-08-05:03:29:20 855661
2009-0805:03:25:54
Name: +FRA/orcl/datafile/appraisal.288.694063519
Tag: APP_INCR
RMAN>
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
e
d
a
a
r
O
RMAN>
4) Report the schema to note the file name for the APPRAISAL tablespace.
RMAN> report schema;
Report of database schema for database with db_unique_name
ORCL
List of Permanent Datafiles
===========================
File Size(MB) Tablespace
RB segs Datafile Name
---- -------- -------------------- ------- ----------------------1
680
SYSTEM
YES
+DATA/orcl/datafile/system.260.694050517
2
570
SYSAUX
NO
+DATA/orcl/datafile/sysaux.266.694050521
3
85
UNDOTBS1
YES
+DATA/orcl/datafile/undotbs1.278.694050521
4
5
USERS
NO
+DATA/orcl/datafile/users.264.694050521
5
100
EXAMPLE
NO
+DATA/orcl/datafile/example.259.694050813
6
25
BR_TBS
NO
/home/oracle/BACKUP/br01.dbf
7
25
APPRAISAL
NO
+FRA/orcl/datafile/appraisal.288.694063519
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
Note that you are now using the Flash Recovery Area data file as the open data file
for the online tablespace.
5) Determine what happened to the original data file.
e
l
c
Key
File S Completion Time
Ckp SCN
Ckp Time
------- ---- - ------------------- ---------- ------------------
a
r
O
Note that it is still there and is listed now as an image copy. But, the reason for
switching was because this data file was considered to be on a damaged disk, or the
data file itself was corrupted.
6) In a separate terminal window, make sure you are at the ~/labs directory.
$ cd ~/labs
7) Remember that the reason for switching was because this data file was considered to
be on a damaged disk, or the data file itself was corrupted in some way. So, run the
rm_asm_file.sh script to delete the file. But first, you must ensure that you are
pointing to the +ASM instance.
$ . oraenv
ORACLE_SID = [orcl] ? +ASM
The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid is
/u01/app/oracle
$ asmcmd rm +DATA/orcl/datafile/appraisal.256.694061937
y
m
8) Eventually, you want to refrain from using the Flash Recovery Area as storage for
active data files. By now, the hardware or corruption problem has been remedied, so
switch the data file back to the original location.
e
d
a
a) Back up the data file, specifying the DATA ASM disk group, using the
DATAFILE template.
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
d) Report the schema to confirm that the data file location has changed.
RMAN> report schema;
Report of database schema for database with db_unique_name
ORCL
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
11) Cross-check the image copy backups and remove the obsolete data file 7 image copy.
Exit RMAN when finished.
RMAN> crosscheck copy;
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
RMAN> exit
e
l
c
a
r
O
In this practice, you execute a long-running RMAN job and monitor its progress to
determine how much longer it is expected to run.
1) Point to the ORCL instance, invoke RMAN and delete all obsolete backups. You need
to perform a cross-check first, so that the repository is up-to-date.
$ . oraenv
orcl
$ rman target / catalog rcatowner@rcat
recovery catalog database Password: oracle_4U <<<not displayed
RMAN> crosscheck backup;
. . .
RMAN> delete noprompt obsolete;
. . .
2) Open a second terminal window. Change to the labs directory and point to the
20cl instance. Invoke SQL*Plus and connect as SYSDBA. You use this second
session to monitor a database backup.
$ . oraenv
orcl
$ sqlplus / as sysdba
e
d
a
c
A
3) Return to your first terminal window. In your RMAN session, begin a database
backup to the tape device.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
y
m
4) Use your SQL*Plus session to monitor the progress of the database backup by
querying the V$SESSION_LONGOPS view. By using this view, you can determine
whether the backup is progressing normally or hanging. If the backup is progressing
normally, the TIME_REMAINING column should be decreasing. Execute the
query_longops2.sql script a few times to query V$SESSION_LONGOPS.
Since the script contains multiple SELECT statements, you cannot enter slash to
rerun the script. You must type or paste the script name for each run. Each time you
should see the TIME_REMAINING value decreasing for the SID associated with the
backup task. The detail data section pertains to individual channel openings and
closings. The aggregate data section describes the entire RMAN job progress.
SQL> @query_longops2.sql
Detail Data
-------------------------------------Detail Progress Information (per file)
SID START_TIME
ELAPSED_SECONDS TIME_REMAINING
---------- ------------------- --------------- -------------40 2009-08-05:05:12:19
20
24
y
m
Aggregate Data
-----------------------------Aggregate Progress Information
e
d
a
c
A
SID
SERIAL#
CONTEXT
SOFAR TOTALWORK %_COMPLETE
------- ---------- ---------- ---------- ---------- ------21
934
4
43999
236000
18.64
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
SQL> @query_longops2.sql
Detail Data
-------------------------------------Detail Progress Information (per file)
SID START_TIME
ELAPSED_SECONDS TIME_REMAINING
---------- ------------------- --------------- -------------40 2009-08-05:05:13:26
12
35
Aggregate Data
-----------------------------Aggregate Progress Information
e
l
c
a
r
O
SID
SERIAL#
CONTEXT
SOFAR TOTALWORK %_COMPLETE
-------- ---------- ---------- ---------- ---------- ------21
934
4
131039
236000
55.53
Oracle Database 11g: Administration Workshop II A - 91
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
In this optional practice, you create a data dictionary corruption that you analyze using
Support Workbench and ADRCI. If you begin this practice, you must complete it.
1) Execute the hm_setup.sh script from the labs subdirectory. This script
corrupts the data dictionary.
$ . oraenv
orcl
$ cd ~/labs
$ cat hm_setup.sh
#!/bin/bash
cd /home/oracle/labs
sqlplus / as sysdba <<EOF
set echo on
create table scott.tabjmw(c number) tablespace users;
variable obj number;
begin
select object_id into :obj from dba_objects where
owner='SCOTT' and object_name='TABJMW';
end;
/
print obj;
update tab$ set cols=1001 where obj#=:obj;
commit;
EOF
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
$ ./hm_setup.sh
c
A
OBJ
---------74657
SQL>
1 row updated.
e
l
c
e
d
a
SQL>
Commit complete.
$
a
r
O
y
m
d) On the Run Dictionary Integrity Check page, specify a Run Name: DictCheck
and click OK.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e) Back to the Advisor Central Checkers page, you should see a Confirmation
message indicating that your check ran successfully.
f) Select your DictCheck run and click Details.
e
l
c
g) This takes you to the Run Details Findings tabbed page, where you can see some
Data Corruption. In particular, you should see the following finding: SQL
dictionary health check: invalid column number 8 on object TAB$ failed.
a
r
O
: Dictionary I
: MANUAL
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
: COMPLETED
Start Time
23:12:55.920739 +07:00
End Time
11 +07:00
Error Encountered
c
A
: 2009-07-22
: 2009-07-22 23:13:01.5127
: 0
Source Incident Id
: 0
: 0
e
l
c
a
r
O
e
d
a
: 481
Check Name
ntegrity Check
Mode
Status
y
m
Finding Name
: Dictionary Inconsistency
Finding ID
: 482
: FAILURE
Status
: OPEN
Priority
: CRITICAL
Message
: SQL dictionary health check: i
nvalid column number 8 on
object TAB$ failed
Message
: Damaged rowid is AAAAACAABAAAU
fPAAC - description: Object
SCOTT.TABJMW is referenced
SQL>
4) Navigate to your EM Home page. What do you observe in the Alerts section?
You should see a new critical alert (Data Failure) for the previously detected
corruption in the Alerts section of the Home page. (It may take a while to appear.)
y
m
e
d
a
5) Flush your shared pool and buffer cache first, and then exit and reconnect as the SYS
user.
$ sqlplus / as sysdba
SQL> alter system flush shared_pool;
System altered.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
SQL>
SQL> alter system flush buffer_cache;
System altered.
SQL> exit
$ sqlplus / as sysdba
6) From a SQL*Plus session connected as the SYS user, execute the following
statement: select * from scott.tabjmw;
Question: What do you observe?
e
l
c
a
r
O
Answer: At first the session seems to hang, then the ORA-03113 error is displayed.
7) Use EM to investigate the previous problem.
a) From the EM Home page, you should see one active incident. Click the Active
Incident link. If not, click Software and Support. On the Software and Support
tabbed page, click Support Workbench in the Support section.
b) On the Support Workbench Problems tabbed page, you should see a new Active
Incident whose description is similar to ORA 7445 [qcstda()+690].
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
h) On the Incident Details page, in the Application Information section, you can see
the cause the incident. It is: "select * from scott.tabjmw".
e
l
c
a
r
O
You can also see two dump files generated from the Dump Files tabbed page. The
first one corresponds to the incident dump file and is located in the ADR directory
/u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_nnnn
n. The second one is the classical corresponding trace file located in
/u01/app/oracle/diag/rdbms/orcl/orcl/trace.
y
m
e
d
a
c
A
h) Click the eyeglasses icon in the View Contents column for the incident trace (first
row).
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
i) If you did not save your Host credentials previously, then the Host Credentials
page is displayed. Enter oracle as username and enter oracle as password,
then click Continue.
8) On the Contents page, you see the structured trace information. Expand the
incident_dump and custom_assert_dump nodes.
e
l
c
a
r
O
y
m
e
d
a
c
A
10) This prints the culprit SQL statement in the window below the Trace Map.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
12) On the Incident Details page again, click the Problem Key link.
e
l
c
a
r
O
13) On the Problem Details page, click Edit to the right of the SR field.
14) Enter 1234 in the SR Number pop-up window that appears and click OK. It is
assumed that you already opened an SR (1234) with MetaLink.
Oracle Database 11g: Administration Workshop II A - 100
15) You should now see the SR number on the Problem Details page.
16) Click the Activity Log tab.
17) This takes you to the Activity Log tabbed page, on which you can now see your last
action on the problem. You can optionally enter a comment here. (If you do, click
Add Comment to save your comment.)
y
m
e
d
a
18) Back to your terminal window, locate your incident and your health check report in
ADR. (Your incident number may be different.)
$ cd $ORACLE_BASE/diag/rdbms/orcl/orcl
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
$ ls
alert cdump
sweep trace
$ cd incident
$ ls -la
total 12
drwxr-x--- 3
drwxr-x--- 13
drwxr-xr-x 2
hm
incident
incpkg
ir
lck
c
A
metadata
stage
$ cd incdir_8729
$ ls
orcl_ora_14872_i8729.trc
e
l
c
$ cd ../..
$ ls
alert cdump
sweep trace
a
r
O
hm
incident
orcl_ora_14872_i8729.trm
incpkg
ir
lck
metadata
stage
All
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
21) From the Problem Details page, click Quick Package in the Investigate and Resolve
section.
e
l
c
a
r
O
22) On the Quick Packaging: Create New Package page, leave the default package name
(something similar to ORA7445qc_20090723011838) and select No for Send to
Oracle Support entry.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
24) On the Quick Packaging: View Contents page, you can see the list of incidents that
are part of this package. There should be only one incident in your case. Click Next.
e
l
c
a
r
O
25) On the Quick Packaging: View Manifest page, look at the package name and the path.
28) The Processing: Generating Upload File for Package page appears. Wait until it is
finished.
29) On the Confirmation page, you should see something similar to: "Generating an
upload file for package: ORA7445qc_20090723011838 has failed.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
31) On the Problem Details page, click the Activity Log tab.
32) Back to the Problem Details Activity Log tabbed page, you should now see two new
entries in the log reporting about the package creation for this problem.
33) In the Summary section, click Yes to the right of the Packaged entry.
e
l
c
34) This takes you to the Packages page, from where you can see your package.
a
r
O
y
m
This takes you to the Package Details page, where you can see the package details.
36) Click the Files tab.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
On the Files tabbed page, you can now see the Full Package Content view.
37) Use ADRCI to determine the list of existing packages.
a
r
O
$ adrci
ADRCI: Release 11.1.0.5.0 - Beta on Thu May 24 07:57:13 2007
Oracle Database 11g: Administration Workshop II A - 105
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
adrci> exit
38) After analyzing the problem, you know that the number of columns for TABJMW is
wrong in TAB$. Fix the issue by updating TAB$ and close your problem. You can
execute hm_fix.sh from the labs subdirectory for that purpose.
$ cd ~/labs
$ cat hm_fix.sh
#!/bin/bash
# For training purpose only
e
l
c
a
r
O
OBJ
---------74657
SQL>
1 row updated.
SQL>
Commit complete.
$
y
m
e
d
a
40) On the Package Details page, click the problem link to the right of the Problems in
Package field in the Summary section.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
41) On the Problem Details Incidents tabbed page, select your incident and click Close.
e
l
c
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
-- Create user
CREATE USER bc IDENTIFIED BY oracle_4U
DEFAULT TABLESPACE bctbs
QUOTA UNLIMITED ON bctbs;
GRANT CREATE SESSION TO bc;
e
l
c
y
m
a
r
O
./bc_setup.sh
2) Log into SQL*Plus as the SYS user and execute the bc_critical script, which
corrupts the data file. Enter your displayed block number.
$ sqlplus / as sydba
SQL> @bc_critical
Connected.
FILE_NO
BLOCK_NO
---------- ---------7
129
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
e
d
a
c
A
System altered.
e
l
c
a
r
O
SQL>
y
m
e
d
a
RMAN> exit
c
A
4) Use the RMAN list failure command to provide details about the errors.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
565 2009-07-23:16:11:04
Block 129 in datafile 7: '/home/oracle/BACKUP/bctbs01.dbf' is
media corrupt
Object BCCOPY owned by BC might be unavailable
571 2009-07-23:16:11:05
Block 130 in datafile 7: '/home/oracle/BACKUP/bctbs01.dbf' is
media corrupt
Object BCCOPY owned by BC might be unavailable
SQL>
SQL> exit
e
l
c
a
r
O
Summary
------Datafile 7:
more corrupt
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
9) To clean up the practice environment, run the bc_cleanup.sh script from the
$HOME/labs directory.
e
l
c
y
m
$ cat bc_cleanup.sh
#!/bin/bash
# For training purpose only
#-- Cleanup the tablespace, and user from the corrupt blocks
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
1) Log into SQL*Plus as the SYS user and execute the flada_setup script from the
$HOME/labs directory. The setup script creates a second undo tablespace, a small
FLA_TBS1 tablespace, and the ARCHIVE_ADMIN user with the oracle_4U
password. The password is case-sensitive by default. Take a few moments to inspect
the script before executing it.
$ sqlplus / as sysdba
SQL> @flada_setup
Connected.
SQL> set serveroutput on
SQL> -- set verify on
SQL> set term on
SQL> set lines 200
SQL> set pages 44
SQL> set pause on
SQL>
SQL> /*== Create a tablespace for your flashback data archive
==*/
SQL> DROP TABLESPACE fla_tbs1 INCLUDING CONTENTS
2 /
DROP TABLESPACE fla_tbs1 INCLUDING CONTENTS
*
ERROR at line 1:
ORA-00959: tablespace 'FLA_TBS1' does not exist
e
d
a
y
m
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
SQL>
SQL> /*== Create a second undo tablespace for testing ==*/
SQL> DROP TABLESPACE undotbs2 INCLUDING CONTENTS
2 /
DROP TABLESPACE undotbs2 INCLUDING CONTENTS
*
ERROR at line 1:
ORA-00959: tablespace 'UNDOTBS2' does not exist
e
l
c
ra
Tablespace created.
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
SQL> /*== Create an ARCHIVE_ADMIN user like the HR user ==*/
SQL> /*==
with FLA_TBS1 default tablespace ==*/
SQL> CREATE USER ARCHIVE_ADMIN PROFILE DEFAULT IDENTIFIED BY
"oracle_4U"
2 DEFAULT TABLESPACE FLA_TBS1 TEMPORARY TABLESPACE TEMP
3 ACCOUNT UNLOCK;
User created.
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
SQL> GRANT ALTER SESSION TO ARCHIVE_ADMIN;
Grant succeeded.
SQL> GRANT CREATE DATABASE LINK TO ARCHIVE_ADMIN;
Grant succeeded.
SQL> GRANT CREATE SEQUENCE TO ARCHIVE_ADMIN;
Grant succeeded.
SQL> GRANT CREATE SESSION TO ARCHIVE_ADMIN;
Grant succeeded.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
e
l
c
y
m
a
r
O
SQL>
y
m
e
d
a
Entering the command is recommended for better retention, but if typing is a difficulty, you
can also execute the flada_create.sql script.
SQL> CREATE FLASHBACK ARCHIVE fla1
TABLESPACE fla_tbs1
QUOTA 10M
RETENTION 1 YEAR
/ 2
3
4
5
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
5) Give the privilege to use the FLA1 archive to the HR user, by executing the following
command:
GRANT FLASHBACK ARCHIVE on FLA1 to HR;
e
l
c
Grant succeeded.
ra
SQL>
6) You now switch to the role of a flashback archive user. Connect as the HR user with
the oracle_4U password. To enable this flashback data archive for the
EMPLOYEES table, execute the following command:
ALTER TABLE hr.employees FLASHBACK ARCHIVE fla1;
SQL> connect HR
Enter password: oracle_4U <<< not displayed
Connected.
SQL> ALTER TABLE hr.employees FLASHBACK ARCHIVE fla1;
Table altered.
SQL>
7) To view and increase the salary of Mr. Fox three times by 1000, execute the
flada_dml script as the HR user. This produces activity in the flashback data
archive.
SQL> @flada_dml
SQL> REM "********************************************** "
SQL> REM "For demo purposes ONLY: Flashback Data Archive "
SQL>
SQL> set echo on
SQL> set serveroutput on
SQL> -- set verify on
SQL> set term on
SQL> set lines 200
SQL> set pages 44
SQL> set pause on pause "Press [Enter] to continue..."
SQL>
SQL> /*== Query the current salary for Mr. Fox ==*/
SQL>
SQL> SELECT employee_id, last_name, salary
2 FROM
hr.employees
3 WHERE last_name = 'Fox'
4 /
Press [Enter] to continue...
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
EMPLOYEE_ID LAST_NAME
SALARY
----------- ------------------------- ---------170 Fox
9600
1 row selected.
SQL>
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
e
l
c
a
r
O
SQL>
SQL> /*== Increase the salary three times by 1000 ==*/
SQL>
SQL> UPDATE hr.employees
Oracle Database 11g: Administration Workshop II A - 122
1 row updated.
SQL> COMMIT
2 /
Commit complete.
SQL>
2
3
4
UPDATE hr.employees
SET salary = salary + 1000
WHERE last_name = 'Fox'
/
1 row updated.
SQL> COMMIT
2 /
Commit complete.
SQL>
2
3
4
y
m
UPDATE hr.employees
SET
salary = salary + 1000
WHERE last_name = 'Fox'
/
1 row updated.
SQL> COMMIT
2 /
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
Commit complete.
SQL>
SQL> /*== Query the up-to-date value for Mr. Fox ==*/
SQL>
SQL> SELECT employee_id, last_name, salary
2 FROM
hr.employees
3 WHERE last_name = 'Fox'
4 /
Press [Enter] to continue...
e
l
c
EMPLOYEE_ID LAST_NAME
SALARY
----------- ------------------------- ---------170 Fox
12600
a
r
O
1 row selected.
Oracle Database 11g: Administration Workshop II A - 123
8) To query the internal name of the archive table, execute the following command:
SELECT * FROM USER_FLASHBACK_ARCHIVE_TABLES;
SQL> SELECT * FROM USER_FLASHBACK_ARCHIVE_TABLES;
TABLE_NAME
OWNER_NAME
------------------------------ -----------------------------FLASHBACK_ARCHIVE_NAME
-------------------------------------------------------------ARCHIVE_TABLE_NAME
----------------------------------------------------EMPLOYEES
HR
FLA1
y
m
SYS_FBA_HIST_73137
1 row selected.
SQL>
e
d
a
c
A
9) To ensure that the following queries use the archive tables, and not the undo, switch
the undo tablespaces and drop the old one. As a SYS user, assign UNDOTBS2 as the
current undo tablespace, by using Enterprise Manager > Server> Automatic Undo
Management > Change Tablespace button, selecting the UNDOTBS2 tablespace,
and clicking OK, or by executing the following commands:
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
connect / as sysdba
e
l
c
ra
Note: If you execute the DROP command too quickly, while internal processing still
occurs, you might receive an ORA-30013 error. Wait several minutes and try again.
10) As the HR user, choose a time after the creation of the flashback data archive and
before you executed the erroneous DML. To view Mr. Foxs employee record as of
that time, execute the following query (replace '15' MINUTE with your chosen
historic date, format examples: '50' SECOND, '10' DAY, '5' MONTH):
Note: You receive an ORA-1466 error, if the time you specify a time before the
flashback data archive was started. Reduce the time to a smaller interval and try
again. If you still see the salary of 12600, increase your time interval.
SELECT employee_id, last_name, salary
FROM
hr.employees AS OF TIMESTAMP
(SYSTIMESTAMP - INTERVAL '15' MINUTE)
WHERE last_name = 'Fox';
Entering the command is recommended for better retention and selecting the right
time interval, but if typing is a difficulty, you can also execute the flada_sel.sql
script.
SQL> connect hr
Ener password: oracle_4U <<< not displayed
Connected.
SQL> SELECT employee_id, last_name, salary
2 FROM hr.employees AS OF TIMESTAMP
3
(SYSTIMESTAMP - INTERVAL '15' MINUTE)
4
WHERE last_name = 'Fox';
EMPLOYEE_ID LAST_NAME
SALARY
----------- ------------------------- ---------170 Fox
9600
1 row selected.
SQL>
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
e
d
a
c
A
11) As the HR user, you realize that the recent updates were mistakes. To revert to the
original values for your chosen historic date (for example, ten minutes ago), execute
the following command (replace '15' MINUTE with your chosen historic date):
UPDATE hr.employees
SET salary = (SELECT salary FROM hr.employees
AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '15' MINUTE)
WHERE last_name = 'Fox')
WHERE last_name = 'Fox';
Entering the command is recommended for better retention and selecting the right
time interval, but if typing is a difficulty, you can also execute the flada_upd.sql
script.
SQL> UPDATE hr.employees
2 SET salary = (SELECT salary FROM hr.employees
3
AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '15' MINUTE)
4
WHERE last_name = 'Fox')
e
l
c
a
r
O
1 row updated.
SQL>
12) From your SQL*Plus session, connect to the database as the SYS user and list the
data dictionary views available to you. Execute the flada_list1.sql file:
SQL> connect / as sysdba
Connected.
SQL> @flada_list1
SQL> REM "******************************************* "
SQL> REM "For demo purposes ONLY:"
SQL>
SQL> connect / as sysdba
Connected.
SQL>
SQL> set echo on
SQL> set serveroutput on
SQL> -- set verify on
SQL> set term on
SQL> set lines 200
SQL> set pages 44
SQL> set pause on pause "Press [Enter] to continue ..."
SQL>
SQL> /*== To list the available data dictioary views ==*/
SQL>
SQL> SELECT table_name
2 FROM
dict
3 WHERE table_name LIKE '%FLASHBACK_ARCHIVE%'
4 /
Press [Enter] to continue ...
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
TABLE_NAME
-----------------------------DBA_FLASHBACK_ARCHIVE
DBA_FLASHBACK_ARCHIVE_TABLES
DBA_FLASHBACK_ARCHIVE_TS
USER_FLASHBACK_ARCHIVE
USER_FLASHBACK_ARCHIVE_TABLES
a
r
O
e
l
c
col
col
col
col
DESC dba_flashback_archive
Oracle Database 11g: Administration Workshop II A - 126
y
m
SQL>
SQL> /*== To query the time when the flashback data archive(s)
have been created ==*/
SQL>
SQL> SELECT flashback_archive_name, create_time, status
2 FROM
dba_flashback_archive
3 /
Press [Enter] to continue ...
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
FLASHBACK_ARCHIVE_NAME
CREATE_TIME
STATUS
------------------------- -------------------------------------------------------------------------- ------FLA1
05-JUN-09 11.06.09.000000000 PM
SQL> pause Press [Enter] to continue ...
Press [Enter] to continue ...
SQL>
SQL> DESC dba_flashback_archive_ts
Name
Null?
Type
---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------FLASHBACK_ARCHIVE_NAME
NOT NULL VARCHAR2(255)
e
l
c
a
r
O
y
m
e
d
a
c
A
SQL>
SQL> DESC dba_flashback_archive_tables
Name
Null?
Type
---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------TABLE_NAME
NOT NULL VARCHAR2(30)
OWNER_NAME
NOT NULL VARCHAR2(30)
FLASHBACK_ARCHIVE_NAME
NOT NULL VARCHAR2(255)
ARCHIVE_TABLE_NAME
VARCHAR2(53)
STATUS
VARCHAR2(8)
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
ra
SQL>
SQL> pause Press [Enter] to continue ...
Press [Enter] to continue ...
SQL> clear columns
SQL>
13) As the HR user (with the oracle_4U password), list the FLASHBACK_ARCHIVE
data dictionary tables, which are accessible to you. You can execute the
flada_list2 script, if you prefer to not enter the commands directly.
SQL> connect hr
Enter password: oracle_4U <<< not dislplayed
Connected.
SQL> @flada_list2
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
TABLE_NAME
-----------------------------USER_FLASHBACK_ARCHIVE
USER_FLASHBACK_ARCHIVE_TABLES
e
l
c
y
m
14) To practice additional flashback data archive maintenance tasks, perform the
following steps: Log into SQL*Plus as the ARCHIVE_ADMIN user.
a
r
O
$ sqlplus ARCHIVE_ADMIN
Enter password: oracle_4U <<< not displayed
15) Data in the flashback data archive is automatically purged when the retention time
expires. However, you can also purge data explicitly with the following command to
purge data older than two minutes:
ALTER FLASHBACK ARCHIVE fla1 PURGE BEFORE TIMESTAMP
(SYSTIMESTAMP - INTERVAL '2' MINUTE);
SQL> ALTER FLASHBACK ARCHIVE fla1 PURGE BEFORE
TIMESTAMP(SYSTIMESTAMP - INTERVAL '2' MINUTE);
Flashback archive altered.
SQL>
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
SQL>
SQL> CREATE SMALLFILE TABLESPACE fla_tbs2
2 DATAFILE '$HOME/BACKUP/fla_tbs02.dbf'
3 SIZE 10M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE 32767M
4 NOLOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE
MANAGEMENT AUTO
5 /
e
l
c
y
m
Tablespace created.
a
r
O
SQL>
17) As the ARCHIVE_ADMIN user, add 5 MB of the FLA_TBS2 tablespace to the FLA1
flashback data archive.
SQL> connect ARCHIVE_ADMIN
Enter password: oracle_4U <<< not displayed
Connected.
SQL> ALTER FLASHBACK ARCHIVE fla1 ADD TABLESPACE fla_tbs2
QUOTA 5M;
Flashback archive altered.
SQL>
18) All tables in one specific flashback data archive have the same retention time. Change
the retention time of the FLA1 flashback data archive to two years.
SQL> ALTER FLASHBACK ARCHIVE fla1 MODIFY RETENTION 2 YEAR;
Flashback archive altered.
SQL>
19) As the ARCHIVE_ADMIN user, drop the FLA1 flashback data archive.
Note: Dropping a flashback data archive includes dropping the internal tamperproofed history table. You cannot drop this table directly due to auditing and security
requirements. Dropping a flashback data archive does not drop the tablespaces in
which they are stored, because the tablespaces might contain other data.
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
20) Wait a minute or two and connect as SYS user; clean up your environment by
executing the flada_cleanup.sql script.
SQL> @flada_cleanup
SQL> REM Execute this script script for training purposes only
SQL> REM Undo Cleanup for Flashback Data Archive
SQL> REM Execute script as SYSDBA
SQL>
SQL> set echo on
SQL> set serveroutput on
SQL> set term on
SQL> set lines 200
SQL> set pause on
SQL>
SQL> connect / as sysdba
Connected.
SQL> set echo off
e
l
c
a
r
O
Tablespace created.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
SQL> exit
Note: If you execute the DROP command too quickly while internal processing is still
occurring, you might receive an ORA-30013 error. Wait and try again.
e
l
c
a
r
O
In this practice you use the recycle bin to restore dropped objects. You can do this with
SQL commands or with Enterprise Manager. For the former, perform steps 1 through 4.
For the latter, perform step 1, and then steps 5 through 11.
1) This workshop scenario simulates loss of data. Point to the orcl instance. To
introduce the problem, change directory to $HOME/labs and run the
recyclebin_lab.sh as shown:
$ cd $HOME/labs
$. oraenv
ORACLE_SID = [orcl] ? orcl
$ ./recyclebin_lab.sh
SQL> SQL>
Table dropped.
SQL> SQL> select * from hr.departments
*
ERROR at line 1:
ORA-00942: table or view does not exist
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
2) The lab script drops the HR.DEPARTMENTS table including indexes, restraints, and
so on. Query the DBA_RECYCLE_BIN view to confirm this.
$ sqlplus / as sysdba
SQL> COL OWNER FORMAT A5
SQL> SELECT owner, original_name, droptime
FROM dba_recyclebin WHERE owner = 'HR';
OWNER
----HR
HR
HR
ORIGINAL_NAME
-------------------------------DEPT_ID_PK
DEPARTMENTS
DEPT_LOCATION_IX
e
l
c
DROPTIME
------------------2009-06-06:15:31:05
2009-06-06:15:31:05
2009-06-06:15:31:04
a
r
O
3) Use Flashback Table to restore the dropped objects. You can use Flashback Table
through Enterprise Manager or through SQL*Plus. To flash back the table using
Enterprise Manager, go to step 5.
DEPARTMENT_NAME
MANAGER_ID LOCATION_ID
-------------------------- ---------- ----------Administration
200
1700
Marketing
201
1800
Purchasing
114
1700
5) The HR.DEPARTMENTS table can also be flashed back using Enterprise Manager.
6) Log in as the SYS user with the oracle_4U password and connect as SYSDBA.
7) In EM, navigate to Schema > Tables.
8) Click the Recycle Bin button, enter HR in the Schema Name field and click Go.
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
10) Select DEPARTMENTS from the list and click the Flashback Drop button.
y
m
e
d
a
c
A
11) The Perform Object Level Recovery: Rename page allows you to rename the restored
object. Accept the default or original name and click Next.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
12) On the Review page, inspect the Impact Analysis. Note that the table and dependent
objects are to be restored and note the names they will be restored to.
13) Optionally, click the Show SQL button, review the SQL and click OK.
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
c) Select the DEPARTMENTS table, then the View Data Actions, and click Go to
execute the action.
e
l
c
a
r
O
17) After confirming that the data are restored, click OK. Then exit EM.
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
y
m
b) On the Recovery Settings page, at the bottom of the Flash Recovery section, note
the Lowest SCN [[46r]] (1136492 in this example).
e
d
a
3) Alternatively, you can view and note the current SCN of the database by querying the
V$DATABASE view.
Note: You will need the SCN later.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
SCN: ________________
c
A
$ cd $HOME/labs
$ sqlplus / as sysdba
SQL> SELECT current_scn FROM v$database;
CURRENT_SCN
----------1137367
4) Note the sum of the salaries in the HR.EMPLOYEES table and the count of the rows
in the JOB_HISTORY table.
e
l
c
ra
SUM(SALARY)
----------Oracle Database 11g: Administration Workshop II A - 140
e
d
a
SQL>
SQL> update employees e set salary = least(e.salary,(select
(min_salary + max_salary)/2 * 1.10 from jobs j where j.job_id
= e.job_id)) where job_id not like 'AD_%';
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
c
A
SQL>
SQL> commit;
Commit complete.
SQL>
6) As the SYS user, note the current SCN in the database again, and also the salary sum
and the JOB_HISTORY row count.
Note that these values are different from what was queried in steps 2 and 3.
e
l
c
a
r
O
CURRENT_SCN
-----------
7) Using RMAN, flash back the database to the first SCN value noted in step 2
(1137367 in this example).
a) Shut down and then mount the database by entering the following:
SQL> SHUTDOWN IMMEDIATE
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> STARTUP MOUNT
ORACLE instance started.
Total System Global Area
Fixed Size
Variable Size
Database Buffers
Redo Buffers
Database mounted.
SQL> exit
y
m
481259520
1337324
385878036
88080384
5963776
bytes
bytes
bytes
bytes
bytes
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
b) If you have any RMAN open, close them. Then log in to RMAN again.
$ rman target / nocatalog
connected to target database: ORCL (DBID=1220535480, not open)
using target database control file instead of recovery catalog
RMAN>
c) At the RMAN prompt, enter the FLASHBACK DATABASE command, and supply
the SCN number recorded in step 2:
e
l
c
a
r
O
8) Before opening the database for read and write operations, verify that the database
was flashed back to the correct SCN by looking at the contents of the tables and
seeing that they are back to what was noted in step 3.
a) Logged into SQL*Plus as SYSDBA, enter the following coomand to open the
database in read-only mode:
SQL> alter database open read only;
Database altered.
b) Enter the following at the SQL prompt to determine the salary sum for the
EMPLOYEES table.
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
9) Open the database for read and write opeations. You have to use the RESETLOGS
keyword.
a) Shut down the database:
e
l
c
a
r
O
481259520
1337324
385878036
88080384
y
m
bytes
bytes
bytes
bytes
5963776 bytes
11) Query the V$FLASHBACK_DATABASE_LOG view and determine the lowest SCN
that the database can be flashed back to. Record your answer here: _____________
SQL> set wrap off
SQL> select * from v$FLASHBACK_DATABASE_LOG;
y
m
e
d
a
SQL>
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
12) View the overhead associated with flashback logging and related operations by
querying V$FLASHBACK_DATABASE_STAT. What is the average number of bytes
of flashback data written per minute during this time interval?
SQL> select * from V$FLASHBACK_DATABASE_STAT;
truncating (as requested) before column
ESTIMATED_FLASHBACK_SIZE
e
l
c
a
r
O
Note: Your results will probably vary slightly from those shown here.
e
d
a
14) To turn off the flashback database functionality, execute the following command.
SQL> ALTER DATABASE FLASHBACK OFF;
Database altered.
SQL> exit
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
y
m
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
In this practice, you use the various new memory management capabilities.
1) For your orcl database, navigate into the labs directory, turn off archiving, and
stop Enterprise Manager Database Control.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
$ cd ~/labs
$ ./orcl_to_noarchivelog.sh
Database closed.
Database dismounted.
ORACLE instance shut down.
ORACLE instance started.
Total System Global Area
Fixed Size
Variable Size
Database Buffers
Redo Buffers
Database mounted.
481259520
1337352
373295096
100663296
5963776
bytes
bytes
bytes
bytes
bytes
Database altered.
y
m
Database altered.
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
2) Make a copy of your SPFILE, logged in to SQL*Plus for the orcl instance as the
SYS user with the oracle_4U password.
$ sqlplus / as sysdba
SQL> CREATE PFILE='/tmp/initorcl.ora.bak' FROM SPFILE;
File created.
SQL>
e
l
c
a
r
O
y
m
e
d
a
System altered.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
System altered.
a
r
O
System altered.
SQL> alter system set "pga_aggregate_target" = 0 SCOPE=SPFILE;
Oracle Database 11g: Administration Workshop II A-148
@amm_setup.sql
REM "************************** "
REM "For training purposes ONLY, execute as the oracle OS
set
set
set
set
set
set
echo on
serveroutput on
term on
lines 200
pages 44
pause on pause "Press [Enter] to continue..."
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
SQL>
SQL> drop tablespace mytemp including contents and datafiles;
drop tablespace mytemp including contents and datafiles
*
ERROR at line 1:
ORA-00959: tablespace 'MYTEMP' does not exist
e
l
c
y
m
a
r
O
y
m
Grant succeeded.
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
SQL>
SQL>
SQL> SELECT substr(COMPONENT, 0, 10) COMP, CURRENT_SIZE CS,
USER_SPECIFIED_SIZE US
2
FROM v$memory_dynamic_components
3
WHERE CURRENT_SIZE!=0;
Press [Enter] to continue...
e
l
c
a
r
O
COMP
CS
US
---------- ---------- ----------
167772160
4194304
4194304
289406976
104857600
192937984
0
0
0
0
0
0
6 rows selected.
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
SQL>
5) Log in as the AMM user with the oracle_4U password, recreate the TABSGA table and
insert rows by pressing Enter to continue the script.
SQL> connect amm
Enter password: oracle_4U <<< not displayed
Connected.
SQL> @amm_setup2.sql
SQL> REM "************************** "
SQL> REM "For training purposes ONLY
SQL> REM Connected as the AMM user with the oracle_4U
password
SQL> set serveroutput on
SQL> set term on
SQL> set lines 200
SQL> set pages 44
SQL> set pause on pause "Press [Enter] to continue..."
SQL> drop table tabsga purge;
drop table tabsga purge
*
ERROR at line 1:
ORA-00942: table or view does not exist
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
SQL>
SQL> create table tabsga(a number, b number) tablespace
tbssga;
Table created.
SQL>
SQL> begin
2
for i in 1..100000 loop
3
insert into tabsga values (i, i);
4
end loop;
5 end;
6 /
e
l
c
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
Procedure created.
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
b) Confirm that there are no errors and query the dynamic memory components
again by pressing Enter to continue the script.
SQL> show errors
No errors.
SQL>
SQL> SELECT substr(COMPONENT, 0, 10) COMP, CURRENT_SIZE CS,
USER_SPECIFIED_SIZE US
2
FROM v$memory_dynamic_components
3
WHERE CURRENT_SIZE!=0;
Press [Enter] to continue...
e
l
c
ra
COMP
CS
US
---------- ---------- ---------Oracle Database 11g: Administration Workshop II A-152
167772160
4194304
4194304
289406976
104857600
192937984
0
0
0
0
0
0
6 rows selected.
SQL>
SQL> pause Press [Enter] to exit the script...
Press [Enter] to exit the script...
6) Connect as SYSDBA in your SQL*Plus session, shut down and start your database
instance and then connect again as the AMM user with the oracle_4U password:
SQL> connect / as sysdba
Connected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> STARTUP
ORACLE instance started.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
e
d
a
c
A
7) As the AMM user, determine the current settings for the various memory buffers as
well as the list of resized operations that were done since you started your instance.
e
l
c
ra
SQL> @amm_components.sql
SQL> set serveroutput on
SQL> set term on
Oracle Database 11g: Administration Workshop II A-153
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
100663296
0
104857600
104857600
0
0
0
0
0
0
0
4194304
67108864
71303168
75497472
96468992
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
GROW
GROW
INITIALIZ
ING
IMMEDIATE COMPLETE
COMPLETE
COMPLETE
IMMEDIATE COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
IMMEDIATE COMPLETE
IMMEDIATE COMPLETE
IMMEDIATE COMPLETE
26 rows selected.
SQL> pause Press [Enter] to exit the script...
Press [Enter] to exit the script...
y
m
e
d
a
8) Remain connected as the AMM user in your SQL*Plus session and execute the
following query. Immediately after that, determine the component sizes and resized
operations. You can use query1.sql script for that purpose. What do you observe?
select /*+ PARALLEL(s 24) */ count(*) from (select /*+
parallel(s 24) */ * from tabsga s group by a);
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a) Execute the amm_query1.sql script. You can see that the large pool has a much
bigger size while the buffer cache is smaller. This memory transfer was
automatically done by the system.
SQL> @amm_query1.sql
SQL> select /*+ PARALLEL(s 24) */ count(*) from (select /*+
parallel(s 24) */ * from tabsga s group by a);
COUNT(*)
---------100000
SQL>
SQL> column COMP format a12
SQL>
SQL> select substr(COMPONENT, 0, 10) COMP, CURRENT_SIZE CS,
USER_SPECIFIED_SIZE US from v$memory_dynamic_components where
CURRENT_SIZE!=0;
e
l
c
a
r
O
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
DEFAULT 2K
DEFAULT 4K
DEFAULT 8K
DEFAULT 16
DEFAULT 32
KEEP buffe
RECYCLE bu
PGA Target
DEFAULT bu
shared poo
DEFAULT bu
shared poo
DEFAULT bu
shared poo
DEFAULT bu
large pool
a
r
O
e
l
c
0
0
0
0
0
0
0
125829120
92274688
79691776
88080384
83886080
83886080
88080384
79691776
8388608
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
SHRINK
GROW
SHRINK
GROW
SHRINK
GROW
SHRINK
GROW
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
DEFERRED
DEFERRED
IMMEDIATE
IMMEDIATE
c
A
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
67108864
71303168
75497472
62914560
58720256
54525952
12582912
16777216
20971520
29360128
33554432
25165824
29360128
25165824
20971520
16777216
16777216
12582912
8388608
33554432
37748736
41943040
46137344
50331648
54525952
4194304
79691776
75497472
71303168
71303168
67108864
62914560
58720256
54525952
50331648
46137344
41943040
37748736
33554432
83886080
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
GROW
GROW
GROW
GROW
GROW
GROW
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
GROW
GROW
GROW
GROW
GROW
GROW
GROW
GROW
GROW
GROW
GROW
GROW
GROW
GROW
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
70 rows selected.
SQL>
SQL>
e
l
c
9) Redo the same thing as in the previous step, but this time use the following query.
You can use amm_query2.sql script for that purpose. What do you observe?
a
r
O
y
m
y
m
e
d
a
6 rows selected.
SQL>
SQL> select substr(COMPONENT, 0, 10) COMP, FINAL_SIZE,
OPER_TYPE, OPER_MODE, status from v$memory_resize_ops order by
START_TIME;
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
COMP
FINAL_SIZE OPER_TYPE OPER_MODE STATUS
------------ ---------- --------- --------- --------shared poo
67108864 STATIC
COMPLETE
shared poo
71303168 GROW
IMMEDIATE COMPLETE
shared poo
75497472 GROW
IMMEDIATE COMPLETE
large pool
4194304 GROW
IMMEDIATE COMPLETE
large pool
4194304 STATIC
COMPLETE
java pool
4194304 STATIC
COMPLETE
streams po
0 STATIC
COMPLETE
SGA Target
188743680 STATIC
COMPLETE
ASM Buffer
0 STATIC
COMPLETE
DEFAULT bu
104857600 STATIC
IMMEDIATE COMPLETE
DEFAULT bu
104857600 STATIC
COMPLETE
DEFAULT bu
100663296 STATIC
IMMEDIATE COMPLETE
DEFAULT bu
96468992 STATIC
IMMEDIATE COMPLETE
DEFAULT bu
96468992 INITIALIZ IMMEDIATE COMPLETE
ING
e
l
c
a
r
O
DEFAULT 2K
0 STATIC
COMPLETE
a
r
O
e
l
c
0
0
0
0
0
0
125829120
92274688
79691776
88080384
83886080
83886080
88080384
79691776
8388608
67108864
71303168
75497472
62914560
58720256
54525952
12582912
16777216
20971520
29360128
33554432
25165824
29360128
25165824
20971520
16777216
16777216
12582912
8388608
33554432
37748736
41943040
46137344
50331648
54525952
4194304
79691776
75497472
71303168
71303168
67108864
62914560
58720256
54525952
50331648
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
SHRINK
GROW
SHRINK
GROW
SHRINK
GROW
SHRINK
GROW
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
GROW
GROW
GROW
GROW
GROW
GROW
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
GROW
GROW
GROW
GROW
GROW
GROW
GROW
GROW
GROW
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
DEFERRED
DEFERRED
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
d
a
y
m
pool
pool
pool
pool
pool
46137344
41943040
37748736
33554432
83886080
GROW
GROW
GROW
GROW
GROW
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
70 rows selected.
SQL>
10) Still connected as the AMM user from your SQL*Plus session, execute the following
command and, immediately afterward, determine the memory component sizes and
the list of resize operations. You can use amm_query3.sql for that purpose. What
do you observe?
Possible Answer: The same style of growing and shrinking of the memory
components.
SQL> @amm_query3.sql
SQL> exec testpga(500000);
PL/SQL procedure successfully completed.
SQL>
SQL> column COMP format a12
SQL>
SQL> select substr(COMPONENT, 0, 10) COMP, CURRENT_SIZE CS,
USER_SPECIFIED_SIZE US from v$memory_dynamic_components where
CURRENT_SIZE!=0;
y
m
e
d
a
COMP
CS
US
------------ ---------- ----------
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
shared poo
large pool
java pool
SGA Target
DEFAULT bu
PGA Target
88080384
83886080
4194304
188743680
4194304
125829120
c
A
0
0
0
0
0
0
6 rows selected.
SQL>
SQL> select substr(COMPONENT, 0, 10) COMP, FINAL_SIZE,
OPER_TYPE, OPER_MODE, status from v$memory_resize_ops order by
START_TIME;
e
l
c
a
r
O
COMP
FINAL_SIZE OPER_TYPE OPER_MODE STATUS
------------ ---------- --------- --------- --------DEFAULT bu
96468992 INITIALIZ IMMEDIATE COMPLETE
ING
Oracle Database 11g: Administration Workshop II A-160
a
r
O
e
l
c
0
0
0
75497472
71303168
67108864
4194304
4194304
4194304
0
188743680
125829120
96468992
100663296
0
104857600
104857600
0
0
0
0
92274688
79691776
88080384
83886080
88080384
83886080
79691776
8388608
75497472
71303168
67108864
62914560
58720256
54525952
12582912
16777216
20971520
25165824
29360128
33554432
37748736
75497472
46137344
50331648
54525952
83886080
79691776
4194304
STATIC
STATIC
STATIC
GROW
GROW
STATIC
STATIC
GROW
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
STATIC
SHRINK
GROW
SHRINK
GROW
GROW
SHRINK
SHRINK
GROW
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
GROW
GROW
GROW
GROW
GROW
GROW
SHRINK
GROW
SHRINK
SHRINK
SHRINK
GROW
GROW
SHRINK
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
DEFERRED
DEFERRED
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
d
a
y
m
8388608
12582912
16777216
16777216
20971520
25165824
29360128
33554432
33554432
37748736
41943040
46137344
50331648
54525952
58720256
62914560
67108864
71303168
71303168
41943040
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
SHRINK
GROW
GROW
GROW
GROW
GROW
GROW
GROW
GROW
GROW
GROW
GROW
SHRINK
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
IMMEDIATE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
COMPLETE
70 rows selected.
y
m
SQL> exit
$
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
e
l
c
12) In Enterprise Manager look at the memory variations that happened during this lab.
What do you observe?
ra
a) Logged into Enterprise Manager as the SYSDBA, click the Server tab.
13) On the Server tabbed page, click Memory Advisors in the Database Configuration
section.
14) On the Memory Advisors page, look at the first two graphics.
15) You should see modifications of the memory components in the second graph, that
the large pool grew and shrank.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
17) To clean up your environment, shut down your database instance, restore the original
SPFILE, turn on archiving and restart your orcl database instance. To do all that,
execute the amm_cleanup.sh script.
$ cd ~/labs
$ ./amm_cleanup.sh
Oracle Enterprise Manager 11g Database Control Release
11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation. All rights
reserved.
https://edrsr37p1.us.oracle.com:1158/em/console/aboutApplicati
on
Stopping Oracle Enterprise Manager 11g Database Control ...
... Stopped.
e
l
c
a
r
O
y
m
e
d
a
481259520
1337352
373295096
100663296
5963776
bytes
bytes
bytes
bytes
bytes
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
SQL>
Database altered.
e
l
c
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
In your database there are several running applications. You want to monitor the
resources that are being used by each application. Create a service configuration for each
application or application function that uses your database.
In this practice, you create the following configuration in the orcl database:
Service Name
SERV1
Usage
1) Use the DBMS_SERVICE package to create a service called SERV1. Then make sure
that you add your service name to your tnsnames.ora file.
a) The recommended method for adding a service name to the tnsnames.ora file
is to use Net Manager. For this exercise, execute the sv1_add.sh script.
Review the tnsnames.ora file at $ORACLE_HOME/network/admin to
confirm that the following lines are included. Substitute the output of the
hostname command for <hostname> below.
y
m
e
d
a
SERV1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)
(HOST = <hostname>.ua.oracle.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = SERV1.example.com)
)
)
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
$ . oraenv
ORACLE_SID = [orcl] ? orcl
$ cd /home/oracle/labs
$ ./sv1_add.sh
edrsr37p1.us.oracle.com
$
e
l
c
ra
$ sqlplus / as sysdba
2) After you have created your services, try connecting to your database by using your
service name. What happens? Why?
Answer: You cannot connect using your service because although it is defined, it is
not started on your instance. You can verify this by looking at the SERVICE_NAME
initialization parameter and by looking at the services known to the listener.
$ lsnrctl services
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 26-JUL2009 16:23:46
Copyright (c) 1991, 2009, Oracle.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM", status READY, has 1 handler(s) for this
service...
Handler(s):
"DEDICATED" established:10098 refused:0 state:ready
LOCAL SERVER
Service "orcl.us.oracle.com" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this
service...
Handler(s):
"DEDICATED" established:3657 refused:0 state:ready
LOCAL SERVER
Service "orclXDB.us.oracle.com" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this
service...
Handler(s):
"D000" established:0 refused:0 current:0 max:1022
state:ready
DISPATCHER <machine: edrsr37p1.us.oracle.com, pid:
6610>
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
(ADDRESS=(PROTOCOL=tcp)(HOST=edrsr37p1.us.oracle.com)(PORT=296
69))
Service "rcat.example.com" has 1 instance(s).
Instance "rcat", status READY, has 1 handler(s) for this
service...
Handler(s):
"DEDICATED" established:3 refused:0 state:ready
LOCAL SERVER
Service "rcatXDB.example.com" has 1 instance(s).
e
l
c
a
r
O
e
d
a
c
A
3) How would you make sure that you can connect using your service? Do it and
connect to your instance by using your service.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
NAME
TYPE
VALUE
----------------------------- ----------- ---------------service_names
string
orcl.us.oracle.com
SQL> EXEC DBMS_SERVICE.START_SERVICE('SERV1')
e
l
c
a
r
O
y
m
string
SERV1.us.oracle.com
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM", status READY, has 1 handler(s) for this
service...
Handler(s):
"DEDICATED" established:10105 refused:0 state:ready
LOCAL SERVER
Service "SERV1.example.com" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this
service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
Service "orcl.us.oracle.com" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this
service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
Service "orclXDB.us.oracle.com" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this
service...
Handler(s):
"D000" established:0 refused:0 current:0 max:1022
state:ready
DISPATCHER <machine: edrsr37p1.us.oracle.com, pid:
6610>
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
(ADDRESS=(PROTOCOL=tcp)(HOST=edrsr37p1.us.oracle.com)(PORT=296
69))
Service "rcat.example.com" has 1 instance(s).
Instance "rcat", status READY, has 1 handler(s) for this
service...
Handler(s):
"DEDICATED" established:3 refused:0 state:ready
LOCAL SERVER
Service "rcatXDB.example.com" has 1 instance(s).
Instance "rcat", status READY, has 1 handler(s) for this
service...
Handler(s):
"D000" established:0 refused:0 current:0 max:1022
state:ready
e
l
c
a
r
O
(ADDRESS=(PROTOCOL=tcp)(HOST=edrsr37p1.us.oracle.com)(PORT=620
66))
The command completed successfully
SQL>
SQL> connect system@SERV1
Enter password: oracle_4U <<< not displayed
Connected.
SQL> exit
4) Execute the sv1_load.sh script as SYSDBA. This script creates a new SV_USER
user. Then you connect to your instance as this user and the SERV1 service. Create
workload activity by executing the sv1_load2.sql script. If this script finishes
before you completed the next step, then use the sv1_sel.sql script to executes the
following query:
SELECT COUNT(*) FROM DBA_OBJECTS,DBA_OBJECTS,DBA_OBJECTS
$ cd ~/labs
$ ./sv1_load.sh
SQL> SQL> SQL> SQL> SQL> drop user sv_user cascade
*
ERROR at line 1:
ORA-01918: user 'SV_USER' does not exist
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
SQL> SQL>
2
User created.
e
d
a
c
A
SQL> SQL>
Grant succeeded.
$
Note: Do not wait for the script to complete before proceeding to the next step.
$ sqlplus sv_user@SERV1
Enter password: oracle_4U <<< not displayed
Connected.
SQL>
SQL>
2
3
4
5
6
@sv1_load2.sql
DECLARE
t number;
BEGIN
for i in 1..2000 loop
select count(*) into t from dba_objects;
end loop;
a
r
O
e
l
c
y
m
END;
/
5) After the execution starts, access the EM Top Consumers page from the Performance
tabbed page, and check if SERV1 is using more resources. Also, check the statistics
on your service with V$SERVICE_STATS from a SQL*Plus session connected as
SYSDBA.
a) On the home page, click the Performance tab. Towards the bottom of the
Performance page, click the Services tab.
y
m
An Active Session graph with the activity aggregated by service name is displayed.
The network service name of each connection is recorded as a separate service. So all
the connections made without a service name are aggregated, as are all the
connections made as SERV1.
e
d
a
c
A
b) Click the Top Consumers link in the Additional Monitoring Links section.
Refresh the Top Consumers Overview page several times.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
c
A
The names and number of services listed in the Top Services Graph depends on the
number and type of connections to the database.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c) You can also see the detailed statistics by navigating to the Top Services tab >
SERV1 link > Statistics tab.
e
l
c
a
r
O
6) If the sv1_load2.sql script finishes before you completed this step, then use the
sv1_sel.sql script to continue creating a workload. When you completed the
tasks, make sure that you stop your running workload by pressing Ctrl + C in your
terminal window.
SQL> @sv1_sel.sql
SQL> select count(*) from dba_objects,dba_objects,dba_objects
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
e
d
a
y
m
SQL> exit
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
In this practice, you manually launch Automatic SQL Tuning to automatically tune a
small application workload. You then investigate the outcomes and configuration
possibilities.
1) In EM, navigate to Server > Automated Maintenance Tasks (in the Oracle Scheduler
section).
a) To check if the task settings are enabled, click Configure, (no matter if the status
is Enabled or Disabled).
b) Toggle Enabled and Disabled, then click Show SQL when the Global Status is
Enabled.
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
e
l
c
a
r
O
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
e
l
c
a
r
O
y
m
SQL> SQL>
$
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
e
d
a
c
A
3) In preparation for the practice, you should log in as the AST user with the oracle_4U
password and execute a workload. Execute the ast_workload_stream.sql script.
This script executes, multiple times a query that is not correctly optimized. The query
in question uses hints that force the optimizer to pick a suboptimal execution plan.
The script executes for approximately 30 to 60 seconds. (Output has been reduced to
minimize clutter.)
$ sqlplus ast
Enter password: oracle_4U <<< not displayed
SQL> @ast_workload_stream.sql
Sun Aug 2 23:31:33 GMT-7 2009
no rows selected
no rows selected
no rows selected
.
.
.
no rows selected
no rows selected
e
l
c
a
r
O
4) Automatic SQL Tuning is implemented using an automated task that runs during
maintenance windows. However, you are not going to wait for the next maintenance
window to open. This might take too long. Instead, you will force the opening of your
next maintenance window now. This will automatically trigger the Automatic SQL
Tuning task. Review and execute the ast_run.sh script to do that. The scripts
execution takes about ten minutes (most likely).
$ cat ast_run.sh
#!/bin/bash
# For training only - execute as oracle OS user
date
sqlplus / as sysdba <<EOF!
set echo on
set serveroutput on
exec dbms_workload_repository.create_snapshot;
variable window varchar2(20);
begin
select upper(to_char(sysdate,'fmday'))||'_WINDOW' into
:window from dual;
end;
/
print window;
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
declare
running number;
Oracle Database 11g: Administration Workshop II A-178
count(*)
running
dba_advisor_executions
task_name = 'SYS_AUTO_SQL_TUNING_TASK' and
status = 'EXECUTING';
if (running = 0) then
exit;
end if;
dbms_lock.sleep(60);
end loop;
dbms_scheduler.close_window(:window);
end;
/
alter system set "_enable_automatic_maintenance"=0
/
-- Re-enable the other guys so they look like they are enabled
in EM.
-- Still they will be disabled because we have set the
underscore.
-exec dbms_auto_task_admin.enable( 'auto optimizer stats collection', null, :window);
exec dbms_auto_task_admin.enable( 'auto space advisor', null, :window);
EOF!
date
$
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
$ ./ast_run.sh
Sun Aug 2 23:42:54 GMT-7 2009
e
l
c
SQL>
WINDOW
-------------------------------SUNDAY_WINDOW
a
r
O
e
d
a
y
m
10
11
SQL>
2
System altered.
SQL> SQL> SQL> SQL> SQL> SQL> >
PL/SQL procedure successfully completed.
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
e
l
c
a
r
O
Sun Aug
7) How can you confirm that a SQL Profile was automatically implemented?
a) In Enterprise Manager, navigate to Server > Automated Maintenance Tasks
(Oracle Scheduler) > Automatic SQL Tuning.
b) On the Automatic SQL Tuning summary page, view the tuning results.
y
m
e
d
a
The task has already run in one maintenance window and has results ready to be
viewed.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
c) Look at the graphs on the Automatic SQL Tuning Result Summary page. (If you
do not see any graphs, return to step 5, execute the work load twice, then continue
with step 6 and 7.)
e
l
c
ra
d) Focus on understanding the pie chart and the bar graph next to it. You should be
able to get a feeling for the general findings breakdown, as well as the number of
SQL profiles implemented by the task.
Oracle Database 11g: Administration Workshop II A-181
f) Find and select the SQL that ran in the AST schema. Note the green check mark
meaning that the profile was implemented.
g) Click the View Recommendations button.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
h) Click the Compare Explain Plans eyeglass icon for the SQL Profile entry.
e
l
c
a
r
O
y
m
j) Look at the old and new explain plans for the query.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
k) Then click the Recommendations for SQL ID locator link (the last of the
breadcrumbs on top of the page) to return to the previous screen.
e
l
c
a
r
O
o) Note that a profile was created automatically for this SQL. The type of AUTO
means it was automatically created.
p) Click the Statistics tab to take a look at the execution history for this SQL.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
q) Depending on the speed of your machine, you may not see two hash values. If
that is the case, ignore this step and the following one. Select Real Time: Manual
Refresh from the View Data and then each of possible two Plan Hash Values from
the corresponding drop-down list. Choose one after the other and wait for the
page to refresh each time.
e
l
c
a
r
O
r) Depending on the speed of your environment, you should see one statement with
a relatively high elapsed time per execution, and one with very low elapsed time
per execution. This shows the improved plan. If you select All from the Plan Hash
Values drop-down list, you might not be able to see the execution corresponding
to the statement after tuning on the Summary graph. This might be because the
workload was too short to execute.
8) Generate a text report for more in-depth information. From the command line,
execute ast_task_report.sh script. What do you observe?
a) Notice the first queries that fetch execution name and object number from the
advisor schema, followed by the final query that gets the text report. In the text
report, look for the section about the SQL profile finding and peruse the
Validation Results section. This shows you the execution statistics observed
during test-execute and allows you to get more of a feeling about the profiles
quality. You can also use the report_auto_tuning_task API to get reports
that span multiple executions of the task.
$ cat ast_task_report.sh
#!/bin/bash
# For training only - execute as oracle OS user
sqlplus / as sysdba <<EOF!
set echo on
set long 1000000000
set longchunksize 1000
set serveroutput on
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
begin
select max(execution_name) keep (dense_rank last order by
execution_start)
into
:last_exec
from
dba_advisor_executions
where task_name = 'SYS_AUTO_SQL_TUNING_TASK';
end;
/
e
l
c
a
r
O
print :last_exec
-Oracle Database 11g: Administration Workshop II A-185
end;
/
object_id
:obj_id
dba_advisor_objects
task_name = 'SYS_AUTO_SQL_TUNING_TASK' and
execution_name = :last_exec and
type = 'SQL' and
attr1 = 'by9m5m597zh19';
print :obj_id
--- Get a text report to drill down on this one query
-set pagesize 0
select dbms_sqltune.report_auto_tuning_task(
:last_exec, :last_exec, 'TEXT', 'TYPICAL', 'ALL', :obj_id)
from dual;
EOF!
y
m
e
d
a
$
$ ./ast_task_report.sh
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
SQL> SQL>
2
3
4
EXECUTION_NAME
STATUS
EXECUTION_START
------------------------------ ----------- ------------------EXEC_176
COMPLETED
08/03/2009 18:33:49
SQL> SQL> SQL> SQL>
2
3
4
5
PL/SQL procedure successfully completed.
SQL> SQL>
LAST_EXEC
-------------------------------EXEC_176
e
l
c
a
r
O
y
m
-----------------------------------------------------------------------------Object ID : 3
Schema Name: AST
SQL ID
: by9m5m597zh19
SQL Text
: select /*+ USE_NL(s c) FULL(s) FULL(c) AST */
c.cust_id,
sum(s.quantity_sold) from sh.sales s,
sh.customers c where
s.cust_id = c.cust_id and c.cust_id < 2 group by
c.cust_id
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
e
l
c
Original Plan
-------------
----------------
--
COMPLETE
191076
COMPLETE
208
160775
200
0
2541
0
39
0
0
0
0
0
0
1
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
d
a
0
0
0
0
0
0
1
Notes
----1. The original plan was first executed to warm the buffer
cache.
2. Statistics for original plan were averaged over next 4
executions.
3. The SQL profile plan was first executed to warm the
buffer cache.
4. Statistics for the SQL profile plan were averaged over
next 9 executions.
2- Index Finding (see explain plans section below)
-------------------------------------------------The execution plan of this statement can be improved by
creating one or more
indices.
a
r
O
e
l
c
y
m
y
m
c
A
e
d
a
------------------------------------------------------------------------------------------------| Id | Operation
| Name
| Rows | Bytes |
Cost (%CPU)| Time
| Pstart| Pstop |
------------------------------------------------------------------------------------------------|
0 | SELECT STATEMENT
|
|
1 |
13 |
893
(1)| 00:00:1
1 |
|
|
|
1 | HASH GROUP BY
|
|
1 |
13 |
893
(1)| 00:00:1
1 |
|
|
|
2 |
NESTED LOOPS
|
|
1 |
13 |
892
(1)| 00:00:1
1 |
|
|
|* 3 |
TABLE ACCESS FULL | CUSTOMERS |
1 |
5 |
405
(1)| 00:00:0
5 |
|
|
|
4 |
PARTITION RANGE ALL|
|
1 |
8 |
488
(2)| 00:00:0
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
c) Modify the graphs begin and end points with the widgets in the upper right.
d) Click the Configure button.
e
l
c
a
r
O
On the Automated Maintenance Tasks Configuration page, you can disable individual
clients and change which windows they run in.
e) Disable the Automatic SQL Tuning client entirely and click Show SQL.
y
m
e
d
a
j) Click Configure.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
l) Optionally, click Show SQl, review the commands and then click Return.
m) Then click Apply to enable Automatic SQL Tuning. You should receive a success
message.
e
l
c
a
r
O
n) Navigate to the Automatic SQL Tuning page. If you are on the Automated
Maintenance Tasks Configuration page, click the Configure button for Automatic
SQL Tuning.
o) On the Automatic SQL Tuning Settings page, select No in front of the Automatic
Implementation of SQL Profiles field, and click Show SQL.
p) Review the command, click Return, and then click Apply. You should receive a
success message.
10) OPTIONAL: You can investigate how to configure Automatic SQL Tuning using
PL/SQL looking at the following script: ast_manual_config.sh and script.
Note: In your case, the task executes quickly because the workload to take into
account is really small. However, you could use the ast_interrupt_task.sh
script from another session to stop the task, should it last too long.
e
d
a
y
m
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
You received complaints that certain batch jobs are using too many system resources and
that a specific user is known to start data warehouse processes during regular business
hours. You decide to use the Database Resource Manager for better system-resource
utilization and control.
Your first effort to balance the situation includes creating an APPUSER consumer group
and assigning it to the default DEFAULT_PLAN resource plan. You then map a couple of
Oracle users and your major OS user to resource groups. Activate the resource plan and
test your assignments. Regularly click Show SQL to review all statements that are new to
you.
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
In this practice, you create an APPUSER consumer group and assign it to the default
DEFAULT_PLAN resource plan. Then you map a couple of Oracle users and your major
OS user to resource groups. Activate the resource plan and test your assignments.
Log in as the SYS user (with oracle_4U password, connect as SYSDBA) and perform
the necessary tasks through Enterprise Manager Database Control or through SQL*Plus.
All scripts for this practice are in the /home/oracle/labs directory.
Whenever you open a new terminal window, execute the oraenv script to set
environment variables for the orcl database.
1) Using Enterprise Manager Database Control, create a resource group called
APPUSER. At this point, do not add users to the group.
a) In Enterprise Manager, select Server > Consumer Groups (in the Resource
Manager section).
b) On the Consumer Groups page, click the Create button.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
c) Enter APPUSER as Consumer Group and ensure that the Scheduling Policy is set
to Round Robin.
Question 1: What does the ROUND-ROBIN parameter value mean?
Possible Answer: ROUND-ROBIN indicates that CPU resources are fairly allocated to
the APPUSER consumer group, according to the active resource plan directives.
d) Optionally, click Show SQL, review the statements, and then click Return
e
l
c
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
b) On the Resource Plans page, select DEFAULT_PLAN and click the Edit button.
c) Click Modify.
e
l
c
a
r
O
e) Click OK.
f) Enter 60 for APPUSER Level 3 and 40 for LOW_GROUP Level 3.
g) Click Show SQL.
DECLARE
spfileValue VARCHAR2(1000);
scopeValue VARCHAR2(10) := 'MEMORY';
planName VARCHAR2(100) :=?;
BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.create_plan_directive(
plan => ?,
group_or_subplan => ?,
comment => ?,
mgmt_p1 => ?, mgmt_p2 => ?, mgmt_p3 => ?, mgmt_p4
mgmt_p5 => ?, mgmt_p6 => ?, mgmt_p7 => ?, mgmt_p8
parallel_degree_limit_p1 => ? ,
switch_io_reqs => ? ,
switch_io_megabytes => ?
,
active_sess_pool_p1 => ?,
queueing_p1 => ?,
switch_group => ?,
switch_time => ?,
switch_estimate => case ? when 'false' then false
'true' then true else false end,
max_est_exec_time => ?,
undo_pool => ? ,
max_idle_time => ?,
max_idle_blocker_time => ?,
switch_for_call => case ? when 'false' then false
'true' then true else false end
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
=> ?,
=> ? ,
c
A
when
when
);
dbms_resource_manager.create_plan_directive(
plan => ?,
group_or_subplan => ?,
comment => ?,
mgmt_p1 => ?, mgmt_p2 => ?, mgmt_p3 => ?, mgmt_p4 => ?,
mgmt_p5 => ?, mgmt_p6 => ?, mgmt_p7 => ?, mgmt_p8 => ? ,
e
l
c
a
r
O
parallel_degree_limit_p1 => ? ,
switch_io_reqs => ? ,
switch_io_megabytes => ?
active_sess_pool_p1 => ?,
queueing_p1 => ?,
switch_group => ?,
switch_time => ?,
switch_estimate => case ? when 'false' then false when
'true' then true else false end,
max_est_exec_time => ?,
undo_pool => ? ,
max_idle_time => ?,
max_idle_blocker_time => ?,
switch_for_call => case ? when 'false' then false when
'true' then true else false end
);
dbms_resource_manager.submit_pending_area();
select value into spfileValue from v$parameter where name =
'spfile';
IF spfileValue IS NOT NULL then
EXECUTE IMMEDIATE
'alter system set resource_manager_plan = '||planName||' scope
=BOTH';
END IF;
dbms_resource_manager.switch_plan( plan_name => ? , sid => ? ,
allow_scheduler_plan_switches => FALSE );
END;
y
m
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
i) On the Edit Resource Plan: DEAFULT_PLAN page, click Apply to assign the
APPUSER and the LOW_GROUP consumer groups to the DEFAULT_PLAN
resource plan. (You activate this plan later.)
a
r
O
3) Configure Consumer Group Mappings, so that the HR Oracle user belongs to the
APPUSER consumer group, and the SCOTT user to the LOW_GROUP consumer
group. For the SCOTT user, confirm that his ORACLE_USER attribute has a higher
priority than the CLIENT_OS_USER attribute.
a) In Enterprise Manager, select Server > Consumer Group Mappings.
b) Select Oracle User and click the Add Rule for Selected Type button.
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
d) Move the HR user into the Selected Oracle User region, and then click OK.
e) You should receive a success message. On the Consumer Group Mappings
General page, click Show SQL.
e
l
c
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
h) Select Oracle User again, and click the Add Rule for Selected Type button.
e
l
c
a
r
O
i) Select LOW_GROUP from the Selected Consumer Group drop-down list, and
move SCOTT into the Selected Oracle User area, and then click OK.
j)
You should receive a success message (but do not yet apply your changes.) On
the Consumer Group Mappings page, click the Priorities tab.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
k) Confirm that Oracle User has a higher priority than Client OS User.
l) Click Apply to assign the SCOTT user to the LOW_GROUP consumer group.
You should receive a success message.
4) Configure Consumer Group Mappings so that the oracle OS user belongs to the
SYS_GROUP consumer group.
a) Return to the Consumer Group Mappings General page.
e
l
c
b) Select Client OS User and click the Add Rule for Selected Type button.
a
r
O
c) Select SYS_GROUP from the Selected Consumer Group drop-down list, move
oracle into the Selected Client OS User area, and click OK.
You should receive a success message.
y
m
e
d
a
c
A
d) Optionally, click Show SQL, review the statements, and click Return.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
c
A
e) Click Apply to assign the oracle OS user to the SYS_GROUP consumer group.
You should receive a success message.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
c) Click the Consumer Groups Privileges tab. If you see an error regarding the
password for the PM user, enter oracle_4U in both the password fields.
d) Click the Edit List button.
e) Move the APPUSER, LOW_GROUP, and SYS_GROUP consumer groups to
Selected Consumer Groups and click OK.
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
b) On the Resource Plans page, select DEFAULT_PLAN, select Activate from the
Actions drop-down list, and click Go.
7) Test the consumer group mappings. Start two SQL*Plus sessions: the first with the
system/oracle_4U@orcl connect string and the second with the
scott/oracle_4U@orcl connect string.
e
l
c
ra
a) As the oracle user in a terminal window, execute the oraenv script to set
environment variables for the orcl database.
c) As the oracle user in a terminal window, execute the oraenv script to set
environment variables for the orcl database.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
$
y
m
$ sqlplus scott@orcl
Enter password: oracle_4U <<< not displayed
SQL> SET SQLPROMPT "SECOND>"
SECOND>
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
FIRST>@query_rsc_groups.sql
SCHEMANAME
------------------------------DBSNMP
DBSNMP
DBSNMP
SCOTT
FIRST>
RESOURCE_CONSUMER_GROUP
-----------------------------OTHER_GROUPS
OTHER_GROUPS
OTHER_GROUPS
LOW_GROUP
e
l
c
ra
Note: Your output for this step (and the following steps) may not look exactly
like the output shown. The information of concern here is for the specific users
being mentioned.
Oracle Database 11g: Administration Workshop II A-207
g) In the SECOND terminal window, connect as the PM user with the oracle_4U
password:
SECOND>connect pm@orcl
Enter password: oracle_4U <<< not displayed
Connected.
SECOND>
RESOURCE_CONSUMER_GROUP
------------------------------OTHER_GROUPS
OTHER_GROUPS
OTHER_GROUPS
SYS_GROUP
FIRST>
y
m
e
d
a
j) In the SECOND terminal window, connect as the OE user with the oracle_4U
password::
SECOND>connect oe@orcl
Enter password: oracle_4U <<< not displayed
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
Connected.
SECOND>
SCHEMANAME
-----------------------------DBSNMP
DBSNMP
DBSNMP
OE
e
l
c
a
r
O
RESOURCE_CONSUMER_GROUP
------------------------------OTHER_GROUPS
OTHER_GROUPS
OTHER_GROUPS
OTHER_GROUPS
FIRST> exit
m) Question: When testing your OE Oracle user, you notice that OE is in the
OTHER_GROUPS consumer group. Why is that?
Possible Answer: The OE user is not explicitly assigned to another consumer
resource group.
y
m
e
d
a
c
A
b) On the Resource Plans page, select the DEFAULT_PLAN, select Deactivate from
the Actions drop-down list, and click Go.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
d) To reconfigure or undo all consumer group mappings, review and execute the
rsc_cleanup.sh script from your working directory:
$
#
#
#
#
#
#
#
#
cat rsc_cleanup.sh
Oracle Database 11g: Administration Workshop II
Oracle Server Technologies - Curriculum Development
***Training purposes only***
***Not appropriate for production use***
a
r
O
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.set_consumer_group_mapping(
dbms_resource_manager.oracle_user,
'HR',
NULL
);
dbms_resource_manager.set_consumer_group_mapping(
dbms_resource_manager.oracle_user,
'SCOTT',
NULL
);
e
l
c
e
d
a
a
r
O
y
m
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
$ ./rsc_cleanup.sh
c
A
e
l
c
SQL>
SQL>
12
25
ra
17
18
19
20
21
10
11
10
22
11
23
24
e) To delete the APPUSER resource group in Enterprise Manager, select Server >
Consumer Groups.
f) On the Consumer Groups page, select APPUSER and click the Delete button.
g) Confirm your deletion by clicking Yes.
You should receive a success message.
h) Exit Enterprise Manager and close all terminal windows.
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
Schedule:
Repeating: Do not Repeat
Start: Immediately
Options:
No special options
e
d
a
1) As the SYS user, grant CONNECT, RESOURCE, and DBA roles to the HR user.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
$ sqlplus / as sysdba
Connected.
SQL> grant connect, resource, dba to hr;
Grant succeeded.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
c
A
2) Log in to Enterprise Manager Database Control as the HR user with the oracle_4U
password.
e
l
c
3) To create a job, navigate to Server > Jobs (in the Oracle Scheduler region).
a) On the Scheduler Jobs page, click the Create button.
ra
b) On the Create Job - General page, enter and confirm the following values:
Name: CREATE_LOG_TABLE_JOB
Schema: HR
Oracle Database 11g: Administration Workshop II A-214
begin
execute immediate
('create table session_history(
snap_time TIMESTAMP WITH LOCAL TIME ZONE,
num_sessions NUMBER)');
end;
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
c) On the Schedule folder tab, enter and confirm the following values:
Timezone: Your_local_timezone
Repeating: Do not Repeat
Start: Immediately
e
l
c
a
r
O
d) Click Show SQL if you want to view the SQL statement defining your job.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e) Review the statements (Your time zone might be different.) and click Return.
f) Click OK to create the job.
e
l
c
a
r
O
g) If the job does not appear on the Scheduler Jobs page, click the Refresh button
until it succeeds. Also, you may not see it running, but already with the Last
Run Status of SUCCEEDED.
y
m
e
d
a
DECLARE
sess_count
NUMBER;
BEGIN
SELECT COUNT(*) INTO sess_count FROM V$SESSION;
INSERT INTO session_history VALUES (systimestamp,
sess_count);
COMMIT;
END;
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a) Logged into Enterprise Manager as the HR user, naviagate to Server > Programs
or click the Programs in the Related Links section on the Scheduler Jobs page.
e
l
c
c) On the Create Program page, enter and confirm the following values:
ra
Name: LOG_SESS_COUNT_PRGM
Schema: HR
Enabled: Yes
DECLARE
sess_count
NUMBER;
BEGIN
SELECT COUNT(*) INTO sess_count FROM V$SESSION;
INSERT INTO session_history VALUES (systimestamp,
sess_count);
COMMIT;
END;
y
m
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
d
a
a
r
O
y
m
$ sqlplus hr
Enter password: oracle_4U <<< not displayed
c
A
BEGIN
DBMS_SCHEDULER.CREATE_SCHEDULE (
schedule_name => 'SESS_UPDATE_SCHED',
start_date => SYSTIMESTAMP,
repeat_interval => 'FREQ=SECONDLY;INTERVAL=3',
comments => 'Every three seconds');
END;
/
PL/SQL procedure successfully completed.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
d) Verify that the SESS_UPDATE_SCHED schedule has been created. (You may
have to refresh the page for the Schedule to appear.)
e
l
c
a
r
O
e
d
a
y
m
c
A
c) Click Change Command Type, and on the Select Command Option page, select
Program Name, and enter HR.LOG_SESS_COUNT_PRGM in the field next to it,
or use the Lookup (flashlight) icon to select the program.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
d) Click OK.
a
r
O
e
d
a
f) Change the Schedule Type to Use Pre-Defined Schedule, and select the
HR.SESS_UPDATE_SCHED schedule by using the flashlight icon.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
Note that it quicly accumulates previous runs, because it executes every three
seconds.
7) In your SQL*Plus session, check the HR.SESSION_HISTORY table for rows.
a) Enter:
Your result looks different but the second values should be three seconds apart:
e
l
c
SNAP_TIME
-------------------------------------------------------------NUM_SESSIONS
-----------31-JUL-09 03.07.55.101299 PM
41
a
r
O
Question: If there are rows in the table, are the time stamps three seconds apart?
Answer: Yes, there are rows. Yes, the time stamps are three seconds apart.
8) Use Enterprise Manager Database Control to alter the SESS_UPDATE_SCHED
schedule from every three seconds to every three minutes. Then use SQL*Plus to
verify that the rows are now being added every three minutes: query the
HR.SESSION_HISTORY table, ordered by the SNAP_TIME column.
a) In Enterprise Manager, select Server > Schedules.
b) Click the SESS_UPDATE_SCHED link.
c) On the View Schedule page, click Edit.
d) Change the description to Every three minutes.
e) Change Available to Start to Immediately.
y
m
f) Change the value in the Repeat drop-down list from By Seconds to By Minutes.
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
Your result looks different (but the minute values should be three minutes apart):
SNAP_TIME
--------------------------------------------------------------------
NUM_SESSIONS
--------------
31-JUL-09 03.10.39.185103 PM
41
y
m
e
d
a
31-JUL-09 03.13.38.927866 PM
41
10) This is your mandatory cleanup task. Use Enterprise Manager to drop the
LOG_SESSIONS_JOB and CREATE_LOG_TABLE_JOB jobs, the
LOG_SESS_COUNT_PRGM program, and the SESS_UPDATE_SCHED schedule.
Use SQL*Plus to drop the SESSION_HISTORY table, and exit from your session.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
Note: Make sure that you do not delete the wrong schedule.
a) In Enterprise Manager, select Server > Jobs.
e
l
c
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
c) Select Drop the job and stop any running instance, and then click Yes.
d) Go back to the Scheduler Jobs page, select CREATE_LOG_TABLE_JOB, and
click Delete. Select Drop the job and stop any running instance, and then click
Yes.
e) Click the Database Instance breadcrumb at the upper-left corner of the page to
return to the Server page. Then click Programs.
e
l
c
ra
i) Select If there are dependent objects, it will not be dropped, and then click Yes
to confirm.
j) In your SQL*Plus session as the HR user, delete the SESSION_HISTORY table,
and then exit the session. Enter:
SQL> DROP TABLE session_history PURGE;
Table dropped.
SQL> EXIT
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
In this optional practice, you create and run a lightweight scheduler job. View the
metadata for a lightweight scheduler job. Navigate to your $HOME/labs directory.
1) Create a job template for the lightweight job. The template must be a PL/SQL
procedure or a PL/SQL block. Run the cr_test_log.sql script to create the
test_log table. Then run prog_1.sql. The prog_1.sql script in the
$HOME/labs directory creates a job template.
Note: The job template has a subset of the attributes of a scheduler program. Most of
the attributes of a template cannot be changed for the job.
a) Navigate to the labs directory.
$ cd ~/labs
$
@cr_test_log.sql
-- cleanup previous runs
-- you will see an error the first time this script is
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
Table created.
SQL>
SQL>
SQL>
SQL>
SQL>
2
3
4
@prog_1.sql
REM For training only
set echo on
a
r
O
e
l
c
y
m
BEGIN
-- This will produce an error the first
-- time it is run since PROG_1 does not exist
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
2) Create a lightweight job, using the PL/SQL API. The job will run the my_prog
template daily with an interval of 2, starting immediately.
Note: EM does not expose the JOB_STYLE setting at this time.
a) Logged into SQL*Plus as the system user, execute the my_lwt_job.sql
script.
SQL> @my_lwt_job.sql
SQL> REM For training only
SQL> set echo on
SQL> BEGIN
2
-- the drop procedure will give and error the first
time
3
-- this script is run
4
sys.DBMS_SCHEDULER.DROP_JOB('my_lwt_job');
5 END;
6 /
BEGIN
*
e
l
c
a
r
O
DECLARE
jobname VARCHAR2(30);
BEGIN
-- Create the Job
jobname := 'my_lwt_job';
sys.dbms_scheduler.create_job(
job_name => '"SYSTEM"."MY_LWT_JOB"',
program_name => '"SYSTEM"."PROG_1"',
job_class => '"DEFAULT_JOB_CLASS"',
job_style => 'LIGHTWEIGHT',
repeat_interval => 'FREQ=DAILY;INTERVAL=2',
comments => 'Lightweight job',
enabled => TRUE);
END;
/
y
m
e
d
a
SQL>
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
4) Check the Enterprise Manager Scheduler Jobs page, find the MY_LWT_JOB, and
view the attributes.
e
l
c
a) Log into Enterprise Manager as the SYSTEM user with the oracle_4U password.
a
r
O
b) Navigate to the Scheduler Jobs page. Then click the History tab.
c) View the history of MY_LWT_JOB.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e) Click OK.
a) Navigate to the Scheduler Jobs, All page, select the MY_LWT_JOB job and click
Delete.
e
l
c
a
r
O
b) On the Confirmation page, select Drop the job and any running instance. Click
Yes.
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
CONNECT role
RESOURCE role
DBA role
Because you are going to use the HR user to administer jobs through Database
Control, you need to make sure that HR is registered as a possible administrator.
a) In Enterprise Manager, naviaget to Server > Users (in the Security section).
b) On the Users page, select the HR user and click Edit.
c) On the Edit User page, click the Roles tab.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
e
d
a
c
A
d) If the roles are not yet selected, then click the Edit List button on the right side of
the page. On the Modify Roles page, make sure that the DBA, CONNECT, and
RESOURCE roles are selected. Click OK, then click Apply.
e
l
c
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
h) On the Create Administrators: Properties page, enter HR as Name, ensure that the
Grant SELECT_CATALOG_ROLE is selected and click Review.
i) On the Create Administrator HR: Review page, click the Finish button.
You should receive a success message
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
2) Log in to Enterprise Manager Database Control as the HR user. On the Server tabbed
page, click the Jobs link in the Database Scheduler region. Are there any jobs?
a) Click the Login button to log in as the HR user.
e
l
c
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
e
d
a
y
m
5) Click Windows in the Related Links section. Review the Scheduler Windows page in
Enterprise Manager. Are there any existing windows? Which resource plan is
associated with each window?
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
Answer: There are several windows. All are enabled except WEEKNIGHT_WINDOW
and WEEKEND_WINDOW.
6) Click the MONDAY_WINDOW link. Answer the questions, then click OK.
y
m
e
d
a
Possible Answer: 10 PM
Question 2: For how long does it stay open?
Possible Answer: for 4 hours
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
7) Click Job Classes in the Related Links section and review them.
e
l
c
c
A
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
Question 1: Which resource consumer group is associated with the job class?
Possible Answer: ORA$AT_JCURG_OS is associated with
ORA$AUTOTASK_URGENT_GROUP.
Oracle Database 11g: Administration Workshop II A-238
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
2) From your SQL*Plus session, check the databasewide threshold values for the
Tablespace Space Usage metric using the following command:
SQL> SELECT warning_value,critical_value
FROM
dba_thresholds
WHERE metrics_name='Tablespace Space Usage'
AND
object_name IS NULL;
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
WARNING_VALUE
y
m
e
d
a
c
A
--------------------------------------------------------------------
CRITICAL_VALUE
-------------------------------------------------------------------85
97
tbsalert.dbf. Make sure that this tablespace is locally managed and uses
Automatic Segment Space Management. Do not make it autoextensible, and do not
specify any thresholds for this tablespace. Use Enterprise Manager Database Control
to create it. If this tablespace already exists in your database, drop it first, including its
files.
e
l
c
a) Logged into Enterprise Manager as the SYS user, navigate to Server >
Tablespaces.
a
r
O
y
m
e
l
c
Value
Automatic Storage Management
DATA
DATAFILE
tbsalert
120 MB
TRUE
FALSE
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
d
a
a
r
O
e) Click Continue
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
y
m
e
d
a
c
A
a) On the Tablespaces page, select TBSALERT, click Edit, and then click
Thresholds.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
b) Select Specify Thresholds, and enter 55 as Warning (%) and 70 as Critical (%)
under the Space Used section. Then click Show SQL.
y
m
WARNING_VALUE
-------------------------------------------------------------CRITICAL_VALUE
-------------------------------------------------------------55
70
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
6) In your SQL*Plus session, query the reason and resolution columns from
DBA_ALERT_HISTORY for the TBSALERT tablespace.
SQL> select reason,resolution
from dba_alert_history
where object_name='TBSALERT';
The result should be (if you are repeating this practice, look at the last row):
REASON
RESOLUT
---------------------------------------------------------Threshold is updated on metrics "Tablespace Space Usage"
cleared
SQL> exit
$
e
l
c
a
r
O
----
7) From the labs directory, review and execute the seg_advsr_setup.sh script
that creates and populates new tables in the TBSALERT tablespace.
$ cd ~/labs
$ cat seg_advsr_setup.sh
#!/bin/sh
# For training only, execute as oracle OS user
sqlplus /nolog <<EOF
connect / as sysdba
alter system set disk_asynch_io = FALSE scope = spfile;
shutdown immediate;
startup
set echo on
create table employees1 tablespace tbsalert as select *
hr.employees;
create table employees2 tablespace tbsalert as select *
hr.employees;
create table employees3 tablespace tbsalert as select *
hr.employees;
create table employees4 tablespace tbsalert as select *
hr.employees;
create table employees5 tablespace tbsalert as select *
hr.employees;
alter
alter
alter
alter
alter
table
table
table
table
table
employees1
employees2
employees3
employees4
employees5
enable
enable
enable
enable
enable
row
row
row
row
row
movement;
movement;
movement;
movement;
movement;
BEGIN
FOR i in 1..10 LOOP
insert into employees1 select * from employees1;
insert into employees2 select * from employees2;
insert into employees3 select * from employees3;
insert into employees4 select * from employees4;
insert into employees5 select * from employees5;
commit;
END LOOP;
END;
/
insert into employees1 select * from employees1;
insert into employees2 select * from employees2;
insert into employees3 select * from employees3;
commit;
exit
EOF
$
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
from
from
from
from
from
c
A
e
d
a
$ ./seg_advsr_setup.sh
a
r
O
SQL> Connected.
SQL>
System altered.
y
m
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
10
11
8) Check the fullness level of the TBSALERT tablespace by using Database Control or
SQL*Plus. The current level should be around 60%. Wait a few minutes and check
that the warning level is reached for the TBSALERT tablespace. (If you are too fast
and receive erros, just use your browsers Refresh button, or select your destintion
again.)
e
l
c
a
r
O
b) Enter the following query. Your results should be similar to the following:
SQL> select reason
from dba_outstanding_alerts
where object_name='TBSALERT';
REASON
-------------------------------------------------------------Tablespace [TBSALERT] is [60 percent] full
SQL>
Note: If your result is: no rows selected, wait a little longer and repeat the query.
c) In Enterprise Manager on the Tablespaces page, see Used (%).
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
d) Navigate to the Database home page. You should see the new alert in the Space
Summary section. It might take several minutes for the alert to appear.
e
l
c
9) In your SQL*Plus session, execute the inserts below to add more data to TBSALERT.
Wait a few moments and view the critical level in both the database and Database
Control. Verify that TBSALERT fullness is around 75%.
a
r
O
b) Wait a few minutes and view the critical level in both the database and Database
Control. Verify that TBSALERT fullness is around 75%. In SQL*Plus, enter:
SQL> select sum(bytes) *100 /125829120
from dba_extents
where tablespace_name='TBSALERT';
SUM(BYTES)*100/125829120
-----------------------75
c) Check the outstanding alrets. You may need to wait a few minutes.
SQL> select reason, message_level
from dba_outstanding_alerts
where object_name='TBSALERT';
y
m
e
d
a
REASON
--------------------------------------------
MESSAGE_LEVEL
-------------
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e) Navigate to the Database home page. You should see the new alert in the Space
Summary region. It will take several minutes for the change in status to take
effect. Note the red flag instead of the yellow one.
e
l
c
a
r
O
10) In your SQL*Plus session, execute the following delete statements to delete rows
from tables in TBSALERT. These statements will take several minutes to complete.
Then exit your SQL*Plus session.
SQL> delete employees1;
219136 rows deleted.
SQL> commit;
Commit complete.
SQL> delete employees2;
219136 rows deleted.
SQL> commit;
Commit complete.
SQL> delete employees3;
219136 rows deleted
SQL> commit;
Commit complete.
SQL> exit
$
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
e
d
a
c
A
11) Now, run the Segment Advisor for the TBSALERT tablespace in Enterprise Manager.
Make sure that you run the Advisor in Comprehensive mode without time limitation.
Accept and implement its recommendations. After the recommendations have been
implemented, check whether the fullness level of TBSALERT is below 55%.
a) From the Database home page, select Advisor Central under Related Links and
then click Segment Advisor.
e
l
c
a
r
O
b) On the Segment Advisor: Scope page, select Tablespaces and click Next.
c) On the Segment Advisor: Objects page, click Add, select TBSALERT. Click OK
and then click Show Advanced Options.
d) In the Options section, click Limited and enter 30 for Time Limit (mins)
e
d
a
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
c
A
BEGIN
taskname := 'SEGMENTADV_5033431';
taskdesc :='Get shrink advice based on object growth trend';
numDaysToRetain :='30';
dbms_advisor.create_task('Segment Advisor',?,taskname,taskdesc
,NULL);
dbms_advisor.create_object(taskname, 'TABLESPACE', 'TBSALERT',
' ', ' ', NULL, object_id);
dbms_advisor.set_task_parameter(taskname, 'RECOMMEND_ALL',
'TRUE');
timeLimit :='1800';
dbms_advisor.set_task_parameter(taskname, 'TIME_LIMIT',
timeLimit);
e
l
c
a
r
O
dbms_advisor.set_task_parameter(taskname, 'DAYS_TO_EXPIRE',
numDaysToRetain);
END;
e
d
a
y
m
c
A
j) This takes you back to the Advisor Central page. Click the SEGMENTADV_xxxxx
link in the Name column.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
k) On the Segment Advisor Task page, click the Recommendation Details button .
e
l
c
a
r
O
l) If needed, click your browsers Refresh button until you see recommendations for
the TBSALERT tablespace.
m) Click Recommendation Details.
y
m
e
d
a
n) Click the Select All link and then click the Shrink button.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
o) On the Shrink Segment: Options page, make sure that you click the Compact
Segments and Release Space option button. Click Show SQL.
e
l
c
a
r
O
y
m
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
e
d
a
a
r
O
y
m
t) On the View Job page, scroll to the bottom of the page. Under Operation Detail,
you should see that the job succeeded. (If its still running, use your browsers
Refresh button). Then click OK.
e
d
a
c
A
12) Wait a few minutes and check that there are no longer any outstanding alerts for the
TBSALERT tablespace. Then navigate to the Database home page. You should see
Problem Tablespaces: 0.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
13) Retrieve the history of the TBSALERT Tablespace Space Usage metric for the last 24
hours.
ra
a) On the Database home page, select All Metrics in the Related Links region.
b) Expand the Tablespaces Full category, and click the Tablespace Space Used (%)
link.
c) Make sure that you select Real Time: Manual Refresh from the View Data dropdown list. Then click the TBSALERT link.
y
m
e
d
a
d) This takes you to the Tablespace Space Used (%): Tablespace Name TBSALERT
page. Select Last 24 hours from the View Data drop-down list.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
14) Reset the databasewide default thresholds from the Tablespace Space Usage metric
for
a) On the Tablespace Space Used (%): Tablespace Name TBSALERT page, click
the Edit Tablespace link in the related Links section.
e
l
c
b) This opens the Edit Tablespace: TBSALERT page. Click the Thresholds tab.
a
r
O
c) Click Use Database Default Thresholds option in the Space Used (%) section.
Then click Show SQL.
e
d
a
$ ./seg_advsr_cleanup.sh
SQL> Connected.
SQL>
System altered.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
481259520
1337324
385878036
88080384
5963776
bytes
bytes
bytes
bytes
bytes
ra
y
m
SQL>
$
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
Use Oracle Net Manager to configure the LISTENER with the dbtest and
orcl database services.
Test access
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
b) On the Configure ASM: Disk Groups subpage, select DATA disk group.
c) Right click.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
f) Click OK.
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
b) On the Home page, click the +ASM link in the General section.
c) On the ASM Home page, click the Disk Groups tab.
d) You may have to log in to the ASM instance if you have not previously done it
and saved credentials:
e
l
c
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
f) On the Disk Group: DATA page, click at the Pending Operations field in the
General section.
3) To ensure that you are pointing to the orcl database and that this database is in
ARCHIVELOG mode with a 7 GB fast recovery area, execute the
rman_archivelog.sh script from a terminal window in your working directory.
e
l
c
$ . oraenv
ORACLE_SID = [+ASM] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 is
/u01/app/oracle
a
r
O
481259520
1337324
394266644
79691776
5963776
bytes
bytes
bytes
bytes
bytes
SQL>
Database altered.
SQL> Database log mode
Automatic archival
Archive destination
Oldest online log sequence
Next log sequence to archive
Current log sequence
SQL>
$
y
m
e
d
a
c
A
Archive Mode
Enabled
USE_DB_RECOVERY_FILE_DEST
15
17
17
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
4) Set up dbtest as the net service name for your planned dbtest database.
a) In a graphical terminal window as the oracle user, set up your environment to
point to your orcl instance and invoke the netca utility.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
$ netca
e
l
c
a
r
O
b) On the Welcome page, select Local Net Service Name configuration, and click Next.
c) On the Net Service Name Configuration page, select Add and click Next.
e) On the Net Service Name Configuration, Select Protocols page, select TCP and
click Next.
y
m
e
d
a
f) On the Net Service Name Configuration, TCP/IP Protocol page, enter your host
name, for example, edrsr37p1.us.oracle.com, select Use the standard port
number of 1521, and then click Next.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
g) On the Net Service Name Configuration, Test page, select No, do not test
(because your dbtest database does not yet exist) and click Next.
h) On the Net Service Name Configuration, Net Service Name page, enter dbtest
as Net Service Name, and then click Next.
i) Click No in answer to the question Would you like to configure another net
service name? and then click Next.
j) When you see the completion message, click Next again.
k) Finally, click Finish.
5) Use Oracle Net Manager to configure the LISTENER with the dbtest and orcl
database services.
e
l
c
a
r
O
$ . oraenv
ORACLE_SID = [orcl] ? +ASM
b) The Oracle Net Manager opens a window. Click the + icon, right before the
word Local, then click the + icon, right before the word Listeners to expand
the nodes in the navigation tree until you see the listener, called LISTENER.
y
m
e
d
a
c) First select LISTENER in the left part of the window then, select Database
Services from the drop-down in the right part of the window.
d) Click the Add Database button.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
l
c
a
r
O
h) From the Oracle Net Manager menu bar, select File > Save Network
Configuration, then File > Exit.
6) Clone a database by using RMAN. Start the duplication process in Enterprise
Manager.
y
m
a) Log in to Enterprise Manager as the SYS user with the oracle_4U password and
connect as SYSDBA.
e
d
a
b) Navigate to Data Movement > Clone Database (in the Move Database Files
section).
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
c) On the Clone Database: Source Type page, select A running database and Use
Recovery Manager (RMAN) to copy database files and then click Continue.
a
r
O
d) On the Clone Database: Source Options page, enter or confirm oracle as the
username and password, click Save as Preferred Credential, and then click
Next.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e) On the Clone Database: Select Destination page, enter dbtest both as Global
Database Name and as Instance Name, and select Automatic Storage
Management (ASM) from the Database Storage drop down list. Then click Next.
e
l
c
f) If the Clone Database: ASM Instance Login page appears, enter oracle_4U as
SYS password, and click Login.
a
r
O
e
d
a
y
m
h) You receive a warming that the FRA is smaller then twice the database size.
Because you plan to rarely use the FRA of this test database, click Yes to
continue.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
e
d
a
y
m
c
A
/u01/app/oracle/product/11.2.0/dbhome_1/network/admin as
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
j) If you receive a warning, that the sqlnet.ora file or the listener.ora file
do not exist, accept the warning by clicking Yes.
e
l
c
a
r
O
k) On the Clone Database: Schedule page, ensure that the job starts immediately and
click Next.
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
l) On the Clone Database: Review page, review the Details, including the Database
Storage and click Submit Job.
m) Wait on the Clone Database job is being submitted page.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
n) The Clone Database: Confirmation page should display a success message. Click
the View Status to transfer to the Job Activity page.
o) This takes you to the Execution page. Occasionally, click your browsers reload
button, to display the job progress until you receive a success message. (The
execution time for your job depends on your hardware and available system
resources.)
e
l
c
a
r
O
p) Scroll to the bottom of the page to see the executed steps. Some of the executed
steps have output logs, for example:
Check Database and Mask data each log into the new duplicated database.
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
b) Connect as the SYS user to your orcl database and execute the following query:
select dbid, name, created, open_mode
from v$database;
$ sqlplus / as sysdba
SQL> select dbid, name, created, open_mode from v$database;
DBID NAME
CREATED
OPEN_MODE
---------- --------- ------------------- -------------------1221383234 ORCL
2009-07-30:19:21:38 READ WRITE
SQL>
c) Now connect as the SYSTEM user with the oracle_4U password to your dbtest
database and execute the preceding query. Exit from SQL*Plus.
SQL> connect system@dbtest
Enter password: oracle_4U <<< not displayed
Connected.
SQL> select dbid, name, created, open_mode from v$database;
e
d
a
y
m
DBID NAME
CREATED
OPEN_MODE
---------- --------- ------------------- -------------------1086723993 DBTEST
2009-08-02:19:12:25 READ WRITE
SQL> exit
$
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
8) With the dbca utility, delete the DBTEST database because it is no longer needed
a. In a terminal window,sStart dbca.
$ dbca
e
l
c
a
r
O
d. Select dbtest from the list of databases to delete. Then click Finish.
f. After the delete operation is finished, click No when asked if you want to perform
another dbca operation.
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
a
r
O
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
Performing Tablespace
Point-in-Time Recovery
y
m
a
r
O
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
d
a
Objectives
After completing this lesson, you should be able to:
List what operations occur when you perform tablespace
point-in-time recovery (TSPITR)
Define the terminology used with TSPITR
Identify the circumstances where TSPITR is a good
solution
Determine the correct target time for the point-in-time
recovery
Identify those situations where TSPITR cannot be used,
and how to work around them
Perform automated TSPITR
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
y
m
c
A
a
r
O
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
SYSTEM tablespace
Undo segment tablespaces
Temporary tablespace
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
RMAN
Auxiliary instance
Control file
Restore
Data file
backups
1
Target database
Restore
Recover
Archived
redo log files
Recovered tablespace
y
m
2
Copyright 2009, Oracle. All rights reserved.
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
RMAN
5
Import metadata
Control file
Target database
Recovered
tablespace
4
Point to recovered tablespace
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
Auxiliary
instance
Export
file
Export
metadata
y
m
e
d
a
c
A
3. Exports the dictionary metadata about objects in the recovered tablespace to the target database
4. Issues SWITCH commands on the target database so that the target database control file points to
the data files in the recovery set that were recovered on the auxiliary instance
5. Imports the dictionary metadata from the auxiliary instance to the target instance, allowing the
recovered objects to be accessed
e
l
c
a
r
O
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
Flashback Query
Flashback Transaction Query
Flashback Version Query
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
Refer to the Oracle Database Backup and Recovery Users Guide for additional examples using the
TS_PITR_CHECK view.
y
m
e
d
a
c
A
Identifying Relationships Between Objects That Span the Recovery Set Boundaries
Before performing TSPITR, you must determine the recovery set. If objects in the tablespaces you
need to recover have relationships with objects in other tablespaces, you need to make provisions for
those objects.
Prior to Oracle Database 11g Release 2, you used the SYS.TS_PITR_CHECK view to identify
relationships between objects that span the recovery set boundaries. Now you should use the
DBMS_TTS.TRANSPORT_SET_CHECK procedure and query the
TRANSPORT_SET_VIOLATIONS view.
Note: RMAN TSPITR automatically executes the DBMS_TTS.TRANSPORT_SET_CHECK
procedure for the recovery set tablespaces and verifies that the query against
TRANSPORT_SET_VIOLATIONS returns no rows. If the query returns rows, RMAN stops TSPITR
processing and any tablespace containment violations must be resolved before TSPITR can proceed.
You can execute the procedure and query the view as described above as a precautionary measure.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
CONNECT TARGET
RECOVER TABLESPACE users, example
UNTIL TIME '2007-06-29:08:00:00'
AUXILIARY DESTINATION
'/u01/app/oracle/oradata/aux';
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
Prior to Oracle Database 11g Release 2, you used the following techniques to specify the existence of
an image copy of a data file:
CONFIGURE AUXNAME command for image copies of recovery set data files or auxiliary set
data files
SET NEWNAME command for image copies of auxiliary set data files
Now you should use the CONFIGURE AUXNAME command only with image copies of auxiliary set
data files. You should use the SET NEWNAME command for image copies of recovery set data files or
auxiliary set data files.
e
l
c
a
r
O
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
To create an Oracle instance suitable for use as an auxiliary instance, perform the following steps:
1. Create an Oracle password file for the auxiliary instance by using the orapwd utility.
2. Create a text initialization parameter file for the auxiliary instance.
3. Verify Oracle Net connectivity to the auxiliary instance using a valid net service name.
To perform TSPITR, complete the following steps:
4. Start the auxiliary instance in NOMOUNT mode.
5. Connect the RMAN client to target and auxiliary instances.
6. Execute the RECOVER TABLESPACE command.
e
l
c
Refer to the Oracle Database Backup and Recovery Users Guide for a detailed example.
a
r
O
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
Restarting manual auxiliary instance after TSPITR failure: If you are managing your own auxiliary
instance and there is a failure in TSPITR, then before you can retry TSPITR, you must shut down the
auxiliary instance, correct the problem, and put the auxiliary instance back in NOMOUNT mode.
a
r
O
Summary
In this lesson, you should have learned how to:
List what operations occur when you perform tablespace
point-in-time recovery (TSPITR)
Define the terminology used with TSPITR
Identify the circumstances where TSPITR is a good
solution
Determine the correct target time for the point-in-time
recovery
Identify those situations where TSPITR cannot be used,
and how to work around them
Perform automated TSPITR
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
y
m
c
A
a
r
O
y
m
a
r
O
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
d
a
Objectives
After completing this lesson, you should be able to:
Describe the difference between user-managed and
server-managed backup and recovery
Perform user-managed complete database recovery
Perform user-managed incomplete database recovery
y
m
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
a
r
O
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Performing a User-Managed
Backup of the Database
No
Yes
ARCHIVELOG
mode?
Shut down.
Copy files.
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Copy
data file
while
online
Database block
t1
t2
t3
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
SQL> STARTUP
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Copy the data files for that tablespace to the backup location:
$ cp $ORACLE_HOME/oradata/orcl/users*.dbf /u02/backup/datafile
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
The ALTER TABLESPACE command affects only those data files that belong to that tablespace.
ALTER DATABASE affects all data files in the database.
Ending Backup Mode: It is important to bring the data files out of backup mode. You cannot have
any data files in backup mode at the time the database is shut down. If you attempt to shut down the
database in that state, you will receive an error. Also, because backup mode causes additional redo to
be generated, there is extra load on the system. There is no reason to have any data files in backup
mode if you are not actively backing them up.
Note: In addition, you need to archive out the current redo log files, and back them up safely as well.
e
l
c
a
r
O
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
$ORACLE_BASE/diag/rdbms/orcl/orcl/trace
You can also specify a name for the trace file by using the AS 'filename' clause.
e
l
c
a
r
O
Performing User-Managed
Complete Database Recovery: Overview
User-managed complete database recovery:
Recovers the database to the most recent SCN
Can be done with the entire database at once, or a data
file or tablespace at a time
Requires a current or backup control file
Requires backups of all files to be recovered
Requires all archive logs up to the present
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Database
open?
Repair hardware.
Shut down.
Mount database.
y
m
Open database.
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
This tells you the extent of the damage, helping you decide what the objects of the RECOVER
command should be.
The V$RECOVERY_LOG view shows which archive log files are needed to perform the recovery. If
the list shows files that have since been moved off the default archive log location, then you have to
restore them to some location before performing recovery.
After recording the results of these queries, shut down the database.
a
r
O
Data files
Archive logs
/disk1/datafile.dbf
/disk2/datafile.dbf
y
m
ONLINE
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
$ cp /disk2/backup/datafile/survey01.dbf \
> $ORACLE_BASE/oradata/ORCL/datafile/survey01.dbf
If any archive logs are needed for recovery, check whether they are still in the default disk location
for archive logs. They may not be, if they have been moved to tape or another disk drive, for
example. If they have been moved, they need to be restored, either to the default archive log location
or to a temporary location. If there is enough space available in the default location (which is
specified by the LOG_ARCHIVE_DEST_1 initialization parameter), then restore them there.
Otherwise, you can put them on some other disk location. When it is time to restore, you can specify
that alternate location to find archive log files.
If you had to move a data file, that fact has to be recorded in the control file. That is done by
executing the ALTER DATABASE RENAME FILE command, as shown in the following example:
e
l
c
ra
Note: You must start the instance and mount the database before executing the ALTER DATABASE
RENAME FILE command.
Oracle Database 11g: Administration Workshop II C - 13
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
Could be DATABASE,
TABLESPACE, or DATAFILE
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Done
Yes
Can bring
data files
online?
No
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
As with the closed database recovery, you first need to query for the files and archive logs that need
to be recovered. Then, take all tablespaces that contain damaged data files offline. Use a command
such as the following to do this:
SQL> ALTER TABLESPACE survey OFFLINE TEMPORARY;
Using the TEMPORARY option causes Oracle to perform a checkpoint on any online data files
belonging to the tablespace. Checkpointed data files do not require recovery when they are brought
back online, because they are up-to-date for the latest SCN of any transactions that would have
affected them. This is the more desirable option, although the data files must be available at the time
this command is run. It is possible that the problem was temporary, and you are able to bring the
tablespaces online with no errors.
e
l
c
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
Performing User-Managed
Incomplete Recovery: Overview
Recover the database to a past point in time in the following
situations:
You want the database to be in the state that existed
before a user error or an administrative error occurred.
The database contains corrupt blocks after you tried block
media recovery.
You are unable to perform complete database recovery
because some of the redo log files are missing.
You want to create a test database that is in the state at
some time in the past.
One or more unarchived redo log files and a data file are
lost.
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
CANCEL
SCN = 1200
y
m
Now
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Performing User-Managed
Incomplete Recovery
y
m
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
e
l
c
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
Performing User-Managed
Incomplete Recovery: Steps
To perform user-managed incomplete recovery, follow these
steps:
1. Shut down the database.
2. Restore data files.
3. Mount the database.
4. Recover the database.
5. Open the database with the RESETLOGS option.
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
SHUTDOWN IMMEDIATE
/BACKUP/*.dbf /u01/db01/ORADATA
STARTUP MOUNT
RECOVER DATABASE UNTIL TIME '2005-11-28:11:44:00';
ALTER DATABASE OPEN RESETLOGS;
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
Because the approximate time of the error is known and the database structure has not changed since
11:44 AM, you can use the UNTIL TIME method:
1. If the database is open, shut it down by using the NORMAL, IMMEDIATE, or TRANSACTIONAL
option.
2. Restore all data files from backup (the most recent if possible). You may also need to restore
archived logs. If there is enough space available, restore to the LOG_ARCHIVE_DEST location
or use the ALTER SYSTEM ARCHIVE LOG START TO <LOCATION> command or the
SET LOGSOURCE <LOCATION> command to change the location.
3. Mount the database.
e
l
c
a
r
O
5. To synchronize data files with control files and redo logs, open the database by using the
RESETLOGS option:
SQL> alter database open resetlogs;
SQL> archive log list
...
Oldest online log sequence 0
Next log sequence to archive 1
Current log sequence 1
When recovery is successful, notify users that the database is available for use, and any data entered
after the recovery time (11:44 AM) will need to be reentered.
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
v$archived_log;
... FIRST_CHANGE#
... ------------... 88330
... 309067
FIRST_TIME
---------05-11-15:12:43
05-11-28:11:26
a
r
O
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Summary
In this lesson, you should have learned how to:
Describe the difference between user-managed and
server-managed backup and recovery
Perform user-managed complete database recovery
Perform user-managed incomplete database recovery
y
m
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
a
r
O
y
m
e
d
a
a
r
O
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
y
m
a
r
O
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
e
d
a
Objectives
After completing this lesson, you should be able to:
Describe the benefits of using ASM
Manage the ASM instance
Create and Drop ASM disk groups
Extend ASM disk groups
Retrieve ASM metadata using various utilities
y
m
e
d
a
c
A
Objectives
This lesson provides a more detailed look at the ASM instance and how to manage it with various
utilities.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Database administrator
dependence on system
administrator
Likelihood of errors
associated with manual
maintenance tasks
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
ASM Instance
The ASM Instance is the process and memory components for
ASM.
System Global Area (SGA) memory
Shared
Pool
Large
Pool
ASM
Cache
Free
Memory
ARBn
GMON
Onnn
PZ9n
y
m
e
d
a
c
A
ASM Instance
Every time ASM or a database is started, a shared memory area called the system global area (SGA)
is allocated and Oracle ASM or database background processes are started. The combination of the
background processes and the SGA is called an Oracle ASM instance or an Oracle Database instance.
The instance represents the CPU and RAM components of a running ASM environment.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
The SGA in an ASM instance is different in memory allocation and usage than the SGA in a database
instance. The SGA in the ASM instance is divided into four primary areas as follows:
Shared Pool: Used for metadata information
Large Pool: Used for parallel operations
ASM Cache: Used for reading and writing blocks during rebalance operations
Free Memory: Unallocated memory available
The minimum recommended amount of memory for an ASM instance is 256 MB. Automatic
memory management is enabled by default on an ASM instance and will dynamically tune the sizes
of the individual SGA memory components. The amount of memory that is needed for an ASM
instance will depend on the amount of disk space being managed by ASM.
The second part of the ASM instance is the background processes. An ASM instance can have many
background processes; not all are always present.
e
l
c
a
r
O
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
ASM Components:
ASM InstancePrimary Processes
The ASM instance primary processes are responsible for ASMrelated activities.
Process Description
RBAL
ARBn
GMON
MARK
Onnn
PZ9n
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
c
A
INSTANCE_TYPE should be set to ASM for ASM instances. This is the only parameter that
must be defined. For database instances, this is set to the value RDBMS.
ASM_POWER_LIMIT controls the speed for a rebalance operation. Values range from 1
through 11, with 11 being the fastest. If omitted, this value defaults to 1.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
LARGE_POOL_SIZE specifies (in bytes) the size of the large pool allocation heap. The large
pool allocation heap is used in shared server systems for session memory, by parallel execution
for message buffers, and by backup processes for disk I/O buffers. The ASM instance makes
use of automatic memory management, so this parameter serves as a minimum size that the
large pool can lowered to.
y
m
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
Database Instance
System Global Area
Shared
Pool
Large
Pool
Buffer
Cache
Processes
ap
nt M
Exte
5
CKPT
DBWR
LGWR
Snnn
e
Clos
Large
Pool
ASM
Cache
3
Processes
RBAL
mit
Com
SMON
PMON
Shared
Pool
le
te Fi
Crea
MARK
GMON
PZ9n
ARBn
Onnn
Other
Other
Other
Other
Other
Other
2
Allocation
Initialize
y
m
ASM Storage
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
V$ASM_ATTRIBUTE
V$ASM_CLIENT
V$ASM_DISK
V$ASM_DISK_IOSTAT
V$ASM_DISK_STAT
V$ASM_DISKGROUP
V$ASM_DISKGROUP_STAT V$ASM_FILE
V$ASM_OPERATION
V$ASM_TEMPLATE
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
OSASM
(asmadmin)
SYSDBA
OSDBA
(asmdba)
SYSOPER
OSOPER
(asmoper)
y
m
e
d
a
c
A
SYSASM: This privilege provides full administrative privilege for the ASM instance.
SYSDBA: This privilege grants access to data stored on ASM, and in the current release, grants
the SYSASM administrative privileges.
SYSOPER: This privilege grants the ability to start and stop ASM instances along with a set of
nondestructive ALTER DISKGROUP commands. Other commands such as CREATE
DISKGROUP are not allowed.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
When ASM is installed, operating system groups are assigned the SYSASM, SYSDBA, and SYSOPER
privileges. These groups are known as the OSASM, OSDBA, and OSOPER groups, respectively.
Membership of these operating system groups automatically assigns the related system privileges to
the operating system user in question
When an ASM instance is first created, sys and asmsnmp are the only ASM users that are defined.
e
l
c
a
r
O
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
bytes
bytes
bytes
bytes
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
INSTANCE_TYPE = ASM
This parameter indicates that an ASM instance, not a database instance, is starting.
When you run the STARTUP command, rather than trying to mount and open a database, this
command attempts to mount the disk groups specified by the initialization parameter
ASM_DISKGROUPS. If you have not entered a value for ASM_DISKGROUPS, you can later
mount disk groups with the ALTER DISKGROUP...MOUNT command.
e
l
c
a
r
O
MOUNT or OPEN: Mounts the disk groups specified in the ASM_DISKGROUPS initialization
parameter. This is the default if no command parameter is specified.
NOMOUNT: Starts up the ASM instance without mounting any disk groups
RESTRICT: Starts up an instance in restricted mode. The RESTRICT clause can be used in
combination with the MOUNT, NOMOUNT, and OPEN clauses.
In restricted mode, database instances cannot use the disk groups. That is, databases cannot
open files that are in that disk group. Also, if a disk group is mounted by an instance in
restricted mode, then that disk group cannot be mounted by any other instance in the cluster.
Restricted mode enables you to perform maintenance tasks on a disk group without interference
from clients. Rebalance operations that occur while a disk group is in restricted mode eliminate
the lock and unlock extent map messaging that occurs between ASM instances in a clustered
environment. This improves the overall rebalance throughput. At the end of a maintenance
period, you must explicitly dismount the disk group and remount it in normal mode.
The ASM shutdown process is initiated when you run the SHUTDOWN command in SQL*Plus.
Before you run this command, ensure that the ORACLE_SID and ORACLE_HOME environment
variables are set so that you can connect to the ASM instance.
Oracle strongly recommends that you shut down all database instances that use the ASM instance
before attempting to shut down the ASM instance.
The following list describes the SHUTDOWN command parameters relevant to ASM.
NORMAL: ASM waits for any in-progress SQL to complete before dismounting all of the disk
groups and shutting down the ASM instance. Before the instance is shut down, ASM waits for
all of the currently connected users to disconnect from the instance. If any database instances
are connected to the ASM instance, then the SHUTDOWN command returns an error and leaves
the ASM instance running. NORMAL is the default shutdown mode.
IMMEDIATE or TRANSACTIONAL: ASM waits for any in-progress SQL to complete before
dismounting all of the disk groups and shutting down the ASM instance. ASM does not wait for
users currently connected to the instance to disconnect. If any database instances are connected
to the ASM instance, then the SHUTDOWN command returns an error and leaves the ASM
instance running.
ABORT: The ASM instance immediately shuts down without the orderly dismount of disk
groups. This causes recovery to occur upon the next ASM startup. If any database instance is
connected to the ASM instance, then the database instance aborts.
y
m
e
d
a
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
Note: The NORMAL, IMMEDIATE, and TRANSACTIONAL forms of shutdown do not apply when
there are connected RDBMS instances. The following error will be returned:
e
l
c
a
r
O
$ . oraenv
ORACLE_SID = [orcl] ? +ASM
The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid is
/u01/app/oracle
$ srvctl start asm -o mount
$ srvctl stop asm -f
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
l
c
a
r
O
bytes
bytes
bytes
bytes
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
e
d
a
c
A
ASM metadata for administration is found inside the dynamic performance views that are contained
within the ASM instance. These views are usually accessed with an ASM utility using the SQL
language. The requirement for knowledge of the SQL language increases the learning curve for
mastering ASM, and SQL language training is not a normal requirement in the learning path of a
systems administrator or storage administrator. The asmcmd utility provides a pseudo-shell-like
environment that accepts UNIX-style syntax for common ASM administration tasks. It can be used
to manage Oracle ASM instances, disk groups, file access control for disk groups, files and
directories within disk groups, templates for disk groups, and volumes.
You can use the asmcmd utility to startup and shutdown your ASM instance. The supported startup
options include:
--nomount (To start the ASM instance without mounting disk groups)
--restrict (To start the ASM instance and restrict database usage)
--pfile <pfile.ora> (To start the ASM instance with a custom pfile)
e
l
c
a
r
O
Disk 1
Disk 2
Disk 3
Disk 4
Disk 5
Disk 6
File 3
File 4
File 1
File 2
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
Files are allocated from the space inside a disk group. The content of files that are stored in a disk
group are evenly distributed, or striped, across the disks in the disk group to eliminate hot spots and
to provide uniform performance across the disks. Each ASM file is completely contained within a
single disk group. However, a disk group can contain files belonging to several databases and a
single database can use different files from multiple disk groups.
A key attribute of a disk group is it's redundancy setting. There are three possible disk group
redundancy settings:
External redundancy, where ASM does not provide any mirroring and the disks are assumed to
highly reliable.
Normal redundancy, where ASM supports 2-way mirroring by default to assure data integrity
for less reliable storage.
High redundancy, where ASM supports 3-way mirroring by default for even greater assurance
of data integrity.
ASM supports the creation of up to 63 disk groups however for most installations you rarely need
more than a few.
e
l
c
a
r
O
ASM Disks
ASM disks:
Are the storage devices provisioned to ASM disk groups
Are accessed through normal O/S interfaces
Must be read and write accessible by the ASM owner
Must be accessible by all nodes in a cluster
May have different O/S names or paths on different nodes
May be:
y
m
e
d
a
c
A
ASM Disks
ASM disk groups contain one or more ASM disks.
ASM disks must be read and write accessible by the ASM owner from all nodes in the cluster.
An ASM disk can be a partition on a disk, but Oracle strongly advises against sharing the physical
disks used by ASM with other applications. This is because the I/O performance of the ASM disks
within a disk group should be similar and consistent for the ASM stripe and mirror policy to work
best. Sharing devices between ASM and other applications makes it difficult to assure similar and
consistent disk performance.
It is not necessary for the O/S device names of ASM disks on separate nodes in a cluster to be the
same. ASM identifies members of a disk group by reading the headers on ASM disks.
Generally, ASM disks are raw LUNs from a storage array presented to ASM. In addition, ASM disks
can also be files on a remote NFS filer.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Allocation Units
ASM disks are divided into allocation units (AU):
AU size is configurable at disk group creation
Default AU size is 1MB:
Small enough to be cached by database and large enough
for efficient sequential access
Allowable AU sizes:
1, 2, 4, 8, 16, 32, or 64 MB.
Large AUs may be useful in very large database (VLDB)
scenarios or when using specialized storage hardware
y
m
e
d
a
c
A
Allocation Units
Within an ASM disk, space is divided into allocation units (AU). The default AU size is one
megabyte, which is small enough to not become a hot spot, but large enough to provide efficient
sequential access. You can set the AU size when you create a disk group. You cannot change the AU
size for a disk group. Larger AU sizes may be useful in very large database (VLDB) scenarios or
when using specialized storage hardware. If an AU is constantly accessed, then the database kernel
caches it for more efficient access.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
ASM Files
ASM files:
Are a collection of ASM extents composed of AUs
Variable sized extents support large files
y
m
e
d
a
c
A
ASM Files
ASM exposes a set of files for use by clients of ASM. An ASM file is composed of a set of
allocation units and appears as a normal file to the database kernel.
Each ASM File has a unique system-generated name. The slide shows and example of a fullyqualified ASM file name. The fully-qualified ASM file name represents a hierarchy beginning with a
concatenation of a plus sign with the disk group name. Following the disk group name is the database
name and file type. The final element is composed of a tag name, file number and incarnation
number. An alias can optionally be created to give administrators a more user-friendly means of
referring to an ASM file.
Files are evenly spread across the ASM disks in a disk group using the policy of stripe and mirror
everything (SAME).
ASM natively supports most database related file types, such as data files, log files, control files,
RMAN backups, and others. Prior to Oracle Database 11g Release 2, ASM only supported Oracle
database related files and could not be used to store and manage ASCII trace files and alert logs,
Oracle binaries, the Oracle cluster registry (OCR), and the cluster voting disk. Oracle Database 11g
Release 2 removes this restriction by providing the means to run a general purpose file system over
ASM.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Extent Maps
Disk Group
Disk A
Extent Map
ASM File
1
5
Disk B
2
6
Disk C
3
7
File
Extent
Disk D
y
m
4
8
e
d
a
c
A
Extent Maps
ASM keeps track of a files layout with metadata called an extent map. An extent map is a table that
maps data extents in a file to allocation units on disk.
The relationship between file extents and allocation units is as follows. An extent contains:
One AU for the first 20,000 extents (019999)
4 AUs for the next 20,000 extents (2000039999)
16 AUs for extents above 40,000
Variable size extents, coupled with large allocation units, can be used to accommodate very large
ASM files.
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Striping Granularity
ASM separates striping for load balance and striping for
latency:
Coarse grain striping concatenates allocation units for load
balancing.
For example:
5
ASM Disk Group
Striping Granularity
In ASM striping has two primary purposes:
Load balance I/O across all the disks in a disk group.
Improve I/O latency.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
y
m
e
d
a
c
A
Coarse grain striping spreads allocation units across the disks in a disk group. This is what provides
load balancing for disk groups. When a file is allocated, ASM spreads allocation units evenly across
all of the disks. Sometimes the distribution cannot be perfectly even, but over time it will tend to be
nearly equal. The above diagram shows a file with five allocation units striped across five disks in an
external redundancy disk group containing 8 disks in total.
For the first 20,000 extents, the extent size is equal to the AU size. After 20,000 extents and up to
40,000 extents, then extent sets are always allocated 8 at a time with the extent size equal to 4*AU
size. If the AU size is 1 MB, this means the ASM file will grow 64 MB at a time (8 * 4 * 1 MB). If
the file is coarse grained striped then it is striped across the 8 extent sets with stripes of 1 AU.
Striping is always done at the AU level, not at the extent level. Thus every AU of a coarse grained
file is on a different disk than the previous AU of that file no matter how large the file. After 40,000
extents, the extents are still allocated 8 at a time, but with an extent size equal to 16*AU size.
e
l
c
a
r
O
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
The diagram on this page shows how fine grain striping works. In this example, the first 1 MB
extent of a new file ends up occupying the first 128 KB of 8 different allocation units spread across
the eight disks in the disk group. Consequently, a one megabyte read or write is spread across eight
disks instead of one...
e
l
c
a
r
O
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Failure Group 2
Controller 1
Controller 2
y
m
Disk Group
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Disk B
5
Disk C
Failure Group 2
Disk E
Disk D
Disk F
Disk G
4
Disk H
5 3
Disk Group
Secondary
Extent
y
m
Primary
Extent
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Failure Example
If disk H fails, then the extents it contained are re-created on
surviving disks from surviving mirrors.
Failure Group 1
Disk A
Disk B
5
Disk C
Failure Group 2
Disk E
4
Disk D
1Copy
Copy
Disk F
Disk G
2 3
5 4
Disk H
5 3
Disk Group
y
m
e
d
a
c
A
Failure Example
Extending the example on the previous page, imagine that disk H fails and the data it contains is no
longer accessible. This failure requires that all the extents on the failed disk need to be recovered and
copied to another disk.
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
Extents three and five are copied from the surviving copy to a free region on another disk in the same
failure group. In this example, extent five is copied from disk B to Disk F and extent three is copied
from Disk C to Disk G.
The last step after a disk fails is that ASM drops the failed disk from the disk group.
The removal of a disk triggers essentially the same process, however in that case the extents on the
disk being removed are first copied to an available alternative location.
e
l
c
a
r
O
CREATE DISKGROUP
ASM
instance
DROP DISKGROUP
Database
instance
y
m
ALTER DISKGROUP
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Disk formatting
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
The second statement demonstrates the interactions of discovery strings. Consider the following
configuration:
/devices/A1 is a member of disk group DGROUPA.
/devices/A2 is a member of disk group DGROUPA.
/devices/A3 is a member of disk group DGROUPA.
/devices/A4 is a candidate disk.
The second command adds A4 to the DGROUPA disk group. It ignores the other disks, even though
they match the discovery string, because they are already part of the DGROUPA disk group. The
diagram shows that, when you add a disk to a disk group, the ASM instance ensures that the disk is
addressable and usable. The disk is then formatted and rebalanced. The rebalance process is time
consuming because it moves extents from all files onto the new disk.
Note: Rebalancing does not block any database operations. The main impact that a rebalance process
has is on the I/O load on the system. The higher the power of the rebalance, the more I/O load it puts
on the system. Thus less I/O bandwidth is available for database I/Os.
e
l
c
a
r
O
y
m
e
d
a
c
A
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
This command is generally not necessary because it is automatically done as disks are added,
dropped, or resized. However, it is useful if you want to use the POWER clause to override the default
speed defined by the initialization parameter ASM_POWER_LIMIT. You can change the power level
of an ongoing rebalance operation by reentering the command with a new level. A power level of
zero causes rebalancing to halt until the command is either implicitly or explicitly reinvoked. The
following statement dismounts DGROUPA:
e
l
c
ra
The MOUNT and DISMOUNT options allow you to make one or more disk groups available or
unavailable to the database instances. The ability to manually unmount and mount is useful in a
clustered ASM environment supporting a single instance, when that instance is failed over to a
different node.
Oracle Database 11g: Administration Workshop II D - 31
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
ASM disk
group
ASM
instance
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
Note: In addition to the disk group compatibilities, the compatible parameter (database compatible
version) determines the features that are enabled; it applies to the database or ASM instance
depending on the instance_type parameter. For example: Setting it to 10.1 would preclude use of any
features introduced in Oracle Database 11g (disk online/offline, variable extents, and so on).
e
d
a
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A
a
r
O
Property
Values
Description
au_size
Create,
Alter
1|2|4|8|16|32|64MB
compatible.rdbms
Create,
Alter
compatible.asm
Create,
Alter
compatible.advm
Create,
Alter
disk_repair_time
Create,
Alter
0 M to 232 D
template.tname.
redundancy
Alter
UNPROTECT|MIRROR|HIGH
template.tname.
stripe
Alter
COARSE|FINE
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Using SQL*Plus
Using asmcmd
ASMCMD> ls -l +DATA/orcl/datafile
Type
Redund Striped Time
DATAFILE MIRROR COARSE
JUL 08 21:00:00
DATAFILE MIRROR COARSE
JUL 08 21:00:00
..
Sys Name
Y SYSTEM.256.689832921
Y SYSAUX.257.689832923
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Note: Enterprise Manager Database Control is able to display most of the ASM metadata by simply
navigating among the various ASM web pages.
Primary
extent
Secondary
extent
y
m
e
d
a
c
A
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
a
r
O
Summary
In this lesson, you should have learned how to:
Manage the ASM instance using SQL*plus, asmcmd, and
Enterprise Manager
Create and drop ASM disk groups
Specify ASM compatibility attributes
Extend ASM disk groups
Compare methods of retrieving ASM metadata
y
m
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
e
d
a
c
A
a
r
O
y
m
e
d
a
a
r
O
e
l
c
e
l
c
a
r
O ly
& On
l
a e
n
r
s
e
t
U
n
I
c
A