Recover Pluggable Database

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/12c/r1/pdb/pdb_pitr/pdb_pitr.html
https://oracle-base.com/articles/12c/multitenant-rman-backup-recovery-cdb-and-pdb-12cr1#pdb-recovery

Tested on:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Advanced Analytics
and Real Application Testing options


1.) Simulating some erros on PDB1:

 select name, open_mode from v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB1                           MOUNTED
PDB3                           MOUNTED

alter pluggable database all open;

Pluggable database altered.

select name, open_mode from v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB1                           READ WRITE
PDB3                           READ WRITE

alter session set container=pdb1;

 select tablespace_name from dba_tablespaces;

TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
TEMP


create tablespace ts_pdb1 datafile '/oracle/oradata/CDB/pdb1/ts_pdb1.dbf' size 10m;

Tablespace created.

alter user test default tablespace ts_pdb1;

User altered.

alter user test quota unlimited on ts_pdb1;

User altered.

--> To connect directly on PDB:

alter system set local_listener='lnx01:1521' scope=both;

select con_id, name, open_mode from v$pdbs;

              CON_ID NAME                           OPEN_MODE
-------------------- ------------------------------ ----------
                   2 PDB$SEED                       READ ONLY
                   3 PDB1                           READ WRITE <===
                   5 PDB3                           READ WRITE

 conn test/test@pdb1
Connected.

show con_id

CON_ID
------------------------------
3

insert into t1 values (1,to_char(sysdate,'ddmmyyyy-hh24miss'));
insert into t1 values (2,to_char(sysdate,'ddmmyyyy-hh24miss'));
insert into t1 values (3,to_char(sysdate,'ddmmyyyy-hh24miss'));

commit;
        
select scn from v$database;

 select CURRENT_SCN from v$database;

         CURRENT_SCN
--------------------
             2058379
             
insert into TEST.t1 values (4,'AFTER SCN 2058379');

commit;

 SELECT * FROM TEST.T1;

                 NUM TEXT
-------------------- ---------------------
                   1 06032016-141735
                   2 06032016-141735
                   3 06032016-141735
                   4 AFTER SCN 2058379


2.) Listing backups:

RMAN> LIST BACKUP OF PLUGGABLE DATABASE PDB1;

using target database control file instead of recovery catalog

List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
22      Full    603.45M    DISK        00:00:04     06-MAR-16
        BP Key: 22   Status: AVAILABLE  Compressed: NO  Tag: TAG20160306T132621
        Piece Name: /data02/backup/CDB/CDB_0mqvq6cc_1_1
  List of Datafiles in backup set 22
  Container ID: 3, PDB Name: PDB1
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  16      Full 2053591    06-MAR-16 /oracle/oradata/CDB/pdb1/system01.dbf
  17      Full 2053591    06-MAR-16 /oracle/oradata/CDB/pdb1/sysaux01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
27      Full    603.45M    DISK        00:00:04     06-MAR-16
        BP Key: 27   Status: AVAILABLE  Compressed: NO  Tag: TAG20160306T133029
        Piece Name: /data02/backup/CDB/CDB_0rqvq6jl_1_1
  List of Datafiles in backup set 27
  Container ID: 3, PDB Name: PDB1
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  16      Full 2053591    06-MAR-16 /oracle/oradata/CDB/pdb1/system01.dbf
  17      Full 2053591    06-MAR-16 /oracle/oradata/CDB/pdb1/sysaux01.dbf

  
--> Please note that SCN from Backup is lower than desired SCN:

3.) Recover PDB1 until  scn: 2058379

 show con_id

CON_ID
------------------------------
3


shut immediate;

Pluggable Database closed.

 show con_id
 
CON_ID
------------------------------
1

select name, con_id, open_mode from v$pdbs;

NAME                                         CON_ID OPEN_MODE
------------------------------ -------------------- ----------
PDB$SEED                                          2 READ ONLY
PDB1                                              3 MOUNTED
PDB3                                              5 READ WRITE

rman target /

RUN {
  SET UNTIL scn 2058379;
  RESTORE PLUGGABLE DATABASE pdb1;
  RECOVER PLUGGABLE DATABASE pdb1;
  ALTER PLUGGABLE DATABASE pdb1 OPEN RESETLOGS;
}

                2> 3> 4> 5> 6>
executing command: SET until clause

Starting restore at 06-MAR-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=27 device type=DISK

creating datafile file number=20 name=/oracle/oradata/CDB/pdb1/ts_pdb1.dbf
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00016 to /oracle/oradata/CDB/pdb1/system01.dbf
channel ORA_DISK_1: restoring datafile 00017 to /oracle/oradata/CDB/pdb1/sysaux01.dbf
channel ORA_DISK_1: reading from backup piece /data02/backup/CDB/CDB_0rqvq6jl_1_1
channel ORA_DISK_1: piece handle=/data02/backup/CDB/CDB_0rqvq6jl_1_1 tag=TAG20160306T133029
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 06-MAR-16

Starting recover at 06-MAR-16
current log archived
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='ecby'

initialization parameters used for automatic instance:
db_name=CDB
db_unique_name=ecby_pitr_pdb1_CDB
compatible=12.1.0.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/oracle
_system_trig_enabled=FALSE
sga_target=800M
processes=200
#No auxiliary destination in use
enable_pluggable_database=true
_clone_one_pdb_recovery=true
control_files=/oracle/fast_recovery_area/CDB/controlfile/o1_mf_cfs13q8s_.ctl
#No auxiliary parameter file used


starting up automatic instance CDB

Oracle instance started

Total System Global Area     838860800 bytes

Fixed Size                     2929936 bytes
Variable Size                230689520 bytes
Database Buffers             599785472 bytes
Redo Buffers                   5455872 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until  scn 2058379;
# restore the controlfile
restore clone controlfile;

# mount the controlfile
sql clone 'alter database mount clone database';
}
executing Memory Script

executing command: SET until clause

Starting restore at 06-MAR-16
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=12 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 /oracle/fast_recovery_area/CDB/autobackup/2016_03_06/o1_mf_s_905781318_cfrz8pqp_.bkp
channel ORA_AUX_DISK_1: piece handle=/oracle/fast_recovery_area/CDB/autobackup/2016_03_06/o1_mf_s_905781318_cfrz8pqp_.bkp tag=TAG20160306T135518
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/oracle/fast_recovery_area/CDB/controlfile/o1_mf_cfs13q8s_.ctl
Finished restore at 06-MAR-16

sql statement: alter database mount clone database

contents of Memory Script:
{
# set requested point in time
set until  scn 2058379;
# switch to valid datafilecopies
switch clone datafile  16 to datafilecopy
 "/oracle/oradata/CDB/pdb1/system01.dbf";
switch clone datafile  17 to datafilecopy
 "/oracle/oradata/CDB/pdb1/sysaux01.dbf";
switch clone datafile  20 to datafilecopy
 "/oracle/oradata/CDB/pdb1/ts_pdb1.dbf";
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile  1 to
 "/oracle/fast_recovery_area/CDB/datafile/o1_mf_system_cfs140md_.dbf";
set newname for datafile  4 to
 "/oracle/fast_recovery_area/CDB/datafile/o1_mf_undotbs1_cfs140n4_.dbf";
set newname for datafile  3 to
 "/oracle/fast_recovery_area/CDB/datafile/o1_mf_sysaux_cfs140n9_.dbf";
set newname for datafile  6 to
 "/oracle/fast_recovery_area/CDB/datafile/o1_mf_users_cfs149f8_.dbf";
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 4, 3, 6;

switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

datafile 16 switched to datafile copy
input datafile copy RECID=4 STAMP=905783225 file name=/oracle/oradata/CDB/pdb1/system01.dbf

datafile 17 switched to datafile copy
input datafile copy RECID=5 STAMP=905783225 file name=/oracle/oradata/CDB/pdb1/sysaux01.dbf

datafile 20 switched to datafile copy
input datafile copy RECID=6 STAMP=905783225 file name=/oracle/oradata/CDB/pdb1/ts_pdb1.dbf

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 06-MAR-16
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 /oracle/fast_recovery_area/CDB/datafile/o1_mf_system_cfs140md_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /oracle/fast_recovery_area/CDB/datafile/o1_mf_undotbs1_cfs140n4_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /oracle/fast_recovery_area/CDB/datafile/o1_mf_sysaux_cfs140n9_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /oracle/fast_recovery_area/CDB/datafile/o1_mf_users_cfs149f8_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /data02/backup/CDB/CDB_0lqvq6bt_1_1
channel ORA_AUX_DISK_1: piece handle=/data02/backup/CDB/CDB_0lqvq6bt_1_1 tag=TAG20160306T132621
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 06-MAR-16

datafile 1 switched to datafile copy
input datafile copy RECID=11 STAMP=905783240 file name=/oracle/fast_recovery_area/CDB/datafile/o1_mf_system_cfs140md_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=12 STAMP=905783240 file name=/oracle/fast_recovery_area/CDB/datafile/o1_mf_undotbs1_cfs140n4_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=13 STAMP=905783240 file name=/oracle/fast_recovery_area/CDB/datafile/o1_mf_sysaux_cfs140n9_.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=14 STAMP=905783241 file name=/oracle/fast_recovery_area/CDB/datafile/o1_mf_users_cfs149f8_.dbf

contents of Memory Script:
{
# set requested point in time
set until  scn 2058379;
# 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 'PDB1' "alter database datafile
 16 online";
sql clone 'PDB1' "alter database datafile
 17 online";
sql clone 'PDB1' "alter database datafile
 20 online";
sql clone "alter database datafile  6 online";
# recover pdb
recover clone database tablespace  "SYSTEM", "UNDOTBS1", "SYSAUX", "USERS" pluggable database
 'PDB1'   delete archivelog;
sql clone 'alter database open read only';
plsql <<<begin
   add_dropped_ts;
end; >>>;
plsql <<<begin
   save_pdb_clean_scn;
end; >>>;
# shutdown clone before import
shutdown clone abort
plsql <<<begin
   pdbpitr_inspect(pdbname =>  'PDB1');
end; >>>;
}
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  16 online

sql statement: alter database datafile  17 online

sql statement: alter database datafile  20 online

sql statement: alter database datafile  6 online

Starting recover at 06-MAR-16
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 90 is already on disk as file /data01/CDB/archives/1_90_900491294.dbf
archived log for thread 1 with sequence 91 is already on disk as file /data01/CDB/archives/1_91_900491294.dbf
archived log file name=/data01/CDB/archives/1_90_900491294.dbf thread=1 sequence=90
archived log file name=/data01/CDB/archives/1_91_900491294.dbf thread=1 sequence=91
media recovery complete, elapsed time: 00:00:01
Finished recover at 06-MAR-16

sql statement: alter database open read only



Oracle instance shut down


Removing automatic instance
Automatic instance removed
auxiliary instance file /oracle/fast_recovery_area/CDB/datafile/o1_mf_sysaux_cfs140n9_.dbf deleted
auxiliary instance file /oracle/fast_recovery_area/CDB/controlfile/o1_mf_cfs13q8s_.ctl deleted
Finished recover at 06-MAR-16

Statement processed

4.) Checking after recovery

 show con_id

CON_ID
------------------------------
1
14:28:19 SQL> select name, con_id, open_mode from v$pdbs;

NAME                                         CON_ID OPEN_MODE
------------------------------ -------------------- ----------
PDB$SEED                                          2 READ ONLY
PDB1                                              3 READ WRITE
PDB3                                              5 READ WRITE

3 rows selected.

 conn test/test@pdb1;
Connected.

 SELECT * FROM TEST.T1;

                 NUM TEXT
-------------------- --------------------
                   1 06032016-141735
                   2 06032016-141735
                   3 06032016-141735
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