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;

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
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: