博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
理解UNDO表空间
阅读量:2496 次
发布时间:2019-05-11

本文共 3812 字,大约阅读时间需要 12 分钟。

系统可以有多个UNDO表空间,但一个时间点只能一个是Active的。只有在这种情况下会有两上UNDO Active。当原来用一个UNDO,又重新定义一个UNDO,这样还没完成的事务用原来旧的UNDO,后面开始的新事务用新UNDO[@more@]

一个segment 至少要有2extent,对于8Kblock,最多可以有32,765extent.

一个事务只能在一个undo segment,当用完一个extent时,会使用下一个extent,当所有extent用完时,系统会分配更多的extent.但一个undo segment可以让多个事务同时用。

当一个事务已经在查询,另一个DML语句产生, UNDO里的数据用来提供一致性查询。

插入语句用很少的UNDO,他只存插入的新行的指针到UNDO,当回滚时,这个指针找到这些行并执行删除操作。

The data dictionary view DBA_ROLLBACK_SEGS shows both active (online) andinactive (offline) undo segments in both the SYSTEM and undo tablespaces

SQL> select * from v$rollname;

USN NAME

---------- ----------------------------

0 SYSTEM

1 _SYSSMU1$

2 _SYSSMU2$

3 _SYSSMU3$

4 _SYSSMU4$

5 _SYSSMU5$

6 _SYSSMU6$

7 _SYSSMU7$

8 _SYSSMU8$

9 _SYSSMU9$

10 _SYSSMU10$

11 rows selected.

The undo segment with an undo segment number (USN) of 0 is an undo segment reserved for exclusive use by system users such as SYS or SYSTEM or if no other undo segments are online and the data being changed resides in the SYSTEM tablespace. In this example, nine other undo segments

are available in the undo tablespace for user transactions.

The dynamic performance view V$TRANSACTION shows the relationship between a transaction and the undo segments. In the following query, you begin a transaction and then join V$TRANSACTION to V$ROLLNAME to find out the name of the undo segment assigned to the transaction:

SQL> set transaction name 'Update clerk salaries';

Transaction set.

SQL> update hr.employees set salary = salary * 1.25

2 where job_id like '%CLERK';

44 rows updated.

SQL> select xid, status, start_time, xidusn seg_num,

2 r.name seg_name

3 from v$transaction t join v$rollname r

4 on t.xidusn = r.usn

5 where t.name = 'Update clerk salaries';

XID STATUS START_TIME SEG_NUM SEG_NAME

-------- --------- ----------------- ------- -------------

02002F00 ACTIVE 08/01/04 16:20:10 2 _SYSSMU2$

9A140000

1 row selected.

为保证一致性,也可以用这个语句:

SQL> set transaction read only;

Transaction set.

这样只显示这个事务开始之前提交过的事务结果。Only the following statements are permitted in a read-only transaction:

_ SELECT statements without the FOR UPDATE clause

_ LOCK TABLE

_ SET ROLE

_ ALTER SESSION

_ ALTER SYSTEM

UNDO的两个错:

Running

1out of undo space for transactions generates messages such as

ORA-01650: Unable to extend rollback segment;

2long-running queries whose undo entries have been reused by current transactions typically receive the ORA-01555: Snapshot too old message.

Undo_rention

The parameter UNDO_RETENTION specifies, in seconds, how long undo information that has already been committed should be retained until it can be overwritten. This is not a guaranteed limit: if the number of seconds specified by UNDO_RETENTION has not been reached, and if a

transaction needs undo space, already committed undo information can be overwritten.

当把UNDO_RENTION设置为0时,开启undo retention 自动优化,为了保证最长事务的UNDO,系统自动最大限制地不去增加EXTENT。在任何情况下,系统最少保持UNDO信息900S。对未提交的事务不会覆盖UNDO信息。

当你认为UNDO已经设置为一个合理值时,就关掉自动EXTENT。这样单个用户才不会占用太多UNDO而不去经常提交事务。

查看V$UNDOSTAT来设置UNDO大小

SQL> select

2 to_char(begin_time,'yyyy-mm-dd hh24:mi:ss')

3 starttime,

4 to_char(end_time,'yyyy-mm-dd hh24:mi:ss')

5 endtime,

6 undoblks,

7 maxquerylen maxqrylen

8 from v$undostat;

STARTTIME ENDTIME UNDOBLKS MAXQRYLEN

------------------- ------------------- -------- ---------

2004-08-01 08:46:11 2004-08-01 08:48:47 13 0

2004-08-01 08:36:11 2004-08-01 08:46:11 61 0

2004-08-01 08:26:11 2004-08-01 08:36:11 31 0

retention guarantee不是在参数文件里设置的,只能用语句对UNDO表空间进行设置。

SQL> alter tablespace undotbs1 retention guarantee;

Tablespace altered.

Turning off the parameter is just as easy, as you can see in the next example:

SQL> alter tablespace undotbs1 retention noguarantee;

Tablespace altered.

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

转载于:http://blog.itpub.net/668365/viewspace-1003374/

你可能感兴趣的文章
5、JavaWeb学习之基础篇—标签(自定义&JSTL)
查看>>
8、JavaWEB学习之基础篇—文件上传&下载
查看>>
reRender属性的使用
查看>>
href="javascript:void(0)"
查看>>
h:panelGrid、h:panelGroup标签学习
查看>>
f:facet标签 的用法
查看>>
<h:panelgroup>相当于span元素
查看>>
java中append()的方法
查看>>
必学高级SQL语句
查看>>
经典SQL语句大全
查看>>
log日志记录是什么
查看>>
<rich:modelPanel>标签的使用
查看>>
<h:commandLink>和<h:inputLink>的区别
查看>>
<a4j:keeyAlive>的英文介绍
查看>>
关于list对象的转化问题
查看>>
VOPO对象介绍
查看>>
suse创建的虚拟机,修改ip地址
查看>>
linux的挂载的问题,重启后就挂载就没有了
查看>>
docker原始镜像启动容器并创建Apache服务器实现反向代理
查看>>
docker容器秒死的解决办法
查看>>