一聚教程网:一个值得你收藏的教程网站

热门教程

Oracle 12c中PDB随CDB启动的例子

时间:2022-06-29 09:38:52 编辑:袖梨 来源:一聚教程网

12.1.0.2之前,用startup trigger:

 代码如下 复制代码

--在CDB中建立startup trigger
CREATE TRIGGER open_all_pdbs
   AFTER STARTUP
   ON DATABASE
BEGIN
   EXECUTE IMMEDIATE 'alter pluggable database all open';
END open_all_pdbs;
/


12.1.0.2之后,用PDB save state

 代码如下 复制代码

下面的命令可以放pdb保持其关机前的状态,语法如下:
ALTER PLUGGABLE DATABASE [all]|[PDB_NAME] SAVE STATE;
取消设置的话,语法如下:
ALTER PLUGGABLE DATABASE [all]|[PDB_NAME]  DISCARD STATE;
 
如:
alter pluggable database pdbrac1 save state;
alter pluggable database all discard state;
 
 
注意,savle state只是抓取当前的状态进行save,如果当前状态是mount,然后save state了。然后在open all pdb,再重启cdb,重启后只是会恢复到open all pdb之前的状态,即save state时的状态。
 
SQL> show con_name
 
CON_NAME
------------------------------
CDB$ROOT
SQL>
SQL> startup
ORACLE instance started.
 
Total System Global Area 1560281088 bytes
Fixed Size                  2924784 bytes
Variable Size            1056968464 bytes
Database Buffers          486539264 bytes
Redo Buffers               13848576 bytes
Database mounted.
Database opened.
SQL>  --最初时,2个pdb启动后状态都是mounted的。       
SQL>  select NAME,OPEN_MODE from v$pdbs;
 
NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDBRAC1                        MOUNTED
PDBRAC2                        MOUNTED
 
SQL> alter pluggable database PDBRAC1 open;
 
Pluggable database altered.
 
SQL> alter pluggable database pdbrac1 save state;
 
Pluggable database altered.
 
SQL>
SQL>
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL>
SQL>
SQL> startup
ORACLE instance started.
 
Total System Global Area 1560281088 bytes
Fixed Size                  2924784 bytes
Variable Size            1056968464 bytes
Database Buffers          486539264 bytes
Redo Buffers               13848576 bytes
Database mounted.
 Database opened.
SQL>
SQL>
SQL> --save state之后,PDBRAC1就是随cdb一起启动了。
SQL> select NAME,OPEN_MODE from v$pdbs;
 
NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDBRAC1                        READ WRITE
PDBRAC2                        MOUNTED
 
SQL>
SQL> --如果是先save state,在open all,那么记录的状态只是在open all 之前的。
 
SQL> alter pluggable database all save state;
 
Pluggable database altered.
 
SQL> alter pluggable database all open;
 
Pluggable database altered.
 
SQL>
SQL>
SQL>
SQL>
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL>
SQL>
SQL> startup
ORACLE instance started.
 
Total System Global Area 1560281088 bytes
Fixed Size                  2924784 bytes
Variable Size            1056968464 bytes
Database Buffers          486539264 bytes
Redo Buffers               13848576 bytes
Database mounted.
 Database opened.
SQL>
SQL> --因此重启cdb之后,也只是恢复save state时候的状态,即open all之前的,只有PDBRAC1打开的状态。
SQL> select NAME,OPEN_MODE from v$pdbs;
 
NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDBRAC1                        READ WRITE
PDBRAC2                        MOUNTED
 
SQL>

热门栏目