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. Mysql主从热备

    mysql主从配置比较不错的文章,大家可以参考下~ https://www.cnblogs.com/kissdodog/p/5422195.html

  2. 在CentOS Linux下部署Activemq 5

    准备:安装之前首先安装jdk-1.7.x及以上版本 配置/etc/sysconfig/network文件 和/etc/hosts文件,把主机名的解析做清楚: 如: # cat /etc/sysconf ...

  3. apt-get/dpkg常用指令备查

    apt-get install <package> Downloads <package> and all of its dependencies, and installs ...

  4. ClamAV病毒软件的安装和使用

    ClamAV 杀毒是Linux平台最受欢迎的杀毒软件,ClamAV属于免费开源产品,支持多种平台,如:Linux/Unix.MAC OS X.Windows.OpenVMS.ClamAV是基于病毒扫描 ...

  5. 解决3 字节的 UTF-8 序列的字节 3 无效

    maven项目编译正常,运行时候报以下错误: 3 字节的 UTF-8 序列的字节 3 无效 仔细看这个错误的详细信息,会发现是某个xml文件中字符识别的问题,解决办法如下: 在pom.xml中添加以下 ...

  6. oracle闪回数据

    方法一 数据删除了: select * from  t_test  as of timestamp to_timestamp('2011-10-25 13:45:00','yyyy-mm-dd hh2 ...

  7. EGit系列第一篇——创建本地仓库

    首先,用Eclipse创建一个项目,然后右键项目Team\Share Preject... 然后出来Share Preject对话框,选择git 点击下一步配置Git仓库,通常在项目本地目录创建仓库, ...

  8. 【Linux】使用 telnet 提示 Escape character is '^]'的意义

    在linux/unix下使用telnet hostname port连接上主机后会提示Escape character is '^]' 这个提示的意思是按Ctrl + ] 会呼出telnet的命令行, ...

  9. 【cs229-Lecture9】经验风险最小化

    写在前面:机器学习的目标是从训练集中得到一个模型,使之能对测试集进行分类,这里,训练集和测试集都是分布D的样本.而我们会设定一个训练误差来表示测试集的拟合程度(训练误差),虽然训练误差具有一定的参考价 ...

  10. JUnit(>4.0)@BeforeClass、@Before、@Test、@After、@AfterClass、@Ignore

    JUnit 4 开始使用 Java 5 中的注解(annotation),常用的几个 annotation 介绍: @BeforeClass:针对所有测试,只执行一次,且必须为static void ...