Table Point In Time Recovery (PITR) in Oracle Database 12c Release

Oracle version : 12.1.0.2.0  Enterprise Edition
OS : Rhel 6.4
Database Name : ORA12C


sqlplus soumya/soumya

SQL> create table xyz (id number);
SQL> insert into xyz values (1);
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created
SQL> commit;


SQL> SELECT * FROM xyz;

        ID
----------
         1
         1
         1
         1
         1
         1

SQL> select to_char(sysdate,'DD-MON-YYYY HH24:MI:SS') from dual;

TO_CHAR(SYSDATE,'DD-MON-YYYYH)
-----------------------------
2015-05-22:23:16:36

*Make sure that you have a valid RMAN level 0 backup to proceed.
Now lets drop the table and purge recyclebin too.

SQL> drop table xyz;

Table dropped.

SQL> purge recyclebin;

Recyclebin purged.

SQL> select * from xyz;
select * from xyz
              *
ERROR at line 1:
ORA-00942: table or view does not exist

Now We will perform the tablespace point in time recovery until the time before the table was dropped.

For TSPITR, we need to specify the auxiliary destination where RMAN would create a temporary database
by restoring the controlfile, SYSTEM tablespace, UNDO tablespace, SYSAUX tablespace and finally the
tablespace that needs to be recovered.Once the temporary database is restored and recovered, RMAN
automatically exports the contents of tablespace to be recovered from the temproary tablespace to a dump
file and imports this dump into the Target(Main) database where the table was dropped.

RMAN> RECOVER TABLE 'SOUMYA'.'XYZ' until time "to_date('2015-05-22:23:16:36','YYYY-MM:DD:HH24:MI:SS')" AUXILIARY DESTINATION '/u01'
REMAP TABLE 'SOUMYA'.'XYZ':'XYZ1_PREV';

Starting recover at 22-MAY-15
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='vkqb'

initialization parameters used for automatic instance:
db_name=ORA12C
db_unique_name=vkqb_pitr_ORA12C
compatible=12.1.0.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=600M
processes=200
db_create_file_dest=/u01
log_archive_dest_1='location=/u01'
#No auxiliary parameter file used


starting up automatic instance ORA12C

Oracle instance started

Total System Global Area     629145600 bytes

Fixed Size                     2927528 bytes
Variable Size                184550488 bytes
Database Buffers             436207616 bytes
Redo Buffers                   5459968 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2015-05-22:23:16:36','YYYY-MM:DD:HH24:MI:SS')";
# 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 22-MAY-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=22 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/backups/rman_backup/inc_level_1_cum/220515_224615/control_ORA12C_c-254883632-20150522-01
channel ORA_AUX_DISK_1: piece handle=/u01/backups/rman_backup/inc_level_1_cum/220515_224615/control_ORA12C_c-254883632-20150522-01 tag=TAG20150522T224704
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/ORA12C/controlfile/o1_mf_boyv53cn_.ctl
Finished restore at 22-MAY-15

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 "to_date('2015-05-22:23:16:36','YYYY-MM:DD:HH24:MI:SS')";
# 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 tempfile  1 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;

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

renamed tempfile 1 to /u01/ORA12C/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 22-MAY-15
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/ORA12C/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/ORA12C/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/ORA12C/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backups/rman_backup/full_backup/220515_223941/full_ORA12C_20150522_880411183_1_1
channel ORA_AUX_DISK_1: piece handle=/u01/backups/rman_backup/full_backup/220515_223941/full_ORA12C_20150522_880411183_1_1 tag=TAG20150522T223943
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:07
Finished restore at 22-MAY-15

datafile 1 switched to datafile copy
input datafile copy RECID=6 STAMP=880413765 file name=/u01/ORA12C/datafile/o1_mf_system_boyv5bb4_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=7 STAMP=880413765 file name=/u01/ORA12C/datafile/o1_mf_undotbs1_boyv5bcz_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=8 STAMP=880413765 file name=/u01/ORA12C/datafile/o1_mf_sysaux_boyv5bcp_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2015-05-22:23:16:36','YYYY-MM:DD:HH24:MI:SS')";
# 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";
# recover and open database read only
recover clone database tablespace  "SYSTEM", "UNDOTBS1", "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

Starting recover at 22-MAY-15
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting incremental datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /u01/ORA12C/datafile/o1_mf_system_boyv5bb4_.dbf
destination for restore of datafile 00004: /u01/ORA12C/datafile/o1_mf_undotbs1_boyv5bcz_.dbf
destination for restore of datafile 00003: /u01/ORA12C/datafile/o1_mf_sysaux_boyv5bcp_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backups/rman_backup/inc_level_1_cum/220515_224615/inc_level_1_cum_ORA12C_20150522_880411578_4_1
channel ORA_AUX_DISK_1: piece handle=/u01/backups/rman_backup/inc_level_1_cum/220515_224615/inc_level_1_cum_ORA12C_20150522_880411578_4_1 tag=TAG20150522T224618
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01

starting media recovery

archived log for thread 1 with sequence 46 is already on disk as file /u01/app/oracle/fast_recovery_area/1_46_877084402.dbf
archived log file name=/u01/app/oracle/fast_recovery_area/1_46_877084402.dbf thread=1 sequence=46
Executing: alter database datafile 5 offline
archived log file name=/u01/app/oracle/fast_recovery_area/1_46_877084402.dbf thread=1 sequence=46
media recovery complete, elapsed time: 00:00:01
Finished recover at 22-MAY-15

sql statement: alter database 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/ORA12C/controlfile/o1_mf_boyv53cn_.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     629145600 bytes

Fixed Size                     2927528 bytes
Variable Size                184550488 bytes
Database Buffers             436207616 bytes
Redo Buffers                   5459968 bytes

sql statement: alter system set  control_files =   ''/u01/ORA12C/controlfile/o1_mf_boyv53cn_.ctl'' comment= ''RMAN set'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     629145600 bytes

Fixed Size                     2927528 bytes
Variable Size                184550488 bytes
Database Buffers             436207616 bytes
Redo Buffers                   5459968 bytes

sql statement: alter database mount clone database

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2015-05-22:23:16:36','YYYY-MM:DD:HH24:MI:SS')";
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile  5 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  5;

switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

Starting restore at 22-MAY-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=21 device type=DISK

creating datafile file number=5 name=/u01/VKQB_PITR_ORA12C/datafile/o1_mf_testtbs_%u_.dbf
restore not done; all files read only, offline, or already restored
Finished restore at 22-MAY-15

datafile 5 switched to datafile copy
input datafile copy RECID=12 STAMP=880413824 file name=/u01/VKQB_PITR_ORA12C/datafile/o1_mf_testtbs_boyv95p7_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2015-05-22:23:16:36','YYYY-MM:DD:HH24:MI:SS')";
# online the datafiles restored or switched
sql clone "alter database datafile  5 online";
# recover and open resetlogs
recover clone database tablespace  "TESTTBS", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  5 online

Starting recover at 22-MAY-15
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 46 is already on disk as file /u01/app/oracle/fast_recovery_area/1_46_877084402.dbf
archived log file name=/u01/app/oracle/fast_recovery_area/1_46_877084402.dbf thread=1 sequence=46
media recovery complete, elapsed time: 00:00:00
Finished recover at 22-MAY-15

database opened

contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01''";
}
executing Memory Script

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01''

Performing export of tables...
   EXPDP> Starting "SYS"."TSPITR_EXP_vkqb_Dzlo":
   EXPDP> Estimate in progress using BLOCKS method...
   EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   EXPDP> Total estimation using BLOCKS method: 64 KB
   EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
   EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
   EXPDP> . . exported "SOUMYA"."XYZ"                              5.062 KB       2 rows
   EXPDP> Master table "SYS"."TSPITR_EXP_vkqb_Dzlo" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_vkqb_Dzlo is:
   EXPDP>   /u01/tspitr_vkqb_17217.dmp
   EXPDP> Job "SYS"."TSPITR_EXP_vkqb_Dzlo" successfully completed at Fri May 22 23:25:04 2015 elapsed 0 00:00:30
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_vkqb_dagD" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_vkqb_dagD":
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   IMPDP> . . imported "SOUMYA"."XYZ1_PREV"                        5.062 KB       2 rows
   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
   IMPDP> Job "SYS"."TSPITR_IMP_vkqb_dagD" successfully completed at Fri May 22 23:25:28 2015 elapsed 0 00:00:07
Import completed


Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/ORA12C/datafile/o1_mf_temp_boyv7n1j_.tmp deleted
auxiliary instance file /u01/VKQB_PITR_ORA12C/onlinelog/o1_mf_3_boyv9h6g_.log deleted
auxiliary instance file /u01/VKQB_PITR_ORA12C/onlinelog/o1_mf_2_boyv9fc9_.log deleted
auxiliary instance file /u01/VKQB_PITR_ORA12C/onlinelog/o1_mf_1_boyv9bwh_.log deleted
auxiliary instance file /u01/VKQB_PITR_ORA12C/datafile/o1_mf_testtbs_boyv95p7_.dbf deleted
auxiliary instance file /u01/ORA12C/datafile/o1_mf_sysaux_boyv5bcp_.dbf deleted
auxiliary instance file /u01/ORA12C/datafile/o1_mf_undotbs1_boyv5bcz_.dbf deleted
auxiliary instance file /u01/ORA12C/datafile/o1_mf_system_boyv5bb4_.dbf deleted
auxiliary instance file /u01/ORA12C/controlfile/o1_mf_boyv53cn_.ctl deleted
auxiliary instance file tspitr_vkqb_17217.dmp deleted
Finished recover at 22-MAY-15

[oracle@server3 bin]$ sqlplus soumya/soumya
OUMYA@ORA12C> SQL> SELECT * FROM xyz;

        ID
----------
         1
         1
         1
         1
         1
         1



Please share your ideas and opinions about this topic.

If you like this post, then please share with others.
Please subscribe on email for every updates on mail.

Nenhum comentário:

Postar um comentário

Related Posts Plugin for WordPress, Blogger...