About Querying The RMAN Metadata
About Querying The RMAN Metadata
Catalog
Method Needed? Description
LIST No Use this command to list backups, copies, and database
command incarnations. The output displays those files operated on by
the CHANGE, CROSSCHECK, and DELETE commands.
REPORT No Use this command to find out which files need a backup,
command which backups are no longer needed, which files are in the
schema, and so forth.
SHOW No Use this command to display persistent RMAN configuration
command settings.
PRINT Yes Use this command to display the names of the scripts stored in
SCRIPT
the recovery catalog.
command
Recovery Yes Query these views to access the catalog itself. Some
catalog fixed information, such as the names and contents of the stored
views scripts, can only be obtained from the catalog views.
V$ fixed No Query these views to access the target database control file.
views RMAN obtains metadata for the recovery catalog from the
control file. Some V$ views such as V$DATAFILE_HEADER,
Catalog
Method Needed? Description
V$PROCESS, and V$SESSION contain information not found in
the catalog views.
The main source of information about RMAN is the REPORT and LIST command output.
Use these commands to query the RMAN repository and determine what you have
backed up as well as what you need to back up. This information is extremely helpful in
developing an effective backup strategy.
The LIST command displays all RMAN backups (both backup sets and proxy copies) and
copies, while the REPORT command performs more complex analysis. For example, you
can generate a report on which datafiles need a backup and which backup pieces are
obsolete with the REPORT command. RMAN writes the output from the REPORT and LIST
commands to either standard output or a log file.
The SHOW command displays persistent configuration settings. For example, if you
allocate automatic channels with the CONFIGURE command, these settings are displayed in
the SHOW output.
You can control how the output is displayed by using the BY BACKUP and BY FILE options
and choosing between the SUMMARY and VERBOSE options.
The primary purpose of the LIST command is to determine which backups or copies are
available. Note that only backups and copies that completed successfully are stored in the
repository. For example, you can list:
• Backups (backup sets and proxy copies) or image copies recorded in the RMAN
repository
• Backups or image copies of a specified database, tablespace, datafile, archived
redo log, or control file
• Backups and image copies that have expired
• Backups and image copies restricted by options such as time, path name, device
type, tag, or recoverability
• Incarnations of a specified database
Use the RMAN repository to determine what you need to back up. In particular, ensure
that:
• The STATUS columns of the output tables list all backups and image copies as
AVAILABLE
• All datafiles, archived redo logs, and control files that you need backed up are
included in the output
• The backups and copies recorded in the repository are recent
By default, RMAN lists backups by backup, which means that it serially lists each
backup set or proxy copy and then identifies the files included in the backup. By default,
RMAN lists backups and copies in verbose mode, which means that it provides extensive,
multiline information.
1. After connecting to the target database and recovery catalog (if you use one),
execute LIST BACKUP. Specify the desired objects with the listObjList clause.
For example, you can enter:
2. LIST BACKUP; # lists backup sets, backup pieces, and proxy copies
3.
Optionally, specify the EXPIRED keyword to identify those backups that were not
found during a crosscheck:
You can list copies of datafiles, control files, and archived logs. Specify the desired
objects with the listObjList or recordSpec clause. If you do not specify an object,
then RMAN displays copies of all database files and archived redo logs. By default,
RMAN lists backups in verbose mode, which means that it provides extensive, multiline
information.
1. After connecting to the target database and recovery catalog (if you use one),
execute LIST BACKUP with the BY FILE option. Specify the desired objects and
options. For example, you can enter:
2. LIST BACKUP BY FILE;
3.
Optionally, specify the EXPIRED keyword to identify those backups that were not
found during a crosscheck:
Listing Copies
Besides listing backup sets and proxy copies, you can list image copies. Specify the
desired objects with the listObjList, recordSpec, or archivelogRecordSpecifier
clauses. If you do not specify an object, then LIST COPY displays all datafile copies,
control file copies, and archived redo logs. Note that RMAN considers both archived
redo logs and image copies of archived redo logs as copies. By default, RMAN lists
backups in verbose mode which means that it provides extensive, multiline information.
1. After connecting to the target database and recovery catalog (if you use one),
execute LIST COPY. Specify the desired objects and options. For example, you can
enter:
2. LIST COPY; # lists all datafile copies, control file copies, and
archived logs
3. LIST ARCHIVELOG ALL; # lists all archived logs
4.
Optionally, specify the EXPIRED keyword to identify those copies that were not
found during a crosscheck:
By default the LIST output is highly detailed, but you can also specify that RMAN
display the output in summarized form. Specify the desired objects with the
listObjectList or recordSpec clause. If you do not specify an object, then LIST
BACKUP displays all backups. By default, RMAN lists backups in verbose mode.
1. After connecting to the target database and recovery catalog (if you use one),
execute LIST BACKUP. Specify the desired objects and options. For example, you
can enter:
2. LIST BACKUP SUMMARY;
3.
Optionally, specify the EXPIRED keyword to identify those copies that were not
found during a crosscheck:
1. After connecting to the target database and recovery catalog (if you use one),
execute LIST COPY or LIST BACKUP with the listObjList or recordSpec
condition. For example, enter:
2. # lists backups of all files in database
3. LIST BACKUP OF DATABASE;
4.
5. # lists copy of specified datafile
6. LIST COPY OF DATAFILE '?/oradata/trgt/system01.dbf';
7.
8. # lists specified backup set
9. LIST BACKUPSET 213;
10.
11.# lists datafile copy
12.LIST DATAFILECOPY '/tmp/tools01.dbf';
13.
2. You can also restrict the search by specifying the maintQualifier or
RECOVERABLE clause. For example, enter:
3. # specify a backup by tag
4. LIST BACKUP TAG 'weekly_full_db_backup';
5.
6. # specify a backup or copy by device type
7. LIST COPY OF DATAFILE '?/oradata/trgt/system01.dbf' DEVICE TYPE
sbt;
8.
9. # specify a backup or copy by directory or path
10.LIST BACKUP LIKE '/tmp/%';
11.
12.# specify a backup or copy by a range of completion dates
13.LIST COPY OF DATAFILE 2 COMPLETED BETWEEN '10-DEC-2001' AND '17-
DEC-2001';
14.
15.# specify logs backed up at least 2X to tape
16.LIST ARCHIVELOG ALL BACKED UP 2 TIMES TO DEVICE TYPE sbt;
17.
3. Examine the output. For example, sample output follows for a list of copies of
datafile 1:
4. LIST COPY OF DATAFILE 1;
5.
6. List of Datafile Copies
7. Key File S Completion time Ckp SCN Ckp time Name
8. ------- ---- - --------------- ---------- --------------- ------
9. 3 1 A 18-JUL-00 114148 17-JUL-01
/tmp/system01.dbf
1. After connecting to the target database and (optionally) the recovery catalog, run
LIST INCARNATION:
2. LIST INCARNATION;
3.
If you are using a recovery catalog, and if you register multiple target databases in
the same catalog, then you can distinguish them by using the OF DATABASE option:
The preceding output indicates that a RESETLOGS was performed on database trgt
at SCN 164378, resulting in a new incarnation. The incarnation is distinguished
by its incarnation key.
To gain more detailed information from the RMAN repository, generate a report. Use the
REPORT command to answer questions such as the following:
The information that you obtain from reports can be extremely important for your backup
and recovery strategy. In particular, run the REPORT NEED BACKUP and REPORT
UNRECOVERABLE commands regularly to ensure the following:
You can report on objects that require a backup by specifying the NEED BACKUP keyword.
The REDUNDANCY parameter specifies the minimum number of backups or copies that
must exist for a datafile to be considered not in need of a backup. If you do not specify
the parameter, REDUNDANCY defaults to 1. The DAYS parameter indicates that recovery
must begin by using logs more than integer days old. The INCREMENTAL parameter
indicates that more than integer incremental backups are required for complete
recovery.
1. After connecting to the target database and recovery catalog (if you use one), run
CROSSCHECK commands as needed to update the status of backups and copies.
Following is a possible crosscheck session:
2. # allocate maintenance channel for crosscheck if automatic
channels not configured
3. ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE sbt;
4. CROSSCHECK BACKUP; # crosschecks all backups
5. CROSSCHECK COPY; # crosschecks all copies
6.
2. If you have a retention policy configured, then you can just run REPORT NEED
BACKUP without any other options to determine which files need backups (sample
output follows):
3. REPORT NEED BACKUP;
4.
5. RMAN retention policy will be applied to the command
6. RMAN retention policy is set to redundancy 1
7. Report of files with less than 1 redundant backups
8. File #bkps Name
9. ---- ----- -----------------------------------------------------
10.2 0 /oracle/oradata/trgt/undotbs01.dbf
11.3 0 /oracle/oradata/trgt/cwmlite01.dbf
12.4 0 /oracle/oradata/trgt/drsys01.dbf
13.7 0 /oracle/oradata/trgt/tools01.dbf
14.
3. To override the retention policy (or if you do not have a retention policy enabled),
run REPORT NEED BACKUP DAYS. Any files older than the DAYS parameter value
need a new backup because their backups require the specified number of DAYS
worth of archived logs for recovery. For example, run:
4. REPORT NEED BACKUP DAYS = 7 DATABASE; # needs min 7 days of logs
to recover
5. REPORT NEED BACKUP DAYS = 30 TABLESPACE SYSTEM;
6. REPORT NEED BACKUP DAYS = 14 DATAFILE
'?/oradata/trgt/tools01.dbf';
7.
4. To determine which files need an incremental backup, specify the INCREMENTAL
parameter. If complete recovery of a datafile requires more than the specified
number of incremental backups, then RMAN considers it in need of a new
backup. For example, enter:
5. REPORT NEED BACKUP INCREMENTAL = 1 DATABASE;
6. REPORT NEED BACKUP INCREMENTAL = 3 TABLESPACE SYSTEM;
7. REPORT NEED BACKUP INCREMENTAL = 5 DATAFILE
'?/oradata/trgt/users01.dbf';
You can report on objects that are obsolete, that is, superfluous, by specifying the
OBSOLETE keyword. If you do not specify any other options, then REPORT OBSOLETE
displays the backups and copies that are marked obsolete by the current retention policy.
By default, the retention policy is configured to REDUNDANCY of 1.
The REPORT OBSOLETE command supports the RECOVERY WINDOW and REDUNDANCY options
at the command level, which have the same meanings as the options with the same names
on the CONFIGURE command.
1. After connecting to the target database and recovery catalog (if you use one),
issue CROSSCHECK commands as needed to update the status of backups and
copies. Following is a possible crosscheck session:
2. # allocate maintenance channel for crosscheck if automatic
channels not configured
3. ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE sbt;
4. CROSSCHECK BACKUP; # crosschecks all backups
5. CROSSCHECK COPY; # crosschecks all copies
6. RELEASE CHANNEL;
7.
2. Use the OBSOLETE option to identify which backups are obsolete because they are
no longer needed for recovery. For example, enter:
3. # lists backups or copies that are superfluous because they are
not needed to recover
4. # the database to a random point within the past week
5. REPORT OBSOLETE RECOVERY WINDOW OF 7 DAYS;
6. # lists backups or copies that are superfluous because more than
2 copies of the
7. # files exist on tape
8. REPORT OBSOLETE REDUNDANCY = 2 DEVICE TYPE sbt;
9.
3. Use the ORPHAN option to list unusable backups and copies belonging to an
incarnation that is not a direct predecessor of the current incarnation (refer to
"Reports of Orphaned Backups"). For example, enter:
4. REPORT OBSOLETE ORPHAN;
5.
4. Optionally, delete those backups that are obsolete. You can automatically delete
obsolete backups and copies by issuing the DELETE OBSOLETE command. For
example, you can enter:
5. # delete obsolete backups and copies displayed when you issue
REPORT OBSOLETE
6. DELETE OBSOLETE;
7. # delete obsolete backups and copies according to a specified
recovery window
8. DELETE OBSOLETE RECOVERY WINDOW OF 7 DAYS;
9. # delete obsolete backups and copies according to a specified
redundancy
10.DELETE OBSOLETE REDUNDANCY = 2;
11.
Note that RMAN prompts you for confirmation before actually deleting the files.
To suppress the prompt, specify the NOPROMPT option of the DELETE command.
Specify FORCE to delete the files and remove their repository records regardless of
whether the files exist. RMAN ignores any I/O errors for the deleted objects.
Issue the REPORT UNRECOVERABLE command to determine which datafiles have had an
unrecoverable operation performed against an object residing in the datafile after its last
backup.
Assume that you perform an unrecoverable operation on the table employee by issuing
an ALTER TABLE employee ... NOLOGGING statement. If the employee table is located in
datafile 3, then the REPORT command can flag backups of this datafile as unrecoverable.
After connecting to the target database and recovery catalog (if you use one), issue
REPORT UNRECOVERABLE. For example, enter:
REPORT UNRECOVERABLE DATABASE; # examines all datafiles
REPORT UNRECOVERABLE TABLESPACE 'users'; # examines a specific
tablespace
You do not have to use V$ or recovery catalog views to identify the database files. Issue
REPORT SCHEMA to list the files. If you use a recovery catalog, then you also generate
historical reports of the database schema at a past time. You do not need a recovery
catalog, however, to report the current schema.
1. After connecting to the target database and recovery catalog (if you use one),
issue REPORT SCHEMA for a list of all the datafiles and tablespaces in the target
database at the current time:
2. REPORT SCHEMA;
3.
If you use a recovery catalog, then you can use the atClause to specify a past
time, SCN, or log sequence number:
This type of information is useful for incomplete recovery because you can
determine the schema of the database for the time to which you want to recover.
By using the SHOW command, you can perform the queries discussed in the following
sections:
You can use the CONFIGURE command to specify a variety of persistent settings for the
RMAN environment. The SHOW ALL command displays both the CONFIGURE commands
that you have issued as well as RMAN's default configurations. Note that you can return
any CONFIGURE command to its default setting by running CONFIGURE ... CLEAR.
After connecting to the target database and recovery catalog (if you use one), run the
SHOW ALL command. For example, enter the following:
Note that the output is displayed so that you can paste it into a script and run it as an
RMAN command file; hence, you can easily change your entire configuration. You can
even run the script on a different target database.
You can use the CONFIGURE RETENTION POLICY command to specify either the number of
days in the recovery window or the level of redundancy. By default, the retention policy
is set to REDUNDANCY = 1.
After connecting to the target database and recovery catalog (if you use one), run the
SHOW RETENTION POLICY command. For example, enter:
Issue the SHOW CHANNEL command to display the settings for all automatically allocated
channels.
After connecting to the target database and recovery catalog (if you use one), issue the
SHOW CHANNEL command. For example, enter:
SHOW CHANNEL; # shows the CONFIGURE setting for the automatic
channels
Issue the SHOW DEVICE TYPE command to display the configured devices and their
parallelism settings. The DISK device type is preconfigured.
After connecting to the target database and recovery catalog (if you use one), run the
SHOW DEVICE TYPE command. For example, enter:
SHOW DEVICE TYPE; # shows the CONFIGURE DEVICE TYPE ... PARALLELISM
settings
Issue the SHOW DEFAULT DEVICE TYPE command to display the settings for the default
device type used by the automatic channels. When you issue the BACKUP command,
RMAN allocates only default channels of the type set by the CONFIGURE DEFAULT DEVICE
TYPE command. This default device type setting is not in effect when you use commands
other than BACKUP. Note that you cannot disable the default device type: it is always
either DISK (default setting) or sbt.
After connecting to the target database and recovery catalog (if you use one), run the
SHOW DEFAULT DEVICE TYPE command. For example, enter:
SHOW DEFAULT DEVICE TYPE; # shows the CONFIGURE DEFAULT DEVICE TYPE
setting
You can use the CONFIGURE command to set the following behavior for the BACKUP
command:
You can use the CONFIGURE EXCLUDE command to exclude tablespaces from whole
database backups.
After connecting to the target database and recovery catalog (if you use one), run the
SHOW EXCLUDE command. For example, enter:
Use the CONFIGURE ... BACKUP COPIES command to set the number of identical copies
that RMAN makes of each backup. For example, if the value is 3, RMAN produces a
total of three identical copies of each backup piece in a backup set.
After connecting to the target database and recovery catalog (if you use one), run the
SHOW ARCHIVELOG BACKUP COPIES or SHOW DATAFILE BACKUP COPIES commands. For
example, enter:
SHOW DATAFILE BACKUP COPIES; # shows the CONFIGURE DATAFILE BACKUP
COPIES setting
You can run the CONFIGURE MAXSETSIZE command to set the maximum sizes for RMAN
backup sets. The size of a backup set is measured in the total bytes of the included
backup pieces.
After connecting to the target database and recovery catalog (if you use one), issue the
SHOW MAXSETSIZE command. For example, enter:
You can use the CONFIGURE BACKUP OPTIMIZATION command to enable and disable
backup optimization.
After connecting to the target database and recovery catalog (if you use one), issue the
SHOW BACKUP OPTIMIZATION command. For example, enter:
After connecting to the target database and recovery catalog (if you use one), run the
SHOW SNAPSHOT CONTROLFILE command. For example, enter:
You can use the CONFIGURE AUXNAME command to set persistent filenames for auxiliary
channels. For example, you can give new filenames for duplicate or standby datafiles, or
datafiles in a TSPITR operation. Issue the SHOW AUXNAME command to display these
filenames.
After connecting to the target database and recovery catalog (if you use one), issue the
SHOW AUXNAME command. For example, enter:
Use the PRINT SCRIPT command to display the text of a stored script. If desired, you
can save the output to an RMAN log file.
1. Start RMAN and connect to the recovery catalog database and target database,
specifying the LOG argument if you want to print to a message log. For example,
enter the following to specify rman_log:
2. % rman TARGET / CATALOG rman/cat@catdb LOG = rman_log
3.
Note that you must connect to the target database that you connected to when you
created the script.
The RC_STORED_SCRIPT_LINE view contains the text of all stored scripts for all
incarnations of the target databases registered in the recovery catalog.
1. Start SQL*Plus and connect to the recovery catalog database as the catalog
owner. For example, enter the following:
2. % sqlplus rman/cat@catdb
3.
2. Execute the following query, replacing database_key with the numerical primary
key of the target database and script_name with the name of the script:
3. SELECT TEXT
4. FROM RC_DATABASE_INCARNATION i, RC_STORED_SCRIPT_LINE l
5. WHERE i.DB_KEY = database_key
6. AND SCRIPT_NAME = script_name
7. AND i.DB_KEY = s.DB_KEY
8. AND i.CURRENT_INCARNATION = 'YES'
9. /
10.
TEXT
-----------------------------------------------------------------
---------------
{ backup database plus archivelog;}
The RC_STORED_SCRIPT view contains information about all stored scripts for all
incarnations of the target databases registered in the catalog.
1. Start SQL*Plus and connect to the recovery catalog database as the catalog
owner. For example, enter the following:
2. % sqlplus rman/cat@catdb
3.
2. Execute the following query in SQL*Plus, replacing database_key with the
numerical primary key of the target database:
3. SELECT DISTINCT SCRIPT_NAME
4. FROM RC_DATABASE_INCARNATION i, RC_STORED_SCRIPT s
5. WHERE i.DB_KEY = database_key
6. AND i.DB_KEY = s.DB_KEY
7. /
8.
SCRIPT_NAME
-----------------------------------------------------------------
---------------
backup_db
backup_system
The recovery catalog views are not normalized, but are optimized for RMAN usage
rather than user queries. RMAN obtains backup and recovery information from the target
database control file and stores it in the catalog tables.
In general, the recovery catalog views are not as user-friendly as the RMAN reporting
commands. For example, when you start RMAN and connect to a target database, you
obtain the information for this target database only when you issue LIST, REPORT, and
SHOW commands. If you have 10 different target databases registered in the same recovery
catalog, then the catalog views show the information for all incarnations of all databases
registered in the catalog. You often have to perform joins among the views to distinguish
the specific incarnation of the target database that you are interested in.
Most of the catalog views have a corresponding dynamic performance view in the
database server. For example, RC_BACKUP_PIECE corresponds to V$BACKUP_PIECE. The
primary difference between the catalog and server views is that each catalog view
contains information about all the databases registered in the catalog, whereas the server
view contains information only about itself. The two types of views often use different
primary keys to uniquely identify rows.
Most of the catalog views contain the columns DB_KEY and DBINC_KEY. Each target
database can be uniquely identified by either the primary key, which is the DB_KEY
column value, or the DBID, which is the 32-bit unique database identifier. Each
incarnation of each target database is uniquely identified by the DBINC_KEY primary key.
When querying information about a specific incarnation of a target database, you should
use these columns to specify the database. Then, you can perform joins with most of the
other catalog views to obtain the desired information.
The DB_KEY value which is the primary key for a target database, is used only in the
recovery catalog. The easiest way is to obtain the DB_KEY is to use the DBID of the target
database, which is displayed whenever you connect RMAN to the target database. The
DBID, which is a unique system-defined number given to every Oracle database, is what
distinguishes one target database from another target database in the RMAN metadata.
Assume that you want to obtain information about one of the target databases registered
in the recovery catalog. You can easily determine the DBID from this database either by
looking at the output displayed when RMAN connects to the database, or querying a V$
view as in the following:
SELECT DBID
FROM V$DATABASE;
DBID
---------
598368217
You can then obtain the DB_KEY for a target database by running the following query,
where dbid_of_target is the DBID that you previously obtained:
SELECT DB_KEY
FROM RC_DATABASE
WHERE DBID = dbid_of_target;
To obtain information about the current incarnation of a target database, specify the target
database DB_KEY value and perform a join with RC_DATABASE_INCARNATION by using a
WHERE condition to specify that the CURRENT_INCARNATION column value is set to YES.
For example, to obtain information about backup sets in the current incarnation of a target
database with the DB_KEY value of 1, you can execute this script:
You should use the DB_NAME column to specify a database only if you do not have more
than one database registered in the recovery catalog with the same DB_NAME. RMAN
permits you to register more than one database with the same database name, but requires
that the DBID values be different. For example, you can have ten databases with the
DB_NAME value of prod1, each with a different DBID. Because the DBID is the unique
identifier for every database in the metadata, use this value to obtain the DB_KEY and then
use DB_KEY to uniquely identify the database.
RMAN Repository Query Examples
This section contains these topics:
Use the LIST command to query the contents of the recovery catalog or the target
database control file if no recovery catalog is used. You can use several different
parameters to qualify lists.
The following example lists all backups of datafiles in tablespace tbs_1 that were made
after June 11, 2000:
The following example lists all copies of datafile 2 with the tag df2__copy that are in the
/copy directory:
Use the REPORT command to determine which copies and backups are superfluous and so
can be deleted. For example, if you only need to be able to recover the database to a point
within the last two weeks, then issue this command:
You can then delete these obsolete backups and copies by issuing this command:
The following command reports all backups and copies on disk that are obsolete because
three more recent backups or copies are already available:
The following command reports all backups on tape that are obsolete because at least two
backups already exist that were made no more than one week ago:
The following commands reports the database schema in the present, a week ago, and on
September 20, 2000:
REPORT SCHEMA;
REPORT SCHEMA AT TIME 'SYSDATE-7';
REPORT SCHEMA AT TIME "TO_DATE('09/20/01','MM/DD/YY')";
The following command reports on the database schema at log sequence number 12 of
thread 2:
Every time that you perform a RESETLOGS operation on a database, you create a new
incarnation. This example lists all database incarnation of trgt registered in the recovery
catalog: