参考文档:
How to Preserve Open Mode of PDBs When the CDB Restarts (Doc ID 1933511.1)
-- 查看pdb的保留状态.无保留状态
select * from DBA_PDB_SAVED_STATES;
SYS@cdbtest SQL> select * from DBA_PDB_SAVED_STATES;no rows selectedSYS@cdbtest SQL>
-- 查看pdb 的当前的open mode
select CON_ID, NAME, OPEN_MODE, RESTRICTED, OPEN_TIME from gv$containers;
-- 将pdb状态设置为保持现状(当前各个pdb状态为open)
ALTER PLUGGABLE DATABASE all SAVE STATE;
-- 取消pdb的保持状态
ALTER PLUGGABLE DATABASE all DISCARD STATE;SYS@cdbtest SQL> ALTER PLUGGABLE DATABASE all SAVE STATE;Pluggable database altered.SYS@cdbtest SQL>
-- 重启库测试,pdb可以自动起来
SYS@cdbtest SQL> ALTER PLUGGABLE DATABASE all SAVE STATE;Pluggable database altered.SYS@cdbtest SQL>
SYS@cdbtest SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@cdbtest SQL> startup
ORACLE instance started.Total System Global Area 2785014256 bytes
Fixed Size 9167344 bytes
Variable Size 1191182336 bytes
Database Buffers 1577058304 bytes
Redo Buffers 7606272 bytes
Database mounted.
Database opened.
SYS@cdbtest SQL> show pdbs;CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------2 PDB$SEED READ ONLY NO3 TEST READ WRITE NO4 ORCL READ WRITE NO5 BAK READ WRITE NO
SYS@cdbtest SQL>
-- 在12.2.0.1上,可以设置触发器,来使pdb自动启动
As it was mentioned above saving the open state of a PDB is available since 12.1.0.2.
For 12.1.0.1 you may create a database startup trigger to place PDB(s) into a particular open mode at DB startup.
e.g. To open all PDBs at CDB startup, create the following trigger in CDB:
CREATE TRIGGER open_all_pdbsAFTER STARTUP ON DATABASE
BEGINEXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';
END ;
/
-- 补充推荐在rac上保留pdb的状态
Saving the state for PDBs for RAC databases is not recommended.
Oracle RAC will open PDBs on a node if Services are defined on that PDB. It is no longer necessary to save state in Oracle RAC environments.
PDBs may open on nodes where it was not intended.
Per note "Services running simultaneously on preferred and available instances in a multitenant RAC database (Doc ID 2757584.1),"
> In RAC it is not recommended to save the state of PDBs. RAC will open the PDBs on a node if the services are defined on that PDB.
> It is no longer necessary to save the state in RAC environments.
> Saving state leads to opening the service/PDB on the nodes where it is not intended and the performance may be affected adversely.
> An additional check is introduced in Oracheck to give warning about the saved state.
END