UNDO表空间存储着DML操作数据块的前镜像数据,在数据回滚,一致性读,闪回操作,实例恢复的时候都可能用到UNDO表空间中的数据。如果在生产过程中丢失或破坏了UNDO表空间,可能导致某些事务无法回滚,数据库无法恢复到一致性的状态,Oracle实例可能宕机,之后实例无法正常启动;如果有多个UNDO表空间数据文件,丢失其中一个数据文件数据库实例可能不会导致实例宕机,数据库无法干净的关闭(只能SHUTDOWN ABORT),数据库实例能正常的重启,但所有未回滚的数据块依然无法处理,尝试新建UNDO表空间、exp、expdp等操作都会收到ORA-604, ORA-376, and ORA-1110的报错,下面通过一个实际的案例讨论如何处理UNDO损坏后的恢复。

如果你的数据库还能干净的关闭,但在正常情况下无法新建UNDO表空间,那么执行以下的步骤:
I.A. THE DATABASE WAS CLEANLY SHUT DOWN
---------------------------------------
If you are ABSOLUTELY POSITIVE that the database was cleanly shutdown,
i.e., it was closed with either shutdown NORMAL or IMMEDIATE, then
the simplest solution is to offline drop the missing datafile, open the
database in restricted mode, and then drop and recreate the undo 
tablespace to which the file belonged.  DO NOT follow this procedure
if the database was shut down ABORT or if it crashed.
The steps are:
1. Make sure the database was last cleanly shut down.
   Check the alert.log file for this instance.  Go to the bottom of
   the file and make sure the last time you shut the database down
   you got the messages:
        "Shutting down instance (immediate)"
   OR
"alter database close normal 
         Completed: alter database close normal"
   This also includes the case of a clean shutdown followed by a
   failed attempt to startup the database.  In that case, Oracle will
   issue error messages and shut itself down abort.  For the purposes
   of this solution, though, this counts as a clean shutdown.
   If that is not the case, i.e., if the last time YOU shut the database
   down it was in abort mode, or the database crashed itself, it is
   NOT safe to proceed.  You should follow the instructions for
   case I.B below.
2. If using automatic UNDO_MANAGEMENT, comment out this entry from the parameter
   file, or set it to MANUAL. 
将UNDO_MANAGEMENT修改为MANUAL是因为UNDO表空间在自动管理模式下,如果不能成功新建回滚段(后面会DROP现有表空间)将导致数据库实例宕机。
   If using rollback segments, remove all the rollback segments in the
   tablespace to which the lost datafile belongs from the ROLLBACK_SEGMENTS
   parameter in the init.ora file for this instance.  If you are not sure about which rollbacks are
   in that tablespace, simply comment out the whole ROLLBACK_SEGMENTS entry.
3. Mount the database in restricted mode.
   SQL> STARTUP RESTRICT MOUNT
以RESTRICT模式启动实例是避免在处理过程中有其他客户端连接。
4. Offline drop the lost datafile.
   SQL> ALTER DATABASE DATAFILE '' OFFLINE DROP;
5. Open the database.
   SQL> ALTER DATABASE OPEN
   You should receive the message "Statement processed,". 
   If instead you get ORA-604, ORA-376, and ORA-1110, it is likely the shutdown
   was not normal/immediate.  Review the rest of the options available and/or
   contact Oracle Support Services.  
6. Drop the undo tablespace or tablespace which contains rollback segments
   to which the datafile belonged.
   SQL> DROP TABLESPACE INCLUDING CONTENTS;
7. Recreate the undo tablespace.  If using rollback segments, recreate the
   rollback segment tablespace and all it's rollback segments.  Remember to
   bring the rollbacks online after you create them.
  SQL> CREATE TABLESPACE UNDOTBS2 DATAFILE <datafile_name< span="" style="word-wrap: break-word;">> SIZE 1G AUTOEXTEND ON NEXT 100M;
8. Edit the parameter file setting:
   UNDO_MANAGEMENT=AUTO
   UNDO_TABLESPACE=
   If using rollback segments, reinclude the rollbacks you just recreated in
   the ROLLBACK_SEGMENTS parameter in the init.ora file for this instance.
   As rollback segments were brought online in step #7, no need to proceed
   with shutdown/startup as needed for undo tablespace.  All that is required
   is:
   SQL> ALTER SYSTEM DISABLE RESTRICTED SESSION;

如果你的数据库不能正常关闭,只需要在重启数据库实例之前将下面的参数加到参数文件:
_allow_resetlogs_corruption=TRUE
_offline_rollback_segments="_SYSSMU1$"
_offline_rollback_segments="_SYSSMU2$"
_offline_rollback_segments="_SYSSMU3$"
_offline_rollback_segments="_SYSSMU4$"
_offline_rollback_segments="_SYSSMU5$"
_offline_rollback_segments="_SYSSMU6$"
_offline_rollback_segments="_SYSSMU7$"
_offline_rollback_segments="_SYSSMU8$"
_offline_rollback_segments="_SYSSMU9$"
_offline_rollback_segments="_SYSSMU10$"
_corrupted_rollback_segments="_SYSSMU1$"
_corrupted_rollback_segments="_SYSSMU2$"
_corrupted_rollback_segments="_SYSSMU3$"
_corrupted_rollback_segments="_SYSSMU4$"
_corrupted_rollback_segments="_SYSSMU5$"
_corrupted_rollback_segments="_SYSSMU6$"
_corrupted_rollback_segments="_SYSSMU7$"
_corrupted_rollback_segments="_SYSSMU8$"
_corrupted_rollback_segments="_SYSSMU9$"
_corrupted_rollback_segments="_SYSSMU10$"
    rollback_segments的具体值可以从v$rollname中获得。
处理完成后停止数据库实例,去掉以上参数,修改好UNDO相关参数即可正常启动数据库实例,之后再手动处理TEMP表空间丢失的TEMP数据文件。
虽然数据库实例能够正常启动,也恢复了UNDO表空间的使用,但这并不代表不一致的块已经恢复,执行某些查询的时候可能会收到报错,数据库完全恢复正常后应该立即执行一次逻辑备份+物理备份,确保数据库的安全。

如果Oracle在运行中很不幸遇到undo损坏,当然最好的方法是完全恢复,不过如果没有备份,可以采用一种非常规的手段(利用Oracle的隐藏参数),如果此时undo包含未提交的事务,会造成一点点的数据丢失(一般都是可忍受的),如果没有未提交的事务,则不会有数据丢失。其主要步骤有:

1. 修改undo表空间管理为手动;
2. 设置隐藏参数(_offline_rollback_segments或_corrupted_rollback_segments)标识受影响的回滚段,使Oracle忽略其上的未提交事务;
3. 手动删除受影响的回滚段和undo表空间,然后重建新的undo表空间;
4. 还原undo表空间管理为自动。

实验如下:
Step 1.
如果undo数据文件损坏,数据库只能到mount状态,open时会出现以下错误:
ORA-01157: cannot identify/lock data file 14 - see DBWR trace file
ORA-01110: data file 14: 'I:\INTEL_DATA\O06DMS0\UNDO1.O06DMS0'
说明该undo文件已经损坏或丢失,把该文件offline之后就可以打开数据库了:
SQL> alter database datafile 'I:\INTEL_DATA\O06DMS0\UNDO1.O06DMS0' offline drop;
SQL> alter database open;
打开数据库的目的是为了找出受影响的回滚段:
SQL> select segment_name,status from dba_rollback_segs;
SEGMENT_NAME                   STATUS
------------------------------ ----------------
SYSTEM                         ONLINE
_SYSSMU10_1201331463$          OFFLINE
_SYSSMU9_2926456744$           OFFLINE
_SYSSMU8_640224757$            OFFLINE
_SYSSMU7_3984293596$           OFFLINE
_SYSSMU6_3694658906$           OFFLINE
_SYSSMU5_3475919656$           OFFLINE
_SYSSMU4_168502732$            OFFLINE
_SYSSMU3_1987193959$           OFFLINE
_SYSSMU2_3908286755$           OFFLINE
_SYSSMU1_3281912951$           OFFLINE

SQL> show parameter undo

NAME                                 TYPE        VALUE
------------------------------------ ----------- -------------
undo_management                      string      AUTO
undo_retention                       integer     900
undo_tablespace                      string      undo1
关闭数据库:
SQL> shutdown immediate;

Step 2.
创建一个临时的pfile:
SQL> create pfile='H:\initO06DMS0.ora' from spfile;
修改pfile如下:
*.undo_management='manual'   -- undo表空间管理方式修改为手动
*.undo_tablespace='undo2'     --指定一个新的undo表空间
*._offline_rollback_segments=('_SYSSMU10_1201331463$','_SYSSMU9_2926456744$','_SYSSMU8_640224757$','_SYSSMU7_3984293596$','_SYSSMU6_3694658906$','_SYSSMU5_3475919656$','_SYSSMU4_168502732$','_SYSSMU3_1987193959$','_SYSSMU2_3908286755$','_SYSSMU1_3281912951$')  --把所有受影响的回滚段都列在这里
并以改pfile重新启动数据库:
SQL> startup pfile='H:\initO06DMS0.ora'

Step 3.
手动删除受影响的回滚段:
SQL>drop rollback segment "_SYSSMU10_1201331463$";
SQL>drop rollback segment "_SYSSMU9_2926456744$";
SQL>drop rollback segment "_SYSSMU8_640224757$";
SQL>drop rollback segment "_SYSSMU7_3984293596$";
SQL>drop rollback segment "_SYSSMU6_3694658906$";
SQL>drop rollback segment "_SYSSMU5_3475919656$";
SQL>drop rollback segment "_SYSSMU4_168502732$";
SQL>drop rollback segment "_SYSSMU3_1987193959$";
SQL>drop rollback segment "_SYSSMU2_3908286755$";
SQL>drop rollback segment "_SYSSMU1_3281912951$";
手动删除旧的undo表空间:
SQL> drop tablespace undo1 including contents;
重建新的undo表空间:
SQL> create undo tablespace undo2 datafile 'I:\INTEL_DATA\O06DMS0\UNDO2.O06DMS0' size 100m;
创建新的spfile,覆盖旧的spfile:
SQL> create spfile from pfile='H:\initO06DMS0.ora';
关闭数据库:
SQL> shutdown immediate;

Step 4.
以原来的spfile启动数据库:
SQL> startup;
还原undo表空间管理为自动:
SQL> alter system set undo_management='auto' scope=spfile;
取消隐藏参数的设置:
SQL> alter system reset "_offline_rollback_segments" scope=spfile;
重启使其生效:
SQL> shutdown immediate;
SQL> startup
SQL> show parameter undo

NAME                                 TYPE        VALUE
------------------------------------ ----------- -------------------
undo_management                      string      AUTO
undo_retention                       integer     900
undo_tablespace                      string      undo2

最终检查一下:
SQL> select segment_name,status from dba_rollback_segs;

SEGMENT_NAME                   STATUS
------------------------------ ----------------
SYSTEM                         ONLINE
_SYSSMU40_1968985325$          ONLINE
_SYSSMU39_4040503138$          ONLINE
_SYSSMU38_4059847715$          ONLINE
_SYSSMU37_2692202156$          ONLINE
_SYSSMU36_2617425201$          ONLINE
_SYSSMU35_1133967719$          ONLINE
_SYSSMU34_1916939664$          ONLINE
_SYSSMU33_99444166$            ONLINE
_SYSSMU32_162619813$           ONLINE
_SYSSMU31_830375278$           ONLINE

https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:5669213349582

