How To Open The PDBS Automatically When CDB Restarts | Save State of PDBS

In oracle 12c , when we startup the CDB, the PDBS will be in MOUNTED stage. We need to open them manually using alter pluggable PDB open. To make the PDBS open automatically, we can use the saved state option . This feature is available from Oracle 12.1.0.2  onwards 

Start the container database and you will find that all PDBS are in mount stage.

[oracle@prim ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Wed Sep 23 14:47:49 2020

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

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 1140850688 bytes
Fixed Size 8791960 bytes
Variable Size 805308520 bytes
Database Buffers 318767104 bytes
Redo Buffers 7983104 bytes
Database mounted.
Database opened.
SQL>


SQL> show pdbs;

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDBPRIM MOUNTED
4 PDBPRIM2 MOUNTED
5 PDBPRIM4 MOUNTED
6 PDBPRIM5 MOUNTED
SQL>

Connect to the pluggable database and start the pluggable database.

SQL> alter session set container=PDBPRIM;

Session altered.

SQL> startup
Pluggable Database opened.

Connect to Container database and save the state.

SQL> alter session set container=CDB$ROOT;

Session altered.

SQL>
SQL>
SQL> alter pluggable database PDBPRIM save state;

Pluggable database altered.


Verify the state with view dba_pdb_saved_states.

SQL> select con_name, state from dba_pdb_saved_states;

CON_NAME STATE
--------------- --------------
PDBPRIM OPEN


Bounce the container database and verify pluggable database should be in open mode.

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


SQL> startup
ORACLE instance started.

Total System Global Area 1140850688 bytes
Fixed Size 8791960 bytes
Variable Size 805308520 bytes
Database Buffers 318767104 bytes
Redo Buffers 7983104 bytes
Database mounted.
Database opened.

SQL> show pdbs;

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDBPRIM READ WRITE NO
4 PDBPRIM2 MOUNTED
5 PDBPRIM4 MOUNTED
6 PDBPRIM5 MOUNTED

We can discard the state of pluggable database with following command.

SQL> alter pluggable database PDBPRIM discard state;

Pluggable database altered.


SQL> shu immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.


SQL> startup
ORACLE instance started.

Total System Global Area 1140850688 bytes
Fixed Size 8791960 bytes
Variable Size 805308520 bytes
Database Buffers 318767104 bytes
Redo Buffers 7983104 bytes
Database mounted.
Database opened.


SQL> show pdbs;

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDBPRIM MOUNTED
4 PDBPRIM2 MOUNTED
5 PDBPRIM4 MOUNTED
6 PDBPRIM5 MOUNTED

Thanks for visiting this post. Please contact us if you are looking for training.
Subscribe to our channel for unlimited learning. Thank you!!!

Share and Enjoy !

0Shares
0 0 0

Recommended For You

ankushthavali

About the Author: ankushthavali

Leave a Reply

Your email address will not be published. Required fields are marked *