Está en la página 1de 125

Oracle Database 10g:

Backup and Recovery


Volume I Student Guide

D22057GC10
Production 1.0
June 2006
D46524

Authors
Donna Keesling
Maria Billings
Technical Contributors
and Reviewers
Christopher Andrews
Tammy Bednar
Tom Best
Harald van Breederode
Mary Jane Bryksa
Marielle Canning
Tim Chien
Donna Cooksey
Judy Ferstenberg
Gerlinde Frenzen
Joel Goodman
Pete Jones
Isabelle Marchand
Sabiha Miri
Manish Pawar
Jim Spiller
George Stabler
Anthony Woodell

Editor
Daniel Milne

Graphic Designer
Satish Bettegowda

Publisher
Jobi Varghese

Copyright 2006, Oracle. All rights reserved.


Disclaimer
This document contains proprietary information and is protected by copyright and
other intellectual property laws. You may copy and print this document solely for your
own use in an Oracle training course. The document may not be modified or altered in
any way. Except where your use constitutes "fair use" under copyright law, you may
not use, share, download, upload, copy, print, display, perform, reproduce, publish,
license, post, transmit, or distribute this document in whole or in part without the
express authorization of Oracle.
The information contained in this document is subject to change without notice. If you
find any problems in the document, please report them in writing to: Oracle University,
500 Oracle Parkway, Redwood Shores, California 94065 USA. This document is not
warranted to be error-free.
Restricted Rights Notice
If this documentation is delivered to the United States Government or anyone using
the documentation on behalf of the United States Government, the following notice is
applicable:
U.S. GOVERNMENT RIGHTS
The U.S. Governments rights to use, modify, reproduce, release, perform, display, or
disclose these training materials are restricted by the terms of the applicable Oracle
license agreement and/or the applicable U.S. Government contract.
Trademark Notice
Oracle, JD Edwards, PeopleSoft, and Siebel are registered trademarks of Oracle
Corporation and/or its affiliates. Other names may be trademarks of their respective
owners.

Practice for Lesson 1

There are no practices for Lesson 1.

Practice for Lesson 2

In this practice, you configure your database for recoverability.

Practice 2-1: Configure Your Database


1) Use Enterprise Manager to configure your database in ARCHIVELOG mode.
2) Use Enterprise Manager to verify that the Flash Recovery Area has been configured for your
database and increase the Flash Recovery Area size to 3 GB.
3) Set Preferred Credentials in Enterprise Manager.
4) Use Recovery Manager (RMAN) to connect to your target database. Make note of thedatabase
identifier (DBID) of your database.Database Identifier: ____________________________ Make
note of the database identifier (DBID) of your database.
5) Use the RMAN SHOW ALL command to view the configuration settings in yourdatabase and
then exit from your RMAN session.

Practice for Lesson 3

In this practice, you configure automatic backup of the control file. You also configure a
backup of your database using the Oracle-Suggested Backup Strategy feature in
Enterprise Manager Database Control..

Practice 3-1: Use RMAN to Create and Manage Backups


1) Use Enterprise Manager Database Control to configure autobackup of the control file and the
server parameter file.
2) Use Enterprise Manager Database Control to configure backup optimization and enable block
change tracking. Specify /u01/app/oracle/oradata/orcl/chg_track.f for the
name of the blockchange tracking file.
3) Use Enterprise Manager Database Control to create a whole database backup using the Oraclesuggested backup strategy.
4) Use Enterprise Manager to view information about your backups.
5) Use RMAN to create a duplexed backup set of the EXAMPLE tablespace.
6) Use Enterprise Manager Database Control to perform a crosscheck of your backups.

Practice for Lesson 4

In this practice, you use RMAN to perform recovery.

Practice 4-1: Use RMAN to Recover a Datafile


In this practice, you use RMAN to recover a lost datafile. Notice how you are prompted
by Enterprise Manager to recover the lost datafile.
1) Use SQL*Plus to query the HR.REGIONS table. Make note of the number of rows in the
HR.REGIONS table.
2) At the operating system prompt, execute the lab_04_01_02_01.sh script to simulate a
failure in your database. This script deletes the EXAMPLE tablespace datafile.
3) Use SQL*Plus to query the HR.JOBS table.
4) Use Enterprise Manager to perform database recovery of the EXAMPLE tablespace
datafile.
5) Return to your SQL*Plus session and again attempt to query the HR.JOBS table.

10

Practice 4-2: Use the Flash Recovery Area to Quickly Recover a


Datafile
In this practice, you recover a lost datafile by using the Flash Recovery Area for fast
recovery.
1) Use SQL*Plus to query the HR.REGIONS table. Make note of the number of rows in
the HR.REGIONS table.
2) At the operating system prompt, execute the lab_04_02_02_01.sh script to
simulate a failure in your database. This script deletes the EXAMPLE tablespace
datafile.
3) Use SQL*Plus to query the HR.DEPARTMENTS table.
4) Use the RMAN SWITCH TO COPY command to recover the datafile.
5) Query the HR.JOBS table.
6) Using Enterprise Manager Database Control, verify that the datafile being used for
the EXAMPLE tablespace is in the Flash Recovery Area.
7) Make a copy of the datafile in the original location and switch back to it.
8) Use Enterprise Manager Database Control to verify the file.

11

Practice 4-3: Recover Control Files


In this practice, you recover your control file using an autobackup.
1) Use SQL*Plus to view files information for the control files in your database. Query
V$CONTROLFILE.
2) Simulate a failure in your environment by executing the lab_04_03_02_01.sh script to
delete all your control files.
3) You need some more information about your control files. Query
V$CONTROLFILE_RECORD_SECTION to learn more about the contents of your
control file.
4) You have lost all your control files and will need to recover them from the control file
autobackup. Use Recovery Manager to recover the control files.

12

Practice 4-4: Delete Obsolete Backups


1) Use Recovery Manager to view obsolete backups.
2) Use Enterprise Manager Database Control to delete obsolete backups.
3) You can also use RMAN to verify that your obsolete backups were deleted.

13

Practice for Lesson 5


In this practice, you use Oracle Flashback features to recover from errors in your database.

14

Practice 5-1: Enable Flashback Database


1) Use Enterprise Manager to enable Flashback Database.
2) Use the ALTER DATABASE command to enable supplemental logging.

15

Practice 5-2: Set Restore Points and Perform Flashback Table


Restore points are a way to bookmark database points in time. Set a restore point to
remember a significant change so that you can quickly recover to that point in time
without having to record an SCN or time.
1) You must enable row movement to use restore points. Use Enterprise Manager to
enable row movement for the HR.LOCATIONS table.
2) Create a normal restore point.
3) Use SQL*Plus to query the POSTAL_CODE column in the HR.LOCATIONS table.
4) Execute the lab_05_02_04_01.sql script to update the POSTAL_CODE column
in the HR.LOCATIONS table so that all postal codes are set to 11111.
5) Execute the lab_05_02_05_01.sql script to query the POSTAL_CODE column
in the HR.LOCATIONS table again.
6) Restore the POSTAL_CODE column values using the restore point.
7) Return to your SQL*Plus session. Execute the lab_05_02_07_01.sql script to
query the POSTAL_CODE column in HR.LOCATIONS again to be sure the correct values
have been restored.

16

Practice 5-3: Use Flashback Query and Flashback Versions


Query
1. Execute the lab_05_03_01_01.sql script to query the HR.LOCATIONS table for location
ID 1400.
2. Execute the lab_05_03_02_01.sql script to update the POSTAL_CODE column in the
HR.LOCATIONS table, simulating user error.
3. Execute the lab_05_03_03_01.sql script to query the POSTAL_CODE column in
HR.LOCATIONS and view the change.
4. Execute the lab_05_03_04_01.sql script to update the POSTAL_CODE column in the
HR.LOCATIONS table, simulating user error.
5. Use Enterprise Manager to perform Flashback Versions Query to correct the user errors.
6. Return to your SQL*Plus session. Query the HR.LOCATIONS table to confirm the Flashback
operation.

17

Practice 5-4: Use Flashback Database


1) Use Enterprise Manager to verify that Flashback Database is enabled.
2) Use Enterprise Manager to create a Guaranteed Restore Point.
3) Execute the lab_05_04_03_01.sql script to determine the number of rows in
the HR.JOB_HISTORY table. Record the number of rows: ___________
4) Execute the lab_05_04_04_01.sql script to truncate the HR.JOB_HISTORY
table.
4) Execute the lab_05_04_05_01.sql script to determine the number of rows in
the HR.JOB_HISTORY table.
5) Use Flashback Database to restore the HR.JOB_HISTORY table rows.
6) Return to your SQL*Plus session. Execute the lab_05_04_07_02.sql script to query the
HR.JOB_HISTORY table again to be sure the data has been restored.

18

Practice for Lesson 6


In this practice, you create a duplicate database.

19

Practice 6-1: Create a Duplicate Database


In this practice, you use RMAN to create a duplicate database on the same host as your
database.
1) Create an Oracle password file for your auxiliary instance.
2) Use Oracle Net Manager to create an entry called AUXDB in the tnsnames.ora
file.
3) Create an initialization parameter file for the auxiliary instance.
4) Start the auxiliary instance in NOMOUNT mode using the initAUX.ora file.
5) Create a server parameter file (SPFILE).
6) Verify that your target database (orcl database) is mounted or open.
7) Start RMAN with a connection to the target database (orcl) and the auxiliary
instance.
8) Create the duplicate database by executing the DUPLICATE command.
9) Use SQL*Plus to log in to your AUX database and execute a query against the
HR.REGIONS table.
10) Now that you have completed the test recovery by creating a duplicate database, shut
down the aux instance.
11) Change your ORACLE_SID to orcl in preparation for later practices.

20

Practice for Lesson 7


In this practice, you use tablespace point-in-time recovery to recover from unwanted changes to your
database.

21

Practice 7-1: Use Tablespace Point-in-time Recovery


1) Execute the lab_07_01_01_01.sh script to export the HR schema.
2) Execute the lab_07_01_02_02.sql script to create a new tablespace and a new
user in your database.
3) Execute the lab_07_01_03_01.sh script to populate the new tablespace with a
copy of the data from the HR schema.
Note: The import should complete successfully. You will receive error messages
because the import excludes the COUNTRIES, REGIONS, and LOCATIONS tables.
These messages can be ignored.
4) Create a backup of your database using RMAN.
5) Record the current SCN: ____________
6) Record the current time.
7) Execute the lab_07_01_07_01.sql script to query the HRTEST.EMPLOYEES
table and view information about employees in department 60.
Make note of the highest salary that is displayed: ________
8) Execute the lab_07_01_08_01.sql script to update the salaries for the
employees in department 60 and note the highest salary displayed.
Highest salary: _____________
9) You now want to perform TSPITR for the HRTEST tablespace to return it to the state
prior to the updates. Execute the lab_07_01_09_01.sql script to determine
whether there are any dependencies that will prevent the TSPITR operation.
10) You can use Enterprise Manager Database Control or RMAN command line to
perform tablespace point-in-time recovery.
11) Verify that the HRTEST tablespace is online.
12) Verify that the SALARY columns in HRTEST.EMPLOYEES for the employees in
department 60 contain the correct values.
13) Execute the lab_07_01_13_02.sql script to add a constraint to the
HRTEST.DEPARTMENTS table.
14) Assume you need to perform TSPITR on the HRTEST tablespace again. Execute the
lab_07_01_14_02.sql query to determine whether there are any dependencies
outside the recovery set.
15) If you wanted to complete the tablespace point-in-time recovery for the HRTEST tablespace
now, what would you need to do?
22

Note: You will not perform another tablespace point-in-recovery in this practice.
You would need to disable the DEPT_LOC_ID_FK constraint that was added to your
HRTEST.DEPARTMENTS table or you would need to add

23

Practice for Lesson 8


In this practice, you create a recovery catalog in your instructors database and register
your database in the recovery catalog.

24

Practice 8-1: Create the Recovery Catalog and Register the


Database
The tablespace for the recovery catalog and the recovery catalog owner have been created
in the instructor database. The tablespaces are named RCTS01 RCTS12. The users are
named RCUSER01 RCUSER12.
1) Connect to the recovery catalog database (instructors database) with the appropriate
recovery catalog owner name (if you are using PC01, connect as RCUSER01) using
RMAN. Create the recovery catalog in your assigned tablespace. (If you are using
PC01, your assigned tablespace is RCTS01.) The service name is RCDB.
2) Using RMAN, connect to your target database and the recovery catalog database.
3) Using RMAN, execute the command to resynchronize the control file and recovery catalog. What
happens? Why?
4) Register the target database in the recovery catalog. You can use RMAN commandline or
Enterprise Manager for this step.
5) Create an RMAN script named whole_backup to make a whole database backup. Do not
execute the whole_backup script at this time.
6) Use the PRINT command to query the recovery catalog and verify the creation of your
whole_backup script.

7) In preparation for later practices, use RMAN to unregister your database from the
recovery catalog.

25

Practice for Lesson 9


In this practice, you monitor the progress of your RMAN backup jobs.

26

Practice 9-1: Use SQL to Monitor the Progress of RMAN


Backups
1) Invoke RMAN and delete all obsolete backups.
2) Open a second terminal window. Change to the labs directory. Invoke SQL*Plus
and connect as SYSDBA. You will use this second session to monitor a database
backup.
3) Return to your first terminal window. In your RMAN session, begin a whole database
backup.
4) Use your SQL*Plus session to monitor the progress of the whole 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
lab_09_01_04_01.sql script to query V$SESSION_LONGOPS.

27

Practice 9-2: Use Enterprise Manager to Monitor RMAN Jobs


You can easily monitor RMAN jobs in Enterprise Manager.
1) Start Enterprise Manager and log in as SYS/ORACLE as SYSDBA.
2) Delete obsolete backups.
3) Start a whole database backup

28

Practice Solutions

29

Table of Contents
Solutions for Practice 2-1: Configure Your Database .................................................... 5
Solutions for Practice 3-1: Use RMAN to Create and Manage Backups ..................... 10
Solutions for Practice 4-1: Use RMAN to Recover a Datafile ..................................... 17
Solutions for Practice 4-2: Use the Flash Recovery Area to Quickly Recover a Datafile
...................................................................................................................................... 21
Solutions for Practice 4-3: Recover Control Files ........................................................ 26
Solutions for Practice 4-4: Delete Obsolete Backups ................................................... 33
Solutions for Practice 5-1: Enable Flashback Database ............................................... 36
Solutions for Practice 5-2: Set Restore Points and Perform Flashback Table.............. 38
Solutions for Practice 5-3: Use Flashback Query and Flashback Versions Query....... 46
Solutions for Practice 5-4: Use Flashback Database .................................................... 52
Solutions for Practice 6-1: Create a Duplicate Database .............................................. 60
Solutions for Practice 7-1: Use Tablespace Point-in-time Recovery............................ 74
Solutions for Practice 8-1: Create the Recovery Catalog and Register the Database... 89
Solutions for Practice 9-1: Use SQL to Monitor the Progress of RMAN Backups...... 96
Solutions for Practice 9-2: Use Enterprise Manager to Monitor RMAN Jobs ............. 9

30

Practice Solutions for Lesson 1


There are no practices for Lesson 1.

31

Practice Solutions for Lesson 2


In this practice, you configure your database for recoverability.

32

Solutions for Practice 2-1: Configure Your Database


1) Use Enterprise Manager to configure your database in ARCHIVELOG mode.
Answer:
1. Start the Web browser and enter http://your host name:1158/em.
2. Enter SYS in the User Name field and oracle in the Password field. Select
SYSDBA in the Connect As menu. Click Login.
3. Click I agree on the Oracle Database 10g Licensing Information page.
4. Select the Maintenance page.
5. Select Recovery Settings in the Backup/Recovery Settings section.
6. In the Media Recovery section, select ARCHIVELOG Mode and click Apply.

7. The Confirmation page is displayed. Click Yes to restart the database instance.
8. On the Restart Database: Specify Host and Target Database Credentials page. In
the Host Credentials section, enter oracle in the Username and Password fields.
In the Database Credentials section, enter SYS in the Username field and
oracle in the Password field. Select Save as Preferred Credential. Click OK.
9. The Restart Database: Confirmation page is displayed. Click Yes to confirm the
restart of the database instance.
10. The Restart Database: Activity Information page is displayed. Wait a few minutes
and then click Refresh.
2) Use Enterprise Manager to verify that the Flash Recovery Area has been configured
for your database and increase the Flash Recovery Area size to 3 GB.
Answer:
1. Select the Maintenance page.
2. Select Recovery Settings in the Backup/Recovery Settings section.
33

3. Scroll to the Flash Recovery Area and verify that the Flash Recovery Area is enabled.

4. Enter 3 in the Flash Recovery Area Size field and click Apply.
5. The Update Message is displayed. Click the Database instance link to return to the
Maintenance page.
3) Set Preferred Credentials in Enterprise Manager.
Answer:
1. Select Preferences at the top of the Maintenance page.
2. Select Preferred Credentials on the left side of the page.
3. Click the Set Credentials icon for the database instance.
4. Supply the following values:
Normal Username: system
Normal Password: oracle
SYSDBA Username: sys
SYSDBA Password: oracle
Host Username: oracle
Host Password: oracle
5. Click Test. The Credentials successfully verified for orcl.oracle.com message is displayed. If
you have any errors, correct them and click Test again.
6. Click Apply to save the settings.
7. Click Database to return to the Database home page.
4) Use Recovery Manager (RMAN) to connect to your target database. Make note of the database
identifier (DBID) of your database.
Database Identifier: ____________________________
Answer:
34

1. Open a terminal window and log in as oracle/oracle.


2. Start RMAN and connect to the target database by entering the following
command at the operating system prompt: rman target /
[oracle@edrsr10p1 oracle]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Tue
Mar 7 12:51:53 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1090770270)
RMAN>

Make note of the database identifier (DBID) of your database.


3. Use the RMAN SHOW ALL command to view the configuration settings in your
database and then exit from your RMAN session.
Answer:
RMAN> show all;
using target database control file instead of recovery
catalog
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE
DISK TO '%F'; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE
SBT_TAPE TO '%F'; # deft
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO
BACKUPSET; # default
CONFIGURE DEVICE TYPE SBT_TAPE PARALLELISM 1 BACKUP TYPE
TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO
1; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE SBT_TAPE
TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO
1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE
SBT_TAPE TO 1; # default
CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' FORMAT '%U';
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
35

CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default


CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO
'/u01/app/oracle/product/10.2.0/db_1/dbst
RMAN> exit
Recovery Manager complete.

36

Practice Solutions for Lesson 3


In this practice, you configure automatic backup of the control file. You also configure a
backup of your database using the Oracle-Suggested Backup Strategy feature in
Enterprise Manager Database Control.

37

Solutions for Practice 3-1: Use RMAN to Create and Manage Backups
1) Use Enterprise Manager Database Control to configure autobackup of the control file
and the server parameter file.
Answer:
1. Select Maintenance > High Availability > Backup/Recovery Settings > Backup
Settings.
2. On the Backup Settings page, select the Policy tab.
3. In the Backup Policy section, select Automatically backup the control file and
server parameter file (SPFILE) with every backup and database structural
change. Click OK.

4. You are returned to the Maintenance page.


2) Use Enterprise Manager Database Control to configure backup optimization and enable block change
tracking. Specify /u01/app/oracle/oradata/orcl/chg_track.f for the name of the
block change tracking file.
Answer:
1. Select Maintenance > High Availability > Backup/Recovery Settings > Backup Settings.
2. On the Backup Settings page, select the Policy tab.
3. In the Backup Policy section, select Optimize the whole database backup by skipping unchanged
files such as read-only and offline datafiles that have been backed up.
4. Select Enable block change tracking for faster incremental backups and enter
a. /u01/app/oracle/oradata/orcl/chg_track.f in the Block Change
Tracking File field. Click OK.

38

5. You are returned to the Maintenance page.


3) Use Enterprise Manager Database Control to create a whole database backup using the Oraclesuggested backup strategy.
Answer:
1. Select Maintenance > High Availability > Backup/Recovery > Schedule Backup.
2. In the Oracle-Suggested Backup section of the Schedule Backup page, click Schedule OracleSuggested Backup.

3. On the Schedule Oracle-Suggested Backup: Destination page, select Disk. Click Next.
4. Review the information on the Schedule Oracle-Suggested Backup: Setup page. Note that a full
database copy will be performed during the first backup. After that, an incremental backup to disk
will be performed every day. Click Next.

39

5. On the Schedule Oracle-Suggested Backup: Schedule page, you can specify the time for your
backups. Set the Time Zone field to correspond to your time zone.

6. Review the information on the Schedule Oracle-Suggested Backup: Review page.


Click Submit Job.
7. The Status page is displayed indicating that the job has been submitted. Click View Job
to monitor the status of the backup job.
8. Click the Refresh button on your browser to refresh the Execution page. Click the
Backup link to view the output log.

9. In the output log, you can see that RMAN has made a datafile copy backup of
each datafile in your database.

40

10. Click the Database tab to return to the Database Home page.
4) Use Enterprise Manager to view information about your backups.
Answer:

1. Select Maintenance > High Availability > Backup/Recovery > Backup Reports.
2. Click the link for the backup you took in Question 3 to view detailed information about the
backup.

3. Click the Database Instance link to return to the Maintenance page.


5) Use RMAN to create a duplexed backup set of the EXAMPLE tablespace.
Answer:
1. Start RMAN and connect to the target database.
[oracle@edrsr10p1 backup1]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Wed
Mar 22 10:38:18 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1090770270)
2. Create two backup set copies. One copy should be in the

41

/home/oracle/backup1 directory and one copy should be in the


/home/oracle/backup2 directory.
RMAN> @sol_03_01_05_02.rmn
RMAN> backup device type disk
2> copies 2
3> tablespace example
4> format '/home/oracle/backup1/%U',
'/home/oracle/backup2/%U';
Starting backup at 22-MAR-06
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00005
name=/u01/app/oracle/oradata/orcl/example01.dbf
channel ORA_DISK_1: starting piece 1 at 22-MAR-06
channel ORA_DISK_1: finished piece 1 at 22-MAR-06 with 2
copies and tag TAG20063
piece handle=/home/oracle/backup1/0ehejks7_1_1
comment=NONE
piece handle=/home/oracle/backup2/0ehejks7_1_2
comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time:
00:00:15
Finished backup at 22-MAR-06
Starting Control File and SPFILE Autobackup at 22-MAR-06
piece
handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup
/2006_03_22/o1_E
Finished Control File and SPFILE Autobackup at 22-MAR-06
RMAN> **end-of-file**
RMAN>
3. Use the RMAN LIST BACKUP SUMMARY command to view a listing of the backup sets and
pieces. The #Copies column shows the duplexed backup set copies you made. Exit from
RMAN.
RMAN> @sol_03_01_05_03.rmn
RMAN> list backup summary;
using target database control file instead of recovery catalog
List of Backups
===============
Key
TY LV S Device Type Completion Time #Pieces
#Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------ ---------- --5
B F A DISK
21-MAR-06
1
1
NO
TAG200600
42

7
B F A DISK
NO
TAG200607
8
B F A DISK
NO
TAG200603
9
B F A DISK
NO
TAG200608
RMAN> **end-of-file**
RMAN> exit

22-MAR-06

22-MAR-06

22-MAR-06

Recovery Manager complete


6) Use Enterprise Manager Database Control to perform a cross-check of your backups.
Answer:
1. Select Maintenance > High Availability > Backup/Recovery > Manage Current
Backups.
2. Click Crosscheck All.

3. Review the information on the Crosscheck All: Specify Job Parameters page and
accept the default values. Click Submit Job.
4. You receive the Job submission succeeded message. You can click View Job to
monitor the cross-check job. After it completes successfully, return to the
Database Home page.
5. Log out of Enterprise Manager.

43

Practice Solutions for Lesson 4


In this practice, you use RMAN to perform recovery.

44

Solutions for Practice 4-1: Use RMAN to Recover a Datafile


In this practice, you use RMAN to recover a lost datafile. Notice how you are prompted
by Enterprise Manager to recover the lost datafile.
1) Use SQL*Plus to query the HR.REGIONS table. Make note of the number of rows in the
HR.REGIONS table.
Answer:
1. Open a terminal window and log in to SQL*Plus and connect as the HR user with HR as the
password.
2. Query the HR.REGIONS table and record the number of rows. Number of rows: ___________
[oracle@edrsr10p1 oracle]$ sqlplus hr/hr
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Mar 23 12:51:00
2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Production With the Partitioning, OLAP and Data Mining options
SQL> select * from regions;
REGION_ID
---------1
2
3
4

REGION_NAME
------------------------Europe
Americas
Asia
Middle East and Africa

3. Exit from your SQL*Plus session.


2) At the operating system prompt, execute the lab_04_01_02_01.sh script to simulate a failure in
your database. This script deletes the EXAMPLE tablespace datafile.
Answer:
1. At the operating system prompt, change to the labs directory and execute the
lab_04_01_02_01.sh script.
[oracle@edrsr10p1 labs]$ ./lab_04_01_02_01.sh
EXAMPLE tablespace file deleted

3) Use SQL*Plus to query the HR.JOBS table.


Answer:
45

1. Log in to SQL*Plus and connect as the HR user with HR as the password.


2. Query the HR.JOBS table.
SQL> select * from jobs;
select * from jobs
*
ERROR at line 1:
ORA-00376: file 5 cannot be read at this time
ORA-01110: data file 5:
'/u01/app/oracle/oradata/orcl/example01.dbf'
4) Use Enterprise Manager to perform database recovery of the EXAMPLE tablespace datafile.
Answer:
1. Start Enterprise Manager and log in as SYS/ORACLE as SYSDBA.
2. Navigate to the Maintenance page.
3. Select Perform Recovery on the Maintenance page.
4. Click the Datafiles Need Media Recovery link.

5. Select the file and click Next.

46

6. Select No. Restore the files to the default location. Click Next.

7. On the Perform Object Level Recovery: Review page, click Edit RMAN Script to view the
script that will be executed. Click Submit.
8. The Processing page is displayed. After the recovery operation completes, the Result page is
displayed indicating that the recovery operation succeeded.

9. Click OK to return to the Maintenance page.


5) Return to your SQL*Plus session and again attempt to query the HR.JOBS table.
Answer:
1. Query the HR.JOBS table.

47

SQL> select * from jobs;


JOB_ID
MAX_SALARY
------------------AD_PRES
40000
AD_VP
30000
AD_ASST
6000
FI_MGR
16000

MK_REP
9000
HR_REP
9000
PR_REP
10500

JOB_TITLE

MIN_SALARY

----------------------------------- ---------President

20000

Administration Vice President

15000

Administration Assistant

3000

Finance Manager

8200

Marketing Representative

4000

Human Resources Representative

4000

Public Relations Representative

4500

19 rows selected.

48

Solutions for Practice 4-2: Use the Flash Recovery Area to Quickly Recover a
Datafile
In this practice, you recover a lost datafile by using the Flash Recovery Area for fast
recovery.
1) Use SQL*Plus to query the HR.REGIONS table. Make note of the number of rows in the
HR.REGIONS table.
Answer:
1. Log in to SQL*Plus and connect as the HR user with HR as the password.
2. Query the HR.REGIONS table.
3. Exit from SQL*Plus.
2) At the operating system prompt, execute the lab_04_02_02_01.sh script to simulate a failure in
your database. This script deletes the EXAMPLE tablespace datafile.
Answer:
1. At the operating system prompt, change to the labs directory and execute the
lab_04_02_02_01.sh script.
[oracle@edrsr10p1 labs]$ ./lab_04_02_02_01.sh
EXAMPLE tablespace file deleted
[oracle@edrsr10p1 labs]$

3) Use SQL*Plus to query the HR.DEPARTMENTS table.


Answer:
1. Log in to SQL*Plus and connect as the HR user with HR as the password.
2. Query the HR.DEPARTMENTS table.
SQL> select * from departments;
select * from departments
*
ERROR at line 1:
ORA-01116: error in opening database file 5
ORA-01110: data file 5:
'/u01/app/oracle/oradata/orcl/example01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
3. Make note of the number of the datafile that is unavailable. Datafile number: ____
49

4. Exit from your SQL*Plus session.


4)

Use the RMAN SWITCH TO COPY command to recover the datafile.


Answer:
1. Log in to your target database using RMAN.
2. Take the datafile offline.
RMAN> SQL 'alter database datafile 5 offline';
sql statement: alter database datafile 5 offline
3. Execute the SWITCH TO COPY command for the datafile you noted in step 3.
RMAN> switch datafile 5 to copy;
datafile 5 switched to datafile copy
"/u01/app/oracle/flash_recovery_area/ORCL/"

4. Recover the datafile.


RMAN> recover datafile 5;
Starting recover at 24-MAR-06
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=132 devtype=DISK
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: sid=130 devtype=SBT_TAPE
channel ORA_SBT_TAPE_1: Oracle Secure Backup
starting media recovery
media recovery complete, elapsed time: 00:00:03
Finished recover at 24-MAR-06
5. Bring the datafile online.
RMAN> sql 'alter database datafile 5 online';
sql statement: alter database datafile 5 online
RMAN>
6. Exit from your RMAN session.
5) Query the HR.JOBS table.
Answer:
1. Log in to SQL*Plus as HR/HR and query the HR.JOBS table. (Output has been formatted to fit
the code box.)
50

SQL> select * from jobs;


JOB_ID
JOB_TITLE
---------- -----------------------------AD_PRES
President
AD_VP
Administration Vice President

HR_REP
Human Resources Representative
PR_REP
Public Relations Representative

MIN_S MAX_SALARY
----- ---------20000
40000
15000
30000
4000
4500

9000
10500

19 rows selected.

6) Using Enterprise Manager Database Control, verify that the datafile being used for the
EXAMPLE tablespace is in the Flash Recovery Area.
Answer:
1. Select Tablespaces on the Administration page.
2. Select the Example tablespace and click View.

3. Click Return to return to the Tablespaces page.


7) Make a copy of the datafile in the original location and switch back to it.
Answer:
1. Log in to RMAN and connect to your target database.
2. Create an image copy of the datafile in the original location.
RMAN> @sol_04_02_07_02.rmn
RMAN> backup as copy datafile 5
2> format '/u01/app/oracle/oradata/orcl/example01.dbf';
Starting backup at 24-MAR-06
using target database control file instead of recovery
51

catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=129 devtype=DISK
channel ORA_DISK_1: starting datafile copy
input datafile fno=00005
name=/u01/app/oracle/flash_recovery_area/ORCL/datafilef
output filename=/u01/app/oracle/oradata/orcl/example01.dbf
tag=TAG20060324T13447
channel ORA_DISK_1: datafile copy complete, elapsed time:
00:00:07
Finished backup at 24-MAR-06
Starting Control File and SPFILE Autobackup at 24-MAR-06
piece
handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup
/2006_03_24/o1_E
Finished Control File and SPFILE Autobackup at 24-MAR-06
RMAN> **end-of-file**

3. Take the datafile offline.


RMAN> sql 'alter database datafile 5 offline';
sql statement: alter database datafile 5 offline

4. Switch to the new copy you made.


RMAN> switch datafile 5 to copy;
datafile 5 switched to datafile copy
"/u01/app/oracle/oradata/orcl/example01.dbf"

5. Recover the datafile.


RMAN> recover datafile 5;
Starting recover at 24-MAR-06
using channel ORA_DISK_1
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: sid=154 devtype=SBT_TAPE
channel ORA_SBT_TAPE_1: Oracle Secure Backup
starting media recovery
media recovery complete, elapsed time: 00:00:02
Finished recover at 24-MAR-06

6. Bring the datafile back online. Exit from RMAN.


RMAN> sql 'alter database datafile 5 online';
sql statement: alter database datafile 5 online
52

8) Use Enterprise Manager Database Control to verify the file.


Answer:
1. Select Tablespace on the Administration page.
2. Select the EXAMPLE tablespace and click View.

3. Note that the datafile is the one you switched to.


4. Click the Database tab to return to your database home page.

53

Solutions for Practice 4-3: Recover Control Files


In this practice, you recover your control file by using an autobackup.
1) Use SQL*Plus to view files information for the control files in your database. Query
V$CONTROLFILE.
Answer:
1. Log in to SQL*Plus as SYSDBA.
2. Query the NAME column in V$CONTROLFILE. Exit from SQL*Plus.
SQL> SELECT name FROM v$controlfile;
NAME
--------------------------------------------/u01/app/oracle/oradata/orcl/control01.ctl
/u01/app/oracle/oradata/orcl/control02.ctl
/u01/app/oracle/oradata/orcl/control03.ctl
2) Simulate a failure in your environment by executing the lab_04_03_02_01.sh
script to delete all your control files.
Answer:
1. In your terminal window session, change to the labs directory and execute the
lab_04_03_02_01.sh script.
[oracle@edrsr10p1 oracle]$ cd labs
[oracle@edrsr10p1 labs]$ ./lab_04_03_02_01.sh
Control files deleted
[oracle@edrsr10p1 labs]$
3)

You need some more information about your control files. Query
V$CONTROLFILE_RECORD_SECTION to learn more about the contents of your
control file.
Answer:
1. Log in to SQL*Plus as SYSDBA.
2. Query the V$CONTROLFILE_RECORD_SECTION view.
SQL> SELECT * FROM v$controlfile_record_section;
SELECT * FROM v$controlfile_record_section
*
ERROR at line 1:
ORA-00210: cannot open the specified control file
ORA-00202: control file:
'/u01/app/oracle/oradata/orcl/control01.ctl'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
54

4)

You have lost all your control files and will need to recover them from the control file
autobackup. Use Recovery Manager to recover the control files.
Answer:
1. Use SQL*Plus to shut down your instance. Exit from your SQL*Plus session.
[oracle@edrsr10p1 oracle]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 28
10:20:26 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
- Production
With the Partitioning, OLAP and Data Mining options
SQL> shutdown abort
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition
Release 10.2.0.1.0 - Pn
With the Partitioning, OLAP and Data Mining options
[oracle@edrsr10p1 oracle]$
2. Use RMAN to connect to your target database.
[oracle@edrsr10p1 oracle]$ rman
Recovery Manager: Release 10.2.0.1.0 - Production on Tue
Mar 28 10:23:17 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
RMAN> connect target /
connected to target database (not started)
RMAN>

3. Restart the instance in NOMOUNT mode.


RMAN> startup nomount
Oracle instance started
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 109053520 bytes
Database Buffers 171966464 bytes
Redo Buffers 2973696 bytes
55

4. Set the database identifier.


Note: Your database identifier will be a different value from that shown in the
solution. You recorded the database identifier in Practice 2-1.
RMAN> set dbid 1090770270;
executing command: SET DBID

5. Restore the control file from the autobackup.


RMAN> restore controlfile from autobackup;
Starting restore at 28-MAR-06
using target database control file instead of recovery
catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
recovery area destination:
/u01/app/oracle/flash_recovery_area
database name (or database unique name) used for search:
ORCL
channel ORA_DISK_1: autobackup found in the recovery area
channel ORA_DISK_1: autobackup found:
/u01/app/oracle/flash_recovery_area/ORCL/p
channel ORA_DISK_1: control file restore from autobackup
complete
output filename=/u01/app/oracle/oradata/orcl/control01.ctl
output filename=/u01/app/oracle/oradata/orcl/control02.ctl
output filename=/u01/app/oracle/
Finished restore at 28-MAR-06
6. Mount the database.
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
7. Recover the database by issuing the RECOVER DATABASE command.
RMAN> recover database;
Starting recover at 28-MAR-06
Starting implicit crosscheck backup at 28-MAR-06
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
Crosschecked 11 objects
56

Finished implicit crosscheck backup at 28-MAR-06


Starting implicit crosscheck copy at 28-MAR-06
using channel ORA_DISK_1
Crosschecked 5 objects
Finished implicit crosscheck copy at 28-MAR-06
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name:
/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2006_0
3_28/o1_mfc
File Name:
/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2006_0
3_28/o1_mfc
File Name:
/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2006_0
3_28/o1_mfc
File Name:
/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2006_0
3_27/o1_mfp
using channel ORA_DISK_1
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: sid=155 devtype=SBT_TAPE
channel ORA_SBT_TAPE_1: Oracle Secure Backup
starting media recovery
archive log thread 1 sequence 116 is already on disk as
file /u01/app/oracle/flc
archive log thread 1 sequence 117 is already on disk as
file /u01/app/oracle/flc
archive log thread 1 sequence 118 is already on disk as
file /u01/app/oracle/flc
archive log thread 1 sequence 119 is already on disk as
file /u01/app/oracle/org
archive log
filename=/u01/app/oracle/flash_recovery_area/ORCL/archivel
og/2006_06
archive log
filename=/u01/app/oracle/flash_recovery_area/ORCL/archivel
og/2006_07
archive log
filename=/u01/app/oracle/flash_recovery_area/ORCL/archivel
og/2006_08
archive log
filename=/u01/app/oracle/oradata/orcl/redo01.log thread=1
57

sequence=9
media recovery complete, elapsed time: 00:00:02
Finished recover at 28-MAR-06
8. Open the database with the RESETLOGS option.
RMAN> alter database open resetlogs;
database opened
9. Back up the current online redo log file and back up all the archived redo log files.
RMAN> SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
using target database control file instead of recovery
catalog
sql statement: ALTER SYSTEM ARCHIVE LOG CURRENT
RMAN> backup archivelog all;
Starting backup at 10-APR-06
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=159 devtype=DISK
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup
set
input archive log thread=1 sequence=15 recid=53
stamp=587378250
input archive log thread=1 sequence=16 recid=54
stamp=587379659
input archive log thread=1 sequence=17 recid=55
stamp=587379860
input archive log thread=1 sequence=18 recid=56
stamp=587379970
input archive log thread=1 sequence=19 recid=57
stamp=587380091
input archive log thread=1 sequence=20 recid=58
stamp=587380115
input archive log thread=1 sequence=21 recid=59
stamp=587380409
input archive log thread=1 sequence=22 recid=65
stamp=587386310
input archive log thread=1 sequence=23 recid=66
stamp=587386310
input archive log thread=1 sequence=24 recid=67
stamp=587386311
channel ORA_DISK_1: starting piece 1 at 10-APR-06
channel ORA_DISK_1: finished piece 1 at 10-APR-06
piece
handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/
58

2006_04_10/o1_mE
channel ORA_DISK_1: backup set complete, elapsed time:
00:00:26
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup
set
input archive log thread=1 sequence=1 recid=68
stamp=587391539
input archive log thread=1 sequence=2 recid=69
stamp=587391580
channel ORA_DISK_1: starting piece 1 at 10-APR-06
channel ORA_DISK_1: finished piece 1 at 10-APR-06
piece
handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/
2006_04_10/o1_mE
channel ORA_DISK_1: backup set complete, elapsed time:
00:00:02
Finished backup at 10-APR-06
Starting Control File and SPFILE Autobackup at 10-APR-06
piece
handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup
/2006_04_10/o1_E
Finished Control File and SPFILE Autobackup at 10-APR-06

10. Create a whole database backup.


RMAN> backup database;
Starting backup at 10-APR-06
released channel: ORA_SBT_TAPE_1
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001
name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile fno=00003
name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile fno=00005
name=/u01/app/oracle/oradata/orcl/example01.dbf
input datafile fno=00002
name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile fno=00004
name=/u01/app/oracle/oradata/orcl/users01.dbf
input datafile fno=00006
name=/u01/app/oracle/oradata/orcl/example02.dbf
channel ORA_DISK_1: starting piece 1 at 10-APR-06
channel ORA_DISK_1: finished piece 1 at 10-APR-06
piece
handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/
2006_04_10/o1_mE
59

channel ORA_DISK_1: backup set complete, elapsed time:


00:01:25
Finished backup at 10-APR-06
Starting Control File and SPFILE Autobackup at 10-APR-06
piece
handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup
/2006_04_10/o1_E
Finished Control File and SPFILE Autobackup at 10-APR-06

60

Solutions for Practice 4-4: Delete Obsolete Backups


1)

Use Recovery Manager to view obsolete backups.


Answer:
1. In your RMAN session, issue the REPORT OBSOLETE command to determine whether you
have any obsolete backups.
Note: Your results may vary from the following output.
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
-------------------- ------ ------------------ ------------------Archive Log
19
15-MAR-06
/u01/app/oracle/flash_recovery_ac
Archive Log
20
16-MAR-06
/u01/app/oracle/flash_recovery_ac
Archive Log
21
20-MAR-06
/u01/app/oracle/flash_recovery_ac
Archive Log
22
20-MAR-06
/u01/app/oracle/flash_recovery_ac
Archive Log
23
20-MAR-06
/u01/app/oracle/flash_recovery_ac
Archive Log
24
21-MAR-06
/u01/app/oracle/flash_recovery_ac
Datafile Copy
4
21-MAR-06
/u01/app/oracle/flash_recovery_af
Backup Set
5
21-MAR-06
Backup Piece
5
21-MAR-06
/u01/app/oracle/flash_recovery_ap
Backup Set
7
22-MAR-06
Backup Piece
7
22-MAR-06
/u01/app/oracle/flash_recovery_ap
Backup Set
9
22-MAR-06
Backup Piece
10
22-MAR-06
/u01/app/oracle/flash_recovery_ap

2)

Use Enterprise Manager Database Control to delete obsolete backups.


Answer:
1. Invoke Enterprise Manager and log in as sys/oracle as SYSDBA.
2. Select Maintenance > High Availability > Backup/Recovery > Manage Current Backups.

61

3. Click Delete All Obsolete to remove obsolete backups.

4. Review the information on the Delete All Obsolete: Specify Job Parameters page and
click Submit Job.
5. You receive the Job submission succeeded message. You can click View Job to
monitor the job. After it completes successfully, return to the Database Home page.
6. Access the Manage Current Backups page again to view the backup sets and image
copies that were retained.
3)

You can also use RMAN to verify that your obsolete backups were deleted.
Answer:
1. In your RMAN session, execute the REPORT OBSOLETE command.
RMAN> report obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
no obsolete backups found

62

Practice Solutions for Lesson 5


In this practice, you use Oracle Flashback features to recover from errors in your database.

63

Solutions for Practice 5-1: Enable Flashback Database


1)

Use Enterprise Manager to enable Flashback Database.


Answer:
1. Start Enterprise Manager and connect as SYS/ORACLE as SYSDBA.
2. Click the Maintenance tab.
3. Select Recovery Settings in the Backup/Recovery Settings section.
4. Scroll to the Flash Recovery section.
5. Select Enable Flashback Database - flashback logging can be used for fast database point-intime recovery and click Apply.

6. The Confirmation message is displayed. You must restart the database instance to enable
Flashback Database. Click Yes to restart the database instance.
7. Supply the Host and Operating System credentials if they are not filled in by default. Click OK

64

8. The Restart Database: Confirmation page is displayed. Click Yes.


9. The Restart Database:Activity Information page is displayed. Wait a few minutes and click
Refresh.
10. Log in to Enterprise Manager as SYS/ORACLE as SYSDBA.
2)

Use the ALTER DATABASE command to enable supplemental logging.


Answer:
1. In a terminal window, log in to SQL*Plus as SYSDBA.
[oracle@edrsr10p1 oracle]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Apr 18
09:10:07 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
- Production
With the Partitioning, OLAP and Data Mining options
2. Execute the ALTER DATABASE command to enable supplemental logging.
SQL> ALTER DATABASE add supplemental log data;
Database altered.

65

Solutions for Practice 5-2: Set Restore Points and Perform Flashback Table
Restore points are a way to bookmark database points in time. Set a restore point to
remember a significant change so that you can quickly recover to that point in time
without having to record an SCN or time.
1)

You must enable row movement to use restore points. Use Enterprise Manager to
enable row movement for the HR.LOCATIONS table.
Answer:
1. Navigate to the Administration page. Select Tables in the Database Objects section.
2. Enter HR in the Schema field and LOCATIONS in the Object Name field. Click Go.
3. Select the HR.LOCATIONS table and click Edit.

4. Select the Options subtab.


5. Select Yes in the Enable Row Movement menu. Click Apply.

66

2)

6.

The Update Message is displayed indicating that the change has been made to the
HR.LOCATIONS table.

7.

Click the Database tab to return to the home page.

Create a normal restore point.


Answer:
1. Select the Maintenance tab.
2. Select Manage Restore Points in the Backup/Recovery section.
3. Click Create on the Manage Restore Points page.

4. Enter Before_LOC_Update in the Restore Point Name field. Ensure that Normal Restore
Point is selected. Click OK.

5. Your restore point has been created.

67

3)

Use SQL*Plus to query the POSTAL_CODE column in the HR.LOCATIONS table.


Answer:
1. Log in to SQL*Plus as SYSDBA.
2. Execute the lab_05_02_03_02.sql script to query the POSTAL_CODE column of the
HR.LOCATIONS table.
SQL>
SQL>
2
3

@lab_05_02_03_02
SELECT unique (postal_code)
FROM hr.locations
/

POSTAL_CODE
-----------10934
YSW 9T2
2901
26192
M5V 2L7
01307-002

1730
3095
99236
80925
23 rows selected.
4)

Execute the lab_05_02_04_01.sql script to update the POSTAL_CODE column


in the HR.LOCATIONS table so that all postal codes are set to 11111.
Answer:
1. Execute the lab_05_02_04_01.sql script.
SQL>
SQL>
2
3

@lab_05_02_04_01
UPDATE hr.locations
SET postal_code = 11111
/

23 rows updated.
5)

Execute the lab_05_02_05_01.sql script to query the POSTAL_CODE column


in the HR.LOCATIONS table again.
Answer:
1. Execute the lab_05_02_05_01.sql script.

68

SQL>
SQL>
2
3

@lab_05_02_05_01
SELECT unique (postal_code)
FROM hr.locations
/

POSTAL_CODE
-----------11111
6)

Restore the POSTAL_CODE column values using the restore point.


Answer:
1. Return to your Enterprise Manager session.
2. Copy the SCN value in the Creation SCN field to the buffer.

3. Click the database instance link to return to the Maintenance page.


4. Click Perform Recovery.
5. In the Object Level Recovery section, select Tables in the Object Type menu. Click Perform
Object Level Recovery.

69

6. Select Flashback to a known SCN and paste the SCN that you copied in step 2.
Click Next.

7. Click Add Tables to add the HR.LOCATIONS table.

8. Enter HR in the Schema Name field and LOCATIONS in the Table field. Click Search.

9. Select the HR.LOCATIONS table and click OK.

70

10. The HR.LOCATIONS table is added to the Tables to Flashback field. Click

11. Accept the default of Cascade: Flashback the selected tables and all dependent tables
on the Dependency Options page. Click Next.
12. On the Perform Object Level Recovery: Review page, confirm the information. Click
Submit.

13. The Confirmation page is displayed. Click OK to return to the Maintenance page.

7)

Return to your SQL*Plus session. Execute the lab_05_02_07_01.sql script to


query the POSTAL_CODE column in HR.LOCATIONS again to be sure the correct
values have been restored.
Answer:
71

1. Execute the lab_05_02_07_01.sql script.


SQL>
SQL>
2
3

@lab_05_02_07_01
SELECT unique (postal_code)
FROM hr.locations
/

POSTAL_CODE
-----------10934
YSW 9T2

99236
80925
23 rows selected.

72

Solutions for Practice 5-3: Use Flashback Query and Flashback


Versions Query
1)

Execute the lab_05_03_01_01.sql script to query the HR.LOCATIONS table


for location ID 1400.
Answer:
1. In SQL*Plus, execute the lab_05_03_01_01.sql script.
SQL>
SQL>
2
3
4

2)

@lab_05_03_01_01
SELECT *
FROM hr.locations
WHERE location_id = 1400
/

LOCATION_ID STREET_ADDRESS
POSTAL_CODE
----------- ---------------------------------------- ----------CITY
STATE_PROVINCE
CO
------------------------------ ------------------------- 1400 2014 Jabberwocky Rd
26192
Southlake
Texas
US
Execute the lab_05_03_02_01.sql script to update the POSTAL_CODE column
in the HR.LOCATIONS table, simulating user error.

Answer:
1. Invoke SQL*Plus and execute the lab_05_03_02_01.sql script.
SQL>
SQL>
2
3
4

@lab_05_03_02_01
UPDATE hr.locations
SET postal_code = postal_code + 100
WHERE location_id = 1400
/

1 row updated.
SQL> commit
2 /
Commit complete.
3)

Execute the lab_05_03_03_01.sql script to query the POSTAL_CODE column


in HR.LOCATIONS and view the change.
Answer:
1. Execute the lab_05_03_03_01.sql script.
73

SQL>
SQL>
2
3
4

@lab_05_03_03_01
SELECT *
FROM hr.locations
WHERE location_id = 1400
/

LOCATION_ID STREET_ADDRESS
POSTAL_CODE
----------- ---------------------------------------- ----------CITY STATE_PROVINCE
CO
------------------------------ ------------------------- 1400 2014
Jabberwocky Rd 26292
Southlake Texas
US
4)

Execute the lab_05_03_04_01.sql script to update the POSTAL_CODE column


in the HR.LOCATIONS

Answer:
1. Execute the lab_05_03_04_01.sql script.
SQL>
SQL>
2
3
4

@lab_05_03_04_01
UPDATE hr.locations
SET postal_code = postal_code + 100
WHERE location_id = 1400
/

1 row updated.
SQL> commit
2 /
Commit complete.

5)

Use Enterprise Manager to perform Flashback Versions Query to correct the user
errors.
Answer:
1. Navigate to the Administration page.
2. Select Tables in the Database Objects section.
3. Enter HR in the Schema Name field and LOCATIONS in the Table field. Click Go.
74

4. Select the HR.LOCATIONS table. Select Flashback Versions Query in the Actions
menu. Click Go.

5. Choose all the columns by selecting each in the Available Columns list and clicking
Move to move it to the Selected Columns list.

6. Enter where location_id = 1400 in the Bind the Row Value field. Click Next

75

7. Select the oldest change to the table and click Next.

8. Confirm the flashback information. Click Next.

9. Accept the default of Cascade: Flashback the selected tables and all dependent tables. Click
Next.
10. Review the information. Click Submit.

76

11. The Confirmation page is displayed. Click OK.


6)

Return to your SQL*Plus session. Query the HR.LOCATIONS table to confirm the
Flashback operation.
Answer:
1. Execute the lab_05_03_06_01.sql script to query the HR.LOCATIONS table.
SQL>
SQL>
2
3
4

@lab_05_03_06_01
SELECT *
FROM hr.locations
WHERE location_id = 1400
/

LOCATION_ID STREET_ADDRESS
POSTAL_CODE
----------- ---------------------------------------- ----------CITY
STATE_PROVINCE
CO
------------------------------ ------------------------- 1400 2014 Jabberwocky Rd
26192
Southlake
Texas
US

77

Solutions for Practice 5-4: Use Flashback Database


1) Use Enterprise Manager to verify that Flashback Database is enabled.
Answer:
1. Navigate to the Maintenance page.
2. Select Recovery Settings in the Backup/Recovery Settings section. Scroll to the Flash Recovery
section. Verify that Flashback Database is enabled.

3. Click the Database Instance link to return to the Maintenance page.


2)

Use Enterprise Manager to create a Guaranteed Restore Point.


Answer:
1. Select Manage Restore Points in the Backup/Recovery section.
2. Click Create to create a new restore point.
3. Enter Before_Truncate in the Restore Point Name field. Select Guaranteed Restore
Point. Click OK.

78

4. The Restore Point is created.

3)

Execute the lab_05_04_03_01.sql script to determine the number of rows in


the HR.JOB_HISTORY table. Record the number of rows: ___________
Answer:
1. Execute the lab_05_04_03_01.sql script to determine the number of rows in the
HR.JOB_HISTORY table.
SQL>
SQL>
2
3

@lab_05_04_03_01
SELECT count(*)
FROM hr.job_history
/

COUNT(*)
---------10
4)

Execute the lab_05_04_04_01.sql script to truncate the HR.JOB_HISTORY


table.
Answer:
1. Execute the lab_05_04_04_01.sql script.
SQL> @lab_05_04_04_01
SQL> truncate table hr.job_history
2 /
Table truncated.

5)

Execute the lab_05_04_05_01.sql script to determine the number of rows in


the HR.JOB_HISTORY table.
Answer:

79

1. Execute the lab_05_04_05_01.sql script.


SQL>
SQL>
2
3

@lab_05_04_05_01
SELECT count(*)
FROM hr.job_history
/

COUNT(*)
---------0
6)

Use Flashback Database to restore the HR.JOB_HISTORY table rows.


Answer:
1. Return to your Enterprise Manager window.
2. Navigate to the Maintenance page.
3. Select Manage Restore Points in the Backup/Recovery section.
4. Select the BEFORE_TRUNCATE restore point. Click Recover Whole Database To.

5. Enter the host credential information. Click Yes.

6. The database is shut down. Click Refresh.


80

7. Click Perform Recovery.


8. Enter Host Credentials. Click Continue.
9. Enter Database login. Click Login.
10. Click Perform Whole Database Recovery.

11. Select Recover to a prior point in time.


12. Select Restore Point and click the Flashlight icon.
13. Select the BEFORE_TRUNCATE restore point. Click Select
14. The Restore Point field is populated. Click Next.

81

15. Select Yes. Click Next.

16. Review the information. Click Submit.

17. The Processing: Perform Whole Database Recovery page is displayed.


18. The operation is complete. You can scroll through the output to view the details of the operation.
Click Open Database to open the database.

19. The The database has been opened successfully message is displayed. Click OK.
7)

Return to your SQL*Plus session. Execute the lab_05_04_07_02.sql script to


query the HR.JOB_HISTORY table again to be sure the data has been restored.
Answer:
1. Invoke SQL*Plus and log in as SYS/ORACLE as SYSDBA.
2. Execute the lab_05_04_07_02.sql script.
82

SQL>
SQL>
2
3

@query_job_hist
SELECT count(*)
FROM hr.job_history
/

COUNT(*)
---------10

83

Practice Solutions for Lesson 6


In this practice, you create a duplicate database.

84

Solutions for Practice 6-1: Create a Duplicate Database


In this practice, you use RMAN to create a duplicate database on the same host as your database.
1)

Create an Oracle password file for your auxiliary instance.


Answer:
1. Change to the $ORACLE_HOME/dbs directory and use the orapwd utility to create a
password file named orapwaux. Specify a password of oracle and 10 for the number of
entries.
[oracle@edrsr10p1 oracle]$ cd $ORACLE_HOME/dbs
[oracle@edrsr10p1 dbs]$ orapwd file=orapwaux
password=oracle entries=10
[oracle@edrsr10p1 dbs]$ ls
hc_orcl.dat init.ora orapwaux snapcf_orcl.f
initdw.ora lkORCL orapworcl spfileorcl.ora

2)

Use Oracle Net Manager to create an entry called AUXDB in the tnsnames.ora file.
Answer:
1. Open a terminal window and enter netmgr at the operating system prompt.
[oracle@edrsr10p1 oracle]$ netmgr
2. The Oracle Net Manager window appears.
3. Expand Local and Service Naming.
4. Select Service Naming and click the green plus sign to create a new Net service name.

85

5. Enter auxdb in the Net Service Name field and click Next.

6. Select TCP/IP (default) as the protocol. Click Next.


7. Enter the host name of your PC in the Host Name field. Accept the default of 1521 for the port
number. Click Next.

8. Enter aux.oracle.com in the Service Name field. Click Next.

86

9. Click Finish.
10. Select File and Save Network Configuration to save the changes you made.
11. Click File and Exit to exit from Oracle Net Manager.
12. You can view your updated tnsnames.ora file in the
/u01/app/oracle/product/10.2.0/db_1/network/admin directory.
AUXDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =
edrsr10p1.us.oracle.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = aux.oracle.com)
)
3)

Create an initialization parameter file for the auxiliary instance.


