Database 12c: Duplicate PDB


Today morning I wanted to check how to duplicate a PDB. The first questions to me were:

  • Duplicate PDB, how to create an empty PDB and bring it to nomount like non-cdbs?
  • Duplicate within a CDB?

Here the answer:

The duplication process of a PDB works at CDB level. So if you want to duplicate a PDB you have to create an empty CDB instance. Then the needed parts of the CDB will be cloned and all other dropped. This will answer the second question: duplication within a CDB is not out-of-the-box possible. But you are able to clone the PDB or use a shadow CDB.

Here the example to clone:

Setup:

  • Target CDB = CDB12C1
  • Auxiliary CDB = CDB12C3
  • PDB to duplicate = Only PDB1
[bash]$ rman target sys/<password>@cdb12c1 auxiliary sys/<password>@cdb12c3

Recovery Manager: Release 12.1.0.1.0 - Production on Sat Jul 20 13:15:57 2013

Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

connected to target database: CDB12C1 (DBID=2076797181)
connected to auxiliary database: CDB12C3 (not mounted)

RMAN> duplicate target database to CDB12C3 pluggable database pdb1 from active database;

Starting Duplicate Db at 20-JUL-13
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=5 device type=DISK
current log archived

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''CDB12C1'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name = 
 ''CDB12C3'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone from service  'cdb12c1' primary controlfile;
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''CDB12C1'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''CDB12C3'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area     417546240 bytes

Fixed Size                     2289064 bytes
Variable Size                293601880 bytes
Database Buffers             113246208 bytes
Redo Buffers                   8409088 bytes

Starting restore at 20-JUL-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=5 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/opt/oracle/app/oradata/CDB12C3/control01.ctl
Finished restore at 20-JUL-13

database mounted
Skipping pluggable database PDB2
Automatically adding tablespace SYSTEM
Automatically adding tablespace SYSAUX
Automatically adding tablespace PDB$SEED:SYSTEM
Automatically adding tablespace PDB$SEED:SYSAUX
Automatically adding tablespace UNDOTBS1
Skipping tablespace USERS

contents of Memory Script:
{
   set newname for clone datafile  1 to new;
   set newname for clone datafile  3 to new;
   set newname for clone datafile  4 to new;
   set newname for clone datafile  5 to new;
   set newname for clone datafile  7 to new;
   set newname for clone datafile  21 to new;
   set newname for clone datafile  22 to new;
   restore
   from service  'cdb12c1'   clone database
   skip forever tablespace  "USERS",
 "PDB2":"SYSTEM",
 "PDB2":"SYSAUX"   ;
   sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 20-JUL-13
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
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/oradata/CDB12C3/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00005 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00007 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00021 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00022 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 20-JUL-13

sql statement: alter system archive log current
current log archived

contents of Memory Script:
{
   restore clone force from service  'cdb12c1' 
           archivelog from scn  2534976;
   switch clone datafile all;
}
executing Memory Script

Starting restore at 20-JUL-13
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=97
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=98
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 20-JUL-13

datafile 1 switched to datafile copy
input datafile copy RECID=10 STAMP=821279836 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_8ynwdjk0_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=11 STAMP=821279836 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwdqkh_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=12 STAMP=821279836 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_undotbs1_8ynwdynw_.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=13 STAMP=821279836 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_8ynwf5kv_.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=14 STAMP=821279836 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwf8lz_.dbf
datafile 21 switched to datafile copy
input datafile copy RECID=15 STAMP=821279836 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_8ynwfhny_.dbf
datafile 22 switched to datafile copy
input datafile copy RECID=16 STAMP=821279836 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwflo0_.dbf

contents of Memory Script:
{
   set until scn  2535061;
   recover
   clone database
   skip forever tablespace  "USERS",
 "PDB2":"SYSTEM",
 "PDB2":"SYSAUX"    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 20-JUL-13
using channel ORA_AUX_DISK_1

Executing: alter database datafile 6 offline drop
Executing: alter database datafile 23 offline drop
Executing: alter database datafile 24 offline drop
starting media recovery

archived log for thread 1 with sequence 97 is already on disk as file /opt/oracle/app/fast_recovery_area/CDB12C3/archivelog/2013_07_20/o1_mf_1_97_8ynwft7h_.arc
archived log for thread 1 with sequence 98 is already on disk as file /opt/oracle/app/fast_recovery_area/CDB12C3/archivelog/2013_07_20/o1_mf_1_98_8ynwfv8y_.arc
archived log file name=/opt/oracle/app/fast_recovery_area/CDB12C3/archivelog/2013_07_20/o1_mf_1_97_8ynwft7h_.arc thread=1 sequence=97
archived log file name=/opt/oracle/app/fast_recovery_area/CDB12C3/archivelog/2013_07_20/o1_mf_1_98_8ynwfv8y_.arc thread=1 sequence=98
media recovery complete, elapsed time: 00:00:00
Finished recover at 20-JUL-13
Oracle instance started

Total System Global Area     417546240 bytes

Fixed Size                     2289064 bytes
Variable Size                293601880 bytes
Database Buffers             113246208 bytes
Redo Buffers                   8409088 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''CDB12C3'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
}
executing Memory Script

sql statement: alter system set  db_name =  ''CDB12C3'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system reset  db_unique_name scope=spfile
Oracle instance started

Total System Global Area     417546240 bytes

Fixed Size                     2289064 bytes
Variable Size                293601880 bytes
Database Buffers             113246208 bytes
Redo Buffers                   8409088 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "CDB12C3" RESETLOGS ARCHIVELOG 
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES     1024
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP   1  SIZE 50 M ,
  GROUP   2  SIZE 50 M ,
  GROUP   3  SIZE 50 M 
 DATAFILE
  '/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_8ynwdjk0_.dbf',
  '/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_8ynwf5kv_.dbf',
  '/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_8ynwfhny_.dbf'
 CHARACTER SET AL32UTF8

contents of Memory Script:
{
   set newname for clone tempfile  1 to new;
   set newname for clone tempfile  2 to new;
   set newname for clone tempfile  3 to new;
   switch clone tempfile all;
   catalog clone datafilecopy  "/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwdqkh_.dbf", 
 "/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_undotbs1_8ynwdynw_.dbf", 
 "/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwf8lz_.dbf", 
 "/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwflo0_.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 2 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 3 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_temp_%u_.tmp in control file

cataloged datafile copy
datafile copy file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwdqkh_.dbf RECID=1 STAMP=821279854
cataloged datafile copy
datafile copy file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_undotbs1_8ynwdynw_.dbf RECID=2 STAMP=821279854
cataloged datafile copy
datafile copy file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwf8lz_.dbf RECID=3 STAMP=821279854
cataloged datafile copy
datafile copy file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwflo0_.dbf RECID=4 STAMP=821279854

datafile 3 switched to datafile copy
input datafile copy RECID=1 STAMP=821279854 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwdqkh_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=2 STAMP=821279854 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_undotbs1_8ynwdynw_.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=3 STAMP=821279854 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwf8lz_.dbf
datafile 22 switched to datafile copy
input datafile copy RECID=4 STAMP=821279854 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwflo0_.dbf

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Executing: drop pluggable database "PDB2"

contents of Memory Script:
{
   sql clone "alter pluggable database all open";
}
executing Memory Script

sql statement: alter pluggable database all open
Dropping offline and skipped tablespaces
Executing: alter database default tablespace system
Executing: drop tablespace "USERS" including contents cascade constraints
Finished Duplicate Db at 20-JUL-13

RMAN>

Now check the new PDB

SQL> select * from v$pdbs

    CON_ID       DBID    CON_UID GUID                             NAME                           OPEN_MODE  RES OPEN_TIME                                                                   CREATE_SCN TOTAL_SIZE
---------- ---------- ---------- -------------------------------- ------------------------------ ---------- --- --------------------------------------------------------------------------- ---------- ----------
         2 4063775335 4063775335 E1E189D14D2C2049E0430100007FAB5B PDB$SEED                       READ ONLY  NO  20-JUL-13 01.17.36.174 PM                                                      1720752  283115520
         3 3328955419 3328955419 E1EE338E12A16C3EE0430100007F1A4F PDB1                           READ WRITE NO  20-JUL-13 01.17.39.820 PM                                                      2502055  283115520

SQL> 

Important to know is that the GUID of the PDB doesn’t change in the new CDB.

Database 12c: Clone PDBs (offline and online)


In 12c it is possible to clone PDB’s. Here an example:

1. Bring source PDB in correct state:

SQL> select con_id,name,open_mode,restricted from v$pdbs;

    CON_ID NAME                           OPEN_MODE  RES GUID
---------- ------------------------------ ---------- --- --------------------------------
         2 PDB$SEED                       READ ONLY  NO  E1E189D14D2C2049E0430100007FAB5B
         3 PDB1                           READ WRITE NO  E1F01A2ED12F718AE0430100007F25BA

SQL> alter pluggable database pdb1 close;

Pluggable database altered.

SQL> alter pluggable database pdb1 open read only;

Pluggable database altered.

SQL>

2. Clone PDB

SQL> create pluggable database pdb2 from pdb1;

Pluggable database created.

    CON_ID NAME                 OPEN_MODE  RES GUID
---------- -------------------- ---------- --- --------------------------------
         2 PDB$SEED             READ ONLY  NO  E1E189D14D2C2049E0430100007FAB5B
         3 PDB1                 READ ONLY  NO  E1EE338E12A16C3EE0430100007F1A4F
         4 PDB2                 MOUNTED        E1F01A2ED12F718AE0430100007F25BA

SQL> select con_id,name from v$datafile order by 1;
    CON_ID NAME
---------- ----------------------------------------------------------------------------------------------------
         1 /opt/oracle/app/oradata/CDB12C1/system01.dbf
         1 /opt/oracle/app/oradata/CDB12C1/sysaux01.dbf
         1 /opt/oracle/app/oradata/CDB12C1/undotbs01.dbf
         1 /opt/oracle/app/oradata/CDB12C1/users01.dbf
         2 /opt/oracle/app/oradata/CDB12C1/pdbseed/sysaux01.dbf
         2 /opt/oracle/app/oradata/CDB12C1/pdbseed/system01.dbf
         3 /opt/oracle/app/oradata/CDB12C1/E1EE338E12A16C3EE0430100007F1A4F/datafile/o1_mf_system_8ynlfvd5_.dbf
         3 /opt/oracle/app/oradata/CDB12C1/E1EE338E12A16C3EE0430100007F1A4F/datafile/o1_mf_sysaux_8ynlfx2p_.dbf
         4 /opt/oracle/app/oradata/CDB12C1/E1F01A2ED12F718AE0430100007F25BA/datafile/o1_mf_sysaux_8yntf0xb_.dbf
         4 /opt/oracle/app/oradata/CDB12C1/E1F01A2ED12F718AE0430100007F25BA/datafile/o1_mf_system_8yntdzmf_.dbf

3. Bring both PDB’s in correct state

SQL> alter pluggable database pdb1 close;

Pluggable database altered.

SQL> alter pluggable database pdb1 open;

Pluggable database altered.

SQL> alter pluggable database pdb2 open;

Pluggable database altered.

SQL>

As you can see you have to bring a PDB in READ ONLY mode to clone it. I think this is not really suitable for production environments.

After some bainstorming I found a way to clone PDB’s online. All you need is some storage. Here the plan to clone PDBs online:

  1. Duplicate target PDB to a auxiliary PDB
    –> Bring the PDB to an non production environment
  2. Create a clone PDB from the auxiliary PDB
    –> The GUID of the PDB must change to replug in old CDB. I don’t found another way to change the GUID right now.
  3. Unplug an plug the clone PDB in the target CDB
    –> Transport metadata back to target
  4. Cleanup the shadow CDB
    –> Cleanup all

I’vh read that the real online cloning functionality will come in the next release.

Database 12c: Convert Non-CDB with different character set to PDB


Today I want to discuss converting of a Non-CDB with different character set to a PDB. I think this a very interesting part, because it is possible. So you are able to provide multiple Character Sets in one database (maybe). Like in every characterset migration it depends on the character set you want to migrate to.

Here the limits for PDB migration:

  • The character set is the same as the national character set of the CDB. In this case, the plugging operation succeeds (as far as the national character set is concerned).
  • The character set is not the same as the national character set of the CDB. In this case, the new PDB can only be opened in restricted mode for administrative tasks and cannot be used for production. Unless you have a tool that can migrate the national character set of the new PDB to the character set of the CDB, the new PDB is unusable.

“If you cannot migrate your existing databases prior to consolidation, then you have to partition them into sets with plug-in compatible database character sets and plug each set into a separate CDB with the appropriate superset character set”:

  • US7ASCII, WE8ISO8859P1, and WE8MSWIN1252 into a WE8MSWIN1252 CDB
  • WE8ISO8859P15 into a WE8ISO8859P15 CDB
  • JA16SJISTILDE into a JA16SJISTILDE CDB
  • JA16EUC into a JA16EUC CDB
  • KO16KSC5601, KO16MSWIN949 into a KO16MSWIN949 CDB
  • UTF8 and AL32UTF8 into an AL32UTF8 CDB

Here an example of PDB_PLUG_IN_VIOLATIONS for a compatible PDB:

NAME                           CAUSE                  TYPE      MESSAGE                                                                                              STATUS
------------------------------ ---------------------- --------- ---------------------------------------------------------------------------------------------------- ---------
DB12CEE4                       Database CHARACTER SET WARNING   Character set mismatch: PDB character set UTF8 CDB character set AL32UTF8.                           PENDING
DB12CEE4                       Non-CDB to PDB         WARNING   PDB plugged in is a non-CDB, requires noncdb_to_pdb.sql be run.                                      PENDING
DB12CEE4                       Parameter              WARNING   CDB parameter sga_target mismatch: Previous 788529152 Current 2768240640                             PENDING
DB12CEE4                       Parameter              WARNING   CDB parameter pga_aggregate_target mismatch: Previous 262144000 Current 917504000                    PENDING

Migrating from UTF8 to AL32UTF8, after plug-in the database characterset has been changed automatical (it seems to be -> maybe during dictionary check):

SQL> select * from nls_database_parameters where parameter like '%CHARACTERSET';

PARAMETER                      VALUE
------------------------------ ------------------------------
NLS_NCHAR_CHARACTERSET         AL16UTF16
NLS_CHARACTERSET               AL32UTF8

Here an example of PDB_PLUG_IN_VIOLATIONS for a non compatible PDB:

NAME                           CAUSE                  TYPE      MESSAGE                                                                                              STATUS
------------------------------ ---------------------- --------- ---------------------------------------------------------------------------------------------------- ---------
DB12CEE1                       Database CHARACTER SET ERROR     Character set mismatch: PDB character set WE8MSWIN1252 CDB character set AL32UTF8.                   PENDING
DB12CEE1                       Non-CDB to PDB         WARNING   PDB plugged in is a non-CDB, requires noncdb_to_pdb.sql be run.                                      PENDING
DB12CEE1                       Parameter              WARNING   CDB parameter sga_target mismatch: Previous 788529152 Current 2768240640                             PENDING
DB12CEE1                       Parameter              WARNING   CDB parameter pga_aggregate_target mismatch: Previous 262144000 Current 917504000                    PENDING

Migrating from WE8MSWIN1252 to AL32UTF8, after plug-in the database characterset nothing changed:

SQL> select * from nls_database_parameters where parameter like '%CHARACTERSET';

PARAMETER                      VALUE
------------------------------ ------------------------------
NLS_NCHAR_CHARACTERSET         AL16UTF16
NLS_CHARACTERSET               WE8MSWIN1252

As documentated plug-in and convert of both were possible. Example 1 successfully and example 2 with errors in cause of the characterset. Notice: Productive use of the second example is not supported, but possible. Why?

  • R/W open only in restricted session mode –> Maybe user connect as SYSDBA?
  • R/O open possible –> Maybe you can use it for Reporting, without changing characterset?
  • RMAN Backup is possible

Why do I mention this? If you doesn’t take care on the CS during migration to PDB the way back is not as easy as it should be. Of course in this case I have to export and import in another PDB, but I can’t physically migrate back. I have to two options to get to an usable result (WE8MSWIN1252 –>AL32UTF8)

  1. AL32UTF8 is a logical superset and migrationable with export/import procedure
  2. Migration with replication

Directly convert with plug-in is possible but only a usable step for this case, because I’vh to do the migration again in a logical form.

Conslusion: Take care on the characterset before migration to PDB. Not convertable charactersets need an convert be for an logical and no physical or partly physical migration way.

Database 12c: Convert Non-CDB to PDB


To get data from a Non-CDB to a PDB you have to do a convert of a Non-CDB to PDB or use Datapump or a tool for logical migration. The conversion process is similar to unplug and plug of a pdb.

I’vh tried the following ways, which are all possible:

  • 11.2.0.3 –> 12.1.0.1 (First upgrade to a Non-CDB and then convert)
  • 12.1.0.1 EE Non-CDB –> 12.1.0.1 EE
  • 12.1.0.1 SE Non-CDB –> 12.1.0.1 EE
  • 12.1.0.1 EE Non-CDB –> 12.1.0.1 SE
  • 12.1.0.1 SE Non-CDB –> 12.1.0.1 SE

Ok, let’s start.

1. Bring Non-CDB in a consistent state:

[bash]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Thu Jul 18 23:30:06 2013

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> shutdown immediate

Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 1043886080 bytes
Fixed Size 2296280 bytes
Variable Size 692061736 bytes
Database Buffers 343932928 bytes
Redo Buffers 5595136 bytes
Database mounted.
SQL> alter database open read only;

Database altered.

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ ONLY

2. Create the export XML

SQL>
BEGIN
 DBMS_PDB.DESCRIBE(
 pdb_descr_file => '/opt/oracle/unplug/db12c1_convert.xml');
END;
/
PL/SQL procedure successfully completed.

Take a look into the XML File, check the last important part (bold marked):

<?xml version="1.0" encoding="UTF-8"?>
<PDB>
 <pdbname>DB12C1</pdbname>
 <cid>0</cid>
 <byteorder>1</byteorder>
 <vsn>202375168</vsn>
 <dbid>4126847348</dbid>
 <cdbid>4126847348</cdbid>
 <guid>E1CE01B6E8AB0B36E0430100007F25C7</guid>
 <uscnbas>1759919</uscnbas>
 <uscnwrp>0</uscnwrp>
 <rdba>4194824</rdba>
 <tablespace>
 <name>SYSTEM</name>
 <type>0</type>
 <tsn>0</tsn>
 <status>1</status>
 <issft>0</issft>
 <file>
 <path>/opt/oracle/app/oradata/DB12C1/datafile/o1_mf_system_8yjcbjpj_.dbf</path>
 <afn>1</afn>
 <rfn>1</rfn>
 <createscnbas>7</createscnbas>
 <createscnwrp>0</createscnwrp>
 <status>1</status>
 <fileblocks>99840</fileblocks>
 <blocksize>8192</blocksize>
 <vsn>202375168</vsn>
 <fdbid>4126847348</fdbid>
 <fcpsw>0</fcpsw>
 <fcpsb>1759918</fcpsb>
 <frlsw>0</frlsw>
 <frlsb>1720082</frlsb>
 <frlt>821131319</frlt>
 </file>
 </tablespace>
 <tablespace>
 <name>SYSAUX</name>
 <type>0</type>
 <tsn>1</tsn>
 <status>1</status>
 <issft>0</issft>
 <file>
 <path>/opt/oracle/app/oradata/DB12C1/datafile/o1_mf_sysaux_8yjc93j2_.dbf</path>
 <afn>3</afn>
 <rfn>3</rfn>
 <createscnbas>3922</createscnbas>
 <createscnwrp>0</createscnwrp>
 <status>1</status>
 <fileblocks>89600</fileblocks>
 <blocksize>8192</blocksize>
 <vsn>202375168</vsn>
 <fdbid>4126847348</fdbid>
 <fcpsw>0</fcpsw>
 <fcpsb>1759918</fcpsb>
 <frlsw>0</frlsw>
 <frlsb>1720082</frlsb>
 <frlt>821131319</frlt>
 </file>
 </tablespace>
 <tablespace>
 <name>TEMP</name>
 <type>1</type>
 <tsn>3</tsn>
 <status>1</status>
 <issft>0</issft>
 <bmunitsize>128</bmunitsize>
 <file>
 <path>/opt/oracle/app/oradata/DB12C1/datafile/o1_mf_temp_8yjcdrw0_.tmp</path>
 <afn>1</afn>
 <rfn>1</rfn>
 <createscnbas>1720182</createscnbas>
 <createscnwrp>0</createscnwrp>
 <status>1</status>
 <fileblocks>7680</fileblocks>
 <blocksize>8192</blocksize>
 <vsn>202375168</vsn>
 <autoext>1</autoext>
 <maxsize>4194302</maxsize>
 <incsize>80</incsize>
 </file>
 </tablespace>
 <tablespace>
 <name>USERS</name>
 <type>0</type>
 <tsn>4</tsn>
 <status>1</status>
 <issft>0</issft>
 <file>
 <path>/opt/oracle/app/oradata/DB12C1/datafile/o1_mf_users_8yjccxy4_.dbf</path>
 <afn>6</afn>
 <rfn>6</rfn>
 <createscnbas>26029</createscnbas>
 <createscnwrp>0</createscnwrp>
 <status>1</status>
 <fileblocks>640</fileblocks>
 <blocksize>8192</blocksize>
 <vsn>202375168</vsn>
 <fdbid>4126847348</fdbid>
 <fcpsw>0</fcpsw>
 <fcpsb>1759918</fcpsb>
 <frlsw>0</frlsw>
 <frlsb>1720082</frlsb>
 <frlt>821131319</frlt>
 </file>
 </tablespace>
 <optional>
 <csid>178</csid>
 <ncsid>2000</ncsid>
 <options>
 <option>APS=12.1.0.1.0</option>
 <option>CATALOG=12.1.0.1.0</option>
 <option>CATJAVA=12.1.0.1.0</option>
 <option>CATPROC=12.1.0.1.0</option>
 <option>CONTEXT=12.1.0.1.0</option>
 <option>DV=12.1.0.1.0</option>
 <option>JAVAVM=12.1.0.1.0</option>
 <option>OLS=12.1.0.1.0</option>
 <option>ORDIM=12.1.0.1.0</option>
 <option>OWM=12.1.0.1.0</option>
 <option>SDO=12.1.0.1.0</option>
 <option>XDB=12.1.0.1.0</option>
 <option>XML=12.1.0.1.0</option>
 <option>XOQ=12.1.0.1.0</option>
 </options>
 <olsoid>0</olsoid>
 <dv>0</dv>
 <ncdb2pdb>1</ncdb2pdb>
 <APEX>4.2.0.00.27:1</APEX>
 <parameters>
 <parameter>processes=300</parameter>
 <parameter>memory_target=1048576000</parameter>
 <parameter>db_block_size=8192</parameter>
 <parameter>compatible=12.1.0.0.0</parameter>
 <parameter>open_cursors=300</parameter>
 </parameters>
 <tzvers>
 <tzver>primary version:18</tzver>
 <tzver>secondary version:0</tzver>
 </tzvers>
 <walletkey>0</walletkey>
 </optional>
</PDB>

3. Shutdown source database and login in the CDB
4. Check compatibility

SET SERVEROUTPUT ON
DECLARE
 compatible CONSTANT VARCHAR2(3) := 
 CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY(
 pdb_descr_file => '/opt/oracle/unplug/db12c1_convert.xml',
 pdb_name => 'NCDB1')
 WHEN TRUE THEN 'YES'
 ELSE 'NO'
END;
BEGIN
 DBMS_OUTPUT.PUT_LINE(compatible);
END;
/
NO

PL/SQL procedure successfully completed.

SQL> 
/

If the scripts returns NO, then check PDB_PLUG_IN_VIOLATIONS view

SQL> select name,cause,type,message,status from PDB_PLUG_IN_VIOLATIONS where name='NCDB1'

NAME                           CAUSE                  TYPE      MESSAGE                                                                                              STATUS
------------------------------ ---------------------- --------- ---------------------------------------------------------------------------------------------------- ---------
NCDB1                          OPTION                 WARNING   Database option APS mismatch: PDB installed version NULL. CDB installed version 12.1.0.1.0.          PENDING
NCDB1                          OPTION                 WARNING   Database option SDO mismatch: PDB installed version NULL. CDB installed version 12.1.0.1.0.          PENDING
NCDB1                          OPTION                 WARNING   Database option XOQ mismatch: PDB installed version NULL. CDB installed version 12.1.0.1.0.          PENDING
NCDB1                          Non-CDB to PDB         WARNING   PDB plugged in is a non-CDB, requires noncdb_to_pdb.sql be run.                                      PENDING
NCDB1                          Parameter              WARNING   CDB parameter sga_target mismatch: Previous 788529152 Current 1979711488                             PENDING
NCDB1                          Parameter              WARNING   CDB parameter pga_aggregate_target mismatch: Previous 262144000 Current 655360000                    PENDING

6 rows selected.

There are WARNING’s only. We can continue.

5. Plug-in Non-CDB:
5.1 Use the NOCOPY Mode:

SQL> CREATE PLUGGABLE DATABASE ncdb1 USING '/opt/oracle/unplug/db12c1_convert.xml' NOCOPY;
*
ERROR at line 1:
ORA-27038: created file already exists
ORA-01119: error in creating database file
'/opt/oracle/app/oradata/DB12C1/datafile/o1_mf_temp_8yjcdrw0_.tmp'

If use NOCOPY you can delete the tempfile or reuse it

SQL> CREATE PLUGGABLE DATABASE ncdb1 USING '/opt/oracle/unplug/db12c1_convert.xml' NOCOPY TEMPFILE REUSE;

Pluggable database created.

SQL> select name from v$datafile;

NAME
----------------------------------------------------------------------------------------------------
/opt/oracle/app/oradata/CDB12C/datafile/o1_mf_system_8xmpwox6_.dbf
/opt/oracle/app/oradata/CDB12C/datafile/o1_mf_sysaux_8xmptylz_.dbf
/opt/oracle/app/oradata/CDB12C/datafile/o1_mf_undotbs1_8xmpygh6_.dbf
/opt/oracle/app/oradata/pdbseed/system01.dbf
/opt/oracle/app/oradata/CDB12C/datafile/o1_mf_users_8xmpyf7f_.dbf
/opt/oracle/app/oradata/pdbseed/sysaux01.dbf
/opt/oracle/app/oradata/DB12C1/datafile/o1_mf_system_8yjcbjpj_.dbf
/opt/oracle/app/oradata/DB12C1/datafile/o1_mf_sysaux_8yjc93j2_.dbf
/opt/oracle/app/oradata/DB12C1/datafile/o1_mf_users_8yjccxy4_.dbf

9 rows selected.

5.2 Use the COPY mode

SQL> CREATE PLUGGABLE DATABASE ncdb1 USING '/opt/oracle/unplug/db12c1_convert.xml' COPY;

Pluggable database created.

SQL> select name from v$datafile;

NAME
----------------------------------------------------------------------------------------------------
/opt/oracle/app/oradata/CDB12C/datafile/o1_mf_system_8xmpwox6_.dbf
/opt/oracle/app/oradata/CDB12C/datafile/o1_mf_sysaux_8xmptylz_.dbf
/opt/oracle/app/oradata/CDB12C/datafile/o1_mf_undotbs1_8xmpygh6_.dbf
/opt/oracle/app/oradata/pdbseed/system01.dbf
/opt/oracle/app/oradata/CDB12C/datafile/o1_mf_users_8xmpyf7f_.dbf
/opt/oracle/app/oradata/pdbseed/sysaux01.dbf
/opt/oracle/app/oradata/CDB12C/E1CE01B6E8AB0B36E0430100007F25C7/datafile/o1_mf_system_8yjr6xjs_.dbf
/opt/oracle/app/oradata/CDB12C/E1CE01B6E8AB0B36E0430100007F25C7/datafile/o1_mf_sysaux_8yjr7262_.dbf
/opt/oracle/app/oradata/CDB12C/E1CE01B6E8AB0B36E0430100007F25C7/datafile/o1_mf_users_8yjr766m_.dbf

6. Switch containert to PDB and start convert script:

SQL> alter session set container = NCDB1;

Session altered.

SQL> @?/rdbms/admin/noncdb_to_pdb.sql
SQL> SET SERVEROUTPUT ON
SQL> SET FEEDBACK 1
SQL> SET NUMWIDTH 10
SQL> SET LINESIZE 80
SQL> SET TRIMSPOOL ON
SQL> SET TAB OFF
SQL> SET PAGESIZE 100
SQL> 
SQL> WHENEVER SQLERROR EXIT;
SQL> 
SQL> DOC
DOC>#######################################################################
DOC>#######################################################################
DOC> The following statement will cause an "ORA-01403: no data found"
DOC> error if we're not in a PDB.
DOC> This script is intended to be run right after plugin of a PDB,
DOC> while inside the PDB.
DOC>#######################################################################
DOC>#######################################################################
DOC>#
SQL> 
SQL> VARIABLE cdbname VARCHAR2(128)
SQL> VARIABLE pdbname VARCHAR2(128)
SQL> BEGIN
 2 SELECT sys_context('USERENV', 'CDB_NAME')
 3 INTO :cdbname
 4 FROM dual
 5 WHERE sys_context('USERENV', 'CDB_NAME') is not null;
 6 SELECT sys_context('USERENV', 'CON_NAME')
 7 INTO :pdbname
 8 FROM dual
 9 WHERE sys_context('USERENV', 'CON_NAME') <> 'CDB$ROOT';
 10 END;
 11 /

PL/SQL procedure successfully completed.

SQL> 
SQL> COLUMN pdbname NEW_VALUE pdbname
SQL> COLUMN pdbid NEW_VALUE pdbid
SQL> 
SQL> select :pdbname pdbname from dual;

PDBNAME
--------------------------------------------------------------------------------
NCDB1

1 row selected.
...
script is running some very interesting things
...
SQL> alter session set container = "&pdbname";

Session altered.

SQL> 
SQL> -- leave the PDB in the same state it was when we started
SQL> BEGIN
 2 execute immediate '&open_sql &restricted_state';
 3 EXCEPTION
 4 WHEN OTHERS THEN
 5 BEGIN
 6 IF (sqlcode <> -900) THEN
 7 RAISE;
 8 END IF;
 9 END;
 10 END;
 11 /

PL/SQL procedure successfully completed.

SQL> 
SQL> WHENEVER SQLERROR CONTINUE;
SQL>

7. Now you can open the PDB, there may occur an error:

SQL> show con_name

CON_NAME
------------------------------
NCDB1

SQL> alter database open read write;
alter database open read write
*
ERROR at line 1:
ORA-24344: success with compilation error

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

1 row selected.

In alertlog you will see
********************************************** ******************
WARNING: Pluggable Database NCDB1 with pdb id - 3 is altered with warnings.
Please look into PDB_PLUG_IN_VIOLATIONS view for more details.
****************************************************************

8. To correct the ORA-24344 check PDB_PLUG_IN_VIOLATIONS, correct them and resync

SQL> alter session set container=CDB$ROOT;
Session altered.

SQL> alter pluggable database ncdb1 close;

Pluggable database altered.

SQL> alter pluggable database ncdb1 open restricted;

Pluggable database altered.

SQL> exec dbms_pdb.sync_pdb();

PL/SQL procedure successfully completed.

SQL> alter pluggable database ncdb1 close immediate;

Pluggable database altered.

SQL> alter pluggable database ncdb1 open;

Pluggable database altered.

9. Recheck open problems

SQL> select name,cause,type,message,status from PDB_PLUG_IN_VIOLATIONS where name='NCDB1';

NAME                           CAUSE                  TYPE      MESSAGE                                                                                              STATUS
------------------------------ ---------------------- --------- ---------------------------------------------------------------------------------------------------- ---------
NCDB1                          Non-CDB to PDB         ERROR     PDB plugged in is a non-CDB, requires noncdb_to_pdb.sql be run.                                      RESOLVED
NCDB1                          OPTION                 WARNING   Database option APS mismatch: PDB installed version NULL. CDB installed version 12.1.0.1.0.          PENDING
NCDB1                          OPTION                 WARNING   Database option SDO mismatch: PDB installed version NULL. CDB installed version 12.1.0.1.0.          PENDING
NCDB1                          OPTION                 WARNING   Database option XOQ mismatch: PDB installed version NULL. CDB installed version 12.1.0.1.0.          PENDING

9. Done. PDB is ready to use. Don’t forget to backup the new database.

Database 12c: Pluggable database autostart like HAS


Today I discussed with a college the problem of a simple autostart trigger like I posted here.

After some brainstorming I’vh written a new example that acts like oracle HAS (High Availability Service). The pluggable database should have the same state as after a reboot sequence.

Here the coding example:

First create a table in the CDB:

create table pdbs_autostart (
 con_id      number,
 dbid        number,
 name        varchar2(30),
 open_mode   varchar2(10),
 restricted  varchar2(3),
 locked      varchar2(3),
 error       varchar2(200)
);

Further create a startup and shutdown trigger:
Startup trigger:

CREATE OR REPLACE TRIGGER start_pdbs
   AFTER STARTUP ON DATABASE
DECLARE
  opencmd varchar2(100);
  v_errm  varchar2(200);
BEGIN
  for db in (select * from pdbs_autostart) loop
    if db.locked != 'YES' and db.name !='PDB$SEED' and db.open_mode != 'MOUNTED' then
      opencmd := 'alter pluggable database '||db.name||' OPEN '||db.open_mode;
      if db.restricted = 'YES' then
        opencmd := opencmd||' RESTRICTED';
      end if;

      BEGIN
        execute immediate opencmd;
        update pdbs_autostart set error='NO ERROR' where name = db.name;
      EXCEPTION WHEN OTHERS THEN
        v_errm := SUBSTR(SQLERRM, 1 , 200);
        update pdbs_autostart set error=v_errm where name = db.name;
      END;
    else
      update pdbs_autostart set error='Skipped' where name = db.name;
    end if;
  end loop;
  commit;
END;
/

Shutdown tigger:

CREATE OR REPLACE TRIGGER shutdown_pdbs
  BEFORE SHUTDOWN ON DATABASE
BEGIN 
  merge into  pdbs_autostart a
  using       v$pdbs         b
  on          (a.dbid = b.dbid)
  when matched then
    update set a.con_id = b.con_id,a.name = b.name,a.open_mode=b.open_mode,a.restricted=nvl(b.restricted,'NO'),error='' where a.locked = 'NO'
    delete where b.dbid not in (select dbid from v$pdbs )
  when not matched then
    insert values (b.con_id,b.dbid,b.name,b.open_mode,b.restricted,'NO','')
  ;  
  commit;
END; 
/

At every shutdown the state of the database will be written into the table pdbs_autostart. After startup of database the trigger starts all database as saved in table.

I’vh also added an LOCKED column to prevent state change at shutdown. This is useful if you want to permanent save your configuration. Alternativ you can disable the shutdown trigger.

If an error occurs during startup, it will be written in the error column.

Here the construction in action:

SQL> select name,open_mode from v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB3                           MOUNTED
PDB2                           READ ONLY
PDB1                           READ WRITE
PDB4                           READ WRITE
PDB5                           MOUNTED

6 rows selected.

Check the actual state, then start PDB3 and PDB5.

SQL> alter pluggable database pdb3 open;

Pluggable database altered.

SQL> alter pluggable database pdb5 open;

Pluggable database altered.

Check configuration. PDB3 state should be changed at shutdown and should startup at next restart. PDB5 ist LOCKED and should not be overruled at next startup. It will not be started at next time.

SQL> select * from pdbs_autostart;

    CON_ID       DBID NAME                           OPEN_MODE  RES LOCKED ERROR
---------- ---------- ------------------------------ ---------- --- ------ -----------------------------------------------------------------
         3 3328312323 PDB3                           MOUNTED    NO  NO  
         2 4062846046 PDB$SEED                       READ ONLY  NO  NO  
         4 3887199318 PDB2                           READ ONLY  NO  NO  
         7 3881397024 PDB5                           MOUNTED        YES 
         6 3831633646 PDB4                           READ WRITE NO  NO  
         5 3328633065 PDB1                           READ WRITE NO  NO  

6 rows selected.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup
ORACLE instance started.

Total System Global Area 1970864128 bytes
Fixed Size                  2289928 bytes
Variable Size             587206392 bytes
Database Buffers         1375731712 bytes
Redo Buffers                5636096 bytes
Database mounted.
Database opened.
SQL> select name,open_mode from v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB3                           READ WRITE
PDB2                           READ ONLY
PDB1                           READ WRITE
PDB4                           READ WRITE
PDB5                           MOUNTED

6 rows selected.

SQL>

It works! Have fun!

First steps with the new technology: Pluggable Database theory


Today I want to discuss the feature “pluggable database” of the new 12c release. Before we start some theoretical: The Oracle CDB (Containter Database) technology, simple described, is an oracle instance (CDB) with some virtual databases (PDB):

cdb_overview

The CDB$ROOT is the root container which is the container database itself. The PDB$SEED is a template Database for creating new PDB’s. A CDB can manage up to 252 PDB’s.

1. Here some facts

  • Dictionary structure
    • The database dictionary exists in multiple levels. At CDB level which hold all data about all PDB’s and some metadata. At PDB level the dictionary acts like in before.
    • This split dictionary configuration enable a quick and smart migration (unplug/plug) of the database to other systems
    • Each PDB sees a read only copy of the oracle system
  • Instance structure
    • Each PDB can started and stopped separatly
    • Parameters can be adjusted at cdb and pdb level. All parameters of the pdb are saved in the transportset. So if you unplug and plug the PDB to another system, the parameters are not lost.
    • Instance processes are shared between cdb and all pdb’s
    • Each CDB has one shared SGA between the CDB and PDB
  • Database structure
    • There is only one active UNDO Tablespace per CDB instance.
    • Onlinelogs and controlfiles are shared between CDB and PDB’s
    • Permamenty and temporary tablespaces can be shared at CDB level or used local at PDB level
  • Security structure
    • The database users SYS and SYSTEM exists right from first plug.
    • Users can be created at CDB level as common user or local user
    • Users created at PDB level are local for the PDB created in
    • New DBA roles:
      • CDB_DBA for CDB administrators
      • PDB_DBA for PDB administrators
  • High availability structure
    • RMAN Backup should be done at CDB level. Point in time recovery per PDB is possible
    • Physical standby, logical standby and DataGuard operates at CDB level
  • Management of PDB’s
    • There is at least one unique service name for each PDB which can be used for user connections

2. Managing CDB and PDB’s
2.1 Connecting to CDB / PDB

CDB (old style): "sqlplus / as sysdba" 
PDB (new style) via listener: "sqlplus sys/@ as sysdba" 
PDB (new style) via alter system: "alter session set container = <PDBNAME>"

2.1.1 Checking available PDB’s

 sqlplus / as sysdba SQL> select pdb_id,pdb_name,dbid from cdb_pdbs
PDB_ID PDB_NAME DBID
 ---------- ---------- ----------
 2 PDB$SEED 4062846046
 3 PDB12C1 2256791230
 4 PDB12C2 1952495537

2.1.2 Connect to PDB via listener
First check listener and service state:

[bash ~]$ lsnrctl status
LSNRCTL for Linux: Version 12.1.0.1.0 - Production on 08-JUL-2013 23:07:48 Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=0.0.0.0)(PORT=1521)))
 STATUS of the LISTENER
 ------------------------
 Alias LISTENER
 Version TNSLSNR for Linux: Version 12.1.0.1.0 - Production
 Start Date 08-JUL-2013 21:02:10
 Uptime 0 days 2 hr. 5 min. 38 sec
 Trace Level off
 Security ON: Local OS Authentication
 SNMP OFF
 Listener Parameter File /opt/oracle/app/product/12.1.0/dbhome_1/network/admin/listener.ora
 Listening Endpoints Summary...
 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
 Services Summary...
 Service "CDB12C" has 1 instance(s).
 Instance "CDB12C", status READY, has 1 handler(s) for this service...
 Service "CDB12CXDB" has 1 instance(s).
 Instance "CDB12C", status READY, has 1 handler(s) for this service...
 Service "pdb12c1" has 1 instance(s).
 Instance "CDB12C", status READY, has 1 handler(s) for this service...
 Service "pdb12c2" has 1 instance(s).
 Instance "CDB12C", status READY, has 1 handler(s) for this service...
 The command completed successfully

Add tnsnames.ora entry:

PDB12C1 =
 (DESCRIPTION =
 (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
 (CONNECT_DATA =
 (SERVER = DEDICATED)
 (SERVICE_NAME = PDB12C1)
 )
 )

PDB12C2 =
 (DESCRIPTION =
 (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
 (CONNECT_DATA =
 (SERVER = DEDICATED)
 (SERVICE_NAME = PDB12C2)
 )
 )

Finally connect via listener

[bash~]$ sqlplus sys/welcome1@PDB12C1 as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Mon Jul 8 22:48:44 2013
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
 Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
 With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> select database_name from v$database;
DATABASE_NAME
 --------------------------------------------------------------------------------
 PDB12C1

2.1.3 Connect to PDB via “alter session”

Starting at CDB level:
 SQL> select database_name from v$database
 DATABASE_NAME
 ---------------
 CDB12C
SQL> alter session set container = PDB12C1;
 Session altered.
SQL> select database_name from v$database;
 DATABASE_NAME
 ---------------
 PDB12C1

2.1.4 Switching from PDB to CDB

SQL> alter session set container = CDB$ROOT; Session altered.
SQL> select database_name from v$database;
 DATABASE_NAME
 ---------------
 CDB12C

2.2 Starting and stopping
2.2.1 CDB start and stop
The start and stop of a CDB is like in pre 12c databases. You can user startup or shutdown command. You can also use “alter database” command to mount/open database.

2.2.2 PDB start and stop
Show status of all PDB’s:

SQL> select con_id,dbid,name,open_mode from v$pdbs; 
CON_ID DBID NAME OPEN_MODE 
---------- ---------- ---------- ---------- 
2 4062846046 PDB$SEED READ ONLY 
3 2256791230 PDB12C1 READ WRITE 
4 1952495537 PDB12C2 MOUNTED

Minimal state of a PDB is “mounted”.

2.2.2.1 Start PDB

SQL> alter pluggable database PDB12C2 open;

Pluggable database altered.

2.2.2.2 Stop PDB

SQL> alter pluggable database PDB12C2 close immediate;
Pluggable database altered.

2.2.3 Manage all PDB’s at once
2.2.3.1 Stop all PDB’s

SQL> alter pluggable database all close immediate; 

Pluggable database altered.
SQL> select con_id,dbid,name,open_mode from v$pdbs;
 CON_ID DBID NAME OPEN_MODE
 ---------- ---------- ---------- ----------
 2 4062846046 PDB$SEED READ ONLY
 3 2256791230 PDB12C1 MOUNTED
 4 1952495537 PDB12C2 MOUNTED

2.2.3.2 Start all PDB’s

SQL> alter pluggable database all open; Pluggable database altered.
SQL> select con_id,dbid,name,open_mode from v$pdbs;
 CON_ID DBID NAME OPEN_MODE
 ---------- ---------- ---------- ----------
 2 4062846046 PDB$SEED READ ONLY
 3 2256791230 PDB12C1 READ WRITE
 4 1952495537 PDB12C2 READ WRITE