Database 12c: Get back from PDB to Non-CDB


I’vh written many articles about converting a Non-CDB to a PDB. I’m going to check the way back to a Non-CDB now.

First check what a convert to PDB is. The plug-in process of a Non-CDB consists of two parts:

  1. (PHYSICAL) Migration of the necessary datafiles
  2. (LOGICAL) Conversion of the data dictionary with the noncdb_to_pdb.sql script

How it works?

“The non-CDB’s datafiles, together with the manually created manifest, can now be treated as
if they were an ordinarily unplugged PDB and simply plugged in to the target CDB and
opened as a PDB. However, as will be explained immediately, it must be opened with the
Restricted status set to YES. The tablespaces holding quota-consuming data are immediately
viable, just as if this had been a Data Pump import using transportable tablespaces. However,
the former non-CDB’s data dictionary so far has a full description of the Oracle system. This
is now superfluous, and so it must simply be removed. While still with the Restricted status set
to YES, the noncdb_to_pdb.sql script (found on the admin_directory under Oracle Home) must be
run. Now the PDB may be closed and then opened ordinarily.” –> Found here

The seconds step make all physical revert step impossible, because there is datafile 1 or real SYSTEM tablespace any more. These steps are:

  1. RMAN Full or Point-in-time-recovery will restore the whole CDB and not only the PDB. Further this is no PDB to Non-CDB conversion
  2. Transportable Database is not usable because datafile 1 is not the real SYSTEM tablespace

All in all the root problem is, that no datafile 1 or independent SYSTEM tablespace exists any more.

And now the ways to get back:

  1. Transportable Tablespace (this is the smoothest way)
  2. DataPump full export/import
  3. Other logical migration ways like Oracle GoldenGate

I’vh tested old export tool (exp) too, but exporting a PDB will end with the error “EXP-00062: invalid source statements for an object type”

If there are more ways I will appreciate a comment 🙂

Database 12c: RMAN Backup & Recovery of pluggable databases


RMAN Backup and Recovery operation have to be done at CDB level. For RMAN a PDB is just a bunch of datafiles.

Notice: If you want to restore a PDB from another CDB you have to restore the other CDB before and do an unplug an plug to transfer.

1. Backup of a PDB

RMAN> backup pluggable database pdb1 plus archivelog;
Starting backup at 11-JUL-13
 current log archived
 using channel ORA_DISK_1
 channel ORA_DISK_1: starting archived log backup set
 channel ORA_DISK_1: specifying archived log(s) in backup set
 input archived log thread=1 sequence=19 RECID=1 STAMP=820531423
 input archived log thread=1 sequence=20 RECID=2 STAMP=820531461
 input archived log thread=1 sequence=21 RECID=3 STAMP=820532613
 input archived log thread=1 sequence=22 RECID=4 STAMP=820532651
 input archived log thread=1 sequence=23 RECID=5 STAMP=820532930
 input archived log thread=1 sequence=24 RECID=6 STAMP=820533638
 input archived log thread=1 sequence=25 RECID=7 STAMP=820534921
 input archived log thread=1 sequence=26 RECID=8 STAMP=820535377
 channel ORA_DISK_1: starting piece 1 at 11-JUL-13
 channel ORA_DISK_1: finished piece 1 at 11-JUL-13
 piece handle=/opt/oracle/app/fast_recovery_area/CDB12C/backupset/2013_07_11/o1_mf_annnn_TAG20130711T222937_8xy5fkdh_.bkp tag=TAG20130711T222937 comment=NONE
 channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
 Finished backup at 11-JUL-13
Starting backup at 11-JUL-13
 using channel ORA_DISK_1
 channel ORA_DISK_1: starting full datafile backup set
 channel ORA_DISK_1: specifying datafile(s) in backup set
 input datafile file number=00050 name=/opt/oracle/app/oradata/CDB12C/E1433B62351A0F0DE0430100007F3E51/datafile/o1_mf_sysaux_8xy5brt3_.dbf
 input datafile file number=00049 name=/opt/oracle/app/oradata/CDB12C/E1433B62351A0F0DE0430100007F3E51/datafile/o1_mf_system_8xy5bq9w_.dbf
 channel ORA_DISK_1: starting piece 1 at 11-JUL-13
 channel ORA_DISK_1: finished piece 1 at 11-JUL-13
 piece handle=/opt/oracle/app/fast_recovery_area/CDB12C/E1433B62351A0F0DE0430100007F3E51/backupset/2013_07_11/o1_mf_nnndf_TAG20130711T222938_8xy5flmr_.bkp tag=TAG20130711T222938 comment=NONE
 channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
 Finished backup at 11-JUL-13
Starting backup at 11-JUL-13
 current log archived
 using channel ORA_DISK_1
 channel ORA_DISK_1: starting archived log backup set
 channel ORA_DISK_1: specifying archived log(s) in backup set
 input archived log thread=1 sequence=27 RECID=9 STAMP=820535385
 channel ORA_DISK_1: starting piece 1 at 11-JUL-13
 channel ORA_DISK_1: finished piece 1 at 11-JUL-13
 piece handle=/opt/oracle/app/fast_recovery_area/CDB12C/backupset/2013_07_11/o1_mf_annnn_TAG20130711T222945_8xy5fsxz_.bkp tag=TAG20130711T222945 comment=NONE
 channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
 Finished backup at 11-JUL-13
Starting Control File and SPFILE Autobackup at 11-JUL-13
 piece handle=/opt/oracle/app/fast_recovery_area/CDB12C/autobackup/2013_07_11/o1_mf_s_820535387_8xy5fvdw_.bkp comment=NONE
 Finished Control File and SPFILE Autobackup at 11-JUL-13

As you can see is a backup of an PDB just a backup of the datafiles and the CDB archivelogs.

2. Full Restore & Recover of PDBs

RMAN> alter pluggable database pdb1 close;

Statement processed

RMAN> run {
2> restore pluggable database pdb1;
3> recover pluggable database pdb1;
4> }

Starting restore at 11-JUL-13
using channel ORA_DISK_1

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 00049 to /opt/oracle/app/oradata/CDB12C/E1433B62351A0F0DE0430100007F3E51/datafile/o1_mf_system_8xy5bq9w_.dbf
channel ORA_DISK_1: restoring datafile 00050 to /opt/oracle/app/oradata/CDB12C/E1433B62351A0F0DE0430100007F3E51/datafile/o1_mf_sysaux_8xy5brt3_.dbf
channel ORA_DISK_1: reading from backup piece /opt/oracle/app/fast_recovery_area/CDB12C/E1433B62351A0F0DE0430100007F3E51/backupset/2013_07_11/o1_mf_nnndf_TAG20130711T222938_8xy5flmr_.bkp
channel ORA_DISK_1: piece handle=/opt/oracle/app/fast_recovery_area/CDB12C/E1433B62351A0F0DE0430100007F3E51/backupset/2013_07_11/o1_mf_nnndf_TAG20130711T222938_8xy5flmr_.bkp tag=TAG20130711T222938
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 11-JUL-13

Starting recover at 11-JUL-13
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 11-JUL-13

RMAN> alter pluggable database pdb1 open;

Statement processed

RMAN>

3. PDB Point in time Recovery (PITR)

PDB PITR is in real mutible Tablespace  point-in-time recovery (TPITR). RMAN is triggering the PITR transparently. After all you have to open the pdb with “alter pluggable database open resetlogs“.

RMAN> alter pluggable database pdb1 close;

Statement processed

RMAN> run {
2> set until time "to_date('23:00 11-07-2013','hh24:mi dd-mm-yyyy')";
3> restore pluggable database pdb1;
4> recover pluggable database pdb1;
5> }

executing command: SET until clause

Starting restore at 11-JUL-13
using channel ORA_DISK_1

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 00049 to /opt/oracle/app/oradata/CDB12C/E1433B62351A0F0DE0430100007F3E51/datafile/o1_mf_system_8xy5bq9w_.dbf
channel ORA_DISK_1: restoring datafile 00050 to /opt/oracle/app/oradata/CDB12C/E1433B62351A0F0DE0430100007F3E51/datafile/o1_mf_sysaux_8xy5brt3_.dbf
channel ORA_DISK_1: reading from backup piece /opt/oracle/app/fast_recovery_area/CDB12C/E1433B62351A0F0DE0430100007F3E51/backupset/2013_07_11/o1_mf_nnndf_TAG20130711T222938_8xy5flmr_.bkp
channel ORA_DISK_1: piece handle=/opt/oracle/app/fast_recovery_area/CDB12C/E1433B62351A0F0DE0430100007F3E51/backupset/2013_07_11/o1_mf_nnndf_TAG20130711T222938_8xy5flmr_.bkp tag=TAG20130711T222938
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 11-JUL-13

Starting recover at 11-JUL-13
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='qzgF'

initialization parameters used for automatic instance:
db_name=CDB12C
db_unique_name=qzgF_pitr_pdb1_CDB12C
compatible=12.1.0.0.0
db_block_size=8192
db_files=200
sga_target=1G
processes=80
diagnostic_dest=/opt/oracle/app
#No auxiliary destination in use
enable_pluggable_database=true
_clone_one_pdb_recovery=true
control_files=/opt/oracle/app/fast_recovery_area/CDB12C/controlfile/o1_mf_8xy7pxl8_.ctl
#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 293602560 bytes
Database Buffers 767557632 bytes
Redo Buffers 5480448 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until time "to_date('23:00 11-07-2013','hh24:mi dd-mm-yyyy')";
# 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 11-JUL-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=111 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 /opt/oracle/app/fast_recovery_area/CDB12C/autobackup/2013_07_11/o1_mf_s_820535387_8xy5fvdw_.bkp
channel ORA_AUX_DISK_1: piece handle=/opt/oracle/app/fast_recovery_area/CDB12C/autobackup/2013_07_11/o1_mf_s_820535387_8xy5fvdw_.bkp tag=TAG20130711T222947
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/opt/oracle/app/fast_recovery_area/CDB12C/controlfile/o1_mf_8xy7pxl8_.ctl
Finished restore at 11-JUL-13

sql statement: alter database mount clone database

contents of Memory Script:
{
# set requested point in time
set until time "to_date('23:00 11-07-2013','hh24:mi dd-mm-yyyy')";
# switch to valid datafilecopies
switch clone datafile 49 to datafilecopy 
 "/opt/oracle/app/oradata/CDB12C/E1433B62351A0F0DE0430100007F3E51/datafile/o1_mf_system_8xy5bq9w_.dbf";
switch clone datafile 50 to datafilecopy 
 "/opt/oracle/app/oradata/CDB12C/E1433B62351A0F0DE0430100007F3E51/datafile/o1_mf_sysaux_8xy5brt3_.dbf";
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile 1 to 
 "/opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_system_8xy7qcfz_.dbf";
set newname for datafile 4 to 
 "/opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_undotbs1_8xy7qch4_.dbf";
set newname for datafile 3 to 
 "/opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_sysaux_8xy7qcj0_.dbf";
set newname for datafile 6 to 
 "/opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_users_8xy7qkcn_.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 49 switched to datafile copy
input datafile copy RECID=7 STAMP=820537745 file name=/opt/oracle/app/oradata/CDB12C/E1433B62351A0F0DE0430100007F3E51/datafile/o1_mf_system_8xy5bq9w_.dbf

datafile 50 switched to datafile copy
input datafile copy RECID=8 STAMP=820537745 file name=/opt/oracle/app/oradata/CDB12C/E1433B62351A0F0DE0430100007F3E51/datafile/o1_mf_sysaux_8xy5brt3_.dbf

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 11-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 /opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_system_8xy7qcfz_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_undotbs1_8xy7qch4_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_sysaux_8xy7qcj0_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_users_8xy7qkcn_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /opt/oracle/app/fast_recovery_area/CDB12C/backupset/2013_07_11/o1_mf_nnndf_TAG20130711T214335_8xy2q7cg_.bkp
channel ORA_AUX_DISK_1: piece handle=/opt/oracle/app/fast_recovery_area/CDB12C/backupset/2013_07_11/o1_mf_nnndf_TAG20130711T214335_8xy2q7cg_.bkp tag=TAG20130711T214335
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 11-JUL-13

datafile 1 switched to datafile copy
input datafile copy RECID=13 STAMP=820537760 file name=/opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_system_8xy7qcfz_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=14 STAMP=820537760 file name=/opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_undotbs1_8xy7qch4_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=15 STAMP=820537760 file name=/opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_sysaux_8xy7qcj0_.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=16 STAMP=820537761 file name=/opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_users_8xy7qkcn_.dbf

contents of Memory Script:
{
# set requested point in time
set until time "to_date('23:00 11-07-2013','hh24:mi dd-mm-yyyy')";
# 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 
 49 online";
sql clone 'PDB1' "alter database datafile 
 50 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 49 online

sql statement: alter database datafile 50 online

sql statement: alter database datafile 6 online

Starting recover at 11-JUL-13
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 22 is already on disk as file /opt/oracle/app/fast_recovery_area/CDB12C/archivelog/2013_07_11/o1_mf_1_22_8xy2rcsv_.arc
archived log for thread 1 with sequence 23 is already on disk as file /opt/oracle/app/fast_recovery_area/CDB12C/archivelog/2013_07_11/o1_mf_1_23_8xy3126w_.arc
archived log for thread 1 with sequence 24 is already on disk as file /opt/oracle/app/fast_recovery_area/CDB12C/archivelog/2013_07_11/o1_mf_1_24_8xy3q6bj_.arc
archived log for thread 1 with sequence 25 is already on disk as file /opt/oracle/app/fast_recovery_area/CDB12C/archivelog/2013_07_11/o1_mf_1_25_8xy4z91m_.arc
archived log for thread 1 with sequence 26 is already on disk as file /opt/oracle/app/fast_recovery_area/CDB12C/archivelog/2013_07_11/o1_mf_1_26_8xy5fk5j_.arc
archived log for thread 1 with sequence 27 is already on disk as file /opt/oracle/app/fast_recovery_area/CDB12C/archivelog/2013_07_11/o1_mf_1_27_8xy5fsrc_.arc
archived log for thread 1 with sequence 28 is already on disk as file /opt/oracle/app/fast_recovery_area/CDB12C/archivelog/2013_07_11/o1_mf_1_28_8xy7pxf9_.arc
archived log file name=/opt/oracle/app/fast_recovery_area/CDB12C/archivelog/2013_07_11/o1_mf_1_22_8xy2rcsv_.arc thread=1 sequence=22
archived log file name=/opt/oracle/app/fast_recovery_area/CDB12C/archivelog/2013_07_11/o1_mf_1_23_8xy3126w_.arc thread=1 sequence=23
archived log file name=/opt/oracle/app/fast_recovery_area/CDB12C/archivelog/2013_07_11/o1_mf_1_24_8xy3q6bj_.arc thread=1 sequence=24
archived log file name=/opt/oracle/app/fast_recovery_area/CDB12C/archivelog/2013_07_11/o1_mf_1_25_8xy4z91m_.arc thread=1 sequence=25
archived log file name=/opt/oracle/app/fast_recovery_area/CDB12C/archivelog/2013_07_11/o1_mf_1_26_8xy5fk5j_.arc thread=1 sequence=26
archived log file name=/opt/oracle/app/fast_recovery_area/CDB12C/archivelog/2013_07_11/o1_mf_1_27_8xy5fsrc_.arc thread=1 sequence=27
archived log file name=/opt/oracle/app/fast_recovery_area/CDB12C/archivelog/2013_07_11/o1_mf_1_28_8xy7pxf9_.arc thread=1 sequence=28
media recovery complete, elapsed time: 00:00:07
Finished recover at 11-JUL-13

sql statement: alter database open read only

Oracle instance shut down

Removing automatic instance
Automatic instance removed
auxiliary instance file /opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_sysaux_8xy7qcj0_.dbf deleted
auxiliary instance file /opt/oracle/app/fast_recovery_area/CDB12C/controlfile/o1_mf_8xy7pxl8_.ctl deleted
Finished recover at 11-JUL-13

RMAN> alter pluggable database pdb1 open;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of sql statement command at 07/11/2013 23:09:38
ORA-01113: file 50 needs media recovery
ORA-01110: data file 50: '/opt/oracle/app/oradata/CDB12C/E1433B62351A0F0DE0430100007F3E51/datafile/o1_mf_sysaux_8xy5brt3_.dbf'

RMAN> alter pluggable database pdb1 open resetlogs;

Statement processed

RMAN>

Per default “Fast Recovery Area” is used for auxiliary datafiles, if FRA is configured.

datafile 1 switched to datafile copy
input datafile copy RECID=13 STAMP=820537760 file name=/opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_system_8xy7qcfz_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=14 STAMP=820537760 file name=/opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_undotbs1_8xy7qch4_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=15 STAMP=820537760 file name=/opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_sysaux_8xy7qcj0_.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=16 STAMP=820537761 file name=/opt/oracle/app/fast_recovery_area/CDB12C/datafile/o1_mf_users_8xy7qkcn_.dbf

If there is not enough space it is possible to use another storage area:

recover pluggable database pdb1 auxiliary destination='/stage/pdb1';