Oracle DBA Tips and Techniques

By Arjun Raja

POINT IN TIME RECOVERY OF TABLESPACE IN PLUGGABLE DATABASE

Posted by Arjun Raja on June 11, 2014

POINT IN TIME RECOVERY OF TABLESPACE IN PLUGGABLE DATABASE

TABLESPACE TEST12C

TABLE – TEST

SQL> @loop
16 /

PL/SQL procedure successfully completed.

SQL> select count (*) from test;

COUNT(*)
———-
10000

SQL>

SQL> select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER
————————
2936965

Now add another 10,000 rows…

@loop.sql

SQL> select count (*) from test;

COUNT(*)
———-
20000

SQL>

Now remove datafile of tablespace test to simulate failure

rm /u02/oradata/cdbd1/pdb1d1/test12c01.dbf

Try updating table :

cdbd1:/u01/oracle/scripts> sqlplus sys/Oracle12c@pdb1d1 as sysdba

SQL*Plus: Release 12.1.0.1.0 xroduction on Fri May 9 13:41:40 2014

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 – 64bit xroduction
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> @loop
16 /
declare
*
ERROR at line 1:
ORA-01116: error in opening database file 12
ORA-01110: data file 12: ‘/u02/oradata/cdbd1/pdb1d1/test12c01.dbf’
ORA-27041: unable to open file
IBM AIX RISC System/6000 Error: 2: No such file or directory
Additional information: 3
Additional information: 4
Additional information: 4194304
ORA-06512: at line 7

SQL>

Now restore and recover tablespace to SCN 2936965 – Total rows must be 10,000 once recovery is complete.

Login to Pluggable Database as sysdba

sqlplus sys/Oracle12c@pdb1d1 as sysdba

SQL> alter tablespace test12c offline immediate;

Tablespace altered.

SQL>

Next Login to CDB ROOT.

cdbd1:/u01/oracle/scripts> rman target /

Recovery Manager: Release 12.1.0.1.0 – xroduction on Fri May 9 14:09:09 2014

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

connected to target database: CDBD1 (DBID=2264962255)

RMAN> RUN {
RECOVER TABLESPACE PDB1D1:TEST12C
UNTIL SCN 2936965
AUXILIARY DESTINATION ‘/u01/oracle/scripts’;
}2> 3> 4> 5>

Starting recover at 09-05-2014 14:09:13
using target database control file instead of recovery catalog
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=21 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=132 device type=DISK
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=’aDbn’

initialization parameters used for automatic instance:
db_name=CDBD1
db_unique_name=aDbn_pitr_PDB1D1_CDBD1
compatible=12.1.0.0.0
db_block_size=8192
db_files=200
sga_target=1G
processes=80
diagnostic_dest=/u01/oracle
db_create_file_dest=/u01/oracle/scripts
log_archive_dest_1=’location=/u01/oracle/scripts’
enable_pluggable_database=true
_clone_one_pdb_recovery=true
#No auxiliary parameter file used

starting up automatic instance CDBD1

Oracle instance started

Total System Global Area 1068937216 bytes

Fixed Size 2368400 bytes
Variable Size 293604464 bytes
Database Buffers 767557632 bytes
Redo Buffers 5406720 bytes
Automatic instance created
Running TRANSPORT_SET_CHECK on recovery set tablespaces
TRANSPORT_SET_CHECK completed successfully

contents of Memory Script:
{
# set requested point in time
set until scn 2936965;
# 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 09-05-2014 14:09:45
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=79 device type=DISK
allocated channel: ORA_AUX_DISK_2
channel ORA_AUX_DISK_2: SID=109 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 /u03/oradata/fast_recovery_area/CDBD1/autobackup/2014_05_09/o1_mf_s_847115717_9prvg5m6_.bkp
channel ORA_AUX_DISK_1: piece handle=/u03/oradata/fast_recovery_area/CDBD1/autobackup/2014_05_09/o1_mf_s_847115717_9prvg5m6_.bkp tag=TAG20140509T135517
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/oracle/scripts/CDBD1/controlfile/o1_mf_9prw9brw_.ctl
Finished restore at 09-05-2014 14:09:47

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 2936965;
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile 1 to new;
set newname for clone datafile 5 to new;
set newname for clone datafile 3 to new;
set newname for clone datafile 10 to new;
set newname for clone datafile 11 to new;
set newname for clone tempfile 1 to new;
set newname for clone tempfile 3 to new;
set newname for datafile 12 to
“/u02/oradata/cdbd1/pdb1d1/test12c01.dbf”;
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 1, 5, 3, 10, 11, 12;
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

executing command: SET NEWNAME

renamed tempfile 1 to /u01/oracle/scripts/CDBD1/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 3 to /u01/oracle/scripts/CDBD1/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 09-05-2014 14:09:53
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2

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 00005 to /u01/oracle/scripts/CDBD1/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u03/oradata/fast_recovery_area/CDBD1/backupset/2014_05_09/o1_mf_nnndf_TAG20140509T110516_9prkhh55_.bkp
channel ORA_AUX_DISK_2: starting datafile backup set restore
channel ORA_AUX_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_2: restoring datafile 00001 to /u01/oracle/scripts/CDBD1/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_2: reading from backup piece /u03/oradata/fast_recovery_area/CDBD1/backupset/2014_05_09/o1_mf_nnndf_TAG20140509T110516_9prkkw9b_.bkp
channel ORA_AUX_DISK_1: piece handle=/u03/oradata/fast_recovery_area/CDBD1/backupset/2014_05_09/o1_mf_nnndf_TAG20140509T110516_9prkhh55_.bkp tag=TAG20140509T110516
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
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 00010 to /u01/oracle/scripts/CDBD1/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00011 to /u01/oracle/scripts/CDBD1/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u03/oradata/fast_recovery_area/CDBD1/F8EEE24DA36C006AE0430AFECB4C494F/backupset/2014_05_09/o1_mf_nnndf_TAG20140509T111533_9prl2p47_.bkp
channel ORA_AUX_DISK_1: piece handle=/u03/oradata/fast_recovery_area/CDBD1/F8EEE24DA36C006AE0430AFECB4C494F/backupset/2014_05_09/o1_mf_nnndf_TAG20140509T111533_9prl2p47_.bkp tag=TAG20140509T111533
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:55
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 00012 to /u02/oradata/cdbd1/pdb1d1/test12c01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u03/oradata/fast_recovery_area/CDBD1/F8EEE24DA36C006AE0430AFECB4C494F/backupset/2014_05_09/o1_mf_nnndf_TAG20140509T125811_9prr33yd_.bkp
channel ORA_AUX_DISK_2: piece handle=/u03/oradata/fast_recovery_area/CDBD1/backupset/2014_05_09/o1_mf_nnndf_TAG20140509T110516_9prkkw9b_.bkp tag=TAG20140509T110516
channel ORA_AUX_DISK_2: restored backup piece 1
channel ORA_AUX_DISK_2: restore complete, elapsed time: 00:01:02
channel ORA_AUX_DISK_2: starting datafile backup set restore
channel ORA_AUX_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_2: restoring datafile 00003 to /u01/oracle/scripts/CDBD1/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_2: reading from backup piece /u03/oradata/fast_recovery_area/CDBD1/backupset/2014_05_09/o1_mf_nnndf_TAG20140509T125811_9prr33xx_.bkp
channel ORA_AUX_DISK_1: piece handle=/u03/oradata/fast_recovery_area/CDBD1/F8EEE24DA36C006AE0430AFECB4C494F/backupset/2014_05_09/o1_mf_nnndf_TAG20140509T125811_9prr33yd_.bkp tag=TAG20140509T125811
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_2: piece handle=/u03/oradata/fast_recovery_area/CDBD1/backupset/2014_05_09/o1_mf_nnndf_TAG20140509T125811_9prr33xx_.bkp tag=TAG20140509T125811
channel ORA_AUX_DISK_2: restored backup piece 1
channel ORA_AUX_DISK_2: restore complete, elapsed time: 00:01:05
Finished restore at 09-05-2014 14:12:01

datafile 1 switched to datafile copy
input datafile copy RECID=6 STAMP=847116721 file name=/u01/oracle/scripts/CDBD1/datafile/o1_mf_system_9prw9l5t_.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=7 STAMP=847116721 file name=/u01/oracle/scripts/CDBD1/datafile/o1_mf_undotbs1_9prw9l8m_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=8 STAMP=847116721 file name=/u01/oracle/scripts/CDBD1/datafile/o1_mf_sysaux_9prwcjs1_.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=9 STAMP=847116721 file name=/u01/oracle/scripts/CDBD1/datafile/o1_mf_system_9prw9so4_.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=10 STAMP=847116721 file name=/u01/oracle/scripts/CDBD1/datafile/o1_mf_sysaux_9prw9sgr_.dbf

contents of Memory Script:
{
# set requested point in time
set until scn 2936965;
# online the datafiles restored or switched
sql clone “alter database datafile 1 online”;
sql clone “alter database datafile 5 online”;
sql clone “alter database datafile 3 online”;
sql clone ‘PDB1D1’ “alter database datafile
10 online”;
sql clone ‘PDB1D1’ “alter database datafile
11 online”;
sql clone ‘PDB1D1’ “alter database datafile
12 online”;
# recover and open resetlogs
recover clone database tablespace “PDB1D1″:”TEST12C”, “SYSTEM”, “UNDOTBS1”, “SYSAUX”, “PDB1D1″:”SYSTEM”, “PDB1D1″:”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 5 online

sql statement: alter database datafile 3 online

sql statement: alter database datafile 10 online

sql statement: alter database datafile 11 online

sql statement: alter database datafile 12 online

Starting recover at 09-05-2014 14:12:02
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2

starting media recovery

archived log for thread 1 with sequence 202 is already on disk as file /u03/oradata/fast_recovery_area/CDBD1/archivelog/2014_05_09/o1_mf_1_202_9prkt4dm_.arc
archived log for thread 1 with sequence 203 is already on disk as file /u03/oradata/fast_recovery_area/CDBD1/archivelog/2014_05_09/o1_mf_1_203_9prky8qq_.arc
archived log for thread 1 with sequence 204 is already on disk as file /u03/oradata/fast_recovery_area/CDBD1/archivelog/2014_05_09/o1_mf_1_204_9prt0qxj_.arc
archived log for thread 1 with sequence 205 is already on disk as file /u03/oradata/fast_recovery_area/CDBD1/archivelog/2014_05_09/o1_mf_1_205_9prw8c8k_.arc
archived log file name=/u03/oradata/fast_recovery_area/CDBD1/archivelog/2014_05_09/o1_mf_1_202_9prkt4dm_.arc thread=1 sequence=202
archived log file name=/u03/oradata/fast_recovery_area/CDBD1/archivelog/2014_05_09/o1_mf_1_203_9prky8qq_.arc thread=1 sequence=203
archived log file name=/u03/oradata/fast_recovery_area/CDBD1/archivelog/2014_05_09/o1_mf_1_204_9prt0qxj_.arc thread=1 sequence=204
archived log file name=/u03/oradata/fast_recovery_area/CDBD1/archivelog/2014_05_09/o1_mf_1_205_9prw8c8k_.arc thread=1 sequence=205
media recovery complete, elapsed time: 00:00:03
Finished recover at 09-05-2014 14:12:07

database opened

contents of Memory Script:
{
sql clone ‘alter pluggable database PDB1D1 open’;
}
executing Memory Script

sql statement: alter pluggable database PDB1D1 open

contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone ‘PDB1D1’ ‘alter tablespace
TEST12C read only’;
# create directory for datapump import
sql ‘PDB1D1’ “create or replace directory
TSPITR_DIROBJ_DPDIR as ”
/u01/oracle/scripts””;
# create directory for datapump export
sql clone ‘PDB1D1’ “create or replace directory
TSPITR_DIROBJ_DPDIR as ”
/u01/oracle/scripts””;
}
executing Memory Script

sql statement: alter tablespace TEST12C read only

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ”/u01/oracle/scripts”

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ”/u01/oracle/scripts”

Performing export of metadata…
EXPDP> Starting “SYS”.”TSPITR_EXP_aDbn_atdu”:
EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
EXPDP> Processing object type TRANSPORTABLE_EXPORT/STATISTICS/MARKER
EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
EXPDP> Master table “SYS”.”TSPITR_EXP_aDbn_atdu” successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_aDbn_atdu is:
EXPDP> /u01/oracle/scripts/tspitr_aDbn_27853.dmp
EXPDP> ******************************************************************************
EXPDP> Datafiles required for transportable tablespace TEST12C:
EXPDP> /u02/oradata/cdbd1/pdb1d1/test12c01.dbf
EXPDP> Job “SYS”.”TSPITR_EXP_aDbn_atdu” successfully completed at Fri May 9 14:13:49 2014 elapsed 0 00:01:05
Export completed

contents of Memory Script:
{
# shutdown clone before import
shutdown clone abort
# drop target tablespaces before importing them back
sql ‘PDB1D1’ ‘drop tablespace
TEST12C including contents keep datafiles cascade constraints’;
}
executing Memory Script

Oracle instance shut down

sql statement: drop tablespace TEST12C including contents keep datafiles cascade constraints

Performing import of metadata…
IMPDP> Master table “SYS”.”TSPITR_IMP_aDbn_anil” successfully loaded/unloaded
IMPDP> Starting “SYS”.”TSPITR_IMP_aDbn_anil”:
IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
IMPDP> Processing object type TRANSPORTABLE_EXPORT/STATISTICS/MARKER
IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
IMPDP> Job “SYS”.”TSPITR_IMP_aDbn_anil” successfully completed at Fri May 9 14:14:52 2014 elapsed 0 00:00:35
Import completed

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

sql statement: alter tablespace TEST12C read write

sql statement: alter tablespace TEST12C offline

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

Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/oracle/scripts/CDBD1/datafile/o1_mf_temp_9prwg2o4_.tmp deleted
auxiliary instance file /u01/oracle/scripts/CDBD1/datafile/o1_mf_temp_9prwft77_.tmp deleted
auxiliary instance file /u01/oracle/scripts/CDBD1/onlinelog/o1_mf_3_9prwfrg6_.log deleted
auxiliary instance file /u01/oracle/scripts/CDBD1/onlinelog/o1_mf_2_9prwfr42_.log deleted
auxiliary instance file /u01/oracle/scripts/CDBD1/onlinelog/o1_mf_1_9prwfqs5_.log deleted
auxiliary instance file /u01/oracle/scripts/CDBD1/datafile/o1_mf_sysaux_9prw9sgr_.dbf deleted
auxiliary instance file /u01/oracle/scripts/CDBD1/datafile/o1_mf_system_9prw9so4_.dbf deleted
auxiliary instance file /u01/oracle/scripts/CDBD1/datafile/o1_mf_sysaux_9prwcjs1_.dbf deleted
auxiliary instance file /u01/oracle/scripts/CDBD1/datafile/o1_mf_undotbs1_9prw9l8m_.dbf deleted
auxiliary instance file /u01/oracle/scripts/CDBD1/datafile/o1_mf_system_9prw9l5t_.dbf deleted
auxiliary instance file /u01/oracle/scripts/CDBD1/controlfile/o1_mf_9prw9brw_.ctl deleted
auxiliary instance file tspitr_aDbn_27853.dmp deleted
Finished recover at 09-05-2014 14:14:56

RMAN> exit

Recovery Manager complete.

Now bring the tablespace online by logging into the Pluggable database as sysdba

cdbd1:/u01/oracle/scripts> sqlplus sys/Oracle12c@pdb1d1 as sysdba

SQL> ALTER TABLESPACE TEST12C ONLINE;

Tablespace altered.

SQL> select count (*) from test;

COUNT(*)
———-
10000

SQL>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: