undo 在12C R1版本中只支持Global Shared Undo模式, 所有container共享一个UNDO表空间, 目前保留这种模式只是为了升级过渡, 在12C R2引入了PDB Local UNDO模式,每个container都有自己的UNDO 表空间, 对于RAC是每个实例每个container都有自己的UNDO表空间, 这也正是推荐的.在DBCA时会有local undo选项,且默认勾选。
local undo 模式的好处:
1.减少undo表空间的争用,同时方便拔插
2.只有使用local undo才支持下面的新特性: Refresh PDB, Flashback PDB ,( Hot Clone, Relocate PDB in open read/write mode)
3.point-in-time recovery PDB
一、 local undo 转 shared undo :
查看数据库是否开启 local undo ,如果 PROPERTY_VALUE 为 true 表示已经开启。
SQL>
col PROPERTY_NAME for a25;
col PROPERTY_VALUE for a25;
select PROPERTY_NAME,PROPERTY_VALUE from database_properties where property_name='LOCAL_UNDO_ENABLED';
PROPERTY_NAME PROPERTY_VALUE
------------------------- -------------------------
LOCAL_UNDO_ENABLED TRUE
SQL>shutdown immediate;
SQL>startup upgrade;
SQL>show con_nameCON_NAME
------------------------------
CDB$ROOT
SQL>alter database local undo off;
SQL>shutdown immediate;
SQL>startup;
SQL>show pdbs
SQL>alter session set container=pdb01;
e/o1_mf_undotbs1_djszmxkc_.dbf
SQL>select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
SQL>
col PROPERTY_NAME for a30;
col PROPERTY_VALUE for a20;
select PROPERTY_NAME,PROPERTY_VALUE from database_properties where property_name='LOCAL_UNDO_ENABLED';
PROPERTY_NAME PROPERTY_VALUE
------------------------- -------------------------
LOCAL_UNDO_ENABLED FALSE
SQL>
col file_name for a70;
select a.CON_ID,a.TABLE CON_ID TABLESPACE_NAME FILE_NAME
from cdb_tablespaces a,CDB_DATA_FILES b
where a.TABLESPACE_NAME=b.TABLESPACE_NAME and a.con_id=b.con_id and a.CONTENTS='UNDO';
--------- ------------------------------ ----------------------------------------
3 UNDOTBS1 /home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/
datafile/o1_mf_undotbs1_djszmxkc_.dbfSPACE_NAME,b.FILE_NAME
SQL>drop tablespace UNDOTBS1 including contents and datafiles; ( 切记PDB中执行 )
SQL>select name from v$datafile where name like '%undo%';
NAME
-----------------------------------------------------------------------------
/home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_undotbs1_djsyyjlk_.dbf > 现在已经是 cdb 中的undo datafile 了。
二、 shared undo 转 local undo :
SQL> shutdown immediate;
SQL> startup upgrade;
SQL> show con_name >确认是 cdb,如果不是 cdb,则 alter session set container=cdb$root;
SQL> alter database local undo on;
SQL> shutdown immediate;
SQL> startup;
SQL>show pdbs
SQL>alter session set container=pdb01;
SQL>select name from v$datafile where name like '%undo%';
NAME
--------------------------------------------------------------------------------
/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafil
e/o1_mf_undo_1_djz4jq1z_.dbf
SQL>
col PROPERTY_NAME for a30;
col PROPERTY_VALUE for a20;
select PROPERTY_NAME,PROPERTY_VALUE from database_properties where property_name='LOCAL_UNDO_ENABLED';
PROPERTY_NAME PROPERTY_VALUE
------------------------------ --------------------
LOCAL_UNDO_ENABLED TRUE
说明:打开loacl undo后,自动为当前的PDB创建undo表空间,同时如果以前再新创建pdb,系统将自动创建自己的undo表空间。创建表空间的名字与大小由 PDB$SEED 中的配置信息决定的。