Oracle备份恢复之无备份情况下恢复undo表空间的更多相关文章

  1. 错误ORA-01110,在已删除数据文件情况下如何删除表空间

    如果先行删除了数据文件,再删除表空间,drop tablespace 会出现如下错误: ORA-01116: error in opening database file 89 ORA-01110: ...

  2. Oracle undo 表空间管理 (摘DAVID)

    Oracle 的Undo有两种方式: 一是使用undo 表空间,二是使用回滚段. 我们通过 undo_management 参数来控制使用哪种方式,如果设为auto,就使用UNDO 表空间,这时必须要 ...

  3. Oracle 释放过度使用的Undo表空间

    故障现象:UNDO表空间越来越大,长此下去最终数据因为磁盘空间不足而崩溃: 问题分析:产生问题的原因主要以下两点: 1. 有较大的事务量让Oracle Undo自动扩展,产生过度占用磁盘空间的情况: ...

  4. 监控和管理Oracle UNDO表空间的使用

    对Oracle数据库UNDO表空间的监控和管理是我们日常最重要的工作之一,UNDO表空间通常都是Oracle自动化管理(通过undo_management初始化参数确定):UNDO表空间是用于存储DM ...

  5. Oracle数据库 ORA-01555 快照过旧 (undo表空间:撤销表空间)

    UNDO表空间用于存放UNDO数据,当执行DML操作时,oracle会将这些操作的旧数据写入到UNDO段,以保证可以回滚或者一致读等,而临时表空间主要用来做查询和存放一些缓冲区数据.你听说UNDO也是 ...

  6. Oracle备份恢复之数据库备份、还原、恢复理论

    备份 冷备:关闭数据库并进行数据库物理文件的拷贝过程. 热备:数据库处于open阶段时的备份,通过指令将数据库文件头锁定,然后进行物理系统拷贝,然后通过指令解冻数据文件头,解冻后通过日志文件和undo ...

  7. 在没备份undo的情况下,undo丢失,重启数据库报ORA-01157错误

    今天做了一下undo隐藏参数的实验 在没有备份的情况下,删除正在使用的undo,然后关机 (本次使用的的oracle的隐藏参数,慎用!!!!!!!!!!!!!!) idle> select * ...

  8. 无归档情况下使用BBED处理ORA-01113错误

    在丢失归档情况下,恢复时常会遇到ora-01113错误,以下实验模拟表空间offline,然后在丢失归档文件的情况下使用BBED修改文件头信息,最后恢复数据文件: 数据库版本: SQL> sel ...

  9. 如何在删除ibdata1和ib_logfile的情况下恢复MySQL数据库

    昨天,有个朋友对公司内部使用的一个MySQL实例开启binlog,但是在启动的过程中失败了(他也没提,为何会失败),在启动失败后,他删除了ibdata1和ib_logfile,后来,能正常启动了,但所 ...

随机推荐

  1. SpringMVC由浅入深day01_3非注解的处理器映射器和适配器

     3 非注解的处理器映射器和适配器 3.1 非注解的处理器映射器 3.1.1 HandlerMapping处理器映射器 HandlerMapping 负责根据request请求找到对应的Handler ...

  2. mysql的in查询分析

    群里山楂大仙和电台大神探讨到mysql的in查询的问题,问题如下: student表有class_id的索引,但是只查询一个的时候用索引,查两个就不用索引了 这是很奇怪的现象,我试了一下也是这样,真是 ...

  3. UTF8 & GBK之间的转换

    使用lua的时候,在lua中给字符串赋值的中文,但是在C中读出来的就是乱码,是因为在lua中使用的是UTF8编码,而在C(windows下面)中使用的是GBK编码,将UTF8转成GBK就可以了,下面的 ...

  4. error:undefined reference to 'net_message_processor::net_message_processor()'

    net_message_processor是我自己定义的一个类,文件名称分别是net_message_processor.h  & net_message_processor.cpp 和CCD ...

  5. 【代码审计】MIPCMS 远程写入配置文件Getshell

    0x00 环境准备 MIPCMS官网:https://www.mipcms.cn 网站源码版本:MIPCMS内容管理系统 V3.1.0(发布时间:2018-01-01) 程序源码下载:http://w ...

  6. material mem

    http://blog.csdn.net/caihaijiang/article/details/5903133 http://akunamotata.iteye.com/blog/1625804 刷 ...

  7. React Native(十三)——ios键盘挡住textInput

    渐入佳境 用React Native重构的项目也快接近尾声,剩下的就是适配ios的功能了.慢慢地也从中琢磨出了一点门道,于是就遇见了键盘遮挡textInput问题斑斑: 正常页面: android点击 ...

  8. 通过设置P3P头来实现跨域访问COOKIE

    通过设置P3P头来实现跨域访问COOKIE 实际工作中,类似这样的要求很多,比如说,我们有两个域名,我们想实现在一个域名登录后,能自动完成另一个域名的登录,也就是PASSPORT的功能. 我只写一个大 ...

  9. MongoDB安装问题以及启动

    在安装MongoDB的文件中找到bin文件,其中有mongo.exe应用程序,双击打开会出现第二幅图的样子. 将MongoDB服务器作为Windows服务运行,运行后,不知道为什么无法启动,即使删除d ...

  10. Foxmail邮箱最新应用指南二

    Foxmail邮箱最新应用指南二 1.打开Foxmail主界面—工具—账号管理,或者鼠标右击任何已有账号—属性,弹出账号管理窗口,点击左下角的“新建”按钮: 2.输入邮箱地址,下一步→选择邮箱类型(I ...