当一个块被修改后,它的前镜像会被保存在undo段中。undo段是一个循环存储设备,当空间不够用的时候,会覆写重新利用其空间。
但是同一事务不能覆写这个事务内生成的undo数据!undo_retention参数用来设定undo段中的前镜像可以被保持多长时间。但是并不是说,在这个期限内这个块一定不能被覆写!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段 。并且在此过程中没有提交,所以 同一事务不能覆写这个事务内生成的undo数据!
如果我在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.
所以欲修改undo表空间为guarantee,还受到undo_retention和undo表空间的大小的限制。
此时我们才能确保undo段中的undo数据可以保持undo_retention参数设定的时间。
我们来做实验验证一下。首先建立一个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段 。并且在此过程中没有提交,所以 同一事务不能覆写这个事务内生成的undo数据!
如果我在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.
所以欲修改undo表空间为guarantee,还受到undo_retention和undo表空间的大小的限制。
此时我们才能确保undo段中的undo数据可以保持undo_retention参数设定的时间。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9399028/viewspace-684251/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9399028/viewspace-684251/