zoukankan      html  css  js  c++  java
  • 使用alter database datafile 'XXX' offline drop 是否能够恢复(非归档模式下)

    ###########################################################################
     
    SQL> create tablespace test datafile '/u01/app/oracle/oradata/orcl/test01.dbf' size 10M autoextend on next 1M;
     
    Tablespace created.
     
    SQL> create table test(id number,name varchar2(12)) tablespace test;                                              
    Table created.
     
    SQL> insert into test values (1,'colin');
     
    1 row created.
     
    SQL> insert into test values (2,'janey');
     
    1 row created.
     
    SQL> insert into test values (3,'tom');
     
    1 row created.
     
    SQL> insert into test values (4,'adele');
     
    1 row created.
     
    SQL> commit;
     
    Commit complete.
     
    SQL> select * from test;
     
            ID NAME
    ---------- ------------
             1 colin
             2 janey
             3 tom
             4 adele
     
    SQL> alter database datafile '/u01/app/oracle/oradata/orcl/test01.dbf' offline drop;
     
    Database altered.
     
    SQL> commit;
     
    Commit complete.
     
    SQL> select * from test;
    select * from test
                  *
    ERROR at line 1:
    ORA-00376: file 2 cannot be read at this time
    ORA-01110: data file 2: '/u01/app/oracle/oradata/orcl/test01.dbf'
     
    SQL> select LOG_MODE,OPEN_MODE from v$database;
     
    LOG_MODE     OPEN_MODE
    ------------ ----------
    NOARCHIVELOG READ WRITE
     
    SQL> alter database datafile '/u01/app/oracle/oradata/orcl/test01.dbf' online;
    alter database datafile '/u01/app/oracle/oradata/orcl/test01.dbf' online
    *
    ERROR at line 1:
    ORA-01113: file 2 needs media recovery
    ORA-01110: data file 2: '/u01/app/oracle/oradata/orcl/test01.dbf'
     
    SQL> recover datafile '/u01/app/oracle/oradata/orcl/test01.dbf';
    Media recovery complete.
    SQL> alter database datafile '/u01/app/oracle/oradata/orcl/test01.dbf' online;
     
    Database altered.
     
    SQL> select * from test;
     
            ID NAME
    ---------- ------------
             1 colin
             2 janey
             3 tom
             4 adele
     
    恢复成功。那是因为日志还没有切换,使用了online日志。
     
    ###########################################################################
     
    切换日志来测试:
     
    SQL> alter database datafile '/u01/app/oracle/oradata/orcl/test01.dbf' offline drop;
     
    Database altered.
     
    SQL> select * from test;
    select * from test
    *
    ERROR at line 1:
    ORA-00376: file 2 cannot be read at this time
    ORA-01110: data file 2: '/u01/app/oracle/oradata/orcl/test01.dbf'
     
    SQL> alter system switch logfile;
     
    System altered.
     
    SQL> /
     
    System altered.
     
    SQL> /
    /
     
    System altered.
     
    SQL> 
    System altered.
     
    SQL> recover datafile '/u01/app/oracle/oradata/orcl/test01.dbf';
    ORA-00279: change 654004 generated at 07/09/2012 21:07:18 needed for thread 1
    ORA-00289: suggestion : /u01/app/oracle/arch/1_32_777559117.arc
    ORA-00280: change 654004 for thread 1 is in sequence #32
     
    Specify log: {=suggested | filename | AUTO | CANCEL}
    cancel
    Media recovery cancelled.
    SQL> /
     
    System altered.
     
    SQL> recover datafile '/u01/app/oracle/oradata/orcl/test01.dbf';
    ORA-00279: change 654004 generated at 07/09/2012 21:07:18 needed for thread 1
    ORA-00289: suggestion : /u01/app/oracle/arch/1_32_777559117.arc
    ORA-00280: change 654004 for thread 1 is in sequence #32
     
    Specify log: {=suggested | filename | AUTO | CANCEL}
    auto
    ORA-00308: cannot open archived log '/u01/app/oracle/arch/1_32_777559117.arc'
    ORA-27037: unable to obtain file status
    Linux Error: 2: No such file or directory
    Additional information: 3
     
    ORA-00308: cannot open archived log '/u01/app/oracle/arch/1_32_777559117.arc'
    ORA-27037: unable to obtain file status
    Linux Error: 2: No such file or directory
    Additional information: 3
     
    ###########################################################################
    通过以上测试表明,在非归档模式下使用了alter database datafile 'XXX' offline drop命令是不能被恢复的,虽然我上面的第一次实验成功了,那是因为online日志还没有切换,在日志中还能够找到相应的反操作。在第二个实验中,手工切换日志,会提示不能打开归档日志,因为我根本就没有归档,肯定找不到啊,所以不能够恢复的。切记,在非归档模型下不要随意使用一些drop命令,在实际生产环境中日志的切换是很频繁且快的,否则只有掏钱找oracle了。当然,如果在业务不繁忙的系统可以及时的通过online日志进行恢复,这种几率比较小。
     
  • 相关阅读:
    Spring 中的重试机制,简单、实用!
    Docker 常用命令,还有谁不会?
    Java 对象不使用时为什么要赋值为 null?
    为什么 Nginx 比 Apache 更牛叉?
    你还在用命令看日志?快用 Kibana 吧,一张图片胜过千万行日志!
    golang如何体现面向对象思想
    golang 三⾊标记+GC混合写屏障机制
    Golang中逃逸现象-变量何时 栈何时堆
    golang调度器原理与GMP模型设计思想
    golang 程序内存分析方法
  • 原文地址:https://www.cnblogs.com/future2012lg/p/4061817.html
Copyright © 2011-2022 走看看