Saturday, November 9, 2013

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


Cloning Pluggable Databases (PDBs):





Useful Scenario: If you want to test the application patch of your production pluggable database. Clone Pluggable database in a cloned PDB, apply the patch for cloned PDB and test.






[oracle@localhost bin]$ cd /u01/app/oracle/oradata/cdb1
[oracle@localhost cdb1]$ mkdir plugdb4_clone
SQL> select name, open_mode from v$pdbs;
SQL> show parameter db_create_file_dest
SQL> alter system set db_create_file_dest='/u01/app/oracle/oradata/cdb1/plugdb4_clone' scope=both;
SQL> create pluggable database plugdb4_clone from plugdb4;
SQL> alter pluggable database plugdb4_clone open;
SQL> select name, open_mode from v$pdbs;

NAME                                                                                                                    OPEN_MODE
--------------------------------------------------------------------------------        ------------------
PLUGDB4                                                                                                              READ ONLY
PLUGDB4_CLONE                                                                                               READ WRITE

SQL> connect sys/oracle@localhost:1521/cdb1 as sysdba
SQL> alter session set container=cdb$root;
SQL> alter pluggable database plugdb4 close immediate;
SQL> alter pluggable database plugdb4 open;

Plugging a Non-CDB as a Pluggable Database into a Container Database: 




Check the Instances
[oracle@localhost bin]$ ps -ef | grep pmon
oracle    1709     1  0 04:16 ?        00:00:00 ora_pmon_cdb1
oracle    2983     1  0 04:45 ?        00:00:00 ora_pmon_noncdb

Set the environment variables
[oracle@localhost bin]$ export ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
[oracle@localhost bin]$ export ORACLE_SID=noncdb
[oracle@localhost bin]$ ./sqlplus sys/oracle@localhost:1521/noncdb as sysdba

Check Container Name
SQL> show con_name

CON_NAME
-------------------
Non Consolidated
  
Shutting Non-Container Database
SQL> shut immediate;

Startup Non-Container Database in Read Only Mode
[oracle@localhost bin]$ ./sqlplus /nolog
SQL> startup mount exclusive;
SQL> alter database open read only;


Note : Created required directories

Generate XML format file
SQL> exec dbms_pdb.describe(pdb_descr_file=>'/u01/app/oracle/oradata/NONCDB/noncdb.xml');
SQL> shut immediate;

Connect as sys user in Container Database
SQL> connect sys/oracle@localhost:1521/cdb1 as sysdba

Create Pluggable Database with Copy Command
SQL> create pluggable database exnoncdb as clone
using '/u01/app/oracle/oradata/NONCDB/noncdb.xml'
FILE_NAME_CONVERT=('/u01/app/oracle/oradata/NONCDB/datafile/','/u01/app/ora’)
copy;


Open the newly created pluggable database
SQL> alter pluggable database exnoncdb open;
SQL> select name, open_mode from v$pdbs;

NAME                                                  OPEN_MODE
------------------------------                 ------------------
EXNONCDB                                        READ WRITE

SQL> alter pluggable database exnoncdb close;
SQL> select name, open_mode from v$pdbs;

NAME                                            OPEN_MODE
------------------------------           ------------------
EXNONCDB                                  MOUNTED

SQL> alter pluggable database exnoncdb open;
SQL> connect sys/oracle@localhost:1521/exnoncdb as sysdba
SQL> select file_name from dba_data_files;
SQL> select file_name from dba_temp_files;

Execute following script as a Pre-requisites
SQL> @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql

 

No comments:

Post a Comment