您的位置:首页 > 数据库 > Oracle

Oracle undo解读以及管理

2020-07-14 06:27 465 查看

Undo段管理
Undo作用:记录了数据块的前映像数据。
12c中undo分为两种的
本地undo段模式(每个PDB中有一个undo表空间)
共享undo段模式(多个PDB共享一个undo表空间)
本地undo段模式与共享undo段模式可以相互切换操作:

Undo的作用:
事务回滚 实例恢复 一致性读 闪回操作
Undo retention : 指已经提交的undo data还需要保留的时间
Undo块的状态:free active inactive expired
Free:未使用
Active:事务还没有提交
Inactive:事务已经提交,但undo data还需要保留指定的时间,且未超过这个时间。
Expired:undo data已经过期,说明该undo data对应的事务已经提交,并且该undo data已经超出了retention保留时间,可以被覆盖。

Undo自动扩展以及guarantee情况;
1.
对于固定大小的undo表空间:
Noguarantee:
优先保证active块有可用空间存放,Oracle会根据undo表空间的大小和系统负载情况动态调整优化retention的值,事务越繁忙,优化后的retention会越小,Vundostat视图可以查看动态调整后的retention值,vundostat视图可以查看动态调整后的retention值,vundostat视图可以查看动态调整后的retention值,vundodata视图每10分钟生成一行记录,当前时间对应行的tuned_undoretention值会随着事务繁忙程度变化而更新,事务越繁忙,优化后的retention越小
当事务不繁忙时,Oracle会尽可能的加大undo data保留时间

Guarantee:
如果设置了guarantee,就一定保证undo date在提交后必须保留retention的时间。由于undo表空间为固定大小,无法进行自动扩展,inactive必须需要保留相应的时间,那么active空间可能会不足,所以在进行DML事务操作时会报错(undo空间不足)。

对于具有自动扩展属性的undo表空间:
Undo表空间数据文件设置为autoextend on时,数据库以当前设置的undo_retention参数值作为下限值,并会动态调整retention值来满足长时间执行查询语句的一致性读,当undo空间不足时,数据库会扩展undo表空间对应数据文件。
下限值是用来闪回查询。
如果undo表空间数据文件自动扩展达到maxsize最大值,数据库会开始覆盖inactive状态的undo数据。

Ora-01555快照太旧错误:
1.对于一个长时间的执行的查询SQL可能会出现该错误
2.闪回查询
例如:A会话执行一条查询语句,查询数据行数为10亿行,B会话执行一条delete语句,删除1亿行数据,然后进行提交,当B会话事务提交成功后,A数据才查询到这1亿行数据,此时需要undo data来构造一致性读,如果此时undo date被覆盖,那么就会出现Ora-01555错误。

ORA-30036空间不足情况
情况1:
Undo文件非自动扩展,没有设置retention guarantee,Oracle会根据undo表空间的大小和系统负载情况动态调整优化retention的值,此时事务特别繁忙,优化后的retention会很小,即使retention时间再短,也就是说inactive的undo块占用空间很少很少,但是存放active块的空间可能依旧不足,不足以存放大事务块的前映像数据,此时就会出现ORA-30036错误。
情况2:
Undo文件非自动扩展,设置了retention guarantee,事务特别繁忙,retention保留时间不会改变,inactive的undo块占用的空间越来越大,剩余空间不足以存放active的undo块,此时也会出现ORA-30036错误
(当undo文件设置自动扩展时,一般情况不会出现ORA-30036错误)

创建undo表空间(非自动扩展)
create undo tablespace smallundo datafile ‘/u01/app/oracle/oradata/prod/smallundo.dbf’ size 2M

查看表空间中的数据文件是否具有自动扩展属性
select tablespace_name,AUTOEXTENSIBLE from dba_data_files;

修改undo表空间
alter system set undo_tablespace=‘SMALLUNDO’;

SYS@prod>select name,value from v$parameter where name like ‘undo%’;
SYS@prod>show parameter undo

Undo_management 自动管理模式
Undo_tablespace undo表空间
Undo_retention undo inactive保留时间

查看undo模式(12c中可以查看)
SYS@prod>select property_name,property_value from database_properties where property_name = ‘LOCAL_UNDO_ENABLED’。

Alter database local undo off 关闭本地undo模式,即为开启共享模式。

查看是否开启retention guarantee。
Select tablespace_name,retention from dba_tablespaces where tablespace_name like ‘UNDO%’

查看Oracle自行优化后的retention,每十分钟更新一行信息
select TUNED_UNDORETENTION from v$undostat;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: