分享

oracle UNDO表空间不足解决方法

 携手共济 2015-07-02
undo表空间是Oracle特有的概念。undo表空间中会自动分配undo段,这些undo段用来保存事务中的DML语句的undo信息,也就是来保存数据在被修改之前的值。在rollback,实例恢复(前滚),一致性读CR块的构造时会使用到undo信息。由于undo的引入,从而Oracle的select语句实现一致性读时,不需要任何锁

undo表空间和其它表空间有很多类似的地方:undo数据块也会被读到buffer cache缓存起来,修改时也会产生redo log,数据也会写回到undo表空间的磁盘上。所以崩溃后,undo块的buffer cache也会恢复过来。

我们看一下undo表空间:
SQL> show parameter undo_tablespace;
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace                      string      UNDOTBS1

SQL> select file_name,bytes/1024/1024 size_M from dba_data_files where tablespace_name='UNDOTBS1';
FILE_NAME                                          SIZE_M
---------------------------------------------- ----------
/u01/app/oracle/oradata/jiagulun/undotbs01.dbf         60


 

undo表空间的作用:
Oracle开始一个事务,当要修改数据时,会先将修改前的数据保存到undo表空间的undo段中。保存这些修改前的数据的原因下面这些场合需要undo数据:1)事务的回滚;2)实例恢复(回滚);3)一致性读时需要构造CR块;

UNDO表空间不够用,有两种处理方法,1,扩大表空间大小;2,创建新的UNDO表空间,删除原来的

 

一、扩大UNDO表空间

alter   database  UNDOTBS1 datafile   '/opt/oracle/oradata/inms/undotbs02.dbf'   resize   4000M;

 

二、创建新的UNDO表空间,删除原来的

1、创建新的UNDO表空间,并设置自动扩展参数;

create undo tablespace undotbs2 datafile '/oradata/oradata/ddptest/UNDOTBS1.dbf' size    2 1000m reuse autoextend on next 800m maxsize unlimited;

 

2、动态更改spfile配置文件;

alter system set undo_tablespace=undotbs2 scope=both;

 

3、删除原有的UNDO表空间;

drop tablespace undotbs1 including contents;

 

4、确认删除是否成功;

select name from v$tablespace;

 

5、确定$ORACLE_HOME/dbs/spfileoinms.ora内容是否发生变更:

 

$more spfileoinms.ora

 

*.undo_management='AUTO'

*.undo_retention=10800

*.undo_tablespace='UNDOTBS2'

 

如果没有发生变更请执行如下语句:

 

SQL> create pfile from spfile;

如何处理OracleUNDO表空间所对应的数据文件过大

google_protectAndRun("render_ads.js::google_render_ad", google_handleError, google_render_ad); 1 查看undo的表空间大小和最大值  
select   t.file_name,t.tablespace_name,  
t.bytes/1024/1024/1024 "GB",  t.maxbytes/1024/1024/1024   "Max GB" 
 from     dba_data_files     t     where    t.tablespace_name='UNDOTBS1' 

 


   
数据文件为:/oracle/oradata/undo/undotbs01.dbf  
   
2
创建一个新的undo表空间,用来替换原来的undo表空间  
create      undo     tablespace    UNDOTBS2  
datafile     '/oracle/oradata/log/undotbs02.dbf' 
size    10M    autoextend     on    maxsize    unlimited;  
3
把新的undo表空间设置成数据库的undo表空间  
alter     system     set undo_tablespace=UNDOTBS2     scope=both;  
4
再次验证数据库的undo表空间  
 show     parameter     undo_tablespace  
5
等待原UNDO表空间UNDOTBS1 is OFFLINE  
   
 SELECT    r.status    "Status",  
r.segment_name    "Name",  
r.tablespace_name     "Tablespace",  
s.extents     "Extents",  
TO_CHAR((s.bytes/1024/1024),'99999990.000')     "Size" 
FROM     sys.dba_rollback_segs      r, sys.dba_segments    s  
WHERE        r.segment_name = s.segment_name  
AND       s.segment_type IN ('ROLLBACK', 'TYPE2 UNDO')  
and       r.tablespace_name='UNDOTBS1'      and       status='ONLINE' 
如果上面有状态online的对象,可以查询具体对象的sidserial#  
5.1
查看当前是什么在使用这个回滚段  
 SELECT     r.NAME,s.sid,s.serial# Serial,  
s.username ,s.machine ,  
t.start_time,t.status ,  
t.used_ublk ,  
substr(s.program, 1, 15)    "operate" 
FROM      v$session    s, v$transaction    t, v$rollname    r,v$rollstat    g  
WHERE      t.addr = s.taddr  
AND      t.xidusn = r.usn  
AND     r.usn = g.usn  
ORDER     BY     t.used_ublk desc;  
--
比如:对象为:sid  474,serial  6794 
5.2
根据sid查出具体的sql  
select     sql_text    from     v$session a,v$sqltext_with_newlines     b  
  where DECODE(a.sql_hash_value, 0, prev_hash_value, sql_hash_value)=b.hash_value  
  and      a.sid=&sid    order     by     piece  
如果该sql不重要,可以直接kill该会话。  
   
5.3  kill session  
alter system kill session '474,6794';  
5.4 
删除原undo表空间及其系统的数据问题  
drop tablespace UNDOTBS1 including contents and datafiles;  
(在AIX系统中,虽然已经删除了系统所对应的undo表空间的数据文件,但用df -g查看,该系统空间不能释放。  
主要是由于Oracle的一个进程在访问该文件。可以kill Oracle访问进程,或者重启数据库后,即可释放系统的空间。)  
   
   
6
新建立UNDOTBS1表空间  
create     undo     tablespace    UNDOTBS1  
datafile    '/oracle/oradata/undo/undotbs01.dbf' 
size    10M    autoextend   on    maxsize 12G;  
   
7
切换回UNTOTBS1  
alter system set undo_tablespace=UNDOTBS1 scope=both;  
8
等待UNDO表空间UNDOTBS2 is OFFLINE  
 SELECT r.status "Status",  
r.segment_name "Name",  
r.tablespace_name "Tablespace",  
s.extents "Extents",  
TO_CHAR((s.bytes/1024/1024),'99999990.000') "Size" 
FROM sys.dba_rollback_segs r, sys.dba_segments s  
WHERE r.segment_name = s.segment_name  
AND s.segment_type IN ('ROLLBACK', 'TYPE2 UNDO')  
and r.tablespace_name='UNDOTBS2' 
ORDER BY 5 DESC;  
9
删除  
drop    tablespace     UNDOTBS2    including    contents    and     datafiles; 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多