RAC环境如何设置当CDB打开时,PDB 也打开呢?
我需要用到 alter pluggable database orclpdb1 save state 语句。
具体过程,如下面的例子:
在第一个节点执行:
[oracle@orc01 ~]$ export ORACLE_SID=orclcdb1 [oracle@orc01 ~]$ sqlplus / as sysdba SQL> show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 ORCLPDB1 MOUNTED 4 ORCLPDB2 MOUNTED SQL> <<<<< 打开数据库后,执行 “save state" 语句: SQL> alter pluggable database orclpdb1 open; SQL> alter pluggable database orclpdb1 save state; <<<<< 重启数据库: [oracle@orc01 ~]$ srvctl stop database -db orclcdb [root@orc02 ~]# srvctl start database -db orclcdb <<<<< 可以看到,此时,数据库自动打开了(READ WRITE): [oracle@orc01 ~]$ export ORACLE_SID=orclcdb1 [oracle@orc01 ~]$ sqlplus / as sysdba SQL> show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 ORCLPDB1 READ WRITE NO *** 4 ORCLPDB2 MOUNTED SQL> <<<<< 但是我们到另外一个节点去看,看到的是,这个PDB 并没有被打开。 [oracle@orc02 ~]$ export ORACLE_SID=orclcdb2 [oracle@orc02 ~]$ sqlplus / as sysdba SQL> show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 ORCLPDB1 MOUNTED *** 4 ORCLPDB2 MOUNTED SQL>
可以说,PDB 数据库的 save state ,是以节点(instance) 为单位的。
那么,如何再各个节点,都自动打开PDB呢,可以指明 instance 名字:
SQL> alter pluggable database orclpdb1 save state instances=('orclcdb1','orclcdb2'); [oracle@orc01 ~]$ srvctl stop database -db orclcdb [oracle@orc01 ~]$ [oracle@orc01 ~]$ srvctl start database -db orclcdb 节点一查看: SQL> show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 ORCLPDB1 READ WRITE NO 4 ORCLPDB2 MOUNTED SQL> 节点二查看: SQL> show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 ORCLPDB1 MOUNTED 4 ORCLPDB2 MOUNTED
还有一个问题需要注意,如果设置了 PDB 自动打开之后,我怎么知道我已经设置过了呢?可以查询:
SELECT con_name, instance_name, state FROM dba_pdb_saved_states;