(Ebook - PDF) Oracle Enterprise Dba Part 1B - Backup and Recovery Workshop, Volume 2
(Ebook - PDF) Oracle Enterprise Dba Part 1B - Backup and Recovery Workshop, Volume 2
(Ebook - PDF) Oracle Enterprise Dba Part 1B - Backup and Recovery Workshop, Volume 2
30050GC10
Production 1.0
August 1999
M09098
Authors Copyright Oracle Corporation, 1999. All rights reserved.
Technical Contributors
Restricted Rights Legend
and Reviewers
Use, duplication or disclosure by the Government is subject to restrictions for
David Austin commercial computer software and shall be deemed to be Restricted Rights
software under Federal law, as set forth in subparagraph (c) (1) (ii) of DFARS
Ben van Balen 252.227-7013, Rights in Technical Data and Computer Software (October 1988).
Ralf Durben
This material or any portion of it may not be copied in any form or by any means
Bruce AErnst without the express prior written permission of the Worldwide Education Services
Joel Goodman group of Oracle Corporation. Any other copying is a violation of copyright law and
may result in civil and/or criminal penalties.
Bert van Gorkom
Scott Gossett If this documentation is delivered to a U.S. Government Agency not within the
Department of Defense, then it is delivered with “Restricted Right,” as defined in
Lex de Haan FAR 52.227-14, Rights in Data-General, including Alternate III (June 1987).
John Hough Jr.
The information in this document is subject to change without notice. If you find
Alexander Hunold any problems in the documentation, please report them in writing to Education
Peter Kilpatrik Products, Oracle Corporation, 500 Oracle Parkway, Box 659806, Redwood
Shores, CA 94065. Oracle Corporation does not warrant that this document is
Stefan Lindblad
error-free.
Hanne Rue Rasmussen
SQL*Loader, SQL*Net, SQL*Plus, Net8, Oracle Call Interface, Oracle7, Oracle8,
Robert Thome Developer/2000, Developer/2000 Forms, Designer/2000, Oracle Enterprise
Jean-Francois Verrier Manager, Oracle Parallel Server, Oracle Server Manager, PL/SQL, Pro*C,
Steven Wertheimer Pro*C/C++, and Trusted Oracle are trademarks or registered trademarks of
Oracle Corporation.
All other products or company names are used for identification purposes only,
and may be trademarks of their respective owners.
Publisher
John B Dawson
Contents
.....................................................................................................................................................
Contents
Preface
Profile xvii
Related Publications xix
Typographic Conventions xx
Introduction
Objectives I-2
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop iii
Contents
.....................................................................................................................................................
.....................................................................................................................................................
iv Enterprise DBA Part 1B: Backup and Recovery Workshop
Contents
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop v
Contents
.....................................................................................................................................................
.....................................................................................................................................................
vi Enterprise DBA Part 1B: Backup and Recovery Workshop
Contents
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop vii
Contents
.....................................................................................................................................................
.....................................................................................................................................................
viii Enterprise DBA Part 1B: Backup and Recovery Workshop
Contents
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop ix
Contents
.....................................................................................................................................................
.....................................................................................................................................................
x Enterprise DBA Part 1B: Backup and Recovery Workshop
Contents
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop xi
Contents
.....................................................................................................................................................
Appendix A: Practices
Practice Session Note A-2
Practice 2-1 A-3
Practice 3-1 A-4
Practice 4-1 A-5
Practice 5-1 A-6
Practice 5-2 A-7
Practice 6-1 A-11
Practice 7-1 A-13
Practice 8-1 A-14
Practice 9-1 A-15
Practice 10-1 A-16
Practice 11-1 A-17
Practice 12-1 A-18
Practice 13-1 A-19
Appendix C: Hints
Practice 2-1 Hints C-2
Practice 3-1 Hints C-4
Practice 4-1 Hints C-6
Practice 5-1 Hints C-7
.....................................................................................................................................................
xii Enterprise DBA Part 1B: Backup and Recovery Workshop
Contents
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop xiii
Contents
.....................................................................................................................................................
.....................................................................................................................................................
xiv Enterprise DBA Part 1B: Backup and Recovery Workshop
10
.................................
Objectives
Objectives
.....................................................................................................................................................
10-2 Enterprise DBA Part 1B: Backup and Recovery Workshop
Overview
.....................................................................................................................................................
Overview
Overview
Server
process
(Polling)
Recovery Enterprise
Target manager Manager
database (RMAN)
Server
process
(rcvcat)
Overview
Recovery Manager (RMAN) is a utility available in Oracle RDBMS that helps DBAs
manage the backup, restore, and recovery operations on Oracle databases. RMAN has
a powerful command language that is independent of the operating system. RMAN
uses Oracle server processes for backup and recovery operations, and hence, the
backup and recovery operations using RMAN are called Server Managed Backup and
Recovery operations.
Recovery Manager has a command line interface. Oracle Enterprise Manager also
provides a graphic user interface for the Recovery Manager. Recovery Manager can,
however, be used on databases of Oracle8 or higher releases.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-3
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
.....................................................................................................................................................
10-4 Enterprise DBA Part 1B: Backup and Recovery Workshop
Recovery Manager Features
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-5
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
Processes The server processes invoked by RMAN connect to the target database to
perform the backup, restore, and recovery functions through a PL/SQL interface.
Target Database The database for which backup and recovery operations are being
performed using the RMAN is called the target database. The control file of the target
database contains information about its physical structure, such as the size and
location of data files, online and archive logs, and control files. This information is
used by the server processes invoked by RMAN in the backup and recovery using
RMAN.
Channel To perform and record backup and recovery operations, RMAN requires a
link to the target database. This link is referred to as a channel. You must allocate a
channel before you begin the execution of backup or recovery commands. The details
of how to control and tune the backup and recovery operations through the allocation
of channels are discussed in detail in subsequent chapters.
.....................................................................................................................................................
10-6 Enterprise DBA Part 1B: Backup and Recovery Workshop
Recovery Manager Components
.....................................................................................................................................................
Recovery Manager Metadata The data used by RMAN for backup, restore and
recovery operations referred to as RMAN metadata is stored in the control file of the
target database or when available in a schema of a database. This schema is called the
Recovery Catalog. Most of the information stored in the recovery catalog is available
in the control file of the target database.
Although it is not mandatory to have a recovery catalog for use of RMAN, it is
beneficial to setup a recovery catalog. Many of the features of RMAN, such as stored
scripts and automatic backup, are not available without the recovery catalog.
The recovery catalog should be located in a database different from the target
database. The creation and maintenance of recovery catalog are discussed in another
lesson.
Auxiliary Database Using RMAN, you can create a database that is the duplicate of
the target database. Such a duplicate database is called an auxiliary database. The
auxiliary database has very high significance when performing tablespace-point-in-
time-recovery (TSPITR) using RMAN.
Backup Set When you use RMAN to perform a backup, the output files from one
backup operation are referred to as a backup set. Physically, the backup set may
comprise of one or more files. Each physical file of a backup set is called a backup
piece.
Because an Oracle server process is used by RMAN, blocks that are empty are not
stored in the backup.
Image Copies Using RMAN, you can copy the database files from one location to
another on the disks and these copies can serve the purpose of backup. These copies
are called image copies. In an image copy, the empty blocks are also copied over.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-7
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
dbms_rcvcat dbms_backu
Recovery p_restore
Manager
dbms_rcvcat
dbms_rcvman
dbms_rcvman PL/SQL dbms_rcvman
Recovery
Target
catalog
control file
®
DBMS_BACKUP_RESTORE Package
This package is created by the dbmsbkrs.sql and prvtbkrs.plb files. It is
used to interface with Oracle and the operating system for creating, restoring, and
recovering backups of data files and archive logs.
Once the operating system receives information from the packages, the data is stored
on a storage device such as a disk.
.....................................................................................................................................................
10-8 Enterprise DBA Part 1B: Backup and Recovery Workshop
RMAN Setup Considerations
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-9
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
.....................................................................................................................................................
10-10 Enterprise DBA Part 1B: Backup and Recovery Workshop
The Recovery Catalog
.....................................................................................................................................................
Server
process
(Polling)
Recovery Enterprise
Target manager Manager
database (RMAN)
Server
process
(rcvcat)
Server
process
(default)
Recovery
catalog DB
®
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-11
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
.....................................................................................................................................................
10-12 Enterprise DBA Part 1B: Backup and Recovery Workshop
Control File Information
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-13
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
.....................................................................................................................................................
10-14 Enterprise DBA Part 1B: Backup and Recovery Workshop
Connecting Without a Recovery Catalog
.....................................................................................................................................................
You should connect as a user with SYSDBA privileges on the target database to use
RMAN. This helps in performing the privileged operations such as startup and
shutdown. To connect from another server, use the TNS alias for the database.
rman target system/manager@db01 nocatalog
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-15
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
Connection Process After you type the RMAN connection command, the following
events occur:
• A user process is created for Recovery Manager.
• The user process creates two Oracle Server processes.
– One default process connected to the target database, for executing SQL
commands, resynching the control file, and recovery roll forward
– One polling process connected to the target database, to locate RPC
completions (only one per instance)
– Backup and recovery information is retrieved from the control file.
.....................................................................................................................................................
10-16 Enterprise DBA Part 1B: Backup and Recovery Workshop
Recovery Manager Modes
.....................................................................................................................................................
Recovery Manager
Recovery Manager acts as a command line interpreter (CLI) with its own
command language. There are two modes of operation with the RMAN—
interactive and batch.
Interactive Mode To run RMAN commands interactively, start RMAN and then
type commands into the command line interface. For example, you can start RMAN
from the UNIX command shell and then execute interactive commands as follows:
$ rman target sys/sys_pwd@db1 catalog rman_db1/rman_db1@catdb
RMAN> run {
2> allocate channel d1 type disk;
3> backup database;
4> }
Batch Mode You can type RMAN commands into a file, and then run the command
file by specifying its name on the command line. The contents of the command file
should be identical to commands entered at the command line.
When running in batch mode, RMAN reads input from a command file and writes
output messages to a log file (if specified).
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-17
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
.....................................................................................................................................................
10-18 Enterprise DBA Part 1B: Backup and Recovery Workshop
RMAN Commands
.....................................................................................................................................................
RMAN Commands
RMAN Commands
RMAN Commands
RMAN uses two types of commands: stand-alone and job commands.
Generally stand-alone commands are self-contained. Following are some of the stand-
alone commands:
• Change
• Connect
• Create Catalog, Resync Catalog
• Create Script, Delete Script, Replace Script
The job commands are usually grouped and RMAN executes the job commands
inside of a run command block sequentially. If any command within the block
fails, RMAN ceases processing—no further commands within the block are
executed.
Users can execute the commands in interactive mode or batch mode. To run RMAN
commands interactively, start RMAN and then type commands into the command
line interface.
You can type RMAN commands into a file. You can then run a list of commands in
batch mode by specifying the command file name in the command line.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-19
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
To Mount the Target Database Ensure that you have connected to RMAN with the
SYSDBA privilege. If you are using recovery catalog, ensure that your target database
is different from the catalog database. Then issue the startup command
RMAN> startup mount pfile=/u01/oracle/db01/pfile/initdb01.ora
To Shut Down the Target Database Ensure that you have connected to RMAN
with the SYSDBA privilege. Then issue the shutdown command
RMAN> shutdown immediate
To List the Current Configuration of the Target Database Use the REPORT
command to get the configuration of the database.
RMAN> report schema;
RMAN> report schema;
RMAN>
.....................................................................................................................................................
10-20 Enterprise DBA Part 1B: Backup and Recovery Workshop
Channel Allocation
.....................................................................................................................................................
Channel Allocation
Channel Allocation
Disk
Server
Channel Allocation
You must allocate a channel before you execute backup and recovery commands.
Each allocated channel establishes a connection from RMAN to a target or auxiliary
database (either a database created with the duplicate command or a temporary
database used in TSPITR) instance by starting a server session on the instance. This
server session performs the backup and recovery operations. Only one RMAN
session communicates with the allocated server sessions.
Each channel usually corresponds to one output device, unless your media
management library is capable of hardware multiplexing.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-21
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
REPORT Command
REPORT Command
REPORT Command
This command helps in analyzing information in the recovery catalog in more
detail.
Reports can be produced for a variety of questions, such as:
• What is the structure of the database?
RMAN> report schema;
• Which files need to be backed up?
RMAN> report need backup ...;
• Which backups can be deleted (that is, are obsolete)?
RMAN> report obsolete;
• Which files are not recoverable because of unrecoverable operations?
RMAN> report unrecoverable ...;
.....................................................................................................................................................
10-22 Enterprise DBA Part 1B: Backup and Recovery Workshop
REPORT NEED BACKUP Command
.....................................................................................................................................................
report
report need
need backup
backup days
days 3;
3;
report
report need
need backup
backup redundancy
redundancy 3;
3;
®
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-23
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
LIST Command
LIST Command
The LIST command is used to produce a detailed report listing all information for the
following:
• Backup sets that contain a backup of a specified list of data files
• Copies of a specified list of data files
• Backup sets that contain a backup of any data file that is a member of a specified
list of tablespaces
• Copies of any data file that is a member of a specified list of tablespaces
• Backup sets that contain a backup of any archived logs with a specified name or
range
• Copies of any archived logs with a specified name or range
• Incarnations of a specified database
.....................................................................................................................................................
10-24 Enterprise DBA Part 1B: Backup and Recovery Workshop
LIST Command
.....................................................................................................................................................
LIST Command
List Incarnation
The example lists all known incarnations of the database DB00.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-25
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
Stored Scripts
Stored Scripts
Restore / Recovery
Recovery
Backup Manager Enterprise
RMAN Manager
Reporting
Control file 1. Report
Target 2. List Stored scripts
database
Catalog
maintenance
1 Create
2. Register
3. Resync
4. Reset Catalog
5. Change
6. Backup /Restore /
database
Recover
Stored Scripts
A recovery manager script is a set of commands that:
• Specify frequently used backup, recover, and restore operations
• Are created using the CREATE SCRIPT command
• Are stored in the recovery catalog
• Can be called only within the RUN command
• Enables you to plan, develop, and test a set of commands for backing up, restoring,
and recovering the database
• Minimize the potential for operator errors.
Storing Scripts
An incremental level 0 backup can be created and stored in a single script called
level0backup. Storing the script in the recovery catalog enables any DBA using
Recovery Manager to access the scripts. To find which scripts are stored, query the
RC_STORED_SCRIPT and RC_STORED_SCRIPT_LINE views.
.....................................................................................................................................................
10-26 Enterprise DBA Part 1B: Backup and Recovery Workshop
Stored Scripts
.....................................................................................................................................................
Script Examples
• Create script
RMAN> create script Level0Backup {
allocate channel d1 type disk;
backup
incremental level 0
format ‘/u01/db01/backup/%d_%s_%p’
fileperset 5
(database include current controlfile);
sql ‘alter database archive log current’;
release channel d1;}
• Execute script
RMAN
RMAN >> run
run {execute
{execute script
script Level0Backup;}
Level0Backup;}
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-27
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
.....................................................................................................................................................
10-28 Enterprise DBA Part 1B: Backup and Recovery Workshop
Stored Scripts
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-29
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
RUN Command
Example To run the Level0Backup script created previously, use the following
syntax:
RMAN > run { execute script Level0Backup ; }
.....................................................................................................................................................
10-30 Enterprise DBA Part 1B: Backup and Recovery Workshop
Media Management
.....................................................................................................................................................
Media Management
Media Management
Media
Recovery Oracle server
management
Manager session
layer
Media
management
server software
Tape library or
single tape
Media Management
To use tape storage for your database backups, RMAN requires a media manager. A
media manager is a utility that loads, labels, and unloads sequential media such as tape
drives for the purpose of backing up, restoring, and recovering data.
Some media management products can manage the entire data movement between
Oracle data files and the backup devices. Some products that use high-speed
connections between storage and media subsystems can reduce much of the backup
load from the primary database server.
Note that the Oracle server does not need to connect to the media management layer
(MML) software when it backs up to disk. Check with your media vendor to
determine whether the version of the media software you own has been certified to
be compatible with RMAN. The Oracle server calls MML software routines to back
up and restore data files to and from media controlled by the media manager.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-31
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
.....................................................................................................................................................
10-32 Enterprise DBA Part 1B: Backup and Recovery Workshop
Summary
.....................................................................................................................................................
Summary
Summary
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 10-33
Lesson 10: Oracle Recovery Manager Overview
.....................................................................................................................................................
Quick Reference
Context Reference
Parameters CONTROL_FILE_RECORD_KEEP_TIME
Dynamic
performance
views
Data DBMS_RCVCAT
dictionary DBMS_RCVMAN
packages
DBMS_BACKUP_RESTORE
Commands ALTER DATABASE ADD LOGFILE
ALTER SYSTEM SWITCH LOGFILE
.....................................................................................................................................................
10-34 Enterprise DBA Part 1B: Backup and Recovery Workshop
11
.................................
Objectives
Objectives
.....................................................................................................................................................
11-2 Enterprise DBA Part 1B: Backup and Recovery Workshop
Overview
.....................................................................................................................................................
Overview
Overview
Restore / Recovery
Recovery
Backup Manager Enterprise
RMAN Manager
Reporting
Control file 1. Report
Target 2. List Stored scripts
database
Catalog
maintenance
1. Create
2. Register
3. Resync
4. Reset Catalog
5. Change
6. Backup /Restore / database
Recover
Overview
Recovery Catalog is an important component of Recovery Manager (RMAN). Even
though it is not mandatory, it is recommended that you use the recovery catalog in
your backup and recovery operations using the RMAN. The database in which the
recovery catalog resides is referred to as the catalog database.
The Recovery Manager is used to store, use, and maintain the information in the
recovery catalog. The recovery catalog is maintained using RMAN in the following
operations:
1 Creating the catalog
2 Registering the catalog with the target database
3 Resynchronizing with the control file of the target database
4 Resetting the database to a previous incarnation
5 Changing some information about the backup/recovery files
6 Performing a backup, restore or recovery operation
You can use the REPORT and LIST commands of RMAN to obtain information from
the recovery catalog. You could also store the backup scripts often used in the
recovery catalog as stored scripts.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-3
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
Storage To increase the speed and ease of recovery, while simultaneously reducing
the risk of data loss, use the following guidelines:
• Do not create the recovery catalog in the target database. Choose a separate
database with data files on different disks.
• If the recovery catalog is located on the same system as the target database, store
the recovery catalog in a database on separate disks.
• If there are many databases to back up, consider creating a separate recovery
catalog database to hold the information on the target databases.
• Your backup strategy should include a method for backing up the recovery
catalog.
.....................................................................................................................................................
11-4 Enterprise DBA Part 1B: Backup and Recovery Workshop
Overview
.....................................................................................................................................................
Facilities When you use a recovery catalog, RMAN can perform a wider variety of
automated backup and recovery functions such as:
• Stored scripts for backup and recovery operations
• Maintain record of backup and recovery operations for a time period suited to the
user
Size When you use a recovery catalog, RMAN requires that you maintain a recovery
catalog schema as well as any associated space used by that schema. The size of the
recovery catalog schema depends on the following factors.
• The number of databases monitored by the catalog. It is recommended that you
have a separate catalog for each database.
• The number and size of scripts stored in the catalog. Depending on the complexity
and variety of backup operations being performed on the target database you may
have fewer or more scripts stored in the catalog.
• The number and frequency of generation of archive logs.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-5
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
Recovery Catalog Backup If you use a recovery catalog, decide which database
you will use to install the recovery catalog schema, and also how you will back up this
database. If you use RMAN to back up several databases, you may want to create a
separate recovery catalog database and create the RMAN user in that database. Also, it
is recommended that you operate this database in ARCHIVELOG mode.
If you have more than one database to back up, you can create more than one recovery
catalog and have each database serve as the other’s recovery catalog. For example,
assume that you maintain two production databases, one called PRD1 and a second
called PRD2. You can install the recovery catalog for PRD1 in the PRD2 database,
and the recovery catalog for the PRD2 database in PRD1.
.....................................................................................................................................................
11-6 Enterprise DBA Part 1B: Backup and Recovery Workshop
Creating the Recovery Catalog
.....................................................................................................................................................
RMAN >
2. Create catalog owner
3. Grant privileges
Target
Control file database
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-7
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
.....................................................................................................................................................
11-8 Enterprise DBA Part 1B: Backup and Recovery Workshop
Creating the Recovery Catalog
.....................................................................................................................................................
RMAN>
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-9
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
Remote connection
rman
rman target
target sys/oracle@db01
sys/oracle@db01
RMAN-6005:
RMAN-6005: connected
connected to
to target
target database:
database: ……
RMAN>
RMAN> connect
connect catalog
catalog rman_db1/rman_db1@catdb
rman_db1/rman_db1@catdb
®
.....................................................................................................................................................
11-10 Enterprise DBA Part 1B: Backup and Recovery Workshop
Connecting Using a Recovery Catalog
.....................................................................................................................................................
Resync Catalog
RMAN >
Target
Control file database
$$ rman
rman target
target scott/tiger@db01
scott/tiger@db01 catalog
catalog rman/rman@catdb
rman/rman@catdb
RMAN
RMAN >> resync
resync catalog;
catalog;
®
Resync Catalog
Most of the information in the recovery catalog is derived from the control file of the
target database. Any structural changes, such as adding tablespaces to the database,
cause the control file and recovery catalog to become “out of synch” if the recovery
catalog is not updated. The catalog would be synchronized any time a new BACKUP
or COPY command is issued with the catalog. However, this synchronization could
cause a delay in the backup operation.
The following factors may influence how often you resync:
• The rate of archive log creation
• Frequency of database structure changes
• The need for faster resynchronizations
The RESYNC CATALOG command updates the following records:
• Log switch records: Created when a log switch occurs. Recovery Manager tracks
this information so it knows what archive logs it should expect to find.
• Archived log copy records: Associated with archived logs that were created by
archiving an online log, by copying an existing archived log, or by restoring an
archived log backup set.
• Backup history records: Associated with backup sets, backup pieces, backup set
members, and file copies. The RESYNC CATALOG command is needed only
when the recovery catalog database was unavailable when a BACKUP or COPY
command was executed.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-11
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
Catalog Maintenance
Catalog Maintenance
Restore / Recovery
Recovery
Backup Manager Enterprise
RMAN Manager
Reporting
Control file 1. Report
Target 2. List Stored scripts
database
Catalog
maintenance
1. Create
2. Register
3. Resync
4. Reset Catalog
5. Change
6. Backup /Restore /
database
Recover
.....................................................................................................................................................
11-12 Enterprise DBA Part 1B: Backup and Recovery Workshop
Catalog Maintenance
.....................................................................................................................................................
Catalog command
Use the CATALOG command to add information to the
catalog
• When backup is taken using OS
• When backup is taken without recovery catalog
The CATALOG command stores:
• Archived logs, data file copies, and control file copies
that belong to the target database
• Only files with the same database incarnation number
RMAN
RMAN >> catalog
catalog datafilecopy
datafilecopy ‘/u01/db1/backup/system01.bak’
‘/u01/db1/backup/system01.bak’
22 >> tag
tag == ‘SYSTBS0429’;
‘SYSTBS0429’;
RMAN
RMAN >> catalog
catalog archivelog
archivelog
2>‘/u01/db1/ARCHIVE/arch_267.log’;
2>‘/u01/db1/ARCHIVE/arch_267.log’;
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-13
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
Example In this scenario a backup of system tablespace has been taken without use
of RMAN. Now the existence of this backup is being registered in the recovery
catalog.
rman target sys/change_on_install@db01
RMAN > connect catalog rman_db1/rman_db1@catdb
RMAN> catalog datafilecopy ’/u01/db1/backup/system01.bak’ tag
’systbs0429’;
RMAN-03022: compiling command: catalog
RMAN-03023: executing command: catalog
RMAN-08050: cataloged datafile copy
RMAN-08513: datafile copy filename=/u01/db1/backup/system01.bak
recid=1 stamp=364062433
RMAN-03023: executing command: partial resync
RMAN-08003: starting partial resync of recovery catalog
RMAN-08005: partial resync complete
RMAN> list backup of datafile
.....................................................................................................................................................
11-14 Enterprise DBA Part 1B: Backup and Recovery Workshop
CHANGE Command
.....................................................................................................................................................
CHANGE Command
CHANGE Command
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-15
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
.....................................................................................................................................................
11-16 Enterprise DBA Part 1B: Backup and Recovery Workshop
Deleting a Backup
.....................................................................................................................................................
Deleting a Backup
Example
RMAN> allocate channel for delete type disk;
RMAN-03022: compiling command: allocate
RMAN-03023: executing command: allocate
RMAN-08030: allocated channel: delete
RMAN-08500: channel delete: sid=13 devtype=DISK
RMAN> change datafilecopy ’/u01/db1/backup/system01.bak’ delete;
RMAN-03022: compiling command: change
RMAN-08070: deleted datafile copy
RMAN-08513: datafile copy filename=/u01/db1/backup/system01.bak
recid=1 stamp=364062433
RMAN> release channel;
RMAN-03022: compiling command: release
RMAN-03023: executing command: release
RMAN-08031: released channel: delete
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-17
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
Example (continued)
Check if the file exists on the disk. On UNIX, use the ls command with the
appropriate command option. On NT, you could use the explorer or DIR command (at
the command prompt) to determine if the file exists.
RMAN> exit
% ls -l /u01/db1/backup/system01.bak
/u01/db1/backup/system01.bak: No such file or directory
Delete Any Backup That Has Been Marked Expired RMAN does not delete any
backup pieces that it is unable to find, but updates their metadata records to expired
status. You can use the DELETE option of the CHANGE command to update expired
backup records in the catalog to status deleted (and delete any existing expired backup
pieces).
RMAN> allocate channel for delete type disk;
RMAN> delete expired backup;
RMAN> release channel;
Remove Record from Catalog You can use the UNCATALOG option of the
CHANGE command to remove backup records from the catalog without actually
deleting the files from the medium. Because the file is not being acted upon by
RMAN, this command option does not require a channel to be allocated.
RMAN> change controlfilecopy ’/u01/db01/backup/sysbak’
2> uncatalog;
RMAN> change datafilecopy 4833 uncatalog;
.....................................................................................................................................................
11-18 Enterprise DBA Part 1B: Backup and Recovery Workshop
Deleting Records of Previous Incarnation
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-19
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
.....................................................................................................................................................
11-20 Enterprise DBA Part 1B: Backup and Recovery Workshop
Recovering the Recovery Catalog
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-21
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
Reporting
Restore / Recovery
Recovery
Backup Manager Enterprise
RMAN Manager
Reporting
Control File 1. Report
Target 2. List Stored scripts
database
Catalog
maintenance
1 Create
2. Register
3. Resync
4. Reset Catalog
5. Change
6. Backup /Restore /
database
Recover
REPORT Command
You use the REPORT command to analyze various aspects of the backup, copy,
restore, and recovery operations.
LIST Command
You use the LIST command to display information on backup sets, file copies, and
archived logs, which are stored in the recovery catalog.
Views
In addition to the REPORT and LIST commands of RMAN, you can use SQL*PLUS
and query the data dictionary and dynamic views that are created when the recovery
catalog is created to obtain the backup, restore, and recovery information stored in the
catalog.
.....................................................................................................................................................
11-22 Enterprise DBA Part 1B: Backup and Recovery Workshop
Recovery Catalog Reporting
.....................................................................................................................................................
Reports
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-23
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
LIST Command
LIST Command
.....................................................................................................................................................
11-24 Enterprise DBA Part 1B: Backup and Recovery Workshop
Stored Scripts
.....................................................................................................................................................
Stored Scripts
Stored Scripts
Restore / Recovery
Recovery
Backup Manager Enterprise
RMAN Manager
Catalog
maintenance
1 Create
2. Register
3. Resync Catalog
4. Reset
Database
5. Change
6. Backup /Restore /
Recover
®
Stored Scripts
A Recovery Manager script is a set of commands that:
• Specify frequently used backup, recover, and restore operations
• Are created using the CREATE SCRIPT command
• Are stored in the recovery catalog
• Can be called only by using the RUN command
• Enable you to plan, develop, and test a set of commands for backing up, restoring,
and recovering the database
• Minimize the potential for operator errors
Storing Scripts
An incremental level 0 backup can be created and stored in a single script called
level0backup. Storing the script in the recovery catalog enables any DBA using
Recovery Manager to access the scripts. To find which scripts are stored, query the
RC_STORED_SCRIPT and RC_STORED_SCRIPT_LINE views.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-25
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
Script Examples
• Create script
RMAN> create script Level0Backup {
allocate channel d1 type disk;
backup
incremental level 0
format ‘/u01/db01/backup/%d_%s_%p’
fileperset 5
(database include current controlfile);
sql ‘alter database archive log current’;
release channel d1;}
• Execute script
RMAN > run {execute script Level0Backup;}
®
.....................................................................................................................................................
11-26 Enterprise DBA Part 1B: Backup and Recovery Workshop
Stored Scripts
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-27
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
.....................................................................................................................................................
11-28 Enterprise DBA Part 1B: Backup and Recovery Workshop
RESET DATABASE Command
.....................................................................................................................................................
Example
RMAN> reset database;
RMAN-03022: compiling command: reset
RMAN-03023: executing command: reset
RMAN-08006: database registered in recovery catalog
RMAN-03023: executing command: full resync
RMAN-08002: starting full resync of recovery catalog
RMAN-08004: full resync complete
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-29
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
Incarnation Number
An incarnation of a database is a number used to identify a version of the database
prior to the log sequence number being reset to zero. This prevents archived and online
redo logs from being applied to an incorrect incarnation of the database. The RESET
DATABASE command is used by Recovery Manager to store database incarnation
information in the recovery catalog. All subsequent backups and log archives done by
the target database are associated with the new database incarnation.
Example
RMAN> list incarnation of database;
RMAN-03022: compiling command: list
RMAN-06240: List of Database Incarnations
RMAN-06241: DB Key Inc Key DB Name DB ID CUR Reset SCN
RMAN-06242: ------ ------- ------- ---------- --- ---------
RMAN-06243: 1 2 ORACLE 1186311932 YES 25730
RMAN-06243: 1 421 ORACLE 1186311932 NO 172279
RMAN> reset database to incarnation 421;
.....................................................................................................................................................
11-30 Enterprise DBA Part 1B: Backup and Recovery Workshop
Data Dictionary Views
.....................................................................................................................................................
Example 1
To determine which databases are currently registered in the recovery catalog:
SQL> select * from rc_database;
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-31
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
Example 2
To determine which tablespaces are currently stored in the recovery catalog for the
target database:
SQL > select DB_KEY, DBINC_KEY, DB_NAME, TS#, NAME,
CREATION_CHANGE# CHANGE#, CREATION_TIME CRE_DATE
from rc_tablespace;
Example 3
To determine which scripts are currently stored in the recovery catalog for the target
database:
SQL> select * from rc_stored_script;
.....................................................................................................................................................
11-32 Enterprise DBA Part 1B: Backup and Recovery Workshop
Summary
.....................................................................................................................................................
Summary
Summary
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-33
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
Summary
.....................................................................................................................................................
11-34 Enterprise DBA Part 1B: Backup and Recovery Workshop
Quick Reference
.....................................................................................................................................................
Quick Reference
Context Reference
Parameters None
Dynamic None
performance
views
Data RC_ARCHIVED_LOG
dictionary RC_BACKUP_CONTROLFILE
views
RC_BACKUP_CORRUPTION
RC_BACKUP_DATAFILE
RC_BACKUP_PIECE
RC_BACKUP_SET
RC_CONTROLFILE_COPY
RC_COPY_CORRUPTION
RC_DATABASE
RC_DATABASE_INCARNATION
RC_DATAFILE
RC_DATAFILE_COPY
RC_STORED_SCRIPT
RC_STORED_SCRIPT_LINE
Commands REGISTER DATABASE
RESET DATABASE
RESYNC CATALOG
CHANGE
CATALOG
REPORT
LIST
CREATE SCRIPT { <commands>; }
REPLACE SCRIPT { <commands>; }
DELETE SCRIPT <name>
PRINT SCRIPT <name>
RUN
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 11-35
Lesson 11: Oracle Recovery Catalog Creation and Maintenance
.....................................................................................................................................................
.....................................................................................................................................................
11-36 Enterprise DBA Part 1B: Backup and Recovery Workshop
12
.................................
Backups Using
Recovery Manager
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Objectives
Objectives
.....................................................................................................................................................
12-2 Enterprise DBA Part 1B: Backup and Recovery Workshop
Overview
.....................................................................................................................................................
Overview
Overview
Server
process
(polling)
Recovery Enterprise
Target manager Manager
database (RMAN)
Server
process
(rcvcat)
Overview
Recovery Manager uses Oracle server processes to perform backup, restoration, and
recovery operations, so the backup operation using Recovery Manager is called a
server-managed backup.
The frequency of backup depends on the business requirements and the resources
available.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-3
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Backup Concepts
Backup Concepts
Note: The online redo log files are not backed up when using Recovery Manager.
.....................................................................................................................................................
12-4 Enterprise DBA Part 1B: Backup and Recovery Workshop
Backup Concepts
.....................................................................................................................................................
Full Backups
A full backup differs from a whole database backup. A whole backup comprises all of
the data files and control file of the target database, whereas a full backup may contain
one or more of the data files, control file or archive logs.
When performing a full backup, an Oracle server process reads the entire file and
copies all blocks into the backup set, skipping only data file blocks that have never
been used. The server session does not skip blocks when backing up archived redo
logs or control files.
Full backup is not a part of the incremental backups. You can create and restore full
backups of data files, data file copies, tablespaces, database, control files, archive logs
and archive log copies. Note that backup sets containing archived redo logs are always
full backups.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-5
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
12-6 Enterprise DBA Part 1B: Backup and Recovery Workshop
Whole Database Backup
.....................................................................................................................................................
Terminology
• Whole backup:
– Target database may be open or closed
– Backup of all data files and control file
• Full backup: Backup of one or more files, which is
not incremental
• Incremental backup: Backup of data files changed
since the last incremental backup
• Image copy: Copy of a data file, control file, or
archive log on to disk
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-7
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
• Image copy
Data Data Copy of data file 3
file 3 file 3
• Backup set
Data Data Data Data Control
file 1 file 4 file 1 file 3 file
.....................................................................................................................................................
12-8 Enterprise DBA Part 1B: Backup and Recovery Workshop
Allocating a Channel
.....................................................................................................................................................
Allocating a Channel
Allocating a Channel
• BACKUP, RESTORE, or RECOVER command
requires at least one channel.
• Allocating a channel starts a server process on the
target database.
• Channels affect the degree of parallelism.
• Channels write to different media types.
• Channels can be used to impose limits.
RMAN
RMAN >> run
run {{
2>
2> allocate
allocate channel
channel c1
c1 type
type disk
disk
3>
3> format = ’/u01/db01/backup/usr0520.bak’;
format = ’/u01/db01/backup/usr0520.bak’;
4>
4> backup
backup datafile
datafile ’/u01/db01/data/user01.dbf’;}
’/u01/db01/data/user01.dbf’;}
Allocating a Channel
Recovery Manager uses the channel processes to communicate between the Oracle
server and the Operating system.
• An Oracle server process for the target database is created for every channel
allocated. Every BACKUP, RESTORE, or RECOVER command issued in
Recovery Manager requires at least one channel.
• The number of channels allocated will be the maximum degree of parallelization
used during backup, restore, or recovery.
• The type of media desired determines the type of channel allocated. Query
V$BACKUP_DEVICE to determine supported device types.
• You can impose limits for the COPY and BACKUP commands by specifying
parameters in the ALLOCATE CHANNEL command:
– Read rate: Limits number of buffers read per second, per file to reduce online
performance through excessive disk I/O.
set limit channel <name> read rate = integer
– Kbytes: Limits backup piece file size created by a channel. This is useful when
there are maximum file sizes for an operating system or device type.
set limit channel <name> kbytes= integer
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-9
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
12-10 Enterprise DBA Part 1B: Backup and Recovery Workshop
Tags
.....................................................................................................................................................
Tags
Tags
Data Data
files 3,4 file 4
Tags
A tag is a meaningful name that you can assign to a backup set or file copy. The
advantages of user tags are as follows:
• Tags provide a useful reference to a collection of file copies or a backup set.
• Tags can be used in the LIST command to locate backed up files easily.
• Tags can be used in the RESTORE and SWITCH commands.
• The same tag can be used for multiple backup sets or file copies.
If a nonunique tag references more than one data file, then Recovery Manager chooses
the most current available file.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-11
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Image Copies
Image Copies
Image copy
RMAN
RMAN >> run
run {{
2>
2> allocate
allocate channel
channel c1
c1 type
type disk;
disk;
3>
3> copy
copy
4>
4> datafile
datafile ’data/df3.dbf’
’data/df3.dbf’ to
to
5>
5> ’backup/df3.dbf’
’backup/df3.dbf’ tag=DF1,
tag=DF1,
6>
6> archivelog
archivelog ’arch_1060.rdo’
’arch_1060.rdo’ toto
7>
7> ’arch_1060.bak’;}
’arch_1060.bak’;}
Image Copies
You can use the Recovery Manager COPY command to create an image copy. An
image produced with the Recovery Manager COPY command uses an Oracle server
session to perform the task.
Recovery Manager can catalog the operating system copies of with the recovery
catalog. For a data file copy made using the operating system to be useful in recovery,
the corresponding tablespace should have been placed in backup mode before making
the copy. This operation is important when the recovery catalog is lost and you must
perform disaster recovery. Only image copies and archived logs can be cataloged.
.....................................................................................................................................................
12-12 Enterprise DBA Part 1B: Backup and Recovery Workshop
Image Copy Characteristics
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-13
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
COPY Command
COPY Command
RMAN
RMAN >> run
run {{
2>
2> allocate
allocate channel
channel d1
d1 type
type disk;
disk;
3>
3> copy
copy level
level 00
4>
4> datafile
datafile 33 to
to ’backup/file3.dbf’,
’backup/file3.dbf’,
5>
5> datafile
datafile 11 to
to ’backup/file1.dbf’;
’backup/file1.dbf’; }}
Data Data
file 3 file 3
Image copy Database
®
Copy Command
The COPY command creates an image copy of a file. The output file is always written
to disk. You can copy data files, archived redo logs, or control files. In many cases,
copying data files is more beneficial than backing them up, because the output is
suitable for use without any additional processing.
You can execute the command from within the braces of a RUN command. Precede a
COPY command with at least one ALLOCATE CHANNEL command specifying the
type of disk option. You cannot make incremental copies.
During the copy operation, an Oracle server process performs checksum for each
block to detect corruption. This detection is also referred to as physical corruption
detection. You can use the NOCHECKSUM option to avoid the checksum operation
and speed up the copy process.
You can use the CHECK LOGICAL option to test data and index blocks that pass
physical corruption checks for logical corruption—for example, corruption of a row
piece or index entry. If logical corruption is detected, the block is logged in the alert
log and trace file of the server process.
When the number of corrupted blocks detected reaches a threshold—defined by the
MAXCORRUPT clause—the copy process is terminated without populating the
views.
.....................................................................................................................................................
12-14 Enterprise DBA Part 1B: Backup and Recovery Workshop
Image Copy Process
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-15
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
12-16 Enterprise DBA Part 1B: Backup and Recovery Workshop
Image Copy of All Data Files
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-17
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
12-18 Enterprise DBA Part 1B: Backup and Recovery Workshop
Monitoring the Copy Process
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-19
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
$ svrmgrl
SVRMGR> alter tablespace system begin backup;
SVRMGR> !cp system01.dbf system01.bak
SVRMGR> alter tablespace system end backup;
SVRMGR> exit;
$ rman target sys/oracle@DB00
rcvcat rman/rman@RCVCAT
RMAN > catalog datafilecopy ’system01.bak’;
Hardware Mirroring
Image copies support systems where data files are stored on mirrored disk volumes. If
one disk of the mirrored disks fails, the mirror can be broken and can be used as an
image copy. This reduces effort and time to restore the file. When the mirror is
resilvered, remove the image copies using the CHANGE . . . DELETE command.
Recovery Manager can then be notified of the new image copies using the CATALOG
command.
.....................................................................................................................................................
12-20 Enterprise DBA Part 1B: Backup and Recovery Workshop
Backup Sets
.....................................................................................................................................................
Backup Sets
Backup Sets
• Image copy
Data Data Copy of data file 3
File 3 File 3
• Backup set
Data Data Data Data Control
file 1 file 4 file 1 file 3 file
Backup Sets
A backup set consists of one or more physical files stored in an Oracle proprietary
format, on either disk or tape. Each backup set can contain one or more Oracle files.
You can make a backup set for one or more of data files, archive logs, or their copies.
Backup sets can be of two types:
• Data file: Can contain data files and control files, but not archived logs
• Archived log: Contains archived logs, not data files or control files
Note: Backup sets may need to be restored by Recovery Manager before recovery can
be performed, unlike image copies which generally are available on disks.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-21
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
BACKUP Command
BACKUP Command
RMAN
RMAN >> run
run {{
2>
2> allocate
allocate channel
channel c1
c1 type
type DISK;
DISK;
3>
3> backup
backup
4>
4> incremental
incremental level
level == 00
5>
5> format
format ’/disk1/data/df_%d_%s_%p.bus’
’/disk1/data/df_%d_%s_%p.bus’
6>
6> (database
(database filesperset
filesperset == 22
7>
7> include
include current
current controlfile);
controlfile); }}
Backup set
Data Data Data Data Control
file 1 file 4 file 1 file 3 file
BACKUP Command
The BACKUP command is executed within the braces of a RUN command. The
output can be written to tape or disk. You can control the number of backup sets that
Oracle produces as well as the number of input files that Recovery Manager places
into a single backup set. If any I/O errors are received when reading files or writing
backup pieces, the job is aborted.
When using the BACKUP command, you must do the following:
• Mount or open the target database. Recovery Manager allows you to make an
inconsistent backup if the database is in ARCHIVELOG mode, but you must apply
redo logs to make the backups consistent for use in recovery operations.
• Use a current control file.
• Execute the BACKUP command within the braces of a RUN command.
• Allocate a channel for execution of the BACKUP command.
• Give each backup piece a unique name. You can have a maximum of 100 backup
pieces in one backup set.
You cannot combine archived redo log files and data files into a single backup. Also,
when performing backups using scripts, you cannot generate unique tag names.
.....................................................................................................................................................
12-22 Enterprise DBA Part 1B: Backup and Recovery Workshop
BACKUP Command
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-23
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Option Significance
include Creates a snapshot of the current control file and places it into each backup
current set produced by this clause.
controlfile
Format Format of the name of output. The following format parameters can be
used either individually or in combination.
%c Specifies the copy number of the backup piece within a set of duplexed
backup pieces.
%p Specifies the backup piece number within the backup set. This value starts
at 1 for each backup set and is increased by 1 as each backup piece is
created.
%s Specifies the backup set number. This number is a counter in the control
file that is increased for each backup set.
%d Specifies database name.
%n Specifies the database name, padded on the right with x characters to a total
length of 8 characters.
%t Specifies the backup set time stamp, which is a 4-byte value derived as the
number of seconds elapsed since a fixed reference time. The combination
of %s and %t can be used to form a unique name for the backup set.
%u Specifies an 8-character name constituted by compressed representations
of the backup set number and the time that the backup set was created
%U Specifies a convenient shorthand for %u_%p_%c that guarantees
uniqueness in generated backup filenames. If you do not specify a format,
Recovery Manager uses %U by default.
.....................................................................................................................................................
12-24 Enterprise DBA Part 1B: Backup and Recovery Workshop
Backup Set Characteristics
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-25
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Data MML
Tape
file 3
Example
RMAN > run { allocate channel c1 type ’SBT_TAPE’;
2> backup (database filesperset = 3); }
The database contains three data files that will be multiplexed together
(filesperset = 3) into one physical file (set) and stored on tape. The data files
are multiplexed by writing n number of blocks from data file 1, then data file 2, then
data file 3, then data file 1, and so on until all files are backed up.
.....................................................................................................................................................
12-26 Enterprise DBA Part 1B: Backup and Recovery Workshop
Parallelization of Backup Sets
.....................................................................................................................................................
Example
• There are nine files that need to be backed up (data files 1 through 9.)
• Data files have been carefully assigned so that each set has approximately the
same number of data blocks to back up (for efficiency.)
– Data files 1, 4, and 5 are assigned to backup set 1.
– Data files 2, 3, and 9 are assigned to backup set 2.
– Data files 6, 7, and 8 are assigned to backup set 3.
• Because there are three files per set, there is no need to use the FILESPERSET
parameter. Three backup sets will be written each of which would contain blocks
from three data files. three channels are used to write in parallel.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-27
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Solution
Use the following command to achieve the specified requirements:
RMAN > run {
2> allocate channel c1 type disk;
3> allocate channel c2 type disk;
4> allocate channel c3 type disk;
6> backup
7> incremental level = 0
8> format ’/disk1/backup/df_%d_%s_%p.bak’
9> (datafile 1,4,5 channel c1 tag=DF1)
10> (datafile 2,3,9 channel c2 tag=DF2)
11> (datafile 6,7,8 channel c3 tag=DF3);
12> sql ’alter system archive log current’;
13> }
.....................................................................................................................................................
12-28 Enterprise DBA Part 1B: Backup and Recovery Workshop
Backup Piece
.....................................................................................................................................................
Backup Piece
Backup Piece
Backup Piece
A logical backup set usually only has one backup piece unless specified using the SET
LIMIT command. A backup piece is a single physical file that can contain one or more
Oracle data files or archived logs. A backup set is a complete set of backup pieces for
a full or incremental backup.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-29
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
12-30 Enterprise DBA Part 1B: Backup and Recovery Workshop
Data File Backup Process
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-31
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Example of Archived Log Backup (from slide) This example backs up archived
logs from log sequence number 1056 to 1058 (inclusive) to a backup set, where each
backup piece contains three archived logs. After the archived logs are copied, they are
deleted from disk and marked as deleted in the V$ARCHIVED_LOG view.
.....................................................................................................................................................
12-32 Enterprise DBA Part 1B: Backup and Recovery Workshop
Archived Log Backup
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-33
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Full, Incremental,
and Cumulative Backups
• Cumulative backups
contain only modified
blocks from the lower or
same level. Cumulative backup
.....................................................................................................................................................
12-34 Enterprise DBA Part 1B: Backup and Recovery Workshop
Full, Incremental, and Cumulative Backups
.....................................................................................................................................................
Full Backups A backup of one or more data files that contain all blocks. A full
backup can contain data files, image copies, archived logs, or control files.
Incremental Backups (Level >= 0) A backup of a control file or data files that
contain only those blocks that have been modified since the previous incremental
backup.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-35
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Incremental Backups
Incremental Backups
Incremental Backups
Incrementals have the following characteristics:
• An incremental level n backup, where n > 0, copies all changed blocks since the
previous incremental (level <= n) backup.
• A level 0 backup set or image copy must first be created. Incremental backups are
then based on changes made to these level 0 backups.
• Fewer blocks are written than when performing level 0 backups.
• Incremental backups are faster than level 0 backups.
• The default behavior of incremental backups is noncumulative.
.....................................................................................................................................................
12-36 Enterprise DBA Part 1B: Backup and Recovery Workshop
Incremental Backups
.....................................................................................................................................................
Rule of Thumb
• Perform level 0 backups if there are many updates to different blocks.
• Perform (level > 0) backups if there are many updates to fewer blocks.
There are two important SCNs:
• Checkpoint_change#:
The data file's checkpoint SCN at the time that the backup began
• Incremental_change#:
Also called incremental start SCN; the checkpoint SCN for the data file as it was in
the previous incremental backup (the backup this one is based on)
For an incremental level n (where n > 0), all blocks copied include:
SCNs >= incremental_change#
that is, all blocks that were modified since the first file was checkpointed and blocks at
the same checkpoint as the file (they may have been modified more than once at the
same SCN in between being written out).
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-37
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Three-Level Scheme
Level 0 Level 1 Level 2 Level 3
.....................................................................................................................................................
12-38 Enterprise DBA Part 1B: Backup and Recovery Workshop
Incremental Backups
.....................................................................................................................................................
Incremental Backups
Level 0 Level 0
Lvl 0 2 2 1 2 2 2 0
Day Sun Mon Tue Wed Thu Fri Sat Sun
Backup Example
You are maintaining a 100 GB database, which is continuously growing. Based on
existing hardware, you determine that open backups of the entire database take 4
hours. Backups consume too much system resources during this period of time,
because the database is online 24 hours a day, 7 days a week. Therefore, level 0
backups cannot be performed more than once a week, but fast recovery in case of
failure is required. You therefore decide on the following backup and recovery
strategy:
A level 0 backup will be performed each week on the day with the least activity. You
determine this day to be Sunday.
RMAN> run {allocate channel c1 type disk
2> format = ’/home/disk1/user4/BACKUP/sun_%s_%p.bus’;
3> backup incremental level = 0 (database); }
Incremental level 2 backups will be performed on every other day, except Wednesday.
In this way, backups will be fast, because only changed blocks from the previous day
will be copied:
RMAN> run {allocate channel c1 type disk
2> format = ’/home/disk1/user4/BACKUP/inc_%s_%p.bus’;
3> backup incremental level = 2 (database); }
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-39
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
12-40 Enterprise DBA Part 1B: Backup and Recovery Workshop
Cumulative Incremental Backups
.....................................................................................................................................................
Level 0 Level 0
Lvl 0 2 2C 1 2C 2C 2C 0
Day Sun Mon Tue Wed Thu Fri Sat Sun
Example (from slide) Cumulative backups duplicate changes already copied by the
previous incremental backup at the same level. Therefore, if an incremental level 2
backup is taken, then the following cumulative level 2 backs up all newly modified
blocks plus those backed up by the incremental level 2. This means that only one
incremental backup of the same level is needed to completely recover.
RMAN> run {allocate channel c1 type disk
2> format = ’/home/disk1/user4/BACKUP/cum_%s_%p.bus’;
3> backup incremental level = 2 cumulative (database);}
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-41
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Backup Constraints
Backup Constraints
Backup Constraints
In performing a backup using Recovery Manager, you need to be aware of the
following:
• The target database instance must be available for Recovery Manager to connect.
If you are not using a recovery catalog, the database must be mounted (for “cold”
backups) or open (for “hot” backups).
• Backups of online redo logs are not supported. If backups of redo logs are
required, the database must be run in ARCHIVELOG mode.
• If the target database is in NOARCHIVELOG mode, only “clean” tablespace and
data file backups can be taken (that is, backups of “offline normal” or “read only”
tablespaces). Database backups can be taken only if the database has first been
shut down cleanly and restarted in mount mode.
• If the target database is in ARCHIVELOG mode, only “current” data files can be
backed up (restored data files are made current by recovery).
• Recovery Manager does not back up parameter files, password files, or operating
system files.
• If a recovery catalog is used, the recovery catalog instance must be open.
.....................................................................................................................................................
12-42 Enterprise DBA Part 1B: Backup and Recovery Workshop
Backup Set Scenarios
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-43
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Example
D:\>rman catalog rman4pc/[email protected] target /
RMAN> run{
2> allocate channel d1 type disk format ’C:\BACKUP\%U’;
3> allocate channel d2 type disk format ’D:\BACKUP\%U’;
4> backup database filesperset 3;
5> release channel d1;
6> release channel d2;
7> }
.....................................................................................................................................................
12-44 Enterprise DBA Part 1B: Backup and Recovery Workshop
Backup Set Scenarios
.....................................................................................................................................................
Example (continued)
RMAN-08030: allocated channel: d1
RMAN-08500: channel d1: sid=9 devtype=DISK
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-45
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Example (continued)
List of Backup Sets
Key Recid Stamp LV Set Stamp Set Count Completion Time
---- ----- --------- -- --------- -------- ---------------
2511 4 365789423 0 365789394 6 18-MAY-99
.....................................................................................................................................................
12-46 Enterprise DBA Part 1B: Backup and Recovery Workshop
Backup Set Scenarios
.....................................................................................................................................................
Example (continued)
List of Data Files Included
File Name LV Type Ckp SCN Ckp Time
--- ------------------------------------ -- ---- ------- --------
1 D:\ORACLE\ORADATA\NEW8I\SYSTEM01.DBF 0 Full 425110 18-MAY-99
RMAN>
Backup of a Tablespace
run {
allocate channel d1 type disk format ’$HOME/INC0/TBS/%U’;
backup incremental level 0 tablespace SYSTEM;
release channel d1;
}
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-47
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
12-48 Enterprise DBA Part 1B: Backup and Recovery Workshop
Backups Using Stored Scripts
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-49
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
2 Execute the script using the CMDFILE option when connecting to Recovery
Manager.
rman catalog rman_db01/rman_db01@catdb target / cmdfile
fullback.rmn log scrpt.log
exit;
3 This script is now created in the recovery catalog as FULLBACKUP.
4 Each time you need to do a full backup, issue the following run command:
RMAN > run { execute script FULLBACKUP; }
RMAN-03021: executing script: BackupExample
RMAN-03022: compiling command: allocate
RMAN-03023: executing command: allocate
...Use the following command to check for block level corruption:
SQL> select * from v$backup_corruption where file# in (1,2,...);
no rows selected
Result
• Four sets are created, each with three multiplexed files.
• These sets are created in parallel, if two channels are allocated. If the keyword
filesperset is not included, only one channel is used, and that channel will
create one piece that contains all ten files. The other channels will be idle.
.....................................................................................................................................................
12-50 Enterprise DBA Part 1B: Backup and Recovery Workshop
Miscellaneous Issues
.....................................................................................................................................................
Miscellaneous Issues
Miscellaneous Issues
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-51
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Detecting Corruption
Recovery Manager detects and can prohibit any attempt to perform operations that
would result in unusable backup files or corrupt restored data files.
Information about corrupt data file blocks encountered during a backup are recorded
in the control file and the alert log. The server identifies corrupt data file blocks, but
they are still included in the backup. The Oracle server records the address of the
corrupt block and the type of corruption in the control file. To view corrupt blocks
from the control file, view either V$BACKUP_CORRUPTION for backup sets or
V$COPY_CORRUPTION for image copies.
To limit the number of previously undetected block corruptions allowed (2 in this
example) for a data file backup, use the set maxcorrupt syntax:
RMAN > run {
2> allocate channel c1 type disk;
3> set maxcorrupt for datafile ’/disk1/data/oem_01.dbf’ to 2;
4> copy level 0 datafile ’/disk1/data/oem_01.dbf’
5> to ’/disk1/backup/oem_01.dbf’;
6> release channel c1; }
.....................................................................................................................................................
12-52 Enterprise DBA Part 1B: Backup and Recovery Workshop
Memory Usage by Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-53
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
12-54 Enterprise DBA Part 1B: Backup and Recovery Workshop
Troubleshooting
.....................................................................................................................................................
Troubleshooting
Troubleshooting
• Use V$SESSION_LONGOPS to check the progress of a backup. For example:
SQL> select sid, serial#, context,
2 round(sofar/totalwork*100,2) "% Complete",
3 substr(to_char(sysdate,’yymmdd hh24:mi:ss’),1,15) "Time"
4 from v$session_longops
5 where compnam = ’dbms_backup_restore’;
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-55
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Troubleshooting (continued)
• Check V$SESSION_WAIT to see what events are being waited for:
SQL> select event, p1text, seconds_in_wait
2 from v$session_wait
3 where wait_time = 0;
Backup Hanging at Beginning After the tape backup has begun, if Recovery
Manager has not output new information, V$SESSION_WAIT will not show any
information for the COMPNAM = ‘DBMS_BACKUP_RESTORE’ statement, and the
backup may seem hung. In this situation, check the media manager to ensure that it has
not hung or terminated abnormally.
Check the sbtio.log file for more information, because most media managers
write information to this file. It is located in $ORACLE_HOME/rdbms/log
directory (not background_dump_dest or user_dump_dest).
No Tape Device Found If the following errors are detected, the 7004 error usually
indicates that no tape device is found.
RMAN-03007: exception occurred ... error is retryable
RMAN-07004: unhandled exception ... on channel c4
RMAN-10032: unhandled exception ... step 4: ORA-06512:at line 158
RMAN-10035: exception raised ... operation failed, retry possible
ORA-19506: failed to create sequential file, name="df_98_1",
parms=""
ORA-27007: failed to open file
...
.....................................................................................................................................................
12-56 Enterprise DBA Part 1B: Backup and Recovery Workshop
Data Dictionary Views
.....................................................................................................................................................
• V$ARCHIVED_LOG
• V$BACKUP_CORRUPTION
• V$COPY_CORRUPTION
• V$BACKUP_DATAFILE
• V$BACKUP_REDOLOG
• V$BACKUP_SET
• V$BACKUP_PIECE
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-57
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
Summary
Summary
.....................................................................................................................................................
12-58 Enterprise DBA Part 1B: Backup and Recovery Workshop
Quick Reference
.....................................................................................................................................................
Quick Reference
Context Reference
Parameters BACKUP_TAPE_IO_SLAVES
DB_BLOCK_SIZE
DB_FILE_DIRECT_IO_COUNT
DISK_ASYNCH_IO
LARGE_POOL_SIZE
SESSIONS
TAPE_ASYNCH_IO
Dynamic V$ARCHIVED_LOG
performance V$BACKUP_CORRUPTION
views
V$COPY_CORRUPTION
V$BACKUP_DATAFILE
V$BACKUP_REDOLOG
V$BACKUP_SET
V$BACKUP_PIECE
V$BACKUP_DEVICE
V$SESSION_LONGOPS
V$SESSION_WAIT
V$SGASTAT
Data None
dictionary
views
Commands RUN { commands; }
ALLOCATE CHANNEL ...;
COPY ...;
BACKUP ...
CREATE SCRIPT { commands; }
RUN { EXECUTE SCRIPT name; }
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 12-59
Lesson 12: Backups Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
12-60 Enterprise DBA Part 1B: Backup and Recovery Workshop
13
.................................
Objectives
Objectives
.....................................................................................................................................................
13-2 Enterprise DBA Part 1B: Backup and Recovery Workshop
Restoration and Recovery Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 13-3
Lesson 13: Restoration and Recovery Using Recovery Manager
.....................................................................................................................................................
Restoring a Database in
NOARCHIVELOG Mode
Example
This example assumes that:
• A full backup taken using RMAN is available on disk.
• The control files are not damaged and hence not restored.
rman target / nocatalog
RMAN> startup mount
RMAN> run {
2> allocate channel d1 type disk;
3> allocate channel d2 type disk; # For Parallel Restore
4> restore database;
5> recover database;
6> sql “alter database open”;}
.....................................................................................................................................................
13-4 Enterprise DBA Part 1B: Backup and Recovery Workshop
Restoring a Database in NOARCHIVELOG Mode
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 13-5
Lesson 13: Restoration and Recovery Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
13-6 Enterprise DBA Part 1B: Backup and Recovery Workshop
Recovering a Tablespace
.....................................................................................................................................................
Recovering a Tablespace
Recovering a Tablespace
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 13-7
Lesson 13: Restoration and Recovery Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
13-8 Enterprise DBA Part 1B: Backup and Recovery Workshop
Relocating a Tablespace
.....................................................................................................................................................
Relocating a Tablespace
Relocating a Tablespace
• Check the location and size of the data file.
• Make sure the tablespace is offline.
• Use SET NEWNAME for restore and SWITCH to record
in control file. Then use the RECOVER command.
• When recovery is finished, bring the tablespace online.
run{
allocate channel dev1 type disk:
sql “alter tablespace tbs1 offline immediate”;
set newname for datafile 2 to ‘disk1/data/df2.dbf’;
restore (tablespace tbs1);
switch datafile 2; # Update control file, catalog
recover tablespace tbs1; # Recover the tablespace
sql “alter tablespace tbs1 online”;
release channel dev1;}
®
Relocating a Tablespace
If a data file cannot be accessed because of disk failure, it probably must be restored to
a new location or switched to an existing image copy.
The same procedure is useful when you want to reloacte the tablespace, because you
are running short of disk space in one drive or you are reorganizing the database to
improve performance.
You notice that disk 2 has been corrupted and the database is still open. Occasionally
users complain that they cannot access information in data file number 2:
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 13-9
Lesson 13: Restoration and Recovery Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
13-10 Enterprise DBA Part 1B: Backup and Recovery Workshop
Relocating a Tablespace
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 13-11
Lesson 13: Restoration and Recovery Using Recovery Manager
.....................................................................................................................................................
Recover Syntax
A RECOVER command is usually issued within a RUN or CREATE SCRIPT
command:
recover <Object>;
where: Object database <until_clause>
tablespace <until clause>
Note
• This is not the full syntax.
• The target database must be in mounted state.
• The files being restored must be offline and you can only restore using RMAN
if the backups were taken or registered with RMAN.
.....................................................................................................................................................
13-12 Enterprise DBA Part 1B: Backup and Recovery Workshop
Incomplete Recovery of a Database: Example
.....................................................................................................................................................
Incomplete Recovery
Using RMAN
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 13-13
Lesson 13: Restoration and Recovery Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
13-14 Enterprise DBA Part 1B: Backup and Recovery Workshop
Restoring a Database to a Previous Incarnation
.....................................................................................................................................................
Restoring a Database to a
Previous Incarnation
• List the incarnation of the database.
• Shut down the database and move current files to
another location.
• Start up the database in the NOMOUNT state.
• Reset the database to a previous incarnation.
• Restore the control file from the old incarnation.
• Mount the database.
• Restore data files.
• Recover the database.
• Open the database with RESETLOGS.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 13-15
Lesson 13: Restoration and Recovery Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
13-16 Enterprise DBA Part 1B: Backup and Recovery Workshop
Summary
.....................................................................................................................................................
Summary
Summary
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 13-17
Lesson 13: Restoration and Recovery Using Recovery Manager
.....................................................................................................................................................
.....................................................................................................................................................
13-18 Enterprise DBA Part 1B: Backup and Recovery Workshop
14
.................................
Objectives
Objectives
.....................................................................................................................................................
14-2 Enterprise DBA Part 1B: Backup and Recovery Workshop
Overview
.....................................................................................................................................................
Overview
Overview
Primary
Database
144
145
146 144
145
146 146
144
Transfer
144
145
146 143
145 Archived
144
145
146
Archived Redo Logs Standby
144
145
146 Log Files
Database
Machine 1 146
144
1
145 146
144
1
145 144
146
1
146
144
145
1 143
145
0
144
146
1
145
Machine 2
®
Overview
Database administrators can maintain a duplicate, or standby, copy of a database at a
remote site to provide continued primary database availability in the event of a failure.
The standby database is created with a special copy of the control file from the
primary database. The standby database is kept in close synchronization with the
primary database by applying the primary database’s archived log files to the standby
database. It is therefore necessary to operate the primary database in Archivelog mode
to avail the benefit of a standby database.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 14-3
Lesson 14: Oracle Standby Database
.....................................................................................................................................................
A standby database:
• Is a copy of your primary database on a separate
machine
• Is kept in recovery mode for immediate activation
• Can be in Managed Recovery mode
• Can be opened in Read Only mode for queries
• Becomes the primary database after activation
.....................................................................................................................................................
14-4 Enterprise DBA Part 1B: Backup and Recovery Workshop
Standby Database Features
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 14-5
Lesson 14: Oracle Standby Database
.....................................................................................................................................................
Guidelines
• The standby database operates on Oracle release 7.3
or later.
• Standby and primary databases should be on different
machines.
• The same version, release, and patch of the operating
systems and RDBMS are on the primary and standby
hosts.
The standby host may use a different disk
configuration
• Standby can be activated (READONLY) and returned
to the Standby mode.
• During the activated period, archive logs cannot be
applied
®
.....................................................................................................................................................
14-6 Enterprise DBA Part 1B: Backup and Recovery Workshop
Initialization Parameters
.....................................................................................................................................................
Initialization Parameters
Initialization Parameters
Initialization Parameters
Most parameters for your primary and standby database should be identical.
Initialization parameters, such as CONTROL_FILES,
LOG_FILE_NAME_CONVERT, and DB_FILE_NAME_CONVERT should be
changed. The following parameters are important:
• COMPATIBLE: This parameter must be the same in both databases.
• DB_FILES: This parameter in conjunction control file parameter should be
identical to allow a same number of files on both databases.
• CONTROL_FILES: The values should be different to reduce the chances of
accidentally overwriting the other database’s control files (especially if you are
considering standby on a cluster or the same machine).
• DB_FILE_NAME_CONVERT and LOG_FILE_NAME_CONVERT: Use these
parameters to convert the location of data files and log files if the directory names
are different between the standby and primary machines.
• STANDBY_ARCHIVE_DEST: This parameter is used solely by the standby RFS
process to determine the directory in which to place the archived logs. Oracle uses
this value along with LOG_ARCHIVE_FORMAT to generate the log filename for
the standby site.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 14-7
Lesson 14: Oracle Standby Database
.....................................................................................................................................................
.....................................................................................................................................................
14-8 Enterprise DBA Part 1B: Backup and Recovery Workshop
Creating a Standby Database
.....................................................................................................................................................
Note
• The standby database must be kept in Standby Recovery mode. This allows Oracle
processes to recover the database by applying archived logs to the data files and
prevents the database being accessed by any users.
• Once the standby database is activated to Normal mode, it cannot be returned to
standby recovery mode without re-creating it as a standby database.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 14-9
Lesson 14: Oracle Standby Database
.....................................................................................................................................................
.....................................................................................................................................................
14-10 Enterprise DBA Part 1B: Backup and Recovery Workshop
Maintaining the Standby Database
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 14-11
Lesson 14: Oracle Standby Database
.....................................................................................................................................................
.....................................................................................................................................................
14-12 Enterprise DBA Part 1B: Backup and Recovery Workshop
Read Only Mode of Standby Database
.....................................................................................................................................................
How to Move the Standby Database from Read Only Mode Back to
Manual Recovery Mode
1 Terminate all active user sessions on the standby database.
2 Issue the following statement:
RECOVER STANDBY DATABASE
You can also set the TIMEOUT option in the managed option.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 14-13
Lesson 14: Oracle Standby Database
.....................................................................................................................................................
.....................................................................................................................................................
14-14 Enterprise DBA Part 1B: Backup and Recovery Workshop
Activating the Standby Database
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 14-15
Lesson 14: Oracle Standby Database
.....................................................................................................................................................
SVRMGR>
SVRMGR> recover
recover database;
database;
Primary SQL>
SQL> alter
alter database
database activate
activate
Database 2>
2> standby
standby database;
database;
Transfer
144
145
146 144
145
146 146
144
Archived
TransferLogs,
144
145
146 143
145 Archived
Data Files and
144
146
145
Control
Archived Redo Files
Logs Standby
144
145
146 Log Files
Database
SQL>
SQL> alter
alter database
database create
create 145
144
146
1 145
144
146
1 144
146
1
2>
2> standby
standby controlfile...;
controlfile...; 146
145
144
1 145
143
0
SQL>
SQL> alter
alter system
system archive
archive 145
146
144
1
2>
2> log
log current;
current;
®
.....................................................................................................................................................
14-16 Enterprise DBA Part 1B: Backup and Recovery Workshop
Operating a Standby Database
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 14-17
Lesson 14: Oracle Standby Database
.....................................................................................................................................................
.....................................................................................................................................................
14-18 Enterprise DBA Part 1B: Backup and Recovery Workshop
Structural Change of Primary Database
.....................................................................................................................................................
Altering Log Files Adding or dropping log file groups or members from the
primary database can be done without affecting the standby database.
Clear log files on the primary database by issuing the ALTER DATABASE CLEAR
UNARCHIVED LOGFILE command or using the RESETLOGS option when
opening the database or backing up the control file invalidates the standby database.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 14-19
Lesson 14: Oracle Standby Database
.....................................................................................................................................................
.....................................................................................................................................................
14-20 Enterprise DBA Part 1B: Backup and Recovery Workshop
Nologging Operations at the Primary Database
.....................................................................................................................................................
Nologging Operations
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 14-21
Lesson 14: Oracle Standby Database
.....................................................................................................................................................
Summary
Summary
.....................................................................................................................................................
14-22 Enterprise DBA Part 1B: Backup and Recovery Workshop
Quick Reference
.....................................................................................................................................................
Quick Reference
Context Reference
Parameters DB_FILES
DB_FILE_NAME_CONVERT
COMPATIBLE
CONTROL_FILES
LOG_FILE_NAME_CONVERT
Dynamic None
performance
views
Data None
Dictionary
Views
Commands ALTER DATABASE ACTIVATE STANDBY DATABASE;
DATABASE CREATE STANDBY CONTROLFILE AS ...;
ALTER DATABASE DATAFILE <name> OFFLINE;
ALTER DATABASE MOUNT STANDBY DATABASE;
ALTER DATABASE OPEN RESTRICT;
ALTER DATABASE RECOVER STANDBY DATABASE ...;
ALTER SYSTEM ARCHIVE LOG CURRENT;
RECOVER STANDBY DATABASE;
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 14-23
Lesson 14: Oracle Standby Database
.....................................................................................................................................................
.....................................................................................................................................................
14-24 Enterprise DBA Part 1B: Backup and Recovery Workshop
15
.................................
Workshop
Lesson 15: Workshop
.....................................................................................................................................................
Objectives
Objectives
Instructor Note
Carefully facilitate each session to ensure that timing is maintained. Emphasize the
objectives and timing to students at the beginning of each session. It is up to the
instructor to select from the list of scenarios based on student interests. The workshop
is structured to address six scenarios over the course of the day. Additional scenarios
can be performed as warranted by student interest and knowledge level.
.....................................................................................................................................................
15-2 Enterprise DBA Part 1B: Backup and Recovery Workshop
Workshop Methodology
.....................................................................................................................................................
Workshop Methodology
Workshop Methodology
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 15-3
Lesson 15: Workshop
.....................................................................................................................................................
Recovery Solutions
This workshop simulates a real-world environment in that exact solutions to problems
may not be readily available in the event of a database failure. Therefore, only cursory
instructions are noted in Appendix D for performing restore and recovery operations.
In some cases you may use associated Oracle Worldwide Support bulletins included in
Appendix E. The intent is to familiarize you with available documentation and how to
interpret it to perform a successful database recovery.
.....................................................................................................................................................
15-4 Enterprise DBA Part 1B: Backup and Recovery Workshop
Workshop Approach
.....................................................................................................................................................
Workshop Approach
Workshop Approach
• Physical Investigation:
– Use views and tools to derive information
– View trace files and log files
• Database Configuration:
– Archiving is enabled
– Control files and log files are mirrored
– Control file is backed up
Physical Investigation
Use the tools in the Oracle8i environment, such as the V$ views, data dictionary
views, and facilities in the Server Manager, and Oracle Enterprise Manager (if
available) to derive information about your database environment. Keep the business
requirements in mind and note any deficiencies that you feel will need to be corrected
or implemented to support them.
Database Configuration
Physically modify the database configuration to ensure that:
• Archiving is enabled
• Control files and log files are mirrored and distributed across multiple devices
• The control file is backed up both to trace and in a binary format
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 15-5
Lesson 15: Workshop
.....................................................................................................................................................
Business Requirements
Business Requirements
Business Requirements
The following business requirements should be familiar to you when configuring your
database for backup and recovery.
Peak Usage Varies Across Available Time Frame This database is accessed
globally, so it is used throughout the 24-hour period of one day.
Complete Database Recovery This is a critical business application and data loss
cannot be tolerated. A high number of transactions occur over the 24-hour time frame.
.....................................................................................................................................................
15-6 Enterprise DBA Part 1B: Backup and Recovery Workshop
Resolving a Failure
.....................................................................................................................................................
Resolving a Failure
Resolving a Failure
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 15-7
Lesson 15: Workshop
.....................................................................................................................................................
.....................................................................................................................................................
15-8 Enterprise DBA Part 1B: Backup and Recovery Workshop
Summary
.....................................................................................................................................................
Summary
Summary
• Instructor-facilitated workshop
• Group-oriented
• Hands-on approach
• Simulated “real-world” environment
• Minimize down time and data loss
• Use tools and diagnostics to determine the type of
failure.
Instructor-Facilitated Workshop
The instructor will facilitate the workshop by providing guidance and additional
information as appropriate. This is a change from instructor-led training where the
instructor does the majority of the talking.
Group-Oriented Emphasis
A strong emphasis is placed on teaming with other students in the workshop for
purposes of diagnosing and resolving failures. The ability to successfully complete
each scenario is based upon the cumulative knowledge and problem resolution skills
of each group.
Hands-On Approach
This is meant to be a hands-on workshop, providing students with the maximum
allowable time to be involved in a lab situation.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop 15-9
Lesson 15: Workshop
.....................................................................................................................................................
.....................................................................................................................................................
15-10 Enterprise DBA Part 1B: Backup and Recovery Workshop
A
................................
Practices
Appendix A: Practices
.....................................................................................................................................................
.....................................................................................................................................................
A-2 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 2-1
.....................................................................................................................................................
Practice 2-1
Oracle Recovery Structures and Processes
1 What is the V$ view that you must query for the names of all data files in the
database?
2 What are the V$ views that you must query for finding the current online redo log
and names of all redo logs in the database?
3 What is the V$ view that you must query for the names of all control files in the
database?
4 Name the V$ view that you should check to find the name of the database before
dropping tables or shutting down the database.
5 Name the V$ view that you must query to locate processes still connected to the
instance before shutting down the database.
6 Describe the significance of the parameters LOG_CHECKPOINT_INTERVAL
and FAST_START_IO_TARGET in instance recovery.
7 What init.ora parameter configures the memory area in the SGA that buffers
recovery information in memory before being written to disk?
8 What is the large pool, when is it used, and what initialization parameter
configures it?
9 Optional: Set up mirroring of control files so as to have three control files.
10 Optional: Set up mirroring of redo log files so as to have three members per group.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop A-3
Appendix A: Practices
.....................................................................................................................................................
Practice 3-1
Oracle Backup and Recovery Configuration
1 Connect to SQL*Plus as sysdba and mount the database.
2 List the parameters LOG_ARCHIVE_DEST, LOG_ARCHIVE_START, and
LOG_ARCHIVE_FORMAT, and note the values.
3 Execute the command ARCHIVE LOG LIST. Note the log mode of the database
and whether automatic archival is enabled.
4 Set the database in archivelog mode.
5 Open the database.
6 Shut down the instance with the IMMEDIATE option.
7 Edit the init.ora file to:
– Enable archiving
– Archive log files to two destinations: $HOME/ARCHIVE and $HOME/
ARCHIVE2 directories (The $HOME/ARCHIVE is mandatory, and $HOME/
ARCHIVE2 is optional.)
– Use the archiving format of arch_%s.arc
– Spawn two archive processes at instance start
8 While editing the init.ora file, uncomment the ROLLBACK_SEGMENTS
parameter to place the rollback segments RBS01 and RBS02 when the database
starts.
9 Start up and open the database.
10 Verify that two archive processes are running.
11 Execute the ALTER SYSTEM SWITCH LOGFILE command twice, then show
the values of the ARCHIVE parameters. Do you see any archived log files? What
is the format of the filename?
Advanced Practice
1 Stop automatic archiving by executing the ALTER SYSTEM ARCHIVE LOG
STOP command.
2 Execute the ALTER SYSTEM SWITCH LOGFILE command enough times to
recycle through all the online redo log groups. What happened and why?
3 Establish a second telnet session and connect to SQL*Plus as sysdba.
4 Enable automatic archiving by using the ALTER SYSTEM ARCHIVE LOG
START command.
5 Switch to your first session. What happened and why?
.....................................................................................................................................................
A-4 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 4-1
.....................................................................................................................................................
Practice 4-1
Closed Database Backup
1 While the database is open, connect to the database as sys or system and using
V$ and Data Dictionary Views, make a list of all of the files that must be backed
up for a whole offline database backup.
Note: Copy the redo logs for ease of restore/recovery in noarchivelog mode.
2 Shut down the database with the IMMEDIATE option. Make two whole offline
database backups using the operating system commands. Place one in $HOME/
DONTOUCH directory, and the other in $HOME/BACKUP.
Note: Do not place or remove files from the DONTOUCH directory without
instructor supervision. This copy will be used as the base in Scenarios.
3 Start the instance.
4 Connect as scott/tiger and execute the $HOME/LABS/deptdata.sql
and $HOME/LABS/empdata.sql scripts to create transactions against the
database.
5 Connect as system/manager and make an open backup of the DATA01
tablespace. Copy the file to $HOME/BACKUP directory. Make sure that you do not
overwrite another copy.
6 Use the ALTER DATABASE command to back up the control file to trace.
Connect to Server Manager and execute the $HOME/LABS/spid.sql script to
identify the trace file. Host to the operating system and copy the trace file to
$HOME/BACKUP/cntrl.sql. Using an editor, remove the comments from the
SQL file.
7 Create a binary copy of the control file and put it in the $HOME/BACKUP
directory. Name the backup copy cntrl1.bkp.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop A-5
Appendix A: Practices
.....................................................................................................................................................
Practice 5-1
Complete Database Recovery: Noarchivelog Mode
1 Shut down the database and disable automatic archival (ARC0) by editing the
init.ora parameter file, then start and mount the database. Set the database in
noarchivelog mode, and then open the database. Ensure the desired status by
issuing ARCHIVE LOG LIST command.
2 Shut down the database and perform a full, closed backup by using the operating
system command. (Copy the files to the $HOME/BACKUP/NOARC directory
only.) Start the instance and open the database.
3 Start SQL*Plus and connect by using scott/tiger and run the $HOME/
LABS/newemp.sql script. This script creates new tables in scott’s schema and
adds some information to them.
4 Connect as system/manager and run the following script to record the names
of data files that contain the table NEWEMP:
SQL> select f.file_name from dba_tables t, dba_data_files f
2 where table_name = ‘NEWEMP‘ and
3 t.tablespace_name=f.tablespace_name;
$HOME/DATA/DISK3/data01.dbf
5 Run the $HOME/LABS/breakdb.sql as sys or system in SQL*Plus to
simulate failure.
6 Attempt to restart the database normally. What happened?
7 Shut down the database and use the appropriate operating system command to
replace the current database with the latest backup (from NOARC directory to
DATA directory).
8 Start up and open the database so that it will be available to all users.
9 Connect to the database as scott/tiger to execute a query against the
NEWEMP table. What happened and why?
10 What conclusions can you make about offline backups and recovery for databases
in noarchivelog mode?
.....................................................................................................................................................
A-6 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 5-2
.....................................................................................................................................................
Practice 5-2
Complete Database Recovery: Archivelog Mode
1 Query the V$DATABASE view to see what mode the database is in. Use
ARCHIVE LOG LIST to check the status of archivelog mode and automatic
archiving.
2 Shut down the instance and uncomment the LOG_ARCHIVE_START parameter
in the init.ora. Mount the database and use the ALTER DATABASE
command to enable archiving.
3 Check to make sure archiving is successful by using the ARCHIVE LOG LIST
command. Note the current log sequence number.
4 Perform a closed database backup. Store the backup in the $HOME/BACKUP
directory.
5 Start SQL*Plus and connect by using scott/tiger and run the $HOME/
LABS/newemp.sql script. This script simulates the creation of a new table and
users adding important information to it.
6 Connect as system/manager and run the script $HOME/LABS/
checktbs.sql to note the data files associated with the tablespace that contains
the table NEWEMP.
7 Run the $HOME/LABS/breakdb.sql script to simulate hardware failure.
8 Attempt to shut down and restart the database normally. What happened?
9 The database cannot locate the files for the DATA01 tablespace because of
perceived media failure. Since archiving is enabled, you can now perform a
complete recovery.
10 Use the RECOVER DATABASE command to recover the database.
11 When recovery is complete, open the database to make it available for all users.
12 Query the DBA_TABLESPACES view to see if the tablespace DATA01 is online.
13 Connect to the database as scott/tiger and execute a query against the
NEWEMP table. What happened?
14 Connect as system/manager and query the V$LOG view and note the
sequence number. Compare this value with the value in step 3. What conclusions
can you make about complete recovery?
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop A-7
Appendix A: Practices
.....................................................................................................................................................
Optional Practice 1
1 Run the $HOME/LABS/breakdb.sql script to simulate hardware failure.
2 Attempt to restart the database normally. What happened?
3 The database cannot locate the files for the USER_DATA tablespace because of a
perceived media failure. Because archiving is enabled, you can now perform a
complete recovery.
4 Take the data files for the DATA01 tablespace offline.
5 Open the database to make it available for all users.
6 Take the DATA01 tablespace offline, then restore all data files from the backup.
7 Use the RECOVER TABLESPACE command to recover the tablespace.
8 Put the USER_DATA tablespace back online.
9 Connect to the database as scott/tiger and execute a query against the
NEWEMP table to make sure it still exists.
Optional Practice 2
1 Run the $HOME/LABS/newtbs.sql script to
– Create a new tablespace with a new data file
– Create a table NEW_EMP1 with data on the new tablespace
– Simulate the loss of the new data file
The database cannot locate the file for the NEW_DATA tablespace because of
perceived loss of file. Since archiving is enabled, you can perform a complete
recovery after the recreation of the file for which you have no backup.
2 You can either take the data file for the NEW_DATA tablespace offline, or take the
tablespace offline, because it only contains one data file.
Note: IMMEDIATE option must be included to avoid a checkpoint trying to write
to a nonexistent file.
Confirm the recovery status by querying V$RECOVER_FILE to check the status
of a backup.
3 You now must re-create the file.
4 Use the RECOVER or ALTER DATABASE RECOVER commands to start
applying the archives and the redo logs to the recreated data file.
5 To bring the data file to the point of failure, all needed archived logs and redo logs
are applied.
.....................................................................................................................................................
A-8 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 5-2
.....................................................................................................................................................
6 All data files are now synchronized. When recovery is finished, bring the
tablespace online.
All data is now recovered. Include the file in the backup strategy and notify users
that the tablespace is ready to be used again.
7 Connect to the database as scott/tiger and execute a query against the
NEW_EMP1 table to make sure it still exists.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop A-9
Appendix A: Practices
.....................................................................................................................................................
Optional Practice 3
While you perform the online backup of the DATA01 tablespace, simulate a shutdown
abort of your database. You will need to recover the situation to reopen the database to
the users though an online backup was being performed and not finished.
1 Make an online backup of the DATA01 tablespace.
2 Make an OS backup of the tablespace files.
3 Shut down in ABORT mode.
4 Mount the database.
5 Retrieve from the appropriate dictionary view the information on the active online
backed up data file to be ended.
6 Unfreeze the header to release the backup mode on the data file.
7 Open the database for users.
.....................................................................................................................................................
A-10 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 6-1
.....................................................................................................................................................
Practice 6-1
Recovering from User Failure: Incomplete Recovery
1 If you are unsure whether you have a valid backup from the previous exercise, then
Perform either a whole closed or opened database backup. Store the backup in the
$HOME/BACKUP directory.
2 Start SQL*Plus and connect using scott/tiger and insert rows into the
NEWEMP table by executing the following statement:
SQL> insert into newemp select * from newemp;
3 Select a count of the rows in the NEWEMP table. Note the number of rows.
4 Connect as system/manager and record the data files belonging to the
tablespace that contains the NEWEMP table.
5 Record the current system time using an operating system command.
6 Record the current online log sequence number by querying V$LOG.
7 Connect using scott/tiger and add rows to the NEWEMP table by executing
the following command:
insert into newemp select * from newemp;
8 Get a count of the rows in the NEWEMP table.
9 Run the $HOME/LABS/breaktab.sql script to simulate a user accidentally
dropping the NEWEMP table.
SQL> @$HOME/LABS/breaktab.sql
10 Attempt to query the NEWEMP table. What happened?
11 The database cannot locate the NEWEMP table. Mount the database to perform
recovery.
12 Restore all data files from the backup that you made in step 1.
Note: Check the V$DATAFILE view with the $HOME/LABS/cpdbfile.sh
script. If the files and locations are identical, then run this script. Otherwise, you
may modify this script to match your database structure.
13 Recover the database until the time you noted in step 4.
14 When recovery is complete, open the database using the RESETLOGS option to
enable access for all users.
15 Connect to the database as scott/tiger and execute a query against the
NEWEMP table. What happened and why?
16 Connect as system/manager, query the V$LOG view, and note the sequence
number. Compare this value with the value in step 5. What conclusions can you
make about incomplete recovery?
17 Take a whole offline backup. Store the backup in the $HOME/BACKUP directory.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop A-11
Appendix A: Practices
.....................................................................................................................................................
.....................................................................................................................................................
A-12 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 7-1
.....................................................................................................................................................
Practice 7-1
Oracle Export and Import Utilities
Use the Export and Import utilities to save flat file copies of data offline.
1 Invoke the Export utility to export the EMP and DEPT tables in the scott schema.
2 With SQL*Plus, connect as scott. Drop the EMP and DEPT tables.
3 Restore the EMP and DEPT tables by using the import utility.
4 Query the EMP and DEPT tables to get the number of rows in each of those tables.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop A-13
Appendix A: Practices
.....................................................................................................................................................
Practice 8-1
Starting the Oracle Database with a Missing Data File
1 Connect as sysdba.
2 Shut down the database by using IMMEDIATE.
3 From the operating system prompt, rename the data file $HOME/DATA/DISK3/
temp01.dbf to $HOME/DATA/DISK3/temp01.old.
4 Connect as sysdba and start the database. What error message do you receive?
5 Drop the data files for the TEMPORARY tablespace.
6 Open the database.
7 Drop the TEMPORARY tablespace.
8 Re-create the TEMPORARY tablespace by using the filename temp01.dbf
with a size of 50K.
.....................................................................................................................................................
A-14 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 9-1
.....................................................................................................................................................
Practice 9-1
Types of Troubleshooting
1 Execute the ALTER SYSTEM SWITCH LOGFILE command twice. Change to
the BDUMP directory, list the files, then view the last few lines of
alert_<SID>.log file. You notice that Log Switch is recorded in alert log.
2 Connect to SQL*Plus and use the SHOW command to check the values of the
parameter DB_BLOCK_CHECKSUM.
3 Run the DBVERIFY utility against the user01.dbf data file. Do you see any
corrupted blocks?
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop A-15
Appendix A: Practices
.....................................................................................................................................................
Practice 10-1
1 List some benefits that your organization could obtain by using RMAN.
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
2 What is a recovery catalog, when should it be used, and where should it be
created?
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
3 List the benefits of recovery catalog.
__________________________________________________________
__________________________________________________________
4 While the instance is running, connect to your target database in RMAN without
using the recovery catalog.
5 What are stored scripts? How are they useful?
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
.....................................................................................................................................................
A-16 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 11-1
.....................................................................................................................................................
Practice 11-1
This practice involves learning how to manage, maintain, set up scripts in, and query
the recovery catalog for Recovery Manager. Remember that you have two databases
for this practice: your lab account database–target database, and the Recovery Catalog
database, which contains a recovery catalog schema for your student account.
1 Connect to your target database and recovery catalog using RMAN.
2 Execute the command to resync the control file and recovery catalog. What
happened? Why?
3 Register target database in the recovery catalog at the RMAN prompt.
4 Using RMAN, list all the database incarnations registered in the catalog.
5 Enter the RESET DATABASE command at the RMAN prompt. What happens?
6 View the script $HOME/LABS/crebkup.sql script, and then run it as user
system by logging into target database using SQL*PLUS to create an online
operating system copy of the system tablespace data file in your $HOME/BACKUP
directory.
7 Using RMAN, add the backup mode in step 6 to the catalog.
8 Using RMAN, confirm that the data file has been added to the recovery catalog.
9 Use the RMAN command to remove the backup of the system data file from the
recovery catalog. Do not remove the file from the disk.
10 Use the REPORT command to determine which data files have not yet been
backed up by RMAN today.
11 Connect to your recovery catalog database using SQL*Plus, and query
RC_DATAFILE_COPY to confirm that the data file has been removed from the
recovery catalog.
12 Create a script to make a whole database backup with following information:
Name of script:nightback
Channel name: dbnD (n is the student account number)
Channel type Disk
Format $HOME/BACKUP/%b%d%s%p
Level Database (No archivelogs)
tag nback
DO NOT RUN THIS SCRIPT NOW.
13 Query the recovery catalog and verify whether the script has been created.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop A-17
Appendix A: Practices
.....................................................................................................................................................
Practice 12-1
Backup Using RMAN
1 What are the two supported backup types for Recovery Manager? List some of the
differences between the two backup types.
2 Create an image copy of data files belonging to SYSTEM tablespace. The copy
should be placed in $HOME/BACKUP/INC0 directory with the name of
sys0101.cpy. The tag should be SYSTEM01.
3 Create a script to back up the database following these guidelines:
– The name of the script should be FULLBACK.
– Make a backup set.
– The incremental level should be 0.
– Backup pieces should be on disk in $HOME/INC0 directory.
– The format string should include FULL%n_%s.%p.
– Do not include archivelogs.
– Place four files per backup set.
– Parallel the backup operation in three sessions.
4 Run the script created in step 3 and verify completion of the backup.
5 Using RMAN, back up archive logs generated today to $HOME/BACKUP/INC1
directory.
6 Log in to target database using SQL*PLUS as user scott, and run the script
moreemp.sql. Create a backup of DATA01 tablespace with the following
guidelines:
– It should be a backup set.
– The incremental level should be 2.
– Do not include control file.
– Backup piece should be on disk in $HOME/INC2 directory.
7 Obtain a listing of all data files that have not been backed up in the last two days.
.....................................................................................................................................................
A-18 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 13-1
.....................................................................................................................................................
Practice 13-1
Restore and Recover Using RMAN
It is assumed that the previous practice in Lesson 12 has been completed successfully.
1 Obtain a list of backup sets registered in the catalog.
2 Obtain a list of copies listed in the catalog.
3 Run the script breakdb.sql as sysdba user in a SQL*PLUS session. Then,
using RMAN, recover the DATA01 tablespace.
4 You have determined that DISK3 ($HOME/DATA/DISK3) is corrupted. You must
relocate all the files on DISK3 to another location. You determined that DISK4 has
sufficient space. Using RMAN, relocate all the data files in DISK3 to DISK4.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop A-19
Appendix A: Practices
.....................................................................................................................................................
.....................................................................................................................................................
A-20 Enterprise DBA Part 1B: Backup and Recovery Workshop
B
................................
Practice Solutions
Appendix B: Practice Solutions
.....................................................................................................................................................
.....................................................................................................................................................
B-2 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 2-1 Solutions
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-3
Appendix B: Practice Solutions
.....................................................................................................................................................
.....................................................................................................................................................
B-4 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 3-1 Solutions
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-5
Appendix B: Practice Solutions
.....................................................................................................................................................
3 Execute the command ARCHIVE LOG LIST. Note the log mode of the database
and whether automatic archival is enabled.
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /oracle/core/8.1.5/dbs/arch
Oldest online log sequence 240
Next log sequence to archive 241
Current log sequence 241
4 Set the database in archivelog mode.
SQL> alter database archivelog;
Database altered.
5 Open the database.
SQL> alter database open;
Database altered.
6 Shut down the instance with the IMMEDIATE option.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
7 Edit the init.ora file to:
– Enable archiving
– Archive log files to two destinations: $HOME/ARCHIVE and $HOME/
ARCHIVE2 directories (The $HOME/ARCHIVE is mandatory, and $HOME/
ARCHIVE2 is optional.)
– Use the archiving format of arch_%s.arc
– Spawn two archive processes at instance start
init.ora file
...
log_archive_start = true
log_archive_dest_1 = “LOCATION=$HOME/ARCHIVE/ MANDATORY”
log_archive_dest_2 = “LOCATION=$HOME/ARCHIVE2/ OPTIONAL”
log_archive_max_processes = 2
log_archive_format = arch_%s.arc
.....................................................................................................................................................
B-6 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 3-1 Solutions
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-7
Appendix B: Practice Solutions
.....................................................................................................................................................
log_archive_max_processes 2
log_archive_min_succeed_dest 1
log_archive_format arch_%s.arc
SQL> !ls -l $HOME/ARCHIVE $HOME/ARCHIVE2
/db/oracle/archive/:
total 154
-rw-rw---- 1 oracle dba 77824 Mar 23 03:28 arch_121.arc
-rw-rw---- 1 oracle dba 1024 Mar 23 03:28 arch_122.arc
/db/oracle/archive2/:
total 154
-rw-rw---- 1 oracle dba 77824 Mar 23 03:28 arch_121.arc
-rw-rw---- 1 oracle dba 1024 Mar 23 03:28 arch_122.arc
Advanced Practice
1 Stop automatic archiving by executing the ALTER SYSTEM ARCHIVE LOG
STOP command.
SQL> alter system archive log stop;
System altered.
2 Execute the ALTER SYSTEM SWITCH LOGFILE command enough times to
recycle through all the online redo log groups. What happened and why?
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
The database is in archivelog mode, but since automatic archiving is disabled
the next redo log file cannot be used since it has not been archived.
3 Establish a second telnet session and connect to SQL*Plus as sysdba.
4 Enable automatic archiving by using the ALTER SYSTEM ARCHIVE LOG
START command.
SQL> alter system archive log start;
System altered.
5 Switch to your first session. What happened and why?
You now have the message “System Altered” followed by the SQL
prompt. The archive process has been restarted. The log switch is now
possible because the redo log files were archived when archiving was
restarted.
.....................................................................................................................................................
B-8 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 4-1 Solutions
.....................................................................................................................................................
NAME
--------------------------------------------------------------
/u03/user/db02/DATA/DISK1/control01.ctl
/u03/user/db02/DATA/DISK2/control02.ctl
MEMBER
--------------------------------------------------------------
/u03/user/db02/DATA/DISK3/redo01a.log
/u03/user/db02/DATA/DISK4/redo01b.log
/u03/user/db02/DATA/DISK4/redo02a.log
/u03/user/db02/DATA/DISK3/redo02b.log
7 rows selected.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-9
Appendix B: Practice Solutions
.....................................................................................................................................................
2 Shut down the database with the IMMEDIATE option. Make two whole offline
database backups using the operating system commands. Place one in $HOME/
DONTOUCH directory, and the other in $HOME/BACKUP.
$ cp -rp $HOME/DATA/* $HOME/DONTOUCH
$ cp $ORACLE_HOME/dbs/orapw* $HOME/DONTOUCH
$ cp -rp $HOME/DATA/* $HOME/BACKUP
$ cp $ORACLE_HOME/dbs/orapw* $HOME/BACKUP
Note: Do not place or remove files from the DONTOUCH directory without
instructor supervision. This copy will be used as the base in Scenarios.
3 Start the instance.
4 Connect as scott/tiger and execute the $HOME/LABS/deptdata.sql
and $HOME/LABS/empdata.sql scripts to create transactions against the
database.
SQL> connect scott/tiger
SQL> @$HOME/LABS/empdata.sql;
SQL> @$HOME/LABS/deptdata.sql;
5 Connect as system/manager and make an open backup of the DATA01
tablespace. Copy the file to $HOME/BACKUP directory. Make sure that you do not
overwrite another copy.
SQL> connect system/manager
SQL> alter tablespace data01 begin backup;
SQL> !cp $HOME/DATA/DISK3/data01.dbf $HOME/BACKUP/data01.bkp
SQL> alter tablespace data01 end backup;
6 Use the ALTER DATABASE command to back up the control file to trace.
Connect to SQL*PLUS and execute $HOME/LABS/spid.sql script to identify
the trace file. Exit to the operating system and copy the trace file to $HOME/
BACKUP/cntrl.sql. Using an editor, remove the comments from the SQL file.
SQL> alter database backup controlfile to trace;
SQL> @$HOME/LABS/spid.sql
USERNAME SPID
------------------------------ ---------
SYSTEM <process ID>
SQL> exit
$ cd $HOME/UDUMP
$ cp U1_ora_<process ID>.trc $HOME/BACKUP/cntrl.trc
$ vi $HOME/BACKUP/cntrl.trc
<Remove all comments from the trace file.
Add the PFILE keyword to the STARTUP command.>
.....................................................................................................................................................
B-10 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 4-1 Solutions
.....................................................................................................................................................
7 Create a binary copy of the control file and put it in the $HOME/BACKUP
directory. Name the backup copy cntrl1.bkp.
SQL> alter database backup controlfile to ‘$HOME/BACKUP/
cntrl1.bkp‘;
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-11
Appendix B: Practice Solutions
.....................................................................................................................................................
.....................................................................................................................................................
B-12 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 5-1 Solutions
.....................................................................................................................................................
3 Start SQL*Plus and connect by using scott/tiger and run the $HOME/
LABS/newemp.sql script. This script creates new tables in scott’s schema and
adds some information to them.
SQL> @$HOME/LABS/newemp.sql
4 Connect as system/manager and run the following script to record the names
of data files that contain the table NEWEMP:
SQL> select f.file_name from dba_tables t, dba_data_files f
2 where table_name = ‘NEWEMP‘ and
3 t.tablespace_name=f.tablespace_name;
$HOME/DATA/DISK3/data01.dbf
5 Run the $HOME/LABS/breakdb.sql as sys or system in SQL*Plus to simulate
failure.
SQL> @$HOME/LABS/breakdb.sql
6 Attempt to restart the database normally. What happened?
ORA-01157: cannot identify data file 3- file not found
ORA-01110: data file 3: '$HOME/DATA/DISK3/data01.dbf'
The database cannot open data file number 4. Therefore, the database is left
in the mount state. The database cannot locate the files for the DATA01
tablespace because of perceived media failure.
7 Shut down the database and use the appropriate operating system command to
replace the current database with the latest backup (from NOARC directory to
DATA directory).
SQL> connect / as sysdba;
SQL> shutdown abort;
SQL> !cp -rp $HOME/BACKUP/NOARC/* $HOME/DATA
8 Start up and open the database so that it will be available to all users.
SQL> connect / as sysdba;
SQL> startup pfile=$HOME/LABS/initU7.ora
9 Connect to the database as scott/tiger to execute a query against the
NEWEMP table. What happened and why?
SQL> connect scott/tiger;
SQL> select * from NEWEMP;
ORA-00942: table or view does not exist
The table does not exist because it was created after the last backup was
taken.
10 What conclusions can you make about offline backups and recovery for databases
in noarchivelog mode?
Offline backups can be used to restore the database. Databases in
noarchivelog mode have no archived logs to recover from the previous
backup to the point of failure. Therefore, all changes after the previous
backup have been lost. This explains why the NEWEMP table no longer
exists.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-13
Appendix B: Practice Solutions
.....................................................................................................................................................
.....................................................................................................................................................
B-14 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 5-2 Solutions
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-15
Appendix B: Practice Solutions
.....................................................................................................................................................
11 When recovery is complete, open the database to make it available for all users.
SQL> alter database open;
12 Query the DBA_TABLESPACES view to see if the tablespace DATA01 is online.
SQL > select tablespace_name, status from dba_tablespaces
2> where tablespace_name = ‘DATA01’;
TABLESPACE_NAME STATUS
------------------------------ ---------
DATA01 ONLINE
1 row selected.
13 Connect to the database as scott/tiger and execute a query against the
NEWEMP table. What happened?
SQL> select count(*) from newemp;
COUNT(*)
----------
25
1 row selected
14 Connect as system/manager and query the V$LOG view and note the
sequence number. Compare this value with the value in step 3. What conclusions
can you make about complete recovery?
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS
...
------- ------- --------- ------ ------- --- -------
...
1 1 247 512000 2 YES INACTIVE
2 1 248 512000 2 NO CURRENT
The log sequence numbers now are higher than in step 3 where the database
backup was taken after changing to archivelog mode. During recovery,
archived logs have been applied, and the database has been brought forward
to the current point in time.
.....................................................................................................................................................
B-16 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 5-2 Solutions
.....................................................................................................................................................
Optional Practice 1
1 Run the $HOME/LABS/breakdb.sql script to simulate hardware failure.
SQL> @$HOME/LABS/breakdb.sql
2 Attempt to restart the database normally. What happened?
ORA-01157: cannot identify data file 3- file not found
ORA-01110: data file 3: ’$HOME/DATA/DISK3/data01.dbf’
The database cannot open data file number 3. Therefore, the database is left
in mount mode.
3 The database cannot locate the files for the USER_DATA tablespace because of a
perceived media failure. Because archiving is enabled, you can now perform a
complete recovery.
4 Take the data files for the DATA01 tablespace offline.
SQL > alter database datafile ’$HOME/DATA/DISK3/data01.dbf’
2 offline;
5 Open the database to make it available for all users.
SQL> alter database open;
6 Take the DATA01 tablespace offline, then restore all data files from the backup.
SQL> alter tablespace DATA01 offline immediate;
$ cp $HOME/BACKUP/DISK3/data01.dbf $HOME/DATA/DISK3
7 Use the RECOVER TABLESPACE command to recover the tablespace.
SQL> recover automatic tablespace DATA01;
8 Put the USER_DATA tablespace back online.
SQL> alter tablespace DATA01 online;
9 Connect to the database as scott/tiger and execute a query against the
NEWEMP table to make sure it still exists.
SQL> connect scott/tiger;
SQL> select count(*) from newemp;
COUNT(*)
----------
S25
1 row selected
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-17
Appendix B: Practice Solutions
.....................................................................................................................................................
Optional Practice 2
1 Run the $HOME/LABS/newtbs.sql script as user SYSTEM to:
– Create a new tablespace with a new data file
– Create a table NEW_EMP1 in SCOTT’s schema with data on the new
tablespace
– Simulate the loss of the new data file
SQL> @$HOME/LABS/newtbs.sql
The database cannot locate the file for the NEW_DATA tablespace because of
perceived loss of file. Since archiving is enabled, you can perform a complete
recovery after the recreation of the file for which you have no backup.
2 You can either take the data file for the NEW_DATA tablespace offline, or take
the tablespace offline, because it only contains one data file.
Note: The immediate option must be included to avoid a checkpoint trying to write
to a file which does not exist:
SQL > alter tablespace NEW_DATA offline immediate;
Tablespace altered.
Confirm the recovery status by querying V$RECOVER_FILE to check the status
of a backup.
SQL> select * from v$recover_file;
FILE# ONLINE ERROR CHANGE# TIME
----- ------- ------------------ -------- ---------
7 OFFLINE FILE NOT FOUND 0
3 You now must re-create the file.
SQL > alter database create datafile
2 ’$HOME/DATA/DISK4/new01.dbf’
3 as ’$HOME/DATA/DISK4/new01.dbf’;
Database altered.
SQL> select * from v$recover_file;
FILE# ONLINE ERROR CHANGE# TIME
----- ------- ------------------ --------- ---------
7 OFFLINE 248621 25-MAR-99
4 Use the RECOVER or ALTER DATABASE RECOVER commands to start
applying the archives and the redo logs to the recreated data file.
SQL > recover tablespace NEW_DATA;
.....................................................................................................................................................
B-18 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 5-2 Solutions
.....................................................................................................................................................
5 To bring the data file to the point of failure, all needed archived logs and redo logs
are applied.
6 All data files are now synchronized. When recovery is finished, bring the
tablespace online.
SQL > alter tablespace NEW_DATA online;
All data is now recovered. Include the file in the backup strategy and notify users
that the tablespace is ready to be used again.
7 Connect to the database as scott/tiger and execute a query against the
NEW_EMP1 table to make sure it still exists.
SQL> connect scott/tiger;
SQL> select COUNT(*) from NEW_EMP1;
COUNT(*)
----------
100
1 row selected
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-19
Appendix B: Practice Solutions
.....................................................................................................................................................
Optional Practice 3
While you perform the online backup of the DATA01 tablespace, simulate a shutdown
abort of your database. You will need to recover the situation to reopen the database to
the users, though an online backup was being performed and not finished.
1 Make an online backup of the DATA01 tablespace.
SQL> alter tablespace DATA01 begin backup;
Tablespace altered.
2 Make an OS backup of the tablespace files.
$ cp $HOME/DATA/DISK3/data01.dbf $HOME/BACKUP/DISK3
3 Shut down in ABORT mode.
SQL> shutdown abort;
4 Mount the database.
SQL> connect / as sysdba;
SQL> startup mount pfile=initdb01.ora;
5 Retrieve from the appropriate dictionary view the information on the active online
backed up data file to be ended.
SQL> select * from v$backup;
FILE# STATUS CHANGE# TIME
---------- ------------------ ------- ---------
1 NOT ACTIVE 0
2 NOT ACTIVE 0
3 ACTIVE 228596 25-MAR-99
4 NOT ACTIVE 0
5 NOT ACTIVE 0
6 NOT ACTIVE 0
7 NOT ACTIVE 0
This indicates that file number 4 is currently in hot backup mode.
6 Unfreeze the header to release the backup mode on the data file.
SQL> alter database datafile 3 end backup;
Database altered.
SQL> select * from v$backup;
FILE# STATUS CHANGE# TIME
---------- ------------------ ------- ---------
1 NOT ACTIVE 0
...
3 NOT ACTIVE 228596 25-MAR-99
...
7 Open the database for users.
SQL> alter database open;
Database altered.
.....................................................................................................................................................
B-20 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 6-1 Solutions
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-21
Appendix B: Practice Solutions
.....................................................................................................................................................
.....................................................................................................................................................
B-22 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 6-1 Solutions
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-23
Appendix B: Practice Solutions
.....................................................................................................................................................
.....................................................................................................................................................
B-24 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 6-1 Solutions
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-25
Appendix B: Practice Solutions
.....................................................................................................................................................
11 Recover the database using the UNTIL CANCEL option, stopping before the
Oracle server requests the archived log file you noted in step 8.
Note: Do not use the automatic method. Apply each archived log manually as the
Oracle server requests it.
SQL> recover database until cancel
...
Log applied.
ORA-00279: change 114408 ... needed for thread 1
ORA-00289: suggestion : $HOME/ARCHIVE/dbxx_<missing log>.arc
ORA-00280: change 114408 for thread 1 is in sequence #<missing
log>
ORA-00278: log file ... no longer needed for this recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
12 Type cancel at the recovery prompt.
cancel
Media recovery cancelled.
13 Once recovery is complete, open the database using the RESETLOGS option to
enable access for all users.
SQL> alter database open resetlogs;
Statement processed.
14 Check to make sure all data files are online, then shut down and take a full offline
backup.
SQL> select name, status from v$datafile;
NAME STATUS
--------------------------------------- -------
/u03/user/db02/DATA/DISK1/system01.dbf SYSTEM
/u03/user/db02/DATA/DISK2/rbs01.dbf ONLINE
/u03/user/db02/DATA/DISK3/data01.dbf ONLINE
/u03/user/db02/DATA/DISK2/temp01.dbf ONLINE
/u03/user/db02/DATA/DISK2/indx01.dbf ONLINE
/u03/user/db02/DATA/DISK3/oemrep01.dbf ONLINE
/u03/user/db02/DATA/DISK1/query01.dbf ONLINE
7 rows selected.
.....................................................................................................................................................
B-26 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 7-1 Solutions
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-27
Appendix B: Practice Solutions
.....................................................................................................................................................
.....................................................................................................................................................
B-28 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 8-1 Solutions
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-29
Appendix B: Practice Solutions
.....................................................................................................................................................
.....................................................................................................................................................
B-30 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 9-1 Solutions
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-31
Appendix B: Practice Solutions
.....................................................................................................................................................
2 The next day, the DBA is asked to cancel the wrong insertion made some time the
previous day by Scott on SCOTT.EMP table. The user, however, cannot remember
which row was inserted.
Initialize the LogMiner utility to undo the SQL insert statement executed by Scott
on SCOTT.EMP table the previous day.
Edit the init.ora and add the parameter:
UTL_FILE_DIR=/<full_home_path>/TRACE
SQL> connect / as sysdba
Connected.
SQL> STARTUP
SQL> execute
DBMS_LOGMNR_D.build(‘logdict’,’<full_home_path>/TRACE’);
PL/SQL procedure successfully completed.
3 Specify redo log files to be analyzed.
SQL> execute dbms_logmnr.add_logfile('<full_home_path>/DATA/
DISK3/redo0101.log',dbms_logmnr.NEW);
PL/SQL procedure successfully completed.
SQL> execute dbms_logmnr.add_logfile('<full_home_path>/DATA/
DISK4/redo0201.log',dbms_logmnr.ADDFILE);
PL/SQL procedure successfully completed.
4 Start LogMiner analysis.
SQL> execute
dbms_logmnr.start_logmnr(dictfilename=>'<full_home_path>/
TRACE/logdict');
PL/SQL procedure successfully completed.
5 Find the insertion made the day before (in reality, during the last five minutes).
SQL> select username, timestamp, sql_redo,sql_undo
2 from v$logmnr_contents
3 where seg_name = 'EMP' and seg_owner = ’SCOTT’
4 and username = ’SCOTT’ and timestamp = ’<DD-MON-YY>’;
USERNAME TIMESTAMP
-------------------------------- ---------
SQL_REDO
------------------------------------------------------------
----------------------------------------
SQL_UNDO
.....................................................................................................................................................
B-32 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 9-1 Solutions
.....................................................................................................................................................
------------------------------------------------------------
----------------------------------------
SYS 16-APR-99
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-33
Appendix B: Practice Solutions
.....................................................................................................................................................
.....................................................................................................................................................
B-34 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 11-1 Solutions
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-35
Appendix B: Practice Solutions
.....................................................................................................................................................
5 Enter the RESET DATABASE command at the RMAN prompt. What happens?
RMAN> reset database;
.....................................................................................................................................................
B-36 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 11-1 Solutions
.....................................................................................................................................................
8 Using RMAN, confirm that the data file has been added to the recovery catalog.
RMAN> list copy;
9 Use the RMAN command to remove the backup of the system data file from the
recovery catalog. Do not remove the file from the disk.
RMAN> change datafilecopy
2> ’/u03/user/db01/BACKUP/INC0/system01.cpy’
3> uncatalog;
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-37
Appendix B: Practice Solutions
.....................................................................................................................................................
10 Use the REPORT command to determine which data files have not yet been
backed up by RMAN today.
RMAN> report need backup days 1;
Connected to:
Oracle8i Enterprise Edition Release 8.1.5.0.0 - Production
With the Partitioning and Java options
PL/SQL Release 8.1.5.0.0 - Production
NAME
-----------------------------------------------------------------
DB_NAME FILE#
-------- ----------
/u03/user/db01/BACKUP/INC0/system01.cpy
DB01 1
.....................................................................................................................................................
B-38 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 11-1 Solutions
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-39
Appendix B: Practice Solutions
.....................................................................................................................................................
.....................................................................................................................................................
B-40 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 12-1 Solutions
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop B-41
Appendix B: Practice Solutions
.....................................................................................................................................................
.....................................................................................................................................................
B-42 Enterprise DBA Part 1B: Backup and Recovery Workshop
C
................................
Hints
Appendix C: Hints
.....................................................................................................................................................
.....................................................................................................................................................
C-2 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 2-1 Hints
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop C-3
Appendix C: Hints
.....................................................................................................................................................
.....................................................................................................................................................
C-4 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 3-1 Hints
.....................................................................................................................................................
11 Execute the ALTER SYSTEM SWITCH LOGFILE command twice, then list the
values of the ARCHIVE parameters. Do you see any archived log files? What is
the format of the filename?
Hint: Use the SHOW command in SQL*PLUS session. Then use the “ls”
command at the OS.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop C-5
Appendix C: Hints
.....................................................................................................................................................
.....................................................................................................................................................
C-6 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 5-1 Hints
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop C-7
Appendix C: Hints
.....................................................................................................................................................
.....................................................................................................................................................
C-8 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 5-2 Hints
.....................................................................................................................................................
11 When recovery is complete, open the database to make it available for all users.
Hint: Use the ALTER DATABASE OPEN command.
12 Query the DBA_TABLESPACES view to see if DATA01 is online. Make sure the
tablespace is online.
Hint: Query the TABLESPACE_NAME and STATUS columns of the view
DBA_TABLESPACES.
13 Connect to the database as scott/tiger and execute a query against the
NEWEMP table. What happened and why?
Hint: The table NEWEMP has been recovered. It is possible to recover to a
current time when the database is in ARCHIVELOG mode.
14 Connect as system/manager and query the V$LOG view and note the
sequence number. Compare this value with the value in step 3. What conclusions
can you make about complete recovery?
Hint: Query V$LOG for STATUS = ‘CURRENT’ and note the SEQUENCE#
column.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop C-9
Appendix C: Hints
.....................................................................................................................................................
.....................................................................................................................................................
C-10 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 6-1 Hints
.....................................................................................................................................................
12 Restore all data files from the backup that you made in step 1.
Note: Check the V$DATAFILE view with the $HOME/LABS/cpdbfile.sh
script. If the files and locations are identical, then run this script. Otherwise, you
may modify this file to match your database structure.
13 Recover the database until the time you noted in step 4.
Hint: Use the RECOVER DATABASE UNTIL TIME command.
14 When recovery is complete, open the database using the RESETLOGS option to
enable access for all users.
Hint: Use the ALTER DATABASE OPEN RESETLOGS command.
15 Connect to the database as scott/tiger and execute a query against the
NEWEMP table. What happened and why?
Hint: The table has been recovered.
16 Connect as system/manager and query the V$LOG view and note the
sequence number. Compare this value with the value in step 5. What conclusions
can you make about incomplete recovery?
17 Take a whole offline backup. Store the backup in the $HOME/BACKUP directory.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop C-11
Appendix C: Hints
.....................................................................................................................................................
.....................................................................................................................................................
C-12 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 8-1 Hints
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop C-13
Appendix C: Hints
.....................................................................................................................................................
.....................................................................................................................................................
C-14 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 9-1 Hints
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop C-15
Appendix C: Hints
.....................................................................................................................................................
.....................................................................................................................................................
C-16 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 11-1 Hints
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop C-17
Appendix C: Hints
.....................................................................................................................................................
.....................................................................................................................................................
C-18 Enterprise DBA Part 1B: Backup and Recovery Workshop
Practice 13-1 Hints
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop C-19
Appendix C: Hints
.....................................................................................................................................................
.....................................................................................................................................................
C-20 Enterprise DBA Part 1B: Backup and Recovery Workshop
D
................................
Workshop Scenarios
Appendix D: Workshop Scenarios
.....................................................................................................................................................
Workshop Scenarios
Scenario 1: Loss of INACTIVE Online Redo Log Group
Scenario 2: Loss of CURRENT Online Redo Log Group
Scenario 3: Loss of Control Files
Scenario 4: Loss of Media
Scenario 5: Loss of an Online Rollback Segment Data File (Open or Closed
Database)
Scenario 6: Loss of a System Tablespace Data File
Scenario 7: Loss of a Non-System, Non-Rollback Segment Data File
Scenario 8: Recover from User Errors
Scenario 9: Failure During Hot Backup
Scenario 10: Configuring Recovery Catalog
Scenario 11: Missing Data File
Scenario 12: Loss of a Data File and Missing Archive Log File
Scenario 13: Recover a Lost Data File with No Backup
Scenario 14: Missing Mirrored Online Redo Log Files
Scenario 15: Loss of a Control File and Read-Only Tablespace
Scenario 16: Loss of Non-Essential Data File When Database Is Down
Note: Edit init.ora and comment out REMOTE_LOGIN_PASSWORD_FILE
entry.
Grant DBA to scott.
Ensure that the DATABASE is in ARCHIVELOG mode.
Timings for scenarios may vary, but you can approximate 30 minutes per scenario.
To ensure uniformity, you can copy the files from DONTOUCH directory to DATA
directory (cp -r $HOME/DONTOUCH $HOME/DATA).
Edit the wksh script in $HOME/LABS directory to match the database names. It is
presumed in the script that database names for students will be U1-U15.
Make a control file backup to trace for each database. Edit it and retain it in
DONTOUCH and BACKUP directories.
After each scenario is complete, shut down the database. Copy the data files, control
files and the redo log files from DONTOUCH directory. You may want to remove the
archive logs at the end of each scenario.
.....................................................................................................................................................
D-2 Enterprise DBA Part 1B: Backup and Recovery Workshop
Scenario 1: Loss of INACTIVE Online Redo Log Group
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop D-3
Appendix D: Workshop Scenarios
.....................................................................................................................................................
.....................................................................................................................................................
D-4 Enterprise DBA Part 1B: Backup and Recovery Workshop
Scenario 3: Loss of Control Files
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop D-5
Appendix D: Workshop Scenarios
.....................................................................................................................................................
.....................................................................................................................................................
D-6 Enterprise DBA Part 1B: Backup and Recovery Workshop
Scenario 5: Loss of File Containing Online Rollback Segment
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop D-7
Appendix D: Workshop Scenarios
.....................................................................................................................................................
.....................................................................................................................................................
D-8 Enterprise DBA Part 1B: Backup and Recovery Workshop
Scenario 7: Loss of a Non-System, Non-Rollback Segment Data File
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop D-9
Appendix D: Workshop Scenarios
.....................................................................................................................................................
.....................................................................................................................................................
D-10 Enterprise DBA Part 1B: Backup and Recovery Workshop
Scenario 9: Failure During Hot Backup
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop D-11
Appendix D: Workshop Scenarios
.....................................................................................................................................................
.....................................................................................................................................................
D-12 Enterprise DBA Part 1B: Backup and Recovery Workshop
Scenario 10: Configuring a Recovery Catalog
.....................................................................................................................................................
RMAN>
8 Check that the database has been registered.
RMAN> LIST INCARNATION OF DATABASE;
RMAN-03022: compiling command: list
List of Database Incarnations
DB Key Inc Key DB Name DB ID CUR Reset SCN Reset Time
----- ------ ------- ----- --------- --- ----------
1 2 DB01 1118660359 YES 1 19-JUL-99
RMAN> exit
$ sqlplus rman_db1/rman
SQL> SELECT * FROM RC_DATABASE;
DB_KEY DBINC_KEY DBID NAME RESETLOGS_CHANGE# RESETLOGS
----- -------- ---------- ---- --------------- ---------
1 2 1118660359 DB01 1 19-JUL-99
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop D-13
Appendix D: Workshop Scenarios
.....................................................................................................................................................
.....................................................................................................................................................
D-14 Enterprise DBA Part 1B: Backup and Recovery Workshop
Scenario 12: Loss of a Data File and Missing Archive Log File
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop D-15
Appendix D: Workshop Scenarios
.....................................................................................................................................................
.....................................................................................................................................................
D-16 Enterprise DBA Part 1B: Backup and Recovery Workshop
Scenario 14: Recover a Lost Data File from Archive Logs
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop D-17
Appendix D: Workshop Scenarios
.....................................................................................................................................................
.....................................................................................................................................................
D-18 Enterprise DBA Part 1B: Backup and Recovery Workshop
Scenario 16: Loss of a Control File and Read-Only Tablespace
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop D-19
Appendix D: Workshop Scenarios
.....................................................................................................................................................
.....................................................................................................................................................
D-20 Enterprise DBA Part 1B: Backup and Recovery Workshop
E
................................
Worldwide Support
Bulletins
Appendix E: Worldwide Support Bulletins
.....................................................................................................................................................
Summary Cannot start up the database because a data file was removed from the
file directory
Problem Explanation The Oracle Server verifies the existence and consistency
of each data file registered in the control file after the database is successfully
mounted. If the file is bad or is being unintentionally removed, the following error
may occur:
ORA-01157: cannot identify data file %n - file not found
ORA-01110: data file %n: ’%s’
The following errors may also occur when trying to do a normal shutdown or when
DBWR attempts to write to the file that is being removed:
ORA-01116: error in opening database file %n
ORA-01110: data file %n: ’%s’
ORA-07368: sfofi: open error, unable to open database file.
These errors are followed by an operating system specific error (for instance, error
number 2 in most UNIX platforms).
.....................................................................................................................................................
E-2 Enterprise DBA Part 1B: Backup and Recovery Workshop
Oracle Corporate Support Problem Repository
.....................................................................................................................................................
Solution Description Warning: This solution can only be applied if the removed
data file does NOT belong to the system tablespace or to a rollback tablespace. If
the file belongs to the system tablespace or to a rollback tablespace, please contact
Oracle customer support.
There are cases in which the DBA inadvertently removes a data file from the file
directory, maybe with the incorrect assumption that by removing the file, any
reference to it from the Oracle Server is also removed. It may also be due to the fact
that an operating system error or hardware problem rendered the file unreadable or
inaccessible.
If the file is inaccessible by the Oracle Server, the DBWR may force the data file to
go offline, in which case you would get the following error when trying to access
the data file by any means:
ORA-01135, 00000, ”file %s accessed for DML/query is offline”
// *Cause: Attempted to access a data file that is offline
// *Action: Bring the data file back online
In either case, the easiest way is to drop the entire tablespace that contains the data
file. The steps to be executed from within SQL*DBA are:
1 STARTUP MOUNT
2 For each deleted data file, issue the command
ALTER DATABASE DATAFILE ’full path of filename’ OFFLINE [DROP];
Note: You must use the DROP option if the database is in NOARCHIVELOG
mode, because you cannot recover this file if you apply incomplete media
recovery on it via the command ALTER DATABASE OPEN RESETLOGS.
See the SQL Reference Manual for details.
3 ALTER DATABASE OPEN;
4 DROP TABLESPACE <tablespace> INCLUDING CONTENTS [CASCADE
CONSTRAINTS];
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop E-3
Appendix E: Worldwide Support Bulletins
.....................................................................................................................................................
Problem Description When there is a corrupt data block in the database, one of
the most common errors you might receive when you try to access that corrupted
block is ORA-1578.
Other errors you might also receive to indicate a corruption are:
ora-600 [3339]
ora-600 [3398]
Problem Explanation
ORA-01578, 00000, ”ORACLE data block corrupted (file # %s, block #
%s)”
// *Cause: The data block indicated was corrupted, mostly due to
software // errors.
// *Action: Try to restore the segment containing the block
indicated. This
// may involve dropping the segment and recreating it. If there
// is a trace file, report the errors in it to your ORACLE
// representative.
The bulletin 108491.543 by EPITT discusses how to resolve the ora-1578, although
the concepts may also be applied to the other corruption errors as well.
+==+
.....................................................................................................................................................
E-4 Enterprise DBA Part 1B: Backup and Recovery Workshop
Oracle Corporate Support Problem Repository
.....................................................................................................................................................
Summary
ORA-1115 I/O ERROR READING BLOCK
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop E-5
Appendix E: Worldwide Support Bulletins
.....................................................................................................................................................
Problem Explanation
What causes ORA-1115?
The Oracle server delivers read-from-file requests to the underlying operating
system (except if raw devices are being used). A read request specifies a data file
and a block number to be accessed. If a low-level I/O error prevents the read from
completing successfully, the Oracle server signals an ORA-1115.
The main causes for an ORA-1115 are:
1 Hardware problems
- Disk controller problems (the most common, and usually intermittent)
- Disk problems (including bad blocks and disk malfunctioning)
2 Data block corruption (at the physical level)
Usually caused by previous hardware problems.
3 Problems handling very large data files
In Oracle 7.1.4 and lower on Sun Solaris, bug 233569 causes ORA-1115 and
ORA-7371 when handling data files bigger than 2GB.
Typical scenarios where ORA-1115 can happen include:
• On execution of DML statements
• During exports or imports
• At startup or shutdown
.....................................................................................................................................................
E-6 Enterprise DBA Part 1B: Backup and Recovery Workshop
Oracle Corporate Support Problem Repository
.....................................................................................................................................................
Steps for Solving the Problem When the Cause Is Not Known
1 Try to assess the cause and extent of the problem.
Examine the alert.log file for this instance. Scan the last few days’ entries
for other occurrences of ORA-1115. If you find them, determine the following:
a Do they reference files in different disks?
If so, it is likely that there you have controller problems. Go to Scenario
II.A below.
b Do they reference different files in the same disk?
If so, it is likely that there are problems with that disk. Go to Scenario II. B
below.
c Do they always reference the same data file?
If so, it is likely that the data file contains bad blocks. Go to Scenario II.C
below.
If the file is bigger than 2GB and you are running 7.1.4 or lower on Solaris
platform, see Scenario II.D below.
d If none of the above apply, go to step 2.
2 If the data file is in the SYSTEM tablespace, or the database is in
NOARCHIVELOG mode, shut the database down. Go to step 4.
If shutdown immediate fails, do a shutdown abort.
3 If the database is in ARCHIVELOG mode, you should still shut the database
down. If the database cannot be shut down, take the data file offline.
ALTER DATABASE DATAFILE ’<full_path_file_name>’ OFFLINE;
4 Try to copy the data file to another disk (managed by a different controller, if
possible).
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop E-7
Appendix E: Worldwide Support Bulletins
.....................................................................................................................................................
5 If the copy fails, even after you retry, the data file must be considered lost at this
point. The next action depends on the tablespace to which the lost file belongs. See
the following Solution References to PR entries, according to the different types of
tablespaces, for instructions on how to proceed.
Important: While going through the PR entries below, keep in mind that if you
restore the data file from backup, you need to place it in another disk, preferably
under a different controller, and rename it inside the Oracle server (see the solution
Reference to PR entry 1013480.6 for details). If you recreate any tablespace, make
sure its data files are created in another disk, preferably under a different controller.
TABLESPACE PR ENTRY
------------------- --------------
system 1013182.6
rollback 1013221.6
user 1013173.6
index 1013115.6
temporary 1013104.6
read-only 1013129.6
6 If the database is down, mount it.
7 Rename the data file that you succeeded in copying inside Oracle.
ALTER DATABASE RENAME FILE ’<old_full_path_file_name>’
TO ’<new_full_path_file_name>’;
8 If the database is mounted, open it. If you took the data file offline, perform media
recovery on it, and then bring it online.
RECOVER DATAFILE ’<full_path_file_name>’;
ALTER DATABASE DATAFILE ’<full_path_file_name>’ ONLINE;
.....................................................................................................................................................
E-8 Enterprise DBA Part 1B: Backup and Recovery Workshop
Oracle Corporate Support Problem Repository
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop E-9
Appendix E: Worldwide Support Bulletins
.....................................................................................................................................................
Important: While going through the PR entries below, keep in mind that if you
restore data files from backup, you must place them in disks under other controllers
and rename them inside the Oracle Server (see the solution Reference to PR entry
1013480.6 for details). If you recreate any tablespace, make sure its data files are
created under other controllers.
TABLESPACE PR ENTRY
------------- --------------
system 1013182.6
rollback 1013221.6
user 1013173.6
index 1013115.6
temporary 1013104.6
read-only 1013129.6
8 If the database is mounted, open it. If any of the moved data files is offline, apply
media recovery to it, and then put it online:
RECOVER DATAFILE ’<full_path_file_name>’;
ALTER DATABASE DATAFILE ’<full_path_file_name>’ ONLINE;
Disk Problems If a disk has bad blocks or is malfunctioning, you should focus on
moving its data files to a different disk, if possible. If not, you must consider the
files lost and address the issue according to the tablespaces to which they belong,
while you fix the disk. The steps to follow in this scenario are like those in Scenario
II.A above.
Data Block Corruption If you are certain that the data file has bad blocks, the
data file should be considered LOST if it belongs to the SYSTEM tablespace or to a
ROLLBACK or READ-ONLY tablespace. See the following Solution References
to PR entries, depending on the tablespace to which the data file belongs.
Important: While going through the PR entries below, keep in mind that if you
restore data files from backup, you must place them in different disks (preferably
under other controllers) and rename them inside the Oracle server (see the solution
Reference to PR entry 1013480.6 for details). If you re-create any tablespace, make
sure its data files are created on different disks (preferably under other controllers).
TABLESPACE PR ENTRY
------------------- -------------
system 1013182.6
rollback 1013221.6
user 1013173.6
index 1013115.6
temporary 1013104.6
read-only 1013129.6
.....................................................................................................................................................
E-10 Enterprise DBA Part 1B: Backup and Recovery Workshop
Oracle Corporate Support Problem Repository
.....................................................................................................................................................
If the data file belongs to a user or index tablespace, you may also address the
problem as an object re-creation issue if the ORA-1115 occurs consistently against
the same objects (tables, indexes, and so on.). The following query returns the
object in which the bad block is:
SELECT SEGMENT_NAME, SEGMENT_TYPE FROM DBA_EXTENTS
WHERE FILE_ID = <file_number> and <block_number> BETWEEN BLOCK_ID
AND BLOCK_ID + BLOCKS - 1;
Very Large Data File Problems on Solaris If you are running Oracle 7.1.4 or
lower on a Solaris platform, and you get an ORA-7371 with the ORA-1115 and the
file is bigger than 2GB, you are likely experiencing bug 233569. This bug is fixed in
7.1.6, and patches are available for 7.1.3 (bug 233569) and 7.1.4 (bug 281904).
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop E-11
Appendix E: Worldwide Support Bulletins
.....................................................................................................................................................
Problem Description
Document ID: 107693.969
Title: ROLLBACK SEGMENT NEEDS RECOVERY
Department: RDBMS SUPPORT
Creation Date: 13-February-1995
Last Revision Date: 7-June-1995
Expiration Date:
Revision Number: 1
Distribution Code: EXTERNAL
Category:
Product: GENERIC
Product Version: GENERIC
Platform: GENERIC
Information Type: ADVISORY
Impact: MEDIUM
Abstract: This article discusses what it means when a rollback segment
needs recovery and how to resolve it.
Keywords: ROLLBACK;SEGMENT;NEEDS;RECOVERY;
STATUS;CORRUPT
.....................................................................................................................................................
E-12 Enterprise DBA Part 1B: Backup and Recovery Workshop
Oracle Corporate Support Problem Repository
.....................................................................................................................................................
Overview
This bulletin discusses why a rollback segment has the status of “needs recovery,”
what the status means, and how to resolve it.
Introduction
Rollback segments can be monitored through the data dictionary view,
DBA_ROLLBACK_SEGS. There is a status column that describes what state the
rollback segment is currently in. Normal states are either online or offline.
Occasionally, the status of needs recovery appears.
When a rollback segment is in this state, bringing the rollback segment offline or
online either through the alter rollback segment command, or by removing it from
the ROLLBACK_SEGMENTS parameter in the init.ora, usually has no effect.
Understanding
A rollback segment falls into this status of needs recovery whenever the Oracle
server tries to roll back an uncommitted transaction in its transaction table and fails.
Here are some examples of why a transaction may need to rollback:
1 A user may do a DML transaction and decide to issue rollback.
2 A shutdown abort occurs, and the database must do an instance recovery, in which
case, the Oracle server has to roll back all uncommitted transactions.
When a rollback of a transaction occurs, undo must be applied to the data block
in which the modified rows are found. If that data block is unavailable, the undo
cannot be applied. The result is a corrupted rollback segment with the status of
needs recovery.
What could be some reasons a data block is inaccessible for undo?
1 If a tablespace or a data file is offline or missing
2 If the object the data block belongs to is corrupted
3 If the data block that is corrupt is in the rollback segment itself rather than the
object
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop E-13
Appendix E: Worldwide Support Bulletins
.....................................................................................................................................................
Problem Explanation
Diagnostics and References
* {6123.6,Y,100} ROLLBACK SEGMENT NEEDS RECOVERY
* {6124.6,Y,100} ORA-1545 ON STARTUP
.....................................................................................................................................................
E-14 Enterprise DBA Part 1B: Backup and Recovery Workshop
Oracle Corporate Support Problem Repository
.....................................................................................................................................................
Solution Description This recovery situation requires extra caution. Please call
Oracle Customer Support if you have questions or need assistance.
The main issue in solving this problem is trying to make sure that the active
transactions in the rollback segments do not get lost.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop E-15
Appendix E: Worldwide Support Bulletins
.....................................................................................................................................................
The Database Was Cleanly Shut Down If you are absolutely positive that the
database was cleanly shut down, that is, closed with either shutdown NORMAL or
IMMEDIATE, then the simplest solution is to drop the missing data file offline,
open the database in restricted mode, and then drop and recreate the rollback
tablespace to which the file belonged. Do not follow this procedure if the database
was shut down in ABORT mode or if it crashed.
The steps are:
1 Make sure the database was last cleanly shut down.
Check the alert.log file for this instance. Go to the bottom of the file and
make sure the last time you shut the database down you received the messages:
”alter database dismount
Completed: alter database dismount”
This also includes the case of a clean shutdown followed by a failed attempt to
start up the database. In that case, the Oracle server will issue error messages
and shut itself down abort. For the purposes of this solution, though, this counts
as a clean shutdown.
If that is not the case, that is, if the last time you shut the database down, it was
in ABORT mode, or the database crashed itself, it is not safe to proceed. You
should follow the instructions for case I.B below.
2 Remove all the rollback segments in the tablespace to which the lost data file
belongs from the ROLLBACK_SEGMENTS parameter in the init.ora file for
this instance. If you are not sure about which rollbacks are in that tablespace,
simply comment out the whole ROLLBACK_SEGMENTS entry.
3 Mount the database in restricted mode.
STARTUP RESTRICT MOUNT
4 Drop the lost data file offline.
ALTER DATABASE DATAFILE ’<full_path_file_name>’ OFFLINE DROP;
5 Open the database.
ALTER DATABASE OPEN
If you receive the message “Statement processed,” go to step 7.
If instead you get ORA-604, ORA-376, and ORA-1110, go to step 6.
.....................................................................................................................................................
E-16 Enterprise DBA Part 1B: Backup and Recovery Workshop
Oracle Corporate Support Problem Repository
.....................................................................................................................................................
6 Because opening the database failed, shut the database down and edit the
init.ora file for this instance.
Comment out the ROLLBACK_SEGMENTS parameter and add the following
line:
_corrupted_rollback_segments = ( <rollback1>,...., <rollbackN> )
For example, the above list should contain all the rollbacks originally listed in the
ROLLBACK_SEGMENTS parameter.
Use this parameter only in this specific scenario or as instructed by Oracle
Customer Support, then start up the database in restricted mode:
STARTUP RESTRICT
7 Drop the rollback tablespace to which the data file belonged.
DROP TABLESPACE <tablespace_name> INCLUDING CONTENTS;
8 Recreate the rollback tablespace with all its rollback segments. Remember to bring
the rollbacks online after you create them.
9 Make the database available to all users.
ALTER SYSTEM DISABLE RESTRICTED SESSION;
10 Reinclude the rollbacks you just recreated in the ROLLBACK_SEGMENTS
parameter in the init.ora file for this instance. If you had commented out the
whole ROLLBACK_SEGMENTS entry, simply uncomment it now. If you had to
go through step 6, remove the corrupted ROLLBACK_SEGMENTS parameter
now.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop E-17
Appendix E: Worldwide Support Bulletins
.....................................................................................................................................................
The Database Was Not Cleanly Shut Down This is the situation where the
database was last shut down in ABORT or CRASHED mode. In this case, it is
almost certain that the rollback segments that had extents in the lost data file still
contain active transactions. Therefore, the file cannot be taken offline or dropped.
You must restore the lost data file from a backup and apply media recovery to it. If
the database is in NOARCHIVELOG mode, you will only succeed in recovering the
data file if the redo to be applied is within the range of your online logs. If a backup
of the data file is not available, please contact Oracle Customer Support.
These are the steps:
1 Restore the lost file from a backup.
2 Mount the database.
3 Issue the following query:
SELECT FILE#, NAME, STATUS FROM V$DATAFILE;
If the status of the file you just restored is OFFLINE, you must take it online
before proceeding:
ALTER DATABASE DATAFILE ’<full_path_file_name>’ ONLINE;
4 Issue the following query:
SELECT V1.GROUP#, MEMBER, SEQUENCE#, FIRST_CHANGE#
FROM V$LOG V1, V$LOGFILE V2
WHERE V1.GROUP# = V2.GROUP# ;
This will list all your online redo log files and their respective sequence and first
change numbers.
5 If the database is in NOARCHIVELOG mode, issue the query:
SELECT FILE#, CHANGE# FROM V$RECOVER_FILE;
If the CHANGE# is greater than the minimum FIRST_CHANGE# of your logs, the
data file can be recovered. Remember that all the logs to be applied will be
online logs, and go to step 6.
If the CHANGE# is lesser than the minimum FIRST_CHANGE# of your logs,
the file cannot be recovered. Your options at this point include restoring a full
backup if one is available or forcing the database to open in an inconsistent state
to get a full export out of it. For further details and to assist you in your decision,
please contact Oracle Customer Support.
6 Recover the data file:
RECOVER DATAFILE ’<full_path_file_name>’
.....................................................................................................................................................
E-18 Enterprise DBA Part 1B: Backup and Recovery Workshop
Oracle Corporate Support Problem Repository
.....................................................................................................................................................
7 Confirm each of the logs that you are prompted for until you receive the message
“Media recovery complete.” If you are prompted for a non-existing archived log,
the Oracle server probably needs one or more of the online logs to proceed with
the recovery. Compare the sequence number referenced in the ORA-280 message
with the sequence numbers of your online logs. Then enter the full path name of
one of the members of the redo group whose sequence number matches the one
you are being asked for. Continue to enter online logs as requested until you
receive the message, “Media recovery complete.”
8 Open the database.
The Database Is Up
If you have detected the loss of the rollback data file and the database is still up and
running, do not shut it down. In most cases, it is simpler to solve this problem with
the database up than with it down.
Two approaches are possible in this scenario:
1 The first one involves taking the lost data file offline, restoring it from backup, and
then applying media recovery to it to make it consistent with the rest of the
database. This method can only be used if the database is in ARCHIVELOG
mode.
2 The other approach involves taking offline all the rollback segments in the
tablespace to which the lost data file belongs, dropping the tablespace, and then
recreating it. You may need to kill sessions that have transactions in the rollbacks
involved to force the rollbacks to go offline.
In general, the first approach is simpler to apply. It will also be faster if the data file
and the necessary archived logs can be quickly restored from backup. However,
more user transactions will error out and be rolled back than with the second
approach. Because of read-consistency, queries against certain tables may fail with
the first approach, because the rollback extents from which the Oracle server would
retrieve the data may be in the offlined data file.
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop E-19
Appendix E: Worldwide Support Bulletins
.....................................................................................................................................................
Approach A: Restoring the Data File from Backup As mentioned before, this
approach can only be followed if the database is in ARCHIVELOG mode. Here are
the steps:
1 Take the lost data file offline.
ALTER DATABASE DATAFILE ’<full_path_file_name>’ OFFLINE;
Note: Depending on the current amount of database activity, you may need to
create additional rollback segments in a different tablespace to keep the
database going while you take care of the problem.
2 Restore the data file from a backup.
3 Issue the following query:
SELECT V1.GROUP#, MEMBER, SEQUENCE#
FROM V$LOG V1, V$LOGFILE V2
WHERE V1.GROUP# = V2.GROUP# ;
This will list all your online redo log files and their respective sequence
numbers.
4 Recover the data file:
RECOVER DATAFILE ’<full_path_file_name>’
5 Confirm each of the logs that you are prompted for until you receive the message,
“Media recovery complete.” If you are prompted for a non-existing archived log,
the Oracle server probably needs one or more of the online logs to proceed with
the recovery. Compare the sequence number referenced in the ORA-280 message
with the sequence numbers of your online logs. Then enter the full path name of
one of the members of the redo group whose sequence number matches the one
you are being asked for. Continue to enter online logs as requested until you
receive the message “Media recovery complete.”
6 Bring the data file back online.
ALTER DATABASE DATAFILE ’<full_path_file_name>’ ONLINE;
.....................................................................................................................................................
E-20 Enterprise DBA Part 1B: Backup and Recovery Workshop
Oracle Corporate Support Problem Repository
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop E-21
Appendix E: Worldwide Support Bulletins
.....................................................................................................................................................
.....................................................................................................................................................
E-22 Enterprise DBA Part 1B: Backup and Recovery Workshop
Oracle Corporate Support Problem Repository
.....................................................................................................................................................
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop E-23
Appendix E: Worldwide Support Bulletins
.....................................................................................................................................................
Problem Explanation Oracle’s architecture is tightly coupled in the sense that all
database files, data files, redolog files, and control files must be in sync when the
database is opened or at the end of a checkpoint. This implies that the checkpoint
System Commit Number (SCN) of all data files must be the same. If that is not the
case for a particular data file, an ORA-1113 will be generated. For example, when
you put a tablespace in hot backup mode, the checkpoint SCN of all its data files is
frozen at the current value until you issue the corresponding end backup. If the
database crashes during a hot backup and you try to restart it without doing
recovery, you will likely get ORA-1113 for at least one of the data files in the
tablespace that was being backed up, because its SCN will probably be lower than
that of the control file and the data files in other tablespaces. Likewise, offlining a
data file causes its checkpoint SCN to freeze. If you simply attempt to take the file
online without recovering it first, its SCN will likely be much older than that of the
online data files, and thus an ORA-1113 will result.
.....................................................................................................................................................
E-24 Enterprise DBA Part 1B: Backup and Recovery Workshop
Oracle Corporate Support Problem Repository
.....................................................................................................................................................
The steps to take next depend on the scenario in which the ORA-1113 was issued:
1 At startup after crash with tablespaces in hot backup
a With Oracle 7.1 or lower
i. Mount the database.
ii. Apply media recovery to the database.
RECOVER DATABASE
iii. Confirm each of the archived logs that you are prompted for until you
receive the message, “Media recovery complete.” If you are prompted for
an archived log that does not exist, the Oracle server probably needs one
or more of the online logs to proceed with the recovery. Compare the
sequence number referenced in the ORA-280 message with the sequence
numbers of your online logs. Then enter the full path name of one of the
members of the redo group whose sequence number matches the one you
are being asked for. Keep entering online logs as requested until you
receive the message “Media recovery complete.”
iv. Open the database.
b With Oracle 7.2 or higher
i. Mount the database.
ii. Find out which data files were in hot backup mode when the database
crashed or was shut down in ABORT mode, or the machine was rebooted
by running the query:
SELECT V1.FILE#, NAME
FROM V$BACKUP V1, V$DATAFILE V2
WHERE V1.STATUS = ’ACTIVE’ AND V1.FILE# = V2.FILE# ;
iii. For each of the files returned by the above query, issue the command:
ALTER DATABASE DATAFILE ’<full path name>’ END BACKUP;
iv. Open the database.
2 At startup after restoring a data file or tablespace from a backup
a With the database in ARCHIVELOG mode
i. Mount the database.
ii. Recover the data file:
RECOVER DATAFILE ’<full path name>’
If recovering more than one data file, issue the following:
RECOVER DATABASE
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop E-25
Appendix E: Worldwide Support Bulletins
.....................................................................................................................................................
iii. Confirm each of the archived logs that you are prompted for until you
receive the message, “Media recovery complete.” If you are prompted for
an archived log that does not exist, the Oracle server probably needs one
or more of the online logs to proceed with the recovery. Compare the
sequence number referenced in the ORA-280 message with the sequence
numbers of your online logs. Then enter the full path name of one of the
members of the redo group whose sequence number matches the one you
are being asked for. Keep entering online logs as requested until you
receive the message, “Media recovery complete.”
iv. Open the database.
b With the database in NOARCHIVELOG mode
In this case, you will only succeed in recovering the data file or tablespace if
the redo to be applied to it is within the range of your online logs. Issue the
query:
SELECT FILE#, CHANGE# FROM V$RECOVER_FILE;
Compare the change number you obtain with the FIRST_CHANGE# of your
online logs.
If the CHANGE# is greater than the minimum FIRST_CHANGE# of your logs,
the data file can be recovered. In this case, the procedure to be followed is like
that of scenario II.A above, except that you must always enter the appropriate
online log when prompted, until recovery is finished.
If the CHANGE# is lesser than the minimum FIRST_CHANGE# of your logs,
the file cannot be recovered. Your options at this point include:
- If the data file is in a temporary or index tablespace, you may drop it with an
ALTER DATABASE DATAFILE ’<full path name>’ OFFLINE DROP
statement and then open the database. Once the database is up, you must
drop the tablespace to which the data file belongs and re-create it.
- If the data file is in the SYSTEM or in a rollback tablespace, restore an
up-to-date copy of the data file (if available) or your most recent full backup.
If a full, consistent backup is not available, please contact Oracle Customer
Support.
- For all other cases in this scenario, you must weigh the cost of going to a
backup versus the cost of recreating the tablespace involved, as described in
the two previous cases. For more details or to assist you in your decision,
please contact Oracle Customer Support.
3 Trying to online a data file or tablespace
a Recover the data file:
RECOVER DATAFILE ’<full path name>’
If recovering a tablespace, do the following:
RECOVER TABLESPACE <tablespace>
.....................................................................................................................................................
E-26 Enterprise DBA Part 1B: Backup and Recovery Workshop
Oracle Corporate Support Problem Repository
.....................................................................................................................................................
b Confirm each of the archived logs that you are prompted for until you receive
the message, “Media recovery complete.” If you are prompted for an archived
log that does not exist, the Oracle server probably needs one or more of the
online logs to proceed with the recovery. Compare the sequence number
referenced in the ORA-280 message with the sequence numbers of your online
logs. Enter the full path name of one of the members of the redo group whose
sequence number matches the one you are being asked for. Continue to enter
online logs as requested until you receive the message, “Media recovery
complete.”
.....................................................................................................................................................
Enterprise DBA Part 1B: Backup and Recovery Workshop E-27
Appendix E: Worldwide Support Bulletins
.....................................................................................................................................................
.....................................................................................................................................................
E-28 Enterprise DBA Part 1B: Backup and Recovery Workshop