oracle undo表空间操作

来源:互联网 发布:微信头像制作软件 编辑:程序博客网 时间:2024/04/29 07:41
1.创建undo 表空间
create undo tablespace vic_undo
datafile '/u01/oradata/oracleSid/vic_undo.dbf'
size 100M
autoextend on;


2.查看创建 的表空间
select tablespace_name,extent_management,contents,logging,status
from dba_tablespaces
where content ='UNDO';


3.查看关于还原表空间的数据文件信息
select tablespace_name,file_name,bytes/1024/1024,autoextensible
from dba_data_files
where tablespace_name ='VIC_UNDO';


4.重命名还原表空间
alter tablespace vic_undo rename to my_undo


5.向还原表空间中增加数据文件
alter tablespace vic_undo
add datafile '/u01/oradata/oracleSid/vic_undo2.dbf'
size 100M;


6.查看增加文件的结果 
select tablespace_name,file_name,bytes/1024/1024 ,autoextensible
from dba_data_files
where tablespace_name ='VIC_UNDO';


7.设置数据文件为自动扩展方式
alter database
datafile '/u01/oradata/oracleSid/vic_undo2.dbf'
autoextend on;


8.查看修改的结果 
select tablespace_name,file_name,bytes/1024/1024 ,autoextensible
from dba_data_files
where tablespace_name ='VIC_UNDO';




9.切换表空间
alter system set undo_tablespace=vic_undo;


10.验证修改结果
show parameter undo 


11.表空间切换涉及状态
-旧的表空间正在运行,则该表空间变成 Pending offline.
-用户事务正常运行,切换操作结束,不会等待旧的undo表事务结束
-切换后,所有新的事务所产生的undo数据不会存放在旧的undo表空间,而是会使用新的undo表空间
-pending offline状态 的undo表空间不能被删除
-旧的undo表空间上所有事务都提交后,旧的undo表空间从pending offline状态 变成 offline状态,表空间可以删除 
-drop tablespace undotbs1相当于drop tablespace undotbs1 including content
-如果undo表空间包含inactive状态的undo数据块,不影响被删除,但是可能产生ORA-1555错误,因此最好等待超过undo_retention以后再删除空间。


12.删除undo表空间


drop tablespace undotbs;


先创建一个表空间
create undo tablespace del_undo
datafile '/u01/oradata/oracleSid/del_undo.dbf'
size 100M
autoextend on
maxsize 100M
retention guarantee;


创建一张表,插入数据
create table t (id number,name varchar(20));


insert into t values (1,'shanghai');


切换表空间
alter system set undo=del_undo


查看切换结果
show parameter undo


删除旧的表空间
drop tablespace undotbs;
--这个时候删除会报错
-可能是有事务在旧的表空间上
-可能是undo_retention 参数


修改undo_retention参数,提交事务后,即可 删除 






0 0