oralce中的undo表空间知识点汇总

来源:互联网 发布:vue.js ide 编辑:程序博客网 时间:2024/06/15 08:35

一.还原表空间论述

还原表空间是oracle9i刚刚引入的,用来自动的管理还原(回滚)数据,还原表空间不能包含任何其他的对象,在还原表空间里,extent的管理是local。

1.创建一个基本的undo 表空间

create undo tablespace jinlianundo datafile '/testA/jinlianundo01.dbf' size 20m

2.删除undo 表空间

drop tablespace jinlianundo including contents and datafiles cascade constraints 删除的时候同时删除它的数据文件。

(若当前undo表空间正在使用,则不可删除)

3.select tablespace_name,status,contents from dba_tablespaces
where contents='UNDO' 查询表空间类型为undo的表空间

二.undo表空间的两种管理方式

oracle的undo管理分为两种:一种是使用undo表空间,一种是使用undo段.

我们通过:show parameter undo查看undo_management的取值

如果值为auto,就是用undo表空间进行管理;如果是manual,就是用rollback segment进行管理


一般情况下, 当实例启动的时候,系统自动选择第一个有效的undo表空间或者rollback segment,若两者都没有,就使用system rollback segment,一般情况下,禁止使用system rollback segment。

三.使用rollback segment的情况

select segment_name,tablespace_name,bytes from dba_segments
where segment_type='ROLLBACK'


发现rollback段只有一个存在于system表空间

四.使用undo表空间

show parameter undo查询undo_management如果为auto,则是使用undo表空间进行管理。

select segment_name,tablespace_name,bytes from dba_segments where segment_type='TYPE2 UNDO'查询ubdo管理是undo表空间的undo段信息


除了使用dba_segments视图查询undo段的信息,还可以使用一下两个视图查询:分别是v$rollname与v$rollstat

五.undo_retention参数与retention guarantee参数的使用

select tablespace_name,status,sum(bytes)/1024/1024 M from dba_undo_extents
group by tablespace_name,status

查询当前使用的undo表空间中数据过期的与没有过期的字节大小。

两个参数的详细说明:

undo_retention参数:用于设置undo数据过期时间一般默认时间是900(秒),当超过这个时间时,标记这些数据过期,此时这些数据块会被标记为空闲的,当有新的事物提交时,如果没有多余的数据块,那么这些过期的数据所占用的数据块就会被覆盖。因此,为了可以提高事务的效率,一般情况下,需要设置合适的undo 表空间大小,否则,新的事务会很快覆盖旧的事务。

undo guarantee参数:为了保证在retention指定时间内,新的事务不会覆盖旧的事务。

代码如下:alter tablespace undotbs3 retention guarantee;

取消命令如下:alter tablespace undotbs3 retention noguarantee;

六:管理和维护undo 表空间

问题1:undo表空间满了

解决方法:切换系统undo表空间 alter system set undo_tablespace=undotbs1;

或添加数据文件:alter tablespace undotbs1 add datafiles '/testA/undotbs02.dbf' size 20m resue;

resue参数的含义:若存在该文件,则重用该文件,若指定size大小,则使用指定大小,否则使用原来的大小;如果该文件不存在,则忽略该参数

问题2.undo表空间损坏,且无法使用备份恢复

解决方法:

第一步;关闭数据库.使用create pfile from spfile创建pfile,并使用vi修改一下参数


第二步: startup pfile='$ORACLE_HOME/dbs/initlaw.ora'使用指定pfile进行启动DB

第三步:drop tablespace undotbs1 including contents and datafiles cascade constraints;

 create undo tablespace undotbs1 datafile '/testA/undotbs1.dbf' size 20m;

删除坏的表空间,并创建新的undo表空间

第四步:关闭数据库,修改pfile,并使用pfile生成新的spfile并正常启动数据库

pfile修改如下:

*.undo_management='AUTO'
*.undo_retention=900
*.undo_tablespace='UNDOTBS1'
#undo_management='MANUAL'
#rollback_segments='SYSTEM'

create spfile from pfile重新生成spfile

startup 正常启动







原创粉丝点击