②:在12C R2引入了PDB Local UNDO模式,每个container都有自己的UNDO 表空间, 对于RAC是每个实例每个container都有自己的UNDO表空间, 这也正是推荐的.在DBCA时会有local undo选项,且默认勾选。
local undo 模式的好处:
①:减少undo表空间的争用,同时方便拔插
②:只有使用local undo才支持下面的新特性: Refresh PDB, Flashback PDB ,( Hot Clone, Relocate PDB in open read/write mode)
③:point-in-time recovery PDB
--注意:如果要将local UNO 转为 shared UNO,数据库必须要以upgrade方式启动,否则会报错;
二、 local undo 转 shared undo :
①:查看 local undo 是否开启:(默认是开启 local undo,因为在安装的时候默认是勾选这个选项的)
SQL> col PROPERTY_NAME for a25;
SQL> col PROPERTY_VALUE for a25;
SQL> select PROPERTY_NAME,PROPERTY_VALUE from database_properties where property_name= 'LOCAL_UNDO_ENABLED' ;
PROPERTY_NAME PROPERTY_VALUE
------------------------- -------------------------
LOCAL_UNDO_ENABLED TRUE
注意:在Oracle12.1版本中 undo只支持Global Shared Undo模式,不支持 local undo选项
②:重启数据库,以upgrade方式启动:
SQL> shutdown immediate
SQL> startup upgrade
SQL> alter database local undo off; ---改变 local undo的模式,数据库必须以upgrade方式启动。
SQL> shutdown immediate
SQL> startup
SQL> col PROPERTY_NAME for a25;
SQL> select PROPERTY_NAME,PROPERTY_VALUE from database_properties where property_name= 'LOCAL_UNDO_ENABLED' ;
PROPERTY_NAME PROPERTY_VALUE
------------------------- -------------------------
LOCAL_UNDO_ENABLED FALSE
---注意,从上一步查询得知,local_undo 已经关闭了;
③:把pdb中的undo表空间删除:
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB READ WRITE NO
SQL> alter session set container=testpdb ;
SQL> select tablespace_name from dba_tablespaces; ----查看现在的表空间,
TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
TEST
6 rows selected.
SQL> select name from v $datafile where name like '%undo%' ; ---查看可以得知,目前有两个undo表空间,一个是CDB的,一个是PDB自己的
NAME
--------------------------------------------------------------------------------
/opt/oracle/oradata/orcl/undotbs01 .dbf
/opt/oracle/oradata/orcl/testpdb/undotbs01 .dbf
SQL> drop tablespace UNDOTBS1 including contents and datafiles; ---删除pdb中的undo表空间,(一定是进入到pdb在执行这条命令)
Tablespace dropped.
SQL> select name from v $datafile where name like '%undo%' ; ---此时查看undo表空间,就只剩下CDB中的一个了
NAME
--------------------------------------------------------------------------------
/opt/oracle/oradata/orcl/undotbs01 .dbf
SQL> show con_name;
CON_NAME
------------------------------
TESTPDB
二、shared undo 转 local undo :
SQL> shutdown immediate
SQL> startup upgrade ---必须以upgrade启动数据库
SQL> alter database local undo on; ----开启 local undo模式
SQL> shutdown immediate
SQL> startup
SQL> col PROPERTY_NAME for a25;
SQL> col PROPERTY_VALUE for a25;
SQL> select PROPERTY_NAME,PROPERTY_VALUE from database_properties where property_name= 'LOCAL_UNDO_ENABLED' ;
PROPERTY_NAME PROPERTY_VALUE
------------------------- -------------------------
LOCAL_UNDO_ENABLED TRUE
SQL> alter pluggable database testpdb open ;
SQL> alter session set container=testpdb;
SQL> select name from v $datafile where name like '%undo%' ;
NAME
-----------------------------------------------------------------------------------------------------------------------------------------
/opt/oracle/oradata/orcl/testpdb/system01_i1_undo .dbf