Christoph's 2 Cents

A Backup for My Brain!

Oracle Developement

Quick & Dirty: Create a pluggable database in Oracle 12c

  1. Log in as sys
  2. Change to CDB$ROOT and verify container:
    SQL> alter session set container = cdb$root;
    Session altered.
    SQL> show con_name
    CON_NAME
    ------------------------------
    CDB$ROOT
  3. Create plugable database from seed (this command also adds the new pdb2 directory):
    create pluggable database pdb2 admin user pdb2_admin 
    identified by secret_password
    file_name_convert =(
    '/home/oracle/app/oracle/oradata/cdb1/pdbseed/',
    '/home/oracle/app/oracle/oradata/cdb1/pdb2/'
    );
  4. At this point the database is created and mounted. Open new database:
    SQL> alter pluggable database pdb2 open read write;
  5. List pluggable databases:
    alter session set container=CDB$ROOT;
    col pdb_name for a30
    col status for a10
    col status for a10
    
    select a.pdb_name,a.status,b.open_mode
      from dba_pdbs a, v$pdbs b
     where a.pdb_name = b.name(+)
     order by 1
    /
    PDB_NAME		       STATUS	  OPEN_MODE
    ------------------------------ ---------- ----------
    ORCL			       NORMAL	  READ WRITE
    PDB$SEED		       NORMAL	  READ ONLY
    PDB2			       NORMAL	  READ WRITE
    
  6. Create a new tnsnames.ora entry for the database:
    PDB2 =
        (DESCRIPTION =
            (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
            (CONNECT_DATA =
                (SERVER = DEDICATED)
                (SERVICE_NAME = pdb2)
            )
        )
  7. Log in as pdb2_admin:
    sqlplus pdb2_admin/secret_password@pdb2
  8. Log in as sys to pdb2:
    1. sqlplus sys@pdb2 as sysdba;

      or

    2. sqlplus sys as sysdba;
      alter session set container = pdb2;

The new database will have three tablespaces;

SQL> select tablespace_name,contents from dba_tablespaces;

 TABLESPACE_NAME                CONTENTS
 ------------------------------ ---------
 SYSTEM                         PERMANENT
 SYSAUX                         PERMANENT
 TEMP                           TEMPORARY

For more information see the Oracle-Base article.