12c New Feature - RMAN RECOVER TABLE
So when may we use this fearure?
There is TSPITR ( Tablespace point-in-time recovery) but what if we only want to restore a single table or subset of tables and the tablespace has a large number of tables.
Tables have been logically corrupted or records wrongly purged and we cannot use the FLASHBACK TABLE feature because we do not have enough undo data available to go back to the required point in time.
FLASHBACK DATABASE has not been turned on and remember even if it was turned on, if we are going to use flashback database just to recover some tables, the entire database is being put to a point in time in the past which is not very desirable.
So what does the RMAN RECOVER TABLE command do behind the scenes?
It creates an auxiliary database or instance which is used to recover the tables to a specific point in time. This database will contain a few system related data files like SYSTEM, SYSAUX, UNDO and data files belonging to the tablespace containing the tables we are looking to restore.
In this example it restores SYSTEM,SYSAUX,UNDO tablespaces for CDB and SYSTEM and SYSAUX and EXAMPLE tablespace for PDB
Then it creates a Data Pump export dump file which will contain the recovered table or partitions of tables.
It will then import the data into the target database using Data Pump Import.
Finally it will remove the temporary auxiliary instance.
Let us see an example where we drop the SH.CUSTOMERS table and test the restore and recovery using the new 12c RMAN RECOVER TABLE feature
In this example we have a container database (CDB) called cdb12c and there is a pluggable database (PDB) called testdb1. The SH.CUSTOMERS table is contained in the EXAMPLE tablespace and this is part of the TESTDB1 PDB.
Note that in 12c, when we connect to the root container CDB and issue the BACKUP DATABASE command, all the PDBs also get backed up automatically. But if we want we can do the recovery at the PDB level if required as we will see in this case.
This is the RMAN command we will be using:
RECOVER TABLE sh.customers OF PLUGGABLE DATABASE testdb1
UNTIL TIME ‘sysdate-10/1440′
AUXILIARY DESTINATION ‘/u01/app/oracle/backup/cdb12c’
DATAPUMP DESTINATION ‘/u01/app/oracle/backup/cdb12c’;
We are recovering the table to a point in time 10 minutes ago (just before we dropped the table), and specifying a location on disks where the auxiliary database files will be located as well as the Data Pump export files.
We can see the output of the RMAN RECOVER TABLE command below and I have highlighted some of the key steps being performed.
Note that these are the datafiles being restored of the CDB:
data file #1, 4 and 3
These are the datafiles being restored of the PDB:
data file #8,9 and 11
SQL> select count(*) from customers; COUNT(*) ---------- 55500 SQL> drop table customers cascade constraints; Table dropped.
RMAN> RECOVER TABLE sh.customers OF PLUGGABLE DATABASE testdb1
UNTIL TIME ‘sysdate-10/1440′
AUXILIARY DESTINATION ‘/u01/app/oracle/backup/cdb12c’
DATAPUMP DESTINATION ‘/u01/app/oracle/backup/cdb12c’;
Starting recover at 25-JUL-13
using channel ORA_DISK_1
RMAN-05026: WARNING: presuming following set of tablespaces applies to specified Point-in-Time
List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace UNDOTBS1
Creating automatic instance, with SID=’vpwz’
initialization parameters used for automatic instance:
db_name=CDB12C
db_unique_name=vpwz_pitr_testdb1_CDB12C
compatible=12.1.0.0.0
db_block_size=8192
db_files=200
sga_target=1G
processes=80
diagnostic_dest=/u01/app/oracle
db_create_file_dest=/u01/app/oracle/backup/cdb12c
log_archive_dest_1=’location=/u01/app/oracle/backup/cdb12c’
enable_pluggable_database=true
_clone_one_pdb_recovery=true
#No auxiliary parameter file used
starting up automatic instance CDB12C
Oracle instance started
Total System Global Area 1068937216 bytes
Fixed Size 2296576 bytes
Variable Size 281019648 bytes
Database Buffers 780140544 bytes
Redo Buffers 5480448 bytes
Automatic instance created
contents of Memory Script:
{
# set requested point in time
set until time “sysdate-10/1440″;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone ‘alter database mount clone database’;
# archive current online log
sql ‘alter system archive log current’;
}
executing Memory Script
executing command: SET until clause
Starting restore at 25-JUL-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=82 device type=DISK
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/CDB12C/autobackup/2013_07_24/o1_mf_s_821611376_8yyc3jb2_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/CDB12C/autobackup/2013_07_24/o1_mf_s_821611376_8yyc3jb2_.bkp tag=TAG20130724T092256
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/backup/cdb12c/CDB12C/controlfile/o1_mf_8z11h238_.ctl
Finished restore at 25-JUL-13
sql statement: alter database mount clone database
sql statement: alter system archive log current
contents of Memory Script:
{
# set requested point in time
set until time “sysdate-10/1440″;
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile 1 to new;
set newname for clone datafile 4 to new;
set newname for clone datafile 3 to new;
set newname for clone datafile 8 to new;
set newname for clone datafile 9 to new;
set newname for clone tempfile 1 to new;
set newname for clone tempfile 3 to new;
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 1, 4, 3, 8, 9;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 3 to /u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 25-JUL-13
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/backup/cdb12c/bkp_06ofhicn_1_1
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/backup/cdb12c/bkp_06ofhicn_1_1 tag=TAG20130724T091503
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:35
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00008 to /u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00009 to /u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/backup/cdb12c/bkp_0cofhir0_1_1
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/backup/cdb12c/bkp_0cofhir0_1_1 tag=TAG20130724T092240
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 25-JUL-13
datafile 1 switched to datafile copy
input datafile copy RECID=12 STAMP=821699866 file name=/u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_system_8z11h87b_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=13 STAMP=821699866 file name=/u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_undotbs1_8z11h87f_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=14 STAMP=821699866 file name=/u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_sysaux_8z11h875_.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=15 STAMP=821699866 file name=/u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_system_8z11jcbx_.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=16 STAMP=821699866 file name=/u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_sysaux_8z11jcbr_.dbf
contents of Memory Script:
{
# set requested point in time
set until time “sysdate-10/1440″;
# online the datafiles restored or switched
sql clone “alter database datafile 1 online”;
sql clone “alter database datafile 4 online”;
sql clone “alter database datafile 3 online”;
sql clone ‘TESTDB1′ “alter database datafile
8 online”;
sql clone ‘TESTDB1′ “alter database datafile
9 online”;
# recover and open database read only
recover clone database tablespace “SYSTEM”, “UNDOTBS1″, “SYSAUX”, “TESTDB1″:”SYSTEM”, “TESTDB1″:”SYSAUX”;
sql clone ‘alter database open read only’;
}
executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 1 online
sql statement: alter database datafile 4 online
sql statement: alter database datafile 3 online
sql statement: alter database datafile 8 online
sql statement: alter database datafile 9 online
Starting recover at 25-JUL-13
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 150 is already on disk as file /u01/app/oracle/fast_recovery_area/CDB12C/archivelog/2013_07_24/o1_mf_1_150_8yybs4c0_.arc
archived log for thread 1 with sequence 151 is already on disk as file /u01/app/oracle/fast_recovery_area/CDB12C/archivelog/2013_07_24/o1_mf_1_151_8yyf1pr7_.arc
archived log for thread 1 with sequence 152 is already on disk as file /u01/app/oracle/fast_recovery_area/CDB12C/archivelog/2013_07_24/o1_mf_1_152_8yyf26kh_.arc
archived log for thread 1 with sequence 153 is already on disk as file /u01/app/oracle/fast_recovery_area/CDB12C/archivelog/2013_07_25/o1_mf_1_153_8z119t3l_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/CDB12C/archivelog/2013_07_24/o1_mf_1_150_8yybs4c0_.arc thread=1 sequence=150
archived log file name=/u01/app/oracle/fast_recovery_area/CDB12C/archivelog/2013_07_24/o1_mf_1_151_8yyf1pr7_.arc thread=1 sequence=151
archived log file name=/u01/app/oracle/fast_recovery_area/CDB12C/archivelog/2013_07_24/o1_mf_1_152_8yyf26kh_.arc thread=1 sequence=152
archived log file name=/u01/app/oracle/fast_recovery_area/CDB12C/archivelog/2013_07_25/o1_mf_1_153_8z119t3l_.arc thread=1 sequence=153
media recovery complete, elapsed time: 00:00:03
Finished recover at 25-JUL-13
sql statement: alter database open read only
contents of Memory Script:
{
sql clone ‘alter pluggable database TESTDB1 open read only’;
}
executing Memory Script
sql statement: alter pluggable database TESTDB1 open read only
contents of Memory Script:
{
sql clone “create spfile from memory”;
shutdown clone immediate;
startup clone nomount;
sql clone “alter system set control_files =
”/u01/app/oracle/backup/cdb12c/CDB12C/controlfile/o1_mf_8z11h238_.ctl” comment=
”RMAN set” scope=spfile”;
shutdown clone immediate;
startup clone nomount;
# mount database
sql clone ‘alter database mount clone database’;
}
executing Memory Script
sql statement: create spfile from memory
database closed
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1068937216 bytes
Fixed Size 2296576 bytes
Variable Size 285213952 bytes
Database Buffers 775946240 bytes
Redo Buffers 5480448 bytes
sql statement: alter system set control_files = ”/u01/app/oracle/backup/cdb12c/CDB12C/controlfile/o1_mf_8z11h238_.ctl” comment= ”RMAN set” scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1068937216 bytes
Fixed Size 2296576 bytes
Variable Size 285213952 bytes
Database Buffers 775946240 bytes
Redo Buffers 5480448 bytes
sql statement: alter database mount clone database
contents of Memory Script:
{
# set requested point in time
set until time “sysdate-10/1440″;
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile 11 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 11;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
Starting restore at 25-JUL-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=11 device type=DISK
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00011 to /u01/app/oracle/backup/cdb12c/VPWZ_PITR_TESTDB1_CDB12C/datafile/o1_mf_example_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/backup/cdb12c/bkp_0cofhir0_1_1
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/backup/cdb12c/bkp_0cofhir0_1_1 tag=TAG20130724T092240
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 25-JUL-13
datafile 11 switched to datafile copy
input datafile copy RECID=18 STAMP=821699904 file name=/u01/app/oracle/backup/cdb12c/VPWZ_PITR_TESTDB1_CDB12C/datafile/o1_mf_example_8z11kry7_.dbf
contents of Memory Script:
{
# set requested point in time
set until time “sysdate-10/1440″;
# online the datafiles restored or switched
sql clone ‘TESTDB1′ “alter database datafile
11 online”;
# recover and open resetlogs
recover clone database tablespace “TESTDB1″:”EXAMPLE”, “SYSTEM”, “UNDOTBS1″, “SYSAUX”, “TESTDB1″:”SYSTEM”, “TESTDB1″:”SYSAUX” delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 11 online
Starting recover at 25-JUL-13
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 151 is already on disk as file /u01/app/oracle/fast_recovery_area/CDB12C/archivelog/2013_07_24/o1_mf_1_151_8yyf1pr7_.arc
archived log for thread 1 with sequence 152 is already on disk as file /u01/app/oracle/fast_recovery_area/CDB12C/archivelog/2013_07_24/o1_mf_1_152_8yyf26kh_.arc
archived log for thread 1 with sequence 153 is already on disk as file /u01/app/oracle/fast_recovery_area/CDB12C/archivelog/2013_07_25/o1_mf_1_153_8z119t3l_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/CDB12C/archivelog/2013_07_24/o1_mf_1_151_8yyf1pr7_.arc thread=1 sequence=151
archived log file name=/u01/app/oracle/fast_recovery_area/CDB12C/archivelog/2013_07_24/o1_mf_1_152_8yyf26kh_.arc thread=1 sequence=152
archived log file name=/u01/app/oracle/fast_recovery_area/CDB12C/archivelog/2013_07_25/o1_mf_1_153_8z119t3l_.arc thread=1 sequence=153
media recovery complete, elapsed time: 00:00:00
Finished recover at 25-JUL-13
database opened
contents of Memory Script:
{
sql clone ‘alter pluggable database TESTDB1 open’;
}
executing Memory Script
sql statement: alter pluggable database TESTDB1 open
contents of Memory Script:
{
# create directory for datapump import
sql ‘TESTDB1′ “create or replace directory
TSPITR_DIROBJ_DPDIR as ”
/u01/app/oracle/backup/cdb12c””;
# create directory for datapump export
sql clone ‘TESTDB1′ “create or replace directory
TSPITR_DIROBJ_DPDIR as ”
/u01/app/oracle/backup/cdb12c””;
}
executing Memory Script
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ”/u01/app/oracle/backup/cdb12c”
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ”/u01/app/oracle/backup/cdb12c”
Performing export of tables…
EXPDP> Starting “SYS”.”TSPITR_EXP_vpwz_dvsz”:
EXPDP> Estimate in progress using BLOCKS method…
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
EXPDP> Total estimation using BLOCKS method: 13 MB
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
EXPDP> Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
EXPDP> Processing object type TABLE_EXPORT/TABLE/COMMENT
EXPDP> Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
EXPDP> Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
EXPDP> Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
EXPDP> Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
EXPDP> Processing object type TABLE_EXPORT/TABLE/INDEX/BITMAP_INDEX/INDEX
EXPDP> Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/BITMAP_INDEX/INDEX_STATISTICS
EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
EXPDP> . . exported “SH”.”CUSTOMERS” 14.57 KB 55500 rows
EXPDP> Master table “SYS”.”TSPITR_EXP_vpwz_dvsz” successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_vpwz_dvsz is:
EXPDP> /u01/app/oracle/backup/cdb12c/tspitr_vpwz_91117.dmp
EXPDP> Job “SYS”.”TSPITR_EXP_vpwz_dvsz” successfully completed at Thu Jul 25 09:59:36 2013 elapsed 0 00:00:57
Export completed
contents of Memory Script:
{
# shutdown clone before import
shutdown clone abort
}
executing Memory Script
Oracle instance shut down
Performing import of tables…
IMPDP> Master table “SYS”.”TSPITR_IMP_vpwz_DEsg” successfully loaded/unloaded
IMPDP> Starting “SYS”.”TSPITR_IMP_vpwz_DEsg”:
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
IMPDP> . . imported “SH”.”CUSTOMERS” 14.57 KB 55500 rows
IMPDP> Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
IMPDP> Processing object type TABLE_EXPORT/TABLE/COMMENT
IMPDP> Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
IMPDP> Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
IMPDP> Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
IMPDP> Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
IMPDP> Processing object type TABLE_EXPORT/TABLE/INDEX/BITMAP_INDEX/INDEX
IMPDP> Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/BITMAP_INDEX/INDEX_STATISTICS
IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
IMPDP> Job “SYS”.”TSPITR_IMP_vpwz_DEsg” successfully completed at Thu Jul 25 10:00:09 2013 elapsed 0 00:00:25
Import completed
Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_temp_8z11k004_.tmp deleted
auxiliary instance file /u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_temp_8z11jyob_.tmp deleted
auxiliary instance file /u01/app/oracle/backup/cdb12c/VPWZ_PITR_TESTDB1_CDB12C/onlinelog/o1_mf_3_8z11l3bd_.log deleted
auxiliary instance file /u01/app/oracle/backup/cdb12c/VPWZ_PITR_TESTDB1_CDB12C/onlinelog/o1_mf_2_8z11l2ot_.log deleted
auxiliary instance file /u01/app/oracle/backup/cdb12c/VPWZ_PITR_TESTDB1_CDB12C/onlinelog/o1_mf_1_8z11l220_.log deleted
auxiliary instance file /u01/app/oracle/backup/cdb12c/VPWZ_PITR_TESTDB1_CDB12C/datafile/o1_mf_example_8z11kry7_.dbf deleted
auxiliary instance file /u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_sysaux_8z11jcbr_.dbf deleted
auxiliary instance file /u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_system_8z11jcbx_.dbf deleted
auxiliary instance file /u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_sysaux_8z11h875_.dbf deleted
auxiliary instance file /u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_undotbs1_8z11h87f_.dbf deleted
auxiliary instance file /u01/app/oracle/backup/cdb12c/CDB12C/datafile/o1_mf_system_8z11h87b_.dbf deleted
auxiliary instance file /u01/app/oracle/backup/cdb12c/CDB12C/controlfile/o1_mf_8z11h238_.ctl deleted
auxiliary instance file tspitr_vpwz_91117.dmp deleted
Finished recover at 25-JUL-13
TEST!
SQL> select count(*) from customers; COUNT(*) ---------- 55500
No comments:
Post a Comment