Answer:
1. Create a text initialization parameter file named initAUX.ora from your server parameter file
in the $HOME/auxinstance directory.
[oracle@edrsr10p1 oracle]$ cd $HOME/auxinstance
[oracle@edrsr10p1 auxinstance]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Mar 29
10:51:53 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
- Production
With the Partitioning, OLAP and Data Mining options
SQL> create pfile='$HOME/auxinstance/initAUX.ora' from
spfile;
File created.
2. Edit the initAUX.ora initialization parameter file to make the following changes for the
auxiliary instance:

audit_file_dest='/u01/app/oracle/admin/aux/adump'
background_dump_dest='/u01/app/oracle/admin/aux/bdump
control_files='/u01/app/oracle/oradata/aux/control01.c
tl','/u01/app/oracle/oradata/aux/control02.ctl','/u01/
87

app/oracle/oradata/aux/control03.ctl'
db_name='aux'
user_dump_dest='/u01/app/oracle/admin/aux/udump'
Add the following parameters:
DB_FILE_NAME_CONVERT=/u01/app/oracle/oradata/orcl,
/u01/app/oracle/oradata/aux
LOG_FILE_NAME_CONVERT=/u01/app/oracle/oradata/orcl,
/u01/app/oracle/oradata/aux
Remove the lines at the beginning of the file that begin with orcl.__.
Add the comment character, #, to this line:
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
4) Start the auxiliary instance in NOMOUNT mode using the initAUX.ora file.
Answer:
1. Set the ORACLE_SID environment variable to aux.
[oracle@edrsr10p1 oracle]$ ORACLE_SID=aux
[oracle@edrsr10p1 oracle]$ echo $ORACLE_SID
Aux
2. Invoke SQL*Plus and connect as SYSDBA.
[oracle@edrsr10p1 oracle]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Mar 29
11:38:53 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
3. Start the instance in NOMOUNT mode using the initialization parameter file you created in step 2.
SQL> startup nomount pfile='$HOME/auxinstance/initAUX.ora'
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 92276304 bytes
Database Buffers 188743680 bytes
Redo Buffers 2973696 bytes
5)

Create a server parameter file (SPFILE).


Answer:

88

1. Create a server parameter file with the default name of spfileaux.ora from the text
initialization parameter file.
SQL> create spfile from
pfile='$HOME/auxinstance/initAUX.ora';
File created.
2. Exit from SQL*Plus.
6)

Verify that your target database (orcl database) is mounted or open.


Answer:
1. Set your ORACLE_SID to orcl.
[oracle@edrsr10p1 oracle]$ ORACLE_SID=orcl
[oracle@edrsr10p1 oracle]$ echo $ORACLE_SID
orcl
[oracle@edrsr10p1 oracle]$
2. Log in to SQL*Plus as SYSDBA.
3. Query V$DATABASE to determine whether your database is open.
SQL> select open_mode from v$database;
OPEN_MODE
---------READ WRITE
4. Exit from SQL*Plus.

7) Start RMAN with a connection to the target database (orcl) and the auxiliary instance.
Answer:
1. Set your ORACLE_SID to aux. Invoke RMAN and connect as SYSDBA.Connect to the target
database.
[oracle@edrsr10p1 oracle]$ ORACLE_SID=aux
[oracle@edrsr10p1 oracle]$ echo $ORACLE_SID
aux
[oracle@edrsr10p1 oracle]$ rman
Recovery Manager: Release 10.2.0.1.0 - Production on Thu
Mar 30 07:34:06 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
RMAN> connect auxiliary sys/oracle
connected to auxiliary database: AUX (not mounted)
89

RMAN> connect target sys/oracle@orcl


connected to target database: ORCL (DBID=1090770270)

8)

Create the duplicate database by executing the DUPLICATE command.


Answer:
1. Create a RUN block to allocate the auxiliary channel and execute the DUPLICATE command.
RMAN> run
2> {
3> allocate auxiliary channel aux1 device type disk;
4> duplicate target database to aux;
5> }
allocated channel: aux1
channel aux1: sid=156 devtype=DISK
Starting Duplicate Db at 30-MAR-06
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=154 devtype=DISK
using channel ORA_AUX_SBT_TAPE_1
contents of Memory Script:
{
set until scn 4236965;
set newname for datafile 1 to
"/u01/app/oracle/oradata/aux/system01.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/aux/undotbs01.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/aux/sysaux01.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/aux/users01.dbf";
set newname for datafile 5 to
"/u01/app/oracle/oradata/aux/example01.dbf";
restore
check readonly
clone database
;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
90

executing command: SET NEWNAME


executing command: SET NEWNAME
Starting restore at 30-MAR-06
using channel ORA_AUX_DISK_1
using channel ORA_AUX_SBT_TAPE_1
channel aux1: restoring datafile 00001
input datafile copy recid=23 stamp=586270526
filename=/u01/app/oracle/flash_recf
destination for restore of datafile 00001:
/u01/app/oracle/oradata/aux/system01f
channel ORA_AUX_DISK_1: restoring datafile 00002
input datafile copy recid=20 stamp=586270521
filename=/u01/app/oracle/flash_recf
destination for restore of datafile 00002:
/u01/app/oracle/oradata/aux/undotbs0f
channel ORA_AUX_DISK_1: copied datafile copy of datafile
00002
output filename=/u01/app/oracle/oradata/aux/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003
input datafile copy recid=22 stamp=586270526
filename=/u01/app/oracle/flash_recf
destination for restore of datafile 00003:
/u01/app/oracle/oradata/aux/sysaux01f
channel aux1: copied datafile copy of datafile 00001
output filename=/u01/app/oracle/oradata/aux/system01.dbf
channel aux1: restoring datafile 00004
input datafile copy recid=19 stamp=586270517
filename=/u01/app/oracle/flash_recf
destination for restore of datafile 00004:
/u01/app/oracle/oradata/aux/users01.f
channel ORA_AUX_DISK_1: copied datafile copy of datafile
00003
output filename=/u01/app/oracle/oradata/aux/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005
input datafile copy recid=21 stamp=586270521
filename=/u01/app/oracle/flash_recf
destination for restore of datafile 00005:
/u01/app/oracle/oradata/aux/example0f
channel aux1: copied datafile copy of datafile 00004
output filename=/u01/app/oracle/oradata/aux/users01.dbf
channel ORA_AUX_DISK_1: copied datafile copy of datafile
00005
output filename=/u01/app/oracle/oradata/aux/example01.dbf
Finished restore at 30-MAR-06
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "AUX"
RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
91

MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/u01/app/oracle/oradata/aux/redo01.log' )
SIZE 50 M REUSE,
GROUP 2 ( '/u01/app/oracle/oradata/aux/redo02.log' )
SIZE 50 M REUSE,
GROUP 3 ( '/u01/app/oracle/oradata/aux/redo03.log' )
SIZE 50 M REUSE
DATAFILE
'/u01/app/oracle/oradata/aux/system01.dbf'
CHARACTER SET AL32UTF8
contents of Memory Script:
{
Switch clone datafile all;
}
executing Memory Script
released channel: ORA_AUX_DISK_1
released channel: ORA_AUX_SBT_TAPE_1
datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=586438014
filename=/u01/app/oracle/oradata/auf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=586438014
filename=/u01/app/oracle/oradata/auf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=586438014
filename=/u01/app/oracle/oradata/auf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=586438014
filename=/u01/app/oracle/oradata/auf
contents of Memory Script:
{
set until scn 4236965;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 30-MAR-06
channel aux1: starting incremental datafile backupset
restore
channel aux1: specifying datafile(s) to restore from
92

backup set
destination for restore of datafile 00001:
/u01/app/oracle/oradata/aux/system01f
destination for restore of datafile 00002:
/u01/app/oracle/oradata/aux/undotbs0f
destination for restore of datafile 00003:
/u01/app/oracle/oradata/aux/sysaux01f
destination for restore of datafile 00004:
/u01/app/oracle/oradata/aux/users01.f
destination for restore of datafile 00005:
/u01/app/oracle/oradata/aux/example0f
channel aux1: reading from backup piece
/u01/app/oracle/flash_recovery_area/ORCp
channel aux1: restored backup piece 1
piece
handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/
2006_03_28/o1_m4
channel aux1: restore complete, elapsed time: 00:00:16
starting media recovery
archive log thread 1 sequence 1 is already on disk as file
/u01/app/oracle/flasc
archive log thread 1 sequence 2 is already on disk as file
/u01/app/oracle/flasc
archive log
filename=/u01/app/oracle/flash_recovery_area/ORCL/archivel
og/2006_01
archive log
filename=/u01/app/oracle/flash_recovery_area/ORCL/archivel
og/2006_02
media recovery complete, elapsed time: 00:00:05
Finished recover at 10-APR-06
contents of Memory Script:
{
shutdown clone;
startup clone nomount ;
}
executing Memory Script
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area

285212672 bytes

Fixed Size
Variable Size
Database Buffers

1218992 bytes
92276304 bytes
188743680 bytes
93

Redo Buffers
2973696 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "AUX"
RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/u01/app/oracle/oradata/aux/redo01.log' )
SIZE 50 M REUSE,
GROUP 2 ( '/u01/app/oracle/oradata/aux/redo02.log' )
SIZE 50 M REUSE,
GROUP 3 ( '/u01/app/oracle/oradata/aux/redo03.log' )
SIZE 50 M REUSE
DATAFILE
'/u01/app/oracle/oradata/aux/system01.dbf'
CHARACTER SET AL32UTF8
contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/oracle/oradata/aux/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy
"/u01/app/oracle/oradata/aux/undotbs01.dbf";
catalog clone datafilecopy
"/u01/app/oracle/oradata/aux/sysaux01.dbf";
catalog clone datafilecopy
"/u01/app/oracle/oradata/aux/users01.dbf";
catalog clone datafilecopy
"/u01/app/oracle/oradata/aux/example01.dbf";
catalog clone datafilecopy
"/u01/app/oracle/oradata/aux/example02.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed temporary file 1 to
/u01/app/oracle/oradata/aux/temp01.dbf in control fe
cataloged datafile copy
datafile copy
filename=/u01/app/oracle/oradata/aux/undotbs01.dbf recid=1
stamp=8
cataloged datafile copy
datafile copy
94

filename=/u01/app/oracle/oradata/aux/sysaux01.dbf recid=2
stamp=59
cataloged datafile copy
datafile copy
filename=/u01/app/oracle/oradata/aux/users01.dbf recid=3
stamp=589
cataloged datafile copy
datafile copy
filename=/u01/app/oracle/oradata/aux/example01.dbf recid=4
stamp=9
cataloged datafile copy
datafile copy
filename=/u01/app/oracle/oradata/aux/example02.dbf recid=5
stamp=9
datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=587391888
filename=/u01/app/oracle/oradata/auf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=587391889
filename=/u01/app/oracle/oradata/auf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=587391889
filename=/u01/app/oracle/oradata/auf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=587391889
filename=/u01/app/oracle/oradata/auf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=587391889
filename=/u01/app/oracle/oradata/auf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 10-APR-06
2. After the DUPLICATE DATABASE operation completes, exit from RMAN.
9)

Use SQL*Plus to log in to your AUX database and execute a query against the HR.REGIONS table.
Answer:
1. Verify that ORACLE_SID is set to aux.
95

2. Log in to SQL*Plus as SYSDBA and execute a query against the HR.REGIONS table.
SQL> select * from hr.regions;
REGION_ID REGION_NAME
---------- ------------------------1 Europe
2 Americas
3 Asia
4 Middle East and Africa
10) Now that you have completed the test recovery by creating a duplicate database, shutdown the aux
instance.
Answer:
1. Connect as SYSDBA and execute the SHUTDOWN IMMEDIATE command.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

2. Exit from SQL*Plus.


11) Change your ORACLE_SID to orcl in preparation for later practices.
Answer:
1. At the operating prompt, enter ORACLE_SID=orcl to change your
ORACLE_SID.
[oracle@edrsr10p1 oracle]$ ORACLE_SID=orcl
[oracle@edrsr10p1 oracle]$ echo $ORACLE_SID
orcl

96

Practice Solutions for Lesson 7


In this practice, you use tablespace point-in-time recovery to recover from unwanted changes to your
database.

97

Solutions for Practice 7-1: Use Tablespace Point-in-time Recovery


1)

Execute the lab_07_01_01_01.sh script to export the HR schema.


Answer:
1. In a terminal window, change to the labs directory and execute the
lab_07_01_01_01.sh script to export the HR schema.
[oracle@edrsr10p1 labs]$ ./lab_07_01_01_01.sh
Export: Release 10.2.0.1.0 - Production on Wednesday, 12
April, 2006 13:03:27
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition
Release 10.2.0.1.0 - Produn
With the Partitioning, OLAP and Data Mining options
tarting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/********
dumpfile=hrexp.dmp sr
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 448 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type
SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type
SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type
SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type
SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type
SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type
SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/TRIGGER
Processing object type
SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "HR"."COUNTRIES"
6.085 KB 25 rows
98

. . exported "HR"."DEPARTMENTS"
6.632 KB
27 rows
. . exported "HR"."EMPLOYEES"
15.76 KB
107 rows
. . exported "HR"."JOBS"
6.609 KB
19 rows
. . exported "HR"."JOB_HISTORY"
6.585 KB
10 rows
. . exported "HR"."LOCATIONS"
7.710 KB
23 rows
. . exported "HR"."REGIONS"
5.289 KB
4 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully
loaded/unloaded
**********************************************************
********************
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/u01/app/oracle/product/10.2.0/db_1/rdbms/log/hrexp.dmp
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed
at 13:03:44

2)

Execute the lab_07_01_02_02.sql script to create a new tablespace and a new


user in your database.
Answer:
1. In your terminal window, log in to SQL*Plus as SYSDBA.
2. Execute the lab_07_01_02_02.sql script to create the HRTEST tablespace and
the HRTEST user.
SQL> @lab_07_01_02_02
SQL> SET TERMOUT ON
SQL> CONNECT / AS SYSDBA
Connected.
SQL> REM ***** Tablespace for the HR import *****
SQL> CREATE SMALLFILE TABLESPACE HRTEST
2 DATAFILE '/u01/app/oracle/oradata/orcl/hrtest01.dbf'
SIZE 10M
3 AUTOEXTEND ON NEXT 500K MAXSIZE UNLIMITED LOGGING
4 EXTENT MANAGEMENT LOCAL
5 SEGMENT SPACE MANAGEMENT AUTO;
Tablespace created.
SQL> REM ***** User/schema for the HR import *****
SQL> CREATE USER hrtest
2 PROFILE DEFAULT
3 IDENTIFIED BY hrtest
4 DEFAULT TABLESPACE hrtest
5 TEMPORARY TABLESPACE temp
99

6 QUOTA UNLIMITED ON hrtest


7 ACCOUNT UNLOCK
8 ;
User created.
SQL> GRANT connect, resource
2 TO hrtest;
Grant succeeded.

3)

Execute the lab_07_01_03_01.sh script to populate the new tablespace with a


copy of the data from the HR schema.
Note: The import should complete successfully. You will receive error messages
because the import excludes the COUNTRIES, REGIONS, and LOCATIONS tables.
These messages can be ignored.
Answer:
1. In your terminal window at the operating system prompt, execute the
lab_07_01_03_01.sh script.
[oracle@edrsr10p1 labs]$ ./lab_07_01_03_01.sh
Import: Release 10.2.0.1.0 - Production on Friday, 14
April, 2006 7:08:42
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition
Release 10.2.0.1.0 - Produn
With the Partitioning, OLAP and Data Mining options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully
loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/********
dumpfile=hrexp.dmp par
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"HRTEST" already exists
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type
SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "HRTEST"."DEPARTMENTS"
6.632 KB
27 rows

100

. . imported "HRTEST"."EMPLOYEES"
15.76 KB 107 rows
. . imported "HRTEST"."JOBS"
6.609 KB 19 rows
. . imported "HRTEST"."JOB_HISTORY"
6.585 KB 10 rows
Processing object type
SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type
SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type
SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type
SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/VIEW/VIEW
ORA-39082: Object type VIEW:"HRTEST"."EMP_DETAILS_VIEW"
created with compilatios
Processing object type
SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
ORA-39083: Object type REF_CONSTRAINT failed to create
with error:
ORA-00942: table or view does not exist
Failing sql is:
ALTER TABLE "HRTEST"."DEPARTMENTS" ADD CONSTRAINT
"DEPT_LOC_FK" FOREIGN KEY ("LE
Processing object type SCHEMA_EXPORT/TABLE/TRIGGER
Processing object type
SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_FULL_01" completed with 3
error(s) at 07:08:54

4)

Create a backup of your database using RMAN.


Answer:
1. Invoke RMAN and connect to your target database.
2. Execute the BACKUP DATABASE command.
RMAN> backup database;
Starting backup at 14-APR-06
using target database control file instead of recovery
catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=127 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
101

channel ORA_DISK_1: specifying datafile(s) in backupset


input datafile fno=00001
name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile fno=00003
name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile fno=00005
name=/u01/app/oracle/oradata/orcl/example01.dbf
input datafile fno=00002
name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile fno=00004
name=/u01/app/oracle/oradata/orcl/users01.dbf
input datafile fno=00007
name=/u01/app/oracle/oradata/orcl/hrtest01.dbf
input datafile fno=00006
name=/u01/app/oracle/oradata/orcl/example02.dbf
channel ORA_DISK_1: starting piece 1 at 14-APR-06
channel ORA_DISK_1: finished piece 1 at 14-APR-06
piece
handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/
2006_04_14/o1_mE
channel ORA_DISK_1: backup set complete, elapsed time:
00:01:35
Finished backup at 14-APR-06
Starting Control File and SPFILE Autobackup at 14-APR-06
piece
handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup
/2006_04_14/o1_E
Finished Control File and SPFILE Autobackup at 14-APR-06

5)

Record the current SCN: ____________


Answer:
1. Invoke SQL*Plus as SYSDBA.
2. Query the CURRENT_SCN column in V$DATABASE and record the current SCN.
SQL> select current_scn from V$database;
CURRENT_SCN
----------4725352

6)

Record the current time.


Answer:
1. Execute the date command at the operating system prompt.
[oracle@edrsr10p1 labs]$ date
Fri Apr 14 13:07:57 PDT 2006
102

7)

Execute the lab_07_01_07_01.sql script to query the HRTEST.EMPLOYEES


table and view information about employees in department 60.
Make note of the highest salary that is displayed: ________
Answer:
1. Execute the lab_07_01_07_01.sql script.
SQL> @lab_07_01_07_01
SQL> select employee_id, last_name, salary
2 from employees
3 where department_id = 60
4 /
EMPLOYEE_ID LAST_NAME
SALARY
----------- ------------------------- ---------103 Hunold
9000
104 Ernst
6000
105 Austin
4800
106 Pataballa
4800
107 Lorentz
4200

8)

Execute the lab_07_01_08_01.sql script to update the salaries for the


employees in department 60 and note the highest salary displayed.
Highest salary: _____________
Answer:
1. Execute the lab_07_01_08_01.sql script.
SQL>
SQL>
2
3
4

@lab_07_01_08_01
update hrtest.employees
set salary = salary * 1.25
where department_id = 60
/

5 rows updated.
SQL> select employee_id, last_name, salary
2 from hrtest.employees
3 where department_id = 60
4 /
EMPLOYEE_ID LAST_NAME
SALARY
----------- ------------------------- ---------103 Hunold
11250
104 Ernst
7500
105 Austin
6000
106 Pataballa
6000
107 Lorentz
5250

103

9)

You now want to perform TSPITR for the HRTEST tablespace to return it to the state
prior to the updates. Execute the lab_07_01_09_01.sql script to determine
whether there are any dependencies that will prevent the TSPITR operation.
Answer:
1. Execute the lab_07_01_09_01.sql script.
SQL>
SQL>
2
3
4
5
6
7
8
9

@lab_07_01_09_01
SELECT obj1_owner, obj1_name, obj1_type, ts1_name,
obj2_owner, obj2_name, obj2_type, ts2_name,
constraint_name, reason
FROM SYS.TS_PITR_CHECK
WHERE (TS1_NAME IN ('HRTEST')
AND TS2_NAME NOT IN ('HRTEST'))
OR (TS1_NAME NOT IN ('HRTEST')
AND TS2_NAME IN ('HRTEST'))
/

no rows selected

No rows selected indicates that there are no dependencies to any tablespaces


outside of the recovery set, so you can proceed with the tablespace point-in-time
recovery.
10)

You can use Enterprise Manager Database Control or RMAN command line to
perform tablespace point-in-time recovery.
Answer:
The answer presents the solution using Enterprise Manager Database Control.
If you want to use RMAN command line, refer to the course notes for detailed
information and execute the RECOVER TABLESPACE command as follows:
RECOVER TABLESPACE hrtest UNTIL SCN <scn>
AUXILIARY DESTINATION /u01/app/oracle/oradata/tspitr;
1. Invoke Enterprise Manager Database Control and log in as SYS/ORACLE as SYSDBA.
2. Select the Maintenance page.
3. Select Perform Recovery in the Backup/Recovery section.
4. Select Tablespaces in the Object Level Recovery section. The page refreshes. Accept the
default selection Recover to current time or a previous point-in-time. Click Perform
Object Level Recovery.

104

5. Select Recover to a prior point-in-time and specify the SCN you recorded earlier. Click
Next.

105

6. Specify the auxiliary instance location of /u01/app/oracle/oradata/tspitr. Click


Add to select the tablespace.

7. Select the HRTEST tablespace. Click Select.

106

8. Select the HRTEST tablespace and click Next.

9. Accept No. Restore the files to the default location. On the Perform Object Level Recovery:
Rename page. Click Next.

10. Review the information and click Submit.

107

11. The Processing: Perform Object Level Recovery page is displayed.


12. After the recovery completes, the Perform Recovery: Result page is displayed. You can review
the TSPITR operation by scrolling through the output window.

13. Click OK.


11)

Verify that the HRTEST tablespace is online.


Answer:
1. In Enterprise Manager Database Control, navigate to the Administration page.

2. Select Tablespaces and view the status of the HRTEST tablespace.


108

12)

Verify that the SALARY columns in HRTEST.EMPLOYEES for the employees in


department 60 contain the correct values.
Answer:
1. Invoke SQL*Plus and execute the lab_07_01_12_01.sql script.
SQL> @lab_07_01_12_01
SQL> select employee_id, last_name, salary
2 from hrtest.employees
3 where department_id = 60
4 /
EMPLOYEE_ID LAST_NAME
SALARY
----------- ------------------------- ---------103 Hunold
9000
104 Ernst
6000
105 Austin
4800
106 Pataballa
4800
107 Lorentz
4200
2. The highest salary value should be back to the original value you recorded in step 7.

13)

Execute the lab_07_01_13_02.sql script to add a constraint to the


HRTEST.DEPARTMENTS table.
Answer:
1. Invoke SQL*Plus and connect as SYSDBA.
2. Execute the lab_07_01_13_02.sql script.
SQL> @lab_07_01_13_02
SQL> connect / as sysdba
Connected.
SQL> GRANT references (location_id) on hr.locations to
Hrtest
2 /
Grant succeeded.
SQL> connect hrtest/hrtest
Connected.
109

SQL> ALTER TABLE hrtest.departments


2 ADD CONSTRAINT dept_loc_id_fk FOREIGN KEY
(location_id)
3 REFERENCES hr.locations (location_id)
4 /
Table altered.
14) Assume you need to perform TSPITR on the HRTEST tablespace again. Execute the
lab_07_01_14_02.sql query to determine whether there are any dependencies
outside the recovery set.
Answer:
1. Invoke SQL*Plus and connect as SYSDBA.
2. Execute the lab_07_01_14_02.sql script.
SQL> @lab_07_01_14_02
SQL> set echo on
SQL> SELECT obj1_owner, obj1_name, obj1_type, ts1_name,
2 obj2_owner, obj2_name, obj2_type, ts2_name,
3 constraint_name, reason
4 FROM SYS.TS_PITR_CHECK
5 WHERE (TS1_NAME IN ('HRTEST')
6 AND TS2_NAME NOT IN ('HRTEST'))
7 OR (TS1_NAME NOT IN ('HRTEST')
8 AND TS2_NAME IN ('HRTEST'))
9 /
OBJ1_OWNER OBJ1_NAME OBJ1_TYPE TS1_NAME
--------------------------------------------------------OBJ2_OWNER OBJ2_NAME OBJ2_TYPE TS2_NAME
------------------------------ -------------------------CONSTRAINT_NAME REASON
-----------------------------HR
LOCATIONS
TABLE
EXAMPLE
HRTEST
DEPARTMENTS
TABLE
HRTEST
DEPT_LOC_ID_FK
constraint between tables not contained in recovery set
HR
LOCATIONS
TABLE
EXAMPLE
HRTEST
DEPARTMENTS
TABLE
HRTEST
DEPT_MGR_FK
constraint between tables not contained in recovery set
HR
LOCATIONS
TABLE
EXAMPLE
HRTEST
DEPARTMENTS
TABLE
HRTEST
DEPT_ID_PK
constraint between tables not contained in recovery set
HR

LOCATIONS

TABLE
110

EXAMPLE

HRTEST
DEPARTMENTS
TABLE
HRTEST
DEPT_NAME_NN
constraint between tables not contained in recovery set
15)

If you wanted to complete the tablespace point-in-time recovery for the HRTEST
tablespace now, what would you need to do?
Note: You will not perform another tablespace point-in-recovery in this practice.
Answer:
You would need to disable the DEPT_LOC_ID_FK constraint that was added to your
HRTEST.DEPARTMENTS table or you would need to add the tablespace that
contains the HR.LOCATIONS table to your recovery set.

111

Practice Solutions for Lesson 8


In this practice, you create a recovery catalog in your instructors database and register your database in
the recovery catalog.

112

Solutions for Practice 8-1: Create the Recovery Catalog and Register the Database
The tablespace for the recovery catalog and the recovery catalog owner have been created
in the instructor database. The tablespaces are named RCTS01 RCTS12. The users are
named RCUSER01 RCUSER12.
1)

Connect to the recovery catalog database (instructors database) with the appropriate
recovery catalog owner name (if you are using PC01, connect as RCUSER01) using
RMAN. Create the recovery catalog in your assigned tablespace. (If you are using
PC01, your assigned tablespace is RCTS01.) The service name is RCDB.
Answer: This example uses RCUSER10 as the username and password. Your
assigned username and password may differ from this example.
[oracle@edrsr10p1 oracle]$ rman catalog
rcuser10/rcuser10@rcdb
Recovery Manager: Release 10.2.0.1.0 - Production on Thu
Mar 16 13:58:52 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to recovery catalog database
RMAN> create catalog
recovery catalog created
RMAN> exit
Recovery Manager complete.

2)

Using RMAN, connect to your target database and the recovery catalog database.
Answer:
[oracle@edrsr10p1 oracle]$ rman target / catalog
rcuser10/rcuser10@rcdb
Recovery Manager: Release 10.2.0.1.0 - Production on Thu
Mar 16 14:22:04 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1090770270)
connected to recovery catalog database
RMAN>

3)

Using RMAN, execute the command to resynchronize the control file and recovery
113

catalog. What happens? Why?


Answer: The target database is not yet registered in the recovery catalog, so the
resync command fails.
RMAN> resync catalog;
RMAN-00571:
==========================================================
=
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS
===============
RMAN-00571:
==========================================================
=
RMAN-03002: failure of resync command at 03/16/2006
14:28:21
RMAN-06004: ORACLE error from recovery catalog database:
RMAN-20001: target datg
4)

Register the target database in the recovery catalog. You can use RMAN commandline
or Enterprise Manager for this step.
Answer: Use RMAN command-line OR Enterprise Manager Database Control.
1. Using RMAN:
RMAN> register database;
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
RMAN>
2. Using Enterprise Manager:
Select Recovery Catalog Settings on the Maintenance Page. Select Add Recovery
Catalog on the Recovery Catalog Settings page.

114

The Add Recovery Catalog: Database page is displayed. On this page, enter the
information requested for the recovery catalog database. Click Next.

Review the information on the Add Recovery Catalog: Review page and click
Finish.
The Processing: Configure Catalog page is displayed. After processing completes,
you are returned to the Recovery Catalog Settings page. Select Use Recovery
Catalog and click OK.

115

The Processing: Register Database page is displayed. After the processing


completes, the Recovery Catalog Settings page is displayed indicating that the
database was successfully registered with the recovery catalog.

116

5)

Create an RMAN script named whole_backup to make a whole database backup.


Do not execute the whole_backup script at this time.
Answer:
1. Using RMAN, connect to your target database and the recovery catalog.
[oracle@edrsr10p1 oracle]$ rman target / catalog
rcuser10/rcuser10@rcdb
Recovery Manager: Release 10.2.0.1.0 - Production on Mon
Mar 20 11:59:00 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1090770270)
connected to recovery catalog database
2. Create the whole_backup script using the CREATE SCRIPT command.
RMAN> CREATE SCRIPT whole_backup
2> {
3> BACKUP DATABASE;
4> }
created script whole_backup

6)

Use the PRINT command to query the recovery catalog and verify the creation of
your whole_backup script.
RMAN> PRINT SCRIPT whole_backup;
printing stored script: whole_backup
{BACKUP DATABASE;
}
RMAN>

7)

In preparation for later practices, use RMAN to unregister your database from the
recovery catalog.
Answer:
1. Connect to your target database and the recovery catalog.
2. Execute the UNREGISTER DATABASE command.
RMAN> unregister database;
database name is "ORCL" and DBID is 1090770270
Do you really want to unregister the database (enter YES
or NO)? yes
database unregistered from the recovery catalog
117

Practice Solutions for Lesson 9


In this practice, you monitor the progress of your RMAN backup jobs.

118

Solutions for Practice 9-1: Use SQL to Monitor the Progress of RMAN Backups

1)

Invoke RMAN and delete all obsolete backups.


Answer:
1. Invoke RMAN and connect to your target database.
2. Execute the DELETE OBSOLETE command.
RMAN> delete obsolete;
using target database control file instead of recovery
catalog
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=133 devtype=DISK
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: sid=158 devtype=SBT_TAPE
channel ORA_SBT_TAPE_1: Oracle Secure Backup
Deleting the following obsolete backups and copies:
Type Key Completion Time
Filename/Handle
-------------------- ------ ------------------ ------------------Backup Set 80 14-APR-06
Backup Piece 81 14-APR-06
/u01/app/oracle/flash_recovery_ap
Archive Log 76 14-APR-06
/u01/app/oracle/flash_recovery_ac

Backup Set 101 14-APR-06


Backup Piece 102 14-APR-06
/u01/app/oracle/flash_recovery_ap
Do you really want to delete the above objects (enter YES
or NO)? yes
eleted backup piece
backup piece
handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/
2006_04_8
deleted archive log
archive log
filename=/u01/app/oracle/flash_recovery_area/ORCL/archivel
og/2006_08

Deleted 18 objects
RMAN>

119

2)

Open a second terminal window. Change to the labs directory. Invoke SQL*Plus
and connect as SYSDBA. You will use this second session to monitor a database
backup.

3)

Return to your first terminal window. In your RMAN session, begin a whole database
backup.
Answer:
1. Execute the RMAN BACKUP DATABASE command.
RMAN> backup database;
Starting backup at 17-APR-06
released channel: ORA_SBT_TAPE_1
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001
name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile fno=00003
name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile fno=00005
name=/u01/app/oracle/oradata/orcl/example01.dbf
input datafile fno=00002
name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile fno=00004
name=/u01/app/oracle/oradata/orcl/users01.dbf
input datafile fno=00007
name=/u01/app/oracle/oradata/orcl/hrtest01.dbf
input datafile fno=00006
name=/u01/app/oracle/oradata/orcl/example02.dbf
channel ORA_DISK_1: starting piece 1 at 17-APR-06

4)

Use your SQL*Plus session to monitor the progress of the whole 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
lab_09_01_04_01.sql script to query V$SESSION_LONGOPS.
Answer:

1. Execute the lab_09_01_04_01.sql script.


SQL> @lab_09_01_04_01
SQL> SELECT sid,start_time,elapsed_seconds, time_remaining
2 FROM v$session_longops
3 /
SID START_TIM ELAPSED_SECONDS TIME_REMAINING
---------- --------- --------------- -------------131 17-APR-06
0
Solutions for Practice 9-2: Use Enterprise Manager to Monitor RMAN Jobs
120

You can easily monitor RMAN jobs in Enterprise Manager.


1) Start Enterprise Manager and log in as SYS/ORACLE as SYSDBA.
2) Delete obsolete backups.
Answer:
1. Navigate to the Maintenance page.
2. Select Manage Current Backups.
3. On the Manage Current Backups page, click Delete All Obsolete.
4. Click Submit Job.
5. The job is submitted. Click View Job to view the progress of the Delete All Obsolete job.

121

6. You can view additional information by clicking the links in the Logs section.

7. Click the Database tab to return to the home page.


3) Start a whole database backup.
Answer:
1. Navigate to the Maintenance page.
2. Select Schedule Backup in the Backup/Recovery section.
3. Select Whole Database in the Customized Backup section. Click Schedule Customized Backup.

122

4. Select Full Backup in the Backup Type section. Select Online Backup in the Backup Mode
section. Deselect Also back up all archived logs on disk in the Advanced section. Select
Delete obsolete backups in the Advanced section. Click Next.

5. On the Schedule Customized Backup: Settings page, select Disk. Click Next.
6. Accept the default values on the Schedule Customized Backup: Schedule page. Click Next.
7. Click Submit Job.

123

8. Click View Job.


9. Information about the job is displayed. Click the links in the Logs section to view additional
information.

124

10. You can view detailed information about each job step. Click the Job Run link to return
to the Job page.

11. Click the Database tab to return to the home page.

125

También podría gustarte