How to Open PDBs Automatically After CDB Opened

To open pdbs automatically, for 12.1.0.1, write a database startup trigger. for 12.1.0.2 onwards, open pdbs first, then save the pdbs state.

1) For 12.1.0.1, create a trigger to startup PDBs while CBD is up running.

CREATE OR REPLACE TRIGGER auto_open_pdbs 
  AFTER STARTUP ON DATABASE 
BEGIN 
   EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN'; 
END auto_open_pdbs;
/

2) For 12.1.0.2 onwards including 12.1.0.2, 12.2.0.1, 18c, 19c,and 20c ….

Run below command to open pluggable database, and save the state of PDBs.

ALTER PLUGGABLE DATABASE pdb1 OPEN;
ALTER PLUGGABLE DATABASE pdb1 SAVE STATE;

— For RAC

SQL > ALTER PLUGGABLE DATABASE pdb1 OPEN INSTANCES=all;
SQL > ALTER PLUGGABLE DATABASE pdb1 SAVE STATE INSTANCES=all;

SQL> select CON_ID,CON_NAME,INSTANCE_NAME,STATE,RESTRICTED from dba_pdb_saved_states;

CON_ID CON_NAME INSTANCE_NAM STATE RES
---------- ------- ------------ -------------- ---
3 PDB1 CDB1 OPEN NO
3 PDB1 CDB1 OPEN NO

Check the saved state of containers :

SELECT con_name, instance_name, state FROM dba_pdb_saved_states;

CON_NAME             INSTANCE_NAME        STATE
-------------------- -------------------- --------------
PDB1                 cdb1                 OPEN

SELECT name, open_mode FROM v$pdbs;

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

Shutdown and startup database, the PDB starts up automatically.

shutdown immediate;
startup;

SELECT name, open_mode FROM v$pdbs;

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

To discard any saved state of a pluggable database using below statement.

SQL>alter pluggable database PDB1 discard state instances=all;

Pluggable database altered.

SQL> select CON_ID,CON_NAME,INSTANCE_NAME,STATE,RESTRICTED from dba_pdb_saved_states;

no rows selected