一、UNDO表空间
数据的四种状态
1)active: 表示transaction还没有结束,不可覆盖,
2)unexpired:由已经commit或rollback的数据转换而来的状态, 在undo_retention期内,尽量不覆盖(非强制),加
GUARANTEE属性后强制undo_retention内不覆盖。
3)expired: 由unexpired转换而来,其中的数据是是超过undo_retention的,随时可以覆盖。
4)free: 分配了但未使用过。一般是undo最初创建和扩展时出现,它不是一个常态的。
测试undo空间的循环使用过程:
-
SYS@ prod>create table scott.test as select * from dba_objects;
-
-
Table created.
-
-
SYS@ prod>update scott.test set object_id=1;
-
-
72566 rows updated.
-
-
SYS@ prod>select tablespace_name, status, sum(blocks) * 8192/1024/1024 MB from dba_undo_extents group by tablespace_name, status;
-
-
TABLESPACE_NAME STATUS MB
-
------------------------------ --------- ----------
-
UNDOTBS1 UNEXPIRED 6.25
-
UNDOTBS1 EXPIRED 14.5625
-
UNDOTBS1 ACTIVE 15.125
-
-
SYS@ prod>commit;
-
-
Commit complete.
-
-
SYS@ prod>select tablespace_name, status, sum(blocks) * 8192/1024/1024 MB from dba_undo_extents group by tablespace_name, status;
-
-
TABLESPACE_NAME STATUS MB
-
------------------------------ --------- ----------
-
UNDOTBS1 UNEXPIRED 21.375
-
UNDOTBS1 EXPIRED 14.5625
二、UNDO的作用
1,回滚事物
undo表空间中存放着事物操作数据的前镜像
2,保证数据库读一致性
当事物未结束时,其他回话读undo中的前镜像,保证了一致性
3,实例的恢复
恢复过程:a,redo日志前滚将提交和未提交的数据都写入datafile;b,open database ;c,undo 回滚未提交的数据
4,闪回技术
三、UNDO管理方式
1,manaual 手工:roll segment 还原段
2,auto 自动:undo tablespace (init parameter :undo_management = auto)
AUM表空间自动扩展 缺点:undo_retention参考作为下限值,尽量保证unexpired空间不被覆盖。导致无线的扩展
undo datafile,retention自动调整的越来越大,unexpired的空间不能有效的释放。
易发生的两个错误:
ORA-01555 snapshot too old 快照太旧 ,在unexpired保留区中找不到查询的数据
解决办法:虑延长undo retention,必要时guarantee保证retention时间到才会释放,同时使undo autoextend on
ORA-30036 可能UNDO表空间不足了,新建一个undo tablespace切换
autoextend off: undo_retention的值被忽略 crrent retention 依赖统计信息和表空间大小,以时间换空间 30036
autoextend on: undo_retention的值参考为下限,尽量不覆盖unexpired,以空间换时间
四、UNDO信息查询
1) v$session 查看用户建立的session
2) v$transaction 当前的事务
3) v$rollname undo段的名称
4) v$rollstat undo段的状态
5) v$undostat 查看每10分钟的统计数据
6) dba_undo_extents 查看undo段中不同状态的空间占用
7) dba_rollback_segs 数据字典里记录的undo段状态
select tablespace_name,status from dba_undo_extents group by tablespace_name,status; //各区域状态
select tablespace_name,status,segment_space_management from dba_tablespaces; //UNDO表空间管理方式
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28275505/viewspace-1821130/
,如需转载,请注明出处,否则将追究法律责任。