Saturday, November 9, 2013

Oracle Database 12c – Container Database & Pluggable Databases (Part-4)

Plugging an Unplugged Pluggable Databases (PDBs) in Container Databases (CDBs):



Useful Scenario: If you want to upgrade to the Oracle latest version, but you do not want to apply for all PDBs in Container Database. Unplug PDB from Container Database and plug them into newly created Container Database of higher Oracle version.


Connect to Container Database (CDB1)
SQL> conn sys/oracle@localhost:1521/cdb1 as sysdba
SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT

SQL> select name,open_mode from v$pdbs;

NAME                                                  OPEN_MODE
------------------------------                ------------------
PDB1                                                    READ WRITE
PDB2                                                    MOUNTED

Close Pluggable Database (PDB2) in Container Database (CDB1)
SQL> alter pluggable database pdb2 close immediate;
SQL> alter pluggable database pdb2 unplug into '/u01/app/oracle/oradata/cdb1/pdb1/pdb1.xml';

Drop Pluggable database and keep datafiles
SQL> drop pluggable database pdb2 keep datafiles;

[oracle@localhost bin]$ cd /u01/app/oracle/oradata/cdb1/pdb2
[oracle@localhost pdb2]$ ls -lrth
-rw-r--r--. 1 oracle oinstall 3.5K Jul  4 09:09 pdb2.xml

Connect to Container Database (CDB2)
SQL> connect sys/oracle@localhost:1521/cdb2 as sysdba
SQL> create pluggable database pdb2_plug_nocopy
using '/u01/app/oracle/oradata/cdb1/pdb2/pdb2.xml'
nocopy
tempfile reuse;

SQL> select pdb_name, status from cdb_pdbs where pdb_name='PDB2_PLUG_NOCOPY';
SQL> select open_mode from v$pdbs where name='PDB2_PLUG_NOCOPY';
 


Connect Container Database (CDB1) and close Pluggable Database (PDB1)
SQL> alter pluggable database pdb1 close immediate;
SQL> select name,open_mode from v$pdbs;

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

SQL> alter pluggable database pdb1 unplug into '/u01/app/oracle/oradata/cdb1/pdb1/pdb1.xml';
SQL> drop pluggable database pdb1 keep datafiles;

Connect Container Database (CDB2) and Create required directories
[oracle@localhost bin]$ cd /u01/app/oracle/oradata/cdb2
[oracle@localhost cdb2]$ mkdir pdb2_plug_copy

Plug Unplugged PDB in Container Database (CDB2)
SQL> create pluggable database pdb_plug_copy using '/u01/app/oracle/oradata/cdb1/pdb1/pdb1.xml'
COPY
FILE_NAME_CONVERT=('/u01/app/oracle/oradata/cdb1/pdb1','/u01/app/oracle/oradata/cdb2/pdb1_plug_copy');



SQL> select pdb_name, status from cdb_pdbs where pdb_name='PDB_PLUG_COPY';
SQL> select open_mode from v$pdbs where name='PDB_PLUG_COPY';


No comments:

Post a Comment