Thursday, July 9, 2015

How do I open the pluggable database (PDB) when I start the container database (CDB)?

If you’re running pluggable databases (multitenant) in Oracle 12c, you may wonder; how do I open the pluggable database (PDB) when I start the container database (CDB)?
Well, really it depends on the 12c version you are running on. I will show you the options you have depending the version you are running.

If you are running 12.1.0.1, then you have these options:

a)    Create a trigger that opens all the PDBs in the CDB.

CREATE OR REPLACE TRIGGER <trigger_name>
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE ‘ALTER PLUGGABLE DATABASE ALL OPEN’;
END;
/

b)    Create a trigger that opens only one PDB in the container.

CREATE OR REPLACE TRIGGER <trigger_name>
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE ‘ALTER PLUGGABLE DATABASE <pdb_name> OPEN READ WRITE’;
END;
/

c)    If you are running RAC, then you can use the CRS to open the PDB.

srvctl add service -db <Container_DB_Name> -service <PDB_service_name> -pdb <PDB_name> -preferred "Container_Instance1,Container_Instance2"

Now, if you are running 12.1.0.2 version, there’s a neat new feature that saves the current state of the PDBs when the CDB restarts. In other words, if you save the state of the “pdb1” when is open, next time you start the container the “pdb1” will open automatically.

In order to do this, you can execute:

ALTER PLUGGABLE DATABASE pdb1 SAVE STATE;

If you want to save the state of all the PDBs in the container.

ALTER PLUGGABLE DATABASE ALL SAVE STATE;

To discard the state of the PDBs.

ALTER PLUGGABLE DATABASE salespdb DISCARD STATE;

Want more?
http://docs.oracle.com/database/121/ADMIN/cdb_admin.htm#ADMIN14251
Thanks,

Alfredo