In sweet memories of my ever loving brother "kutty thambi " ARUN KUMAR

Monday, August 8, 2011

RMAN Tablespace Point-in-Time Recovery (TSPITR) 11gR2 Enhancements

One of the good new features in 11g Release 2 is that it enables us to recover from a case of a dropped tablespace. TSPITR (tablespace point in time recovery) has been around in earlier releases, but we could not recover a dropped tablespace.

here is an demo for your reference

  

22:33:43 SQL> select file_name,tablespace_name from dba_data_files;

FILE_NAME TABLESPACE_NAME
-------------------------------------------------------- ---------------
/u01/app/oracle/db2/users01.dbf USERS
/u01/app/oracle/db2/undotbs01.dbf UNDOTBS1
/u01/app/oracle/db2/sysaux01.dbf SYSAUX
/u01/app/oracle/db2/system01.dbf SYSTEM

22:33:52 SQL> create tablespace newtbs1 datafile '/u01/app/oracle/db2/newtbs01.dbf' size 10m;

Tablespace created.

22:34:31 SQL> create user shyam identified by shyam default tablespace newtbs1;

User created.

22:35:24 SQL> grant connect,resource to shyam;

Grant succeeded.

22:35:57 SQL> conn shyam/shyam
Connected.
22:36:16 SQL> create table tb1 ( id number);

Table created.

22:36:26 SQL> insert into tb1 values (123);

1 row created.

Commit complete.
22:36:41 SQL> create table tb2 ( id number);

Table created.

22:37:01 SQL> insert into tb2 values (234);

1 row created.

Commit complete.
22:37:14 SQL> select * from tab;

TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
TB1 TABLE
TB2 TABLE


22:37:20 SQL> conn / as sysdba
Connected.
22:38:16 SQL> alter system switch logfile;

System altered.

22:38:33 SQL> select current_scn from v$database;

CURRENT_SCN
-----------
799576

[oracle@node2 backupnew]$ . oraenv
ORACLE_SID = [db2] ?
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 is /u01/app/oracle
[oracle@node2 backupnew]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Sun Aug 7 22:39:17 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

connected to target database: DB2 (DBID=1922019997)

RMAN> backup as compressed backupset database format '/u01/app/oracle/backup/backupnew/%d_%s_%I_%T' plus archivelog format '/u01/app/oracle/backup/backupnew/%d_%s_%I_

%T';


Starting backup at 07-AUG-11
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=55 device type=DISK
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=3 RECID=1 STAMP=758566663
input archived log thread=1 sequence=4 RECID=2 STAMP=758566818
input archived log thread=1 sequence=5 RECID=3 STAMP=758566872
input archived log thread=1 sequence=6 RECID=4 STAMP=758574317
input archived log thread=1 sequence=7 RECID=5 STAMP=758574431
input archived log thread=1 sequence=8 RECID=6 STAMP=758574724
input archived log thread=1 sequence=9 RECID=7 STAMP=758575149
input archived log thread=1 sequence=10 RECID=8 STAMP=758575987
input archived log thread=1 sequence=11 RECID=9 STAMP=758581906
input archived log thread=1 sequence=12 RECID=10 STAMP=758581906
input archived log thread=1 sequence=13 RECID=11 STAMP=758582156
input archived log thread=1 sequence=14 RECID=12 STAMP=758582234
input archived log thread=1 sequence=15 RECID=13 STAMP=758582326
input archived log thread=1 sequence=16 RECID=14 STAMP=758582432
input archived log thread=1 sequence=17 RECID=15 STAMP=758582528
input archived log thread=1 sequence=18 RECID=16 STAMP=758582961
input archived log thread=1 sequence=19 RECID=17 STAMP=758584593
input archived log thread=1 sequence=20 RECID=18 STAMP=758587114
input archived log thread=1 sequence=21 RECID=19 STAMP=758587224
channel ORA_DISK_1: starting piece 1 at 07-AUG-11
channel ORA_DISK_1: finished piece 1 at 07-AUG-11
piece handle=/u01/app/oracle/backup/backupnew/DB2_22_1922019997_20110807 tag=TAG20110807T224025 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 07-AUG-11

Starting backup at 07-AUG-11
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/db2/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/db2/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/db2/undotbs01.dbf
input datafile file number=00005 name=/u01/app/oracle/db2/newtbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/db2/users01.dbf
channel ORA_DISK_1: starting piece 1 at 07-AUG-11
channel ORA_DISK_1: finished piece 1 at 07-AUG-11
piece handle=/u01/app/oracle/backup/backupnew/DB2_23_1922019997_20110807 tag=TAG20110807T224041 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:45
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 07-AUG-11
channel ORA_DISK_1: finished piece 1 at 07-AUG-11
piece handle=/u01/app/oracle/backup/backupnew/DB2_24_1922019997_20110807 tag=TAG20110807T224041 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-AUG-11

Starting backup at 07-AUG-11
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=22 RECID=20 STAMP=758587349
channel ORA_DISK_1: starting piece 1 at 07-AUG-11
channel ORA_DISK_1: finished piece 1 at 07-AUG-11
piece handle=/u01/app/oracle/backup/backupnew/DB2_25_1922019997_20110807 tag=TAG20110807T224229 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-AUG-11

RMAN> exit


Recovery Manager complete.
[oracle@node2 backupnew]$

22:38:46 SQL> conn shyam/shyam
Connected.
22:43:37 SQL> create table tb3 (id number);

Table created.

22:47:33 SQL> insert into tb3 values(123);

1 row created.

Commit complete.
22:48:27 SQL> select * from tb3;

ID
----------
123

22:48:37 SQL> conn / as sysdba
Connected.
22:48:47 SQL> alter system switch logfile;

System altered.

22:48:54 SQL> select current_scn from v$database;

CURRENT_SCN
-----------
800205

22:49:06 SQL>


22:50:14 SQL> drop tablespace newtbs1 including contents and datafiles;

Tablespace dropped.

22:51:06 SQL>


RMAN> recover tablespace newtbs1 until scn 800205 auxiliary destination '/u01/app/oracle/backup/backupnew';

Starting recover at 07-AUG-11
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='Aunx'

initialization parameters used for automatic instance:
db_name=DB2
db_unique_name=Aunx_tspitr_DB2
compatible=11.2.0.0.0
db_block_size=8192
db_files=200
sga_target=280M
processes=50
db_create_file_dest=/u01/app/oracle/backup/backupnew
log_archive_dest_1='location=/u01/app/oracle/backup/backupnew'
#No auxiliary parameter file used


starting up automatic instance DB2

Oracle instance started

Total System Global Area 292933632 bytes

Fixed Size 1336092 bytes
Variable Size 100666596 bytes
Database Buffers 184549376 bytes
Redo Buffers 6381568 bytes
Automatic instance created


List of tablespaces that have been dropped from the target database:
Tablespace newtbs1

contents of Memory Script:
{
# set requested point in time
set until scn 800205;
# 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';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
}
executing Memory Script

executing command: SET until clause

Starting restore at 07-AUG-11
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=25 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/backup/backupnew/DB2_24_1922019997_20110807
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/backup/backupnew/DB2_24_1922019997_20110807 tag=TAG20110807T224041
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/backupnew/DB2/controlfile/o1_mf_73xmbtfc_.ctl
Finished restore at 07-AUG-11

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

contents of Memory Script:
{
# set requested point in time
set until scn 800205;
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile 1 to new;
set newname for clone datafile 3 to new;
set newname for clone datafile 2 to new;
set newname for clone tempfile 1 to new;
set newname for datafile 5 to
"/u01/app/oracle/db2/newtbs01.dbf";
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 1, 3, 2, 5;
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

renamed tempfile 1 to /u01/app/oracle/backup/backupnew/DB2/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 07-AUG-11
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/backupnew/DB2/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/backup/backupnew/DB2/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/backup/backupnew/DB2/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/db2/newtbs01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/backup/backupnew/DB2_23_1922019997_20110807
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/backup/backupnew/DB2_23_1922019997_20110807 tag=TAG20110807T224041
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:45
Finished restore at 07-AUG-11

datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=758588962 file name=/u01/app/oracle/backup/backupnew/DB2/datafile/o1_mf_system_73xmc12w_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=758588962 file name=/u01/app/oracle/backup/backupnew/DB2/datafile/o1_mf_undotbs1_73xmc148_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=758588962 file name=/u01/app/oracle/backup/backupnew/DB2/datafile/o1_mf_sysaux_73xmc13r_.dbf

contents of Memory Script:
{
# set requested point in time
set until scn 800205;
# online the datafiles restored or switched
sql clone "alter database datafile 1 online";
sql clone "alter database datafile 3 online";
sql clone "alter database datafile 2 online";
sql clone "alter database datafile 5 online";
# recover and open resetlogs
recover clone database tablespace "NEWTBS1", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile 1 online

sql statement: alter database datafile 3 online

sql statement: alter database datafile 2 online

sql statement: alter database datafile 5 online

Starting recover at 07-AUG-11
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 22 is already on disk as file /u01/app/oracle/flash_recovery_area/DB2/archivelog/2011_08_07/o1_mf_1_22_73xkvxsz_.arc
archived log for thread 1 with sequence 23 is already on disk as file /u01/app/oracle/flash_recovery_area/DB2/archivelog/2011_08_07/o1_mf_1_23_73xl7yvr_.arc
archived log for thread 1 with sequence 24 is already on disk as file /u01/app/oracle/flash_recovery_area/DB2/archivelog/2011_08_07/o1_mf_1_24_73xlmfdj_.arc
archived log file name=/u01/app/oracle/flash_recovery_area/DB2/archivelog/2011_08_07/o1_mf_1_22_73xkvxsz_.arc thread=1 sequence=22
archived log file name=/u01/app/oracle/flash_recovery_area/DB2/archivelog/2011_08_07/o1_mf_1_23_73xl7yvr_.arc thread=1 sequence=23
archived log file name=/u01/app/oracle/flash_recovery_area/DB2/archivelog/2011_08_07/o1_mf_1_24_73xlmfdj_.arc thread=1 sequence=24
media recovery complete, elapsed time: 00:00:03
Finished recover at 07-AUG-11

database opened

contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'alter tablespace NEWTBS1 read only';
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01/app/oracle/backup/backupnew''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01/app/oracle/backup/backupnew''";
}
executing Memory Script

sql statement: alter tablespace NEWTBS1 read only

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/app/oracle/backup/backupnew''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/app/oracle/backup/backupnew''

Performing export of metadata...
EXPDP> Starting "SYS"."TSPITR_EXP_Aunx":
EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
EXPDP> Master table "SYS"."TSPITR_EXP_Aunx" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_Aunx is:
EXPDP> /u01/app/oracle/backup/backupnew/tspitr_Aunx_72915.dmp
EXPDP> ******************************************************************************
EXPDP> Datafiles required for transportable tablespace NEWTBS1:
EXPDP> /u01/app/oracle/db2/newtbs01.dbf
EXPDP> Job "SYS"."TSPITR_EXP_Aunx" successfully completed at 23:11:06
Export completed


contents of Memory Script:
{
# shutdown clone before import
shutdown clone immediate
}
executing Memory Script

database closed
database dismounted
Oracle instance shut down

Performing import of metadata...
IMPDP> Master table "SYS"."TSPITR_IMP_Aunx" successfully loaded/unloaded
IMPDP> Starting "SYS"."TSPITR_IMP_Aunx":
IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
IMPDP> Job "SYS"."TSPITR_IMP_Aunx" successfully completed at 23:11:35
Import completed


contents of Memory Script:
{
# make read write and offline the imported tablespaces
sql 'alter tablespace NEWTBS1 read write';
sql 'alter tablespace NEWTBS1 offline';
# enable autobackups after TSPITR is finished
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script

sql statement: alter tablespace NEWTBS1 read write

sql statement: alter tablespace NEWTBS1 offline

sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/app/oracle/backup/backupnew/DB2/datafile/o1_mf_temp_73xmgrpk_.tmp deleted
auxiliary instance file /u01/app/oracle/backup/backupnew/DB2/onlinelog/o1_mf_3_73xmglwq_.log deleted
auxiliary instance file /u01/app/oracle/backup/backupnew/DB2/onlinelog/o1_mf_2_73xmgk7t_.log deleted
auxiliary instance file /u01/app/oracle/backup/backupnew/DB2/onlinelog/o1_mf_1_73xmghq1_.log deleted
auxiliary instance file /u01/app/oracle/backup/backupnew/DB2/datafile/o1_mf_sysaux_73xmc13r_.dbf deleted
auxiliary instance file /u01/app/oracle/backup/backupnew/DB2/datafile/o1_mf_undotbs1_73xmc148_.dbf deleted
auxiliary instance file /u01/app/oracle/backup/backupnew/DB2/datafile/o1_mf_system_73xmc12w_.dbf deleted
auxiliary instance file /u01/app/oracle/backup/backupnew/DB2/controlfile/o1_mf_73xmbtfc_.ctl deleted
Finished recover at 07-AUG-11

RMAN>



23:14:57 SQL> select file_name,tablespace_name from dba_data_files;

FILE_NAME TABLESPACE_NAME
-------------------------------------------------------- ---------------
/u01/app/oracle/db2/users01.dbf USERS
/u01/app/oracle/db2/undotbs01.dbf UNDOTBS1
/u01/app/oracle/db2/sysaux01.dbf SYSAUX
/u01/app/oracle/db2/system01.dbf SYSTEM
/u01/app/oracle/db2/newtbs01.dbf NEWTBS1


SQL> alter tablespace newtbs1 online;

Tablespace altered.


23:15:28 SQL> conn shyam/shyam
Connected.
23:15:54 SQL> select * from tab;

TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
TB1 TABLE
TB2 TABLE
TB3 TABLE




2 comments:

Ram said...

Raj Nice Article. How come it recovers TB3 since you have created that table after the backup ?

Anonymous said...

Hi Ram,
After the backup is restored, the archives will be applied, and the other objects which were not present in the backup they will also be recovered.....

 
Share/Bookmark