10g对undo_retention参数的增强限制

本文探讨了Oracle数据库中UNDO表空间的工作原理,包括如何通过调整undo_retention参数和设置guarantee属性来保证undo数据的保留时间。通过实验验证了同一事务内生成的undo数据不会被覆写,并介绍了在空间不足时如何避免覆盖旧数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当一个块被修改后,它的前镜像会被保存在undo段中。undo段是一个循环存储设备,当空间不够用的时候,会覆写重新利用其空间。
[color=Red]但是同一事务不能覆写这个事务内生成的undo数据!undo_retention参数用来设定undo段中的前镜像可以被保持多长时间。但是并不是说,在这个期限内这个块一定不能被覆写![/color]oracle 10g以前,如果回滚段空间不够,照样会覆写回滚段中先前的内容。
    我们来做实验验证一下。
首先建立一个2M的undo表空间
create  undo tablespce undotbs2 datafile '/u01/app/oracle/oradata/orcl/undotbs2.dbf' size 2M;

将undotbs2更改为默认undo表空间
alter system set undo_tablespace=undotbs2 scope=spfile;

重启数据库,使参数生效。
startup force;

sys@ORCL> show parameter undo

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_management                      string      AUTO
undo_retention                       integer     600
undo_tablespace                      string      UNDOTBS2


conn scott/tiger

create table t(x int);
insert into t values(1);

begin
  for i in 1 .. 10000 loop
    update t set x=x+1;
  end loop;
end;
/

ERROR at line 1:
ORA-30036: unable to extend segment by 8 in undo tablespace 'UNDOTBS2'
ORA-06512: at line 3

这样说明我上面的10000次更新,会使用满undo段 。并且在此过程中没有提交,所以[color=Red]同一事务不能覆写这个事务内生成的undo数据![/color]

如果我在update过程中提交的话,
17:01:02 scott@ORCL> begin
17:01:12   2  for i in 1 .. 10000 loop
17:01:16   3     update t set x=x+1;
17:01:19   4     if mod(i,100)=0 then
17:01:21   5        commit;
17:01:24   6    end if;
17:01:26   7    end loop;
17:01:27   8  end;
17:01:30   9  /

PL/SQL procedure successfully completed.
17:01:34 scott@ORCL>

没有出错,所以我的回滚段被覆写了(要不然会出现ORA-30036错误),但是我的pl/sql块不到5秒钟,而undo_retention=600,所以当回滚段空间不够,照样会覆写回滚段中先前的内容。
在10g中对undo tablespace增加了一个guarantee属性,来强制限制undo_retention设定的时间内回滚段不能被覆写。

sys@ORCL> alter tablespace undotbs2 retention guarantee;
alter tablespace undotbs2 retention guarantee

*
ERROR at line 1:
ORA-30036: unable to extend segment by 8 in undo tablespace 'UNDOTBS2'

2.修改undo_retention的值。
sys@ORCL> alter system set undo_retention=180 scope=spfile;

System altered.

sys@ORCL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@ORCL> startup
ORACLE instance started.

Total System Global Area  209715200 bytes
Fixed Size                  1218580 bytes
Variable Size             109053932 bytes
Database Buffers           92274688 bytes
Redo Buffers                7168000 bytes
Database mounted.
Database opened.
sys@ORCL> alter tablespace undotbs2 retention guarantee;

Tablespace altered.

[color=Red]所以欲修改undo表空间为guarantee,还受到undo_retention和undo表空间的大小的限制。[/color]

此时我们才能确保undo段中的undo数据可以保持undo_retention参数设定的时间。

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/701141/viewspace-402096/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/701141/viewspace-402096/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值