Oracle 12.2.0.1.0 PDB随着CDB启动而启动
Oracle 12.1和Oracle12.2版本,默认情况下PDB不会随着CDB启动而启动;
为了实现PDB随着CDB启动而启动;
在Oracle 12.1版本里,可以使用触发器来实现,触发器如下:
CREATE TRIGGER open_all_pdbs
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';
END ;
/
在Oracle 12.2版本里,除了可以使用触发器,也可以使用命令实现PDB随着CDB启动而启动,命令如下:
ALTER PLUGGABLE DATABASE ORCLPDB SAVE STATE;
实验如下:
一 :CDB启动后,ORCLPDB状态为MOUNTED
SQL> shutdown immediate
SQL> startup
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB MOUNTED
SQL> col name for a10
SQL> select con_id,name,open_mode from v$containers;
CON_ID NAME OPEN_MODE
---------- ---------- ----------
1 CDB$ROOT READ WRITE
2 PDB$SEED READ ONLY
3 ORCLPDB MOUNTED
二:手动启动ORCLPDB数据库
SQL> alter session set container=ORCLPDB;
SQL> show con_id con_name user
SQL> startup
或者
SQL> alter pluggable database orclpdb open;
SQL> alter pluggable database all open;
三:执行命令,保留当前ORCLPDB状态(open)
SQL> ALTER PLUGGABLE DATABASE ORCLPDB SAVE STATE;
四:重启数据库,查看PDB已经随着CDB启动而启动了
SQL> conn /as sysdba
SQL> shutdown immediate
SQL> startup
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
SQL> col name for a10
SQL> select con_id,name,open_mode from v$containers;
CON_ID NAME OPEN_MODE
---------- ---------- ----------
1 CDB$ROOT READ WRITE
2 PDB$SEED READ ONLY
3 ORCLPDB READ WRITE
---查看警告日志也可以看到orclpdb数据库自动启动
[root@chenjch trace]# tail -f alert_orcl.log
2017-04-16T16:33:08.398561+08:00
ORCLPDB(3):Opening pdb with no Resource Manager plan active
Pluggable database ORCLPDB opened read write
五:也可以通过命令改回原来的状态,即启动CDB时PDB不启动;
SQL> ALTER PLUGGABLE DATABASE ORCLPDB DISCARD STATE;
SQL> shutdown immediate
SQL> startup
SQL> col name for a10
SQL> select con_id,name,open_mode from v$containers;
CON_ID NAME OPEN_MODE
---------- ---------- ----------
1 CDB$ROOT READ WRITE
2 PDB$SEED READ ONLY
3 ORCLPDB MOUNTED
SQL> col name for a10
SQL> select con_id,name,open_mode from v$containers;
CON_ID NAME OPEN_MODE
---------- ---------- ----------
1 CDB$ROOT READ WRITE
2 PDB$SEED READ ONLY
3 ORCLPDB MOUNTED
How to Preserve Open Mode of PDBs When the CDB Restarts (文档 ID 1933511.1) |
|
|
In this Document
APPLIES TO: Oracle Database - Enterprise Edition - Version 12.1.0.1 to 12.1.0.1 [Release 12.1] From version 12.1.0.2 it is possible to save or discard the open mode of one or more PDBs when the CDB restarts. This article shows - what is the default open mode for PDBs - how to save or discard the open mode of one or more PDBs when the CDB restarts - how to monitor the save state of the PDBs. What is the default open mode for PDBsThe default open mode for a PDB is MOUNTED (except for PDB$SEED which is READ ONLY and cannot be opened READ WRITE by user). SYS@cnt122> select CON_ID, NAME, OPEN_MODE, RESTRICTED, OPEN_TIME from gv$containers; How to save or discard the open mode of a PDB when the CDB restartsYou use the ALTER PLUGGABLE DATABASE SQL statement with a pdb_save or discard_state clause. The idea is that you can save the current open state of a PDB, so that when CDB restarts this is the open mode the PDB will be in. When you discard the previously saved open mode for a PDB, then the PDB will be in MOUNTED mode when CDB restarts. E.g. to save the current open state for PDBP2, execute the following: SQL> ALTER PLUGGABLE DATABASE PDBP2 SAVE STATE; Pluggable database altered.
E.g. to discard the saved state for PDBP2, execute the following: SQL> ALTER PLUGGABLE DATABASE PDBP2 DISCARD STATE; For Oracle RAC CDB you can use the instances clause together with the in the pdb_save or discard_state clause to specify the instances on which a PDB's open mode is preserved. See more information is in the documentation. How to monitor the save state of the PDBs You can use the DBA_PDB_SAVED_STATES view to see the save state for PDBs, see details in the documentation. SQL> STARTUP PLUGGABLE DATABASE PDBP2 open Only the save state is recorded. Once the discard state command is executed for a PDB, the saved state entry for the pdb is removed from DBA_PDB_SAVED_STATES. SQL> ALTER PLUGGABLE DATABASE PDBP2 DISCARD STATE;
As it was mentioned above saving the open state of a PDB is available since 12.1.0.2. e.g. To open all PDBs at CDB startup, create the following trigger in CDB: CREATE TRIGGER open_all_pdbs |
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29785807/viewspace-2137362/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29785807/viewspace-2137362/