如何进行UNDO表空间空间回收及切换

这期内容当中小编将会给大家带来有关如何进行UNDO表空间空间回收及切换,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

1. 查看 undo 相关参数
show parameter undo
NAME               TYPE     VALUE
------------------ -------- ----------
undo_management    string   AUTO
undo_retention     integer  900
undo_tablespace    string   UNDOTBS

2. 查看当前 undo 表空间的数据文件
select file_name,bytes from dba_data_files where tablespace_name = 'UNDOTBS1';

3. 每个 undo 段最多包含的事务数 (10g 已经废弃)
10g 默认一个 undo 段最多一个事务, undo 段不够时, 自动创建 undo 段
当 undo 表空间不够时, undo 段可以包含 1 个以上的事务 (undo段头可能会出现等待)
show parameter rollback
NAME                                 TYPE            VALUE
------------------------------------ --------------- -------
transactions_per_rollback_segment    integer         5

4. 查看 undo 回滚段状态
select * from dba_rollback_segs;
select a.usn, b.name, a.status, a.xacts, a.rssize/1024/1024/1024, a.hwmsize/1024/1024/1024, a.shrinks from v$rollstat a, v$rollname b where a.usn = b.usn order by a.rssize;

5. 创建新回滚表空间
create undo tablespace undo datafile '/usr/lib/oracle/xe/oradata/XE/undo.dbf' size 10m;

6. 切换 undo 表空间
alter system set undo_tablespace = undotbs scope = both;

7. 确认回滚段状态
反复确认 undo 回滚段状态, 直到全部回滚段为 online 状态, 没有pending_offline 状态, 最好到达 undo_retention 所限定的时间之后再删除
select a.usn, b.name, a.status, a.xacts, a.rssize/1024/1024/1024, a.hwmsize/1024/1024/1024, a.shrinks from v$rollstat a, v$rollname b where a.usn = b.usn order by a.rssize;

8. 删除原回滚表空间
drop tablespace undotbs including contents and datafiles;

上述就是小编为大家分享的如何进行UNDO表空间空间回收及切换了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。