- oracle12.1只能使用触发器
- oracle12.2可用
ALTER pluggable DATABASE ALL save state;
- 高版本建议优先使用第二种模式
- 触发器模式
CREATE TRIGGER open_all_pdbs
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'alter pluggable database all open';
END open_all_pdbs;
/
- 状态保存模式
#12.2以上版本在pdb open状态下打以下命令执行
ALTER pluggable DATABASE ALL save state;–自动启动PDB
ALTER pluggable DATABASE ALL discard state;–取消自动启动PDB
参考如下:
SQL> startup
ORACLE instance started.
Total System Global Area 3741318376 bytes
Fixed Size 9141480 bytes
Variable Size 754974720 bytes
Database Buffers 2969567232 bytes
Redo Buffers 7634944 bytes
Database mounted.
Database opened.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 MOUNTED(默认状态)
SQL> alter session set container=pdb1;--切换到
Session altered.
SQL> alter database open;--开启pdb1 open状态
Database altered.
SQL> alter session set container=cdb$root;--切换到cdb才能执行
Session altered.
SQL> ALTER pluggable DATABASE ALL save state;--这一行修改
Pluggable database altered.
SQL> shutdown immediate; --重启
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 3741318376 bytes
Fixed Size 9141480 bytes
Variable Size 754974720 bytes
Database Buffers 2969567232 bytes
Redo Buffers 7634944 bytes
Database mounted.
Database opened.
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ(修改后状态) WRITE NO