V$ Tables Related to Backup Recovery/Restore
Each release Oracle brought up new features and enhancements to RMAN improving its ease of use and functionality. Using the updateable persistent configuration options (CONFIGURE ….), backup up the database is easier then in the first version of RMAN introduced in 8i. It is help to list the Synonyms containing the word RMAN and BACKUP in them.
Here’s a list from an Oracle 11g database for those with BACKUP in the name:
OBJECT_NAME
——————————
V$BACKUP
V$BACKUP_SET
V$BACKUP_PIECE
V$BACKUP_DATAFILE
V$BACKUP_SPFILE
V$BACKUP_REDOLOG
V$BACKUP_CORRUPTION
V$BACKUP_DEVICE
V$BACKUP_SYNC_IO
V$BACKUP_ASYNC_IO
GV$BACKUP
GV$BACKUP_SET
GV$BACKUP_PIECE
GV$BACKUP_DATAFILE
GV$BACKUP_SPFILE
GV$BACKUP_REDOLOG
GV$BACKUP_CORRUPTION
GV$BACKUP_DEVICE
GV$BACKUP_SYNC_IO
GV$BACKUP_ASYNC_IO
V$BACKUP_FILES
V$RMAN_BACKUP_SUBJOB_DETAILS
V$RMAN_BACKUP_JOB_DETAILS
V$BACKUP_SET_DETAILS
V$BACKUP_PIECE_DETAILS
V$BACKUP_COPY_DETAILS
V$BACKUP_DATAFILE_DETAILS
V$BACKUP_CONTROLFILE_DETAILS
V$BACKUP_ARCHIVELOG_DETAILS
V$BACKUP_SPFILE_DETAILS
V$BACKUP_SET_SUMMARY
V$BACKUP_DATAFILE_SUMMARY
V$BACKUP_CONTROLFILE_SUMMARY
V$BACKUP_ARCHIVELOG_SUMMARY
V$BACKUP_SPFILE_SUMMARY
V$BACKUP_COPY_SUMMARY
V$UNUSABLE_BACKUPFILE_DETAILS
V$RMAN_BACKUP_TYPE
MGMT$HA_BACKUP
39 rows selected.
Here’s a list from the same Oracle 11g database with RMAN in the name:
OBJECT_NAME
——————————
V$RMAN_CONFIGURATION
GV$RMAN_CONFIGURATION
V$RMAN_STATUS
V$RMAN_OUTPUT
GV$RMAN_OUTPUT
V$RMAN_COMPRESSION_ALGORITHM
GV$RMAN_COMPRESSION_ALGORITHM
V$RMAN_BACKUP_SUBJOB_DETAILS
V$RMAN_BACKUP_JOB_DETAILS
V$RMAN_BACKUP_TYPE
V$RMAN_ENCRYPTION_ALGORITHMS
MGMT$HA_RMAN_CONFIG
MGMT$HA_RMAN_CONFIG_ALL
13 rows selected.
Controlfile views to reference are:
V_$ARCHIVE
V_$ARCHIVED_LOG
V_$ARCHIVE_DEST
V_$ARCHIVE_DEST_STATUS
V_$ARCHIVE_GAP
V_$ARCHIVE_PROCESSES
V_$BACKUP_ARCHIVELOG_DETAILS
V_$BACKUP_ARCHIVELOG_SUMMARY
V_$BACKUP_CONTROLFILE_DETAILS
V_$BACKUP_CONTROLFILE_SUMMARY
V_$BACKUP_DATAFILE
V_$BACKUP_DATAFILE_DETAILS
V_$BACKUP_DATAFILE_SUMMARY
V_$CONTROLFILE
V_$CONTROLFILE_RECORD_SECTION
V_$DATAFILE
V_$DATAFILE_COPY
V_$DATAFILE_HEADER
V_$SYSTEM_FIX_CONTROL
V_$PROXY_ARCHIVEDLOG
V_$PROXY_ARCHIVELOG_DETAILS
V_$PROXY_ARCHIVELOG_SUMMARY
V_$PROXY_DATAFILE
GV_$FOREIGN_ARCHIVED_LOG
GV_$PROXY_ARCHIVEDLOG
GV_$PROXY_DATAFILE
GV_$SESSION_FIX_CONTROL
V_$SESSION_FIX_CONTROL
V_$DLM_TRAFFIC_CONTROLLER
V_$FOREIGN_ARCHIVED_LOG
GV_$BACKUP_DATAFILE
GV_$CONTROLFILE
GV_$CONTROLFILE_RECORD_SECTION
GV_$DATAFILE
GV_$DATAFILE_COPY
GV_$DATAFILE_HEADER
GV_$DLM_TRAFFIC_CONTROLLER
GV_$ARCHIVE
GV_$ARCHIVED_LOG
GV_$ARCHIVE_DEST
GV_$ARCHIVE_DEST_STATUS
GV_$ARCHIVE_GAP
GV_$ARCHIVE_PROCESSES
DBA_REGISTERED_ARCHIVED_LOG
DBA_REPRESOL_STATS_CONTROL
USER_REPRESOL_STATS_CONTROL
ALL_REPRESOL_STATS_CONTROL
DBA_FLASHBACK_ARCHIVE
DBA_FLASHBACK_ARCHIVE_TABLES
DBA_FLASHBACK_ARCHIVE_TS
DBA_HIST_DATAFILE
DBA_HIST_WR_CONTROL
USER_FLASHBACK_ARCHIVE
USER_FLASHBACK_ARCHIVE_TABLES
GV_$SYSTEM_FIX_CONTROL
PS_CONTROL_TBL_VW
MGMT_V_DB_CONTROLFILES_ECM
MGMT_V_DB_DATAFILES_ECM
MGMT$DB_CONTROLFILES
MGMT$DB_CONTROLFILES_ALL
MGMT$DB_DATAFILES
MGMT$DB_DATAFILES_ALL
62 rows selected.
That is a lot of objects and views. To view the default RMAN configuration and then check the V$ view to see what is stored you can accomplish this with a query like this:
set linesize 132
column name format a40
column value format a40
set echo on
set serveroutput on
select * from v$rman_configuration
/
CONF# NAME VALUE
1 BACKUP OPTIMIZATION ON
2 DEFAULT DEVICE TYPE TO DISK
3 CONTROLFILE AUTOBACKUP ON
4 DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET
PARALLELISM 2
5 DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1
6 ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1
7 SNAPSHOT CONTROLFILE NAME TO ‘/opt/app/oracle/admin/backup/PS90HRD
V/backupsets/snapcf_ev.f’
8 MAXSETSIZE TO UNLIMITED
9 CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE DISK TO ‘+ps90hr_disk3/ps90hrdv/autoback
TYPE up/%F’
9 rows selected.
If you aren’t using a recovery catalog you can look at the controlfile since this is were backup information is maintained if you aren’t using a recovery catalog:
select type, records_total, records_used
from v$controlfile_record_section
where type like ‘%BACKUP%’
/
TYPE RECORDS_TOTAL RECORDS_USED
—————————- ————- ————
BACKUP SET 1227 224
BACKUP PIECE 1000 331
BACKUP DATAFILE 2126 2126
BACKUP REDOLOG 215 215
BACKUP CORRUPTION 1115 0
BACKUP SPFILE 131 93
6 rows selected.
The records used column isn’t zero because I’ve taken numerous backups, however, if you haven’t completed a backup yet this column will be zero. When RMAN reads the files to determine the files that will be backed up, if any corruption is detected then the corruption views are populated with that information such as file#, block# and contiguous blocks after the initial corrupt block.
RMAN will continue to use the persistent backup configuration settings once they are set unless they are overridden. The RMAN “SHOW” command displays those settings:
SHOW option [,parameter, ...]
RETENTION POLICY
EXCLUDE
BACKUP COPIES
CHANNEL
DEFAULT DEVICE TYPE
DEVICE TYPE
SNAPSHOT CONTROLFILE
…
ALL
RMAN> show all;
Recovery Manager: Release 11.1.0.6.0 – Production on Sat Nov 1 21:32:38 2008
Copyright (c) 1982, 2007, Oracle. All rights reserved.
show all;connected to target database: PS90HRDV (DBID=2173713801)
connected to recovery catalog database
RMAN>
RMAN configuration parameters for database with db_unique_name PS90HRDV are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘+ps90hr_disk3/ps90hrdv/autobackup/%F’;
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 2;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE MAXSETSIZE TO UNLIMITED;
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM ‘AES128′; # default
CONFIGURE COMPRESSION ALGORITHM ‘BZIP2′; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/opt/app/oracle/admin/backup/PS90HRDV/backupsets/snapcf_ev.f’;
You can script the configuration parameters you want to use within a run block to change one or more parameters or just change a single parameter at a time from the RMAN prompt and not use the run block option.
Example:
CONNECT catalog rman/rman
crosscheck copy;
delete expired copy;
crosscheck backup;
delete expired backup;
run {
configure channel 1 device type disk clear;
configure channel 2 device type disk clear;
configure device type disk backup type to backupset parallelism 1;
backup spfile;
configure snapshot controlfile name to ‘/opt/app/oracle/admin/backup/PS90HRDV/backupsets/snapcf_ev.f’;
backup current controlfile;
configure channel 1 device type disk format ‘/opt/app/oracle/admin/backup/PS90HRDV/backupsets/df_t%t_s%s_p%p’ maxpieces
ize 1750 M;
configure channel 2 device type disk format ‘/opt/app/oracle/admin/backup/PS90HRDV/backupsets/df_t%t_s%s_p%p’ maxpieces
ize 1750 M;
configure device type disk backup type to compressed backupset parallelism 2;
backup as compressed backupset incremental level 0 database tag=”ps90hrdv”;
configure channel 1 device type disk format ‘/opt/app/oracle/admin/backup/PS90HRDV/backupsets/al_t%t_s%s_p%p’ maxpieces
ize 5000M;
configure channel 2 device type disk format ‘/opt/app/oracle/admin/backup/PS90HRDV/backupsets/al_t%t_s%s_p%p’ maxpieces
ize 5000M;
backup archivelog all delete all input tag=”ps90hrdv_archivelogs”;
configure channel 1 device type disk clear;
configure channel 2 device type disk clear;
configure snapshot controlfile name to ‘/opt/app/oracle/admin/backup/PS90HRDV/backupsets/snapcf_ev.f’;
backup current controlfile;
configure channel 1 device type disk clear;
}
Create Consistent Backup Script
You can create a RMAN script to generate a database backup without a recovery catalog or with a recovery catalog. You can set the autocontrolfile autobackup feature during configuration so the backup controlfile is used as the catalog to avoid putting creating a separate RMAN database to use its catalog.
connect target;
run {
shutdown immediate;
startup mount pfile=’/opt/app/oracle/admin/ORACLE_SID/pfile/initORCLSID.ora’;
backup incremental level 0 database format ‘/opt/app/oracle/oradata/ORCLSID/backup/%d_bckup_%U’ tag=”closed_bkup”;
shutdown;
startup pfile=’/opt/app/oracle/admin/ORACLE_SID/pfile/initORCLSID.ora’;
}
exit
RMAN> list summary;
RMAN> list backup summary;
RMAN> list backup by file;
If you use for example 2 channels for your backup you’ll see 2 backupsets in the earlier query if you run that query again because RMAN will split the backup across 2 channels which means there will be 2 backupsets created plus there will be a 3rd controlfile backup that will be generated by the CONTROLFILE AUTOBACKUP feature.
A controlfile autobackup will generate a backup controlfile for each of the following commands if they are executed:
BACKUP DATABASE;
BACKUP TABLESPACE;
BACKUP DATAFILE;
BACKUP ARCHIVELOG;
To determine which datafiles need a backup execute the following command:
RMAN> report need backup;
To check and see if any RMAN Backupsets are obsolete and can be removed (deleted), important if you are generating disk backupsets and you don’t have unlimited disk space available to you.
RMAN> report obsolete;
SQL> select recid, stamp, completion_time, incremental_level from v$backup_set;
RECID STAMP COMPLETION_TIME INCREMENTAL_LEVEL
———- ———- ————— —————–
74 669457740 30-OCT-08
77 669458037 30-OCT-08
81 669465792 30-OCT-08
83 669465817 30-OCT-08
84 669501608 30-OCT-08
85 669501611 30-OCT-08
86 669502225 30-OCT-08
87 669502228 30-OCT-08
88 669502858 30-OCT-08 0
89 669503121 30-OCT-08 0
90 669503486 30-OCT-08 0
91 669503494 30-OCT-08
92 669503532 30-OCT-08
93 669503537 30-OCT-08
94 669507033 30-OCT-08
95 669507037 30-OCT-08
96 669507656 30-OCT-08
97 669507895 30-OCT-08
98 669508179 30-OCT-08
99 669508185 30-OCT-08
100 669508210 30-OCT-08
101 669508215 30-OCT-08
102 669509706 30-OCT-08
103 669509710 30-OCT-08
104 669510725 30-OCT-08
105 669510729 30-OCT-08
106 669645074 01-NOV-08
107 669645077 01-NOV-08
108 669645085 01-NOV-08
109 669645088 01-NOV-08
110 669645622 01-NOV-08 0
111 669646213 01-NOV-08 0
112 669646640 01-NOV-08
113 669646643 01-NOV-08
114 669646651 01-NOV-08
115 669646654 01-NOV-08
116 669647173 01-NOV-08 0
117 669647495 01-NOV-08 0
118 669647764 01-NOV-08 0
119 669647775 01-NOV-08
column handle format a32
column tag format a18
select recid, set_stamp, tag, status, handle
from v$backup_piece
order by set_stamp
/
RECID SET_STAMP TAG STA HANDLE
———- ———- —————— — ——————————–
93 669465816 TAG20081030T104336 A +PS90HR_DISK3/ps90hrqa/autobacku
p/c-2291650026-20081030-03
94 669501607 TAG20081030T204007 A /dbbackup/PS90HRQA/al_t669501607
_s84_p1
95 669501610 TAG20081030T204010 A +PS90HR_DISK3/ps90hrqa/autobacku
p/c-2291650026-20081030-04
96 669502225 TAG20081030T205024 A +PS90HR_DISK2/ps90hrqa/backupset
/2008_10_30/nnsnf0_tag20081030t2
05024_0.572.669505825
97 669502227 TAG20081030T205027 A +PS90HR_DISK3/ps90hrqa/autobacku
p/c-2291650026-20081030-05
100 669502244 PS90HRQA A /opt/app/oracle/admin/backup/PS9
0HRQA/backupsets/df_t669502244_s
88_p1
101 669502244 PS90HRQA A /opt/app/oracle/admin/backup/PS9
0HRQA/backupsets/df_t669502244_s
88_p2
98 669502245 PS90HRQA A /opt/app/oracle/admin/backup/PS9
0HRQA/backupsets/df_t669502245_s
89_p1
Recover Database Using an Autobackup of the Controlfile without a Recovery Catalog
Set the NLS_LANG environment variable to its proper setting depending on the values you created your database with. Example:
export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P15
sqlplus> startup nomount;
Start RMAN but do not connect to the target database.
$ rman
RMAN>
Set the database identifier for the target database with the SET DBID command. RMAN displays the DBID whenever you connect to the target. You can also get it by running LIST or by querying the catalog.
Recovery Manager: Release 11.1.0.6.0 – Production on Sat Nov 1 20:57:08 2008
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: PS90HRDV (DBID=2173713801)
RMAN> SET DBID 2173713801;
You can use log files to determine the DBID also, every time RMAN connects to the database the DBID is displayed as shown above, if the database is open or mounted.
Connect to the target database:
RMAN> CONNECT TARGET;
Restore the backup controlfile, then perform the recovery by carrying out the following steps:
Optionally, specify the most recent backup time stamp that RMAN can use when searching for a controlfile autobackup to restore.
If a non-default format was used to create the control file, then specify a non-default format for the restore of the control file.
If the channel that created the control file autobackup was device type sbt (tape), then you must allocate one or more sbt (tape) channels. Because you don’t have a repository available you can’t use the automatic channels. If the autobackup was created on a disk channel, however, then you do not need to manually allocate a disk channel.
Restore the autobackup of the control file, optionally set the maximum number of days backward that RMAN can search (up to 366) and the initial sequence number that is should use in its search for the first day.
Mount the database, and because the repository is now available any automatic channels that you configured are now also available.
If the online logs are inaccessible, then restore and recover the database as described in the incomplete restore and recovery post. You must first terminate recovery by setting the UNTIL clause to a time, log sequence number or SCN before the online redo logs are processes. If the online logs are useable, then restore and recover the database as described in the complete restore and recovery post.
In the following example, the online redo logs have been lost. This example limits the restore of the control file autobackup, then performs the recovery of the database to log sequence 13456, which is the most recent archived log:
run {
set controlfile autobackup format for device type disk to ‘/opt/app/oracle/oradata/ORCLSID/backup/%F’;
allocate channel d1 device type disk;
restore controlfile from autobackup
maxseq 5 # start at sequence 5 and count down
maxdays 5; # start at UNTIL TIME and search back 5 days
mount database;
}
RMAN> run {
restore database;
recover database;
alter database open resetlogs;
}
Backup the database after resetlogs.