zoukankan      html  css  js  c++  java
  • Oracle数据库中数据文件误删除的恢复

    环境说明:

    • 数据库处于归档模式
    • 数据库文件或表空间无备份
    • 数据库的归档日志全部存在(数据文件丢失之后)

    模拟状态:

    • 数据文件丢失及时发现,实例处于运行状态
    • 数据文件丢失未及时发现,实例自检时异常关闭

    数据文件丢失及时发现,实例处于运行状态

    1.创建实验表空间

    sys@DBTREE> create tablespace tbs_d datafile '/u01/app/oracle/oradata/dbtree/tbs_d01.dbf' size 20M autoextend on next 20M;
    
    Tablespace created.
    
    sys@DBTREE> create user u_tbs_d identified by 1 default tablespace tbs_d quota unlimited on tbs_d;
    
    User created.
    
    sys@DBTREE> grant connect,resource to u_tbs_d;
    
    Grant succeeded.
    
    sys@DBTREE> conn u_tbs_d/1
    Connected.
    u_tbs_d@DBTREE> create table tab_t (v_num int);
    
    Table created.
    
    u_tbs_d@DBTREE> begin
      2  for x in 1..10000 loop
      3  insert into tab_t values (x);
      4  end loop;
      5  commit;
      6  end;
      7  /
    
    PL/SQL procedure successfully completed.
    
    u_tbs_d@DBTREE> select count(1) from tab_t;
    
      COUNT(1)
    ----------
         10000
    
    u_tbs_d@DBTREE> select * from tab_t where rownum < 10;
    
         V_NUM
    ----------
           661
           662
           663
           664
           665
           666
           667
           668
           669
    
    9 rows selected.

    2.删除新创建的表空间对应的数据文件

    [oracle@zabbix dbtree]$ ls
    control01.ctl  redo01.log  redo02.log  redo03.log  sysaux01.dbf  system01.dbf  tbs_d01.dbf  temp01.dbf  undotbs01.dbf  users01.dbf  zabbix01.dbf
    [oracle@zabbix dbtree]$ pwd
    /u01/app/oracle/oradata/dbtree
    [oracle@zabbix dbtree]$ rm -f tbs_d01.dbf
    [oracle@zabbix dbtree]$ ls
    control01.ctl  redo01.log  redo02.log  redo03.log  sysaux01.dbf  system01.dbf  temp01.dbf  undotbs01.dbf  users01.dbf  zabbix01.dbf
    
    
    u_tbs_d@DBTREE> select count(1) from tab_t;
    
      COUNT(1)
    ----------
         10000
    
    u_tbs_d@DBTREE> create table tab_t02 as select * from tab_t;
    create table tab_t02 as select * from tab_t
                                          *
    ERROR at line 1:
    ORA-01116: error in opening database file 6
    ORA-01110: data file 6: '/u01/app/oracle/oradata/dbtree/tbs_d01.dbf'
    ORA-27041: unable to open file
    Linux-x86_64 Error: 2: No such file or directory
    Additional information: 3

    3.通过Linux句柄恢复数据文件

    系统层面操作
    [oracle@zabbix dbtree]$ ps -ef | grep dbw
    oracle   31532     1  0 14:44 ?        00:00:00 ora_dbw0_dbtree
    oracle   37263 31440  0 16:06 pts/2    00:00:00 grep --color=auto dbw
    [oracle@zabbix dbtree]$ ll /proc/31532/fd
    total 0
    lr-x------ 1 oracle oinstall 64 Jun 26 16:06 0 -> /dev/null
    l-wx------ 1 oracle oinstall 64 Jun 26 16:06 1 -> /dev/null
    lrwx------ 1 oracle oinstall 64 Jun 26 16:06 10 -> /u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/lkDBTREE
    lr-x------ 1 oracle oinstall 64 Jun 26 16:06 13 -> /u01/app/oracle/product/11.2.0.4/dbhome_1/rdbms/mesg/oraus.msb
    lrwx------ 1 oracle oinstall 64 Jun 26 16:06 14 -> socket:[1507933]
    l-wx------ 1 oracle oinstall 64 Jun 26 16:06 2 -> /dev/null
    lrwx------ 1 oracle oinstall 64 Jun 26 16:06 256 -> /u01/app/oracle/oradata/dbtree/control01.ctl
    lrwx------ 1 oracle oinstall 64 Jun 26 16:06 257 -> /u01/app/oracle/fast_recovery_area/dbtree/control02.ctl
    lrwx------ 1 oracle oinstall 64 Jun 26 16:06 258 -> /u01/app/oracle/oradata/dbtree/system01.dbf
    lrwx------ 1 oracle oinstall 64 Jun 26 16:06 259 -> /u01/app/oracle/oradata/dbtree/sysaux01.dbf
    lrwx------ 1 oracle oinstall 64 Jun 26 16:06 260 -> /u01/app/oracle/oradata/dbtree/undotbs01.dbf
    lrwx------ 1 oracle oinstall 64 Jun 26 16:06 261 -> /u01/app/oracle/oradata/dbtree/users01.dbf
    lrwx------ 1 oracle oinstall 64 Jun 26 16:06 262 -> /u01/app/oracle/oradata/dbtree/zabbix01.dbf
    lrwx------ 1 oracle oinstall 64 Jun 26 16:06 263 -> /u01/app/oracle/oradata/dbtree/tbs_d01.dbf (deleted)
    lrwx------ 1 oracle oinstall 64 Jun 26 16:06 264 -> /u01/app/oracle/oradata/dbtree/temp01.dbf
    lr-x------ 1 oracle oinstall 64 Jun 26 16:06 3 -> /dev/null
    lr-x------ 1 oracle oinstall 64 Jun 26 16:06 4 -> /dev/null
    lr-x------ 1 oracle oinstall 64 Jun 26 16:06 5 -> /dev/null
    lr-x------ 1 oracle oinstall 64 Jun 26 16:06 6 -> /u01/app/oracle/product/11.2.0.4/dbhome_1/rdbms/mesg/oraus.msb
    lr-x------ 1 oracle oinstall 64 Jun 26 16:06 7 -> /proc/31532/fd
    lr-x------ 1 oracle oinstall 64 Jun 26 16:06 8 -> /dev/zero
    lrwx------ 1 oracle oinstall 64 Jun 26 16:06 9 -> /u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/hc_dbtree.dat
    [oracle@zabbix dbtree]$ cp /proc/31532/fd/263 /u01/app/oracle/oradata/dbtree/tbs_d01.dbf
    [oracle@zabbix dbtree]$ ll
    total 3568812
    -rw-r----- 1 oracle oinstall    9748480 Jun 26 16:06 control01.ctl
    -rw-r----- 1 oracle oinstall   52429312 Jun 26 14:47 redo01.log
    -rw-r----- 1 oracle oinstall   52429312 Jun 26 16:06 redo02.log
    -rw-r----- 1 oracle oinstall   52429312 Jun 26 14:47 redo03.log
    -rw-r----- 1 oracle oinstall 1073750016 Jun 26 16:06 sysaux01.dbf
    -rw-r----- 1 oracle oinstall 1073750016 Jun 26 16:06 system01.dbf
    -rw-r----- 1 oracle oinstall   20979712 Jun 26 16:06 tbs_d01.dbf
    -rw-r----- 1 oracle oinstall   30416896 Jun 25 22:00 temp01.dbf
    -rw-r----- 1 oracle oinstall 1073750016 Jun 26 16:05 undotbs01.dbf
    -rw-r----- 1 oracle oinstall  136323072 Jun 26 14:47 users01.dbf
    -rw-r----- 1 oracle oinstall  104865792 Jun 26 14:47 zabbix01.dbf
    
    数据库层面操作
    
    sys@DBTREE> @chkdbf     
    
    TABLESPACE_NAME         FILE_ID FILE_NAME                                                  MB      MAXMB AUT STATUS               ONLINE_
    -------------------- ---------- -------------------------------------------------- ---------- ---------- --- -------------------- -------
    SYSTEM                        1 /u01/app/oracle/oradata/dbtree/system01.dbf              1024      32768 YES AVAILABLE            SYSTEM
    SYSAUX                        2 /u01/app/oracle/oradata/dbtree/sysaux01.dbf              1024      32768 YES AVAILABLE            ONLINE
    UNDOTBS1                      3 /u01/app/oracle/oradata/dbtree/undotbs01.dbf             1024      32768 YES AVAILABLE            ONLINE
    USERS                         4 /u01/app/oracle/oradata/dbtree/users01.dbf                130      32768 YES AVAILABLE            ONLINE
    ZABBIX                        5 /u01/app/oracle/oradata/dbtree/zabbix01.dbf               100      32768 YES AVAILABLE            ONLINE
    TBS_D                         6 /u01/app/oracle/oradata/dbtree/tbs_d01.dbf                 20      32768 YES AVAILABLE            ONLINE
    
    6 rows selected.
    
    sys@DBTREE> alter database datafile 6 offline;
    
    Database altered.
    
    sys@DBTREE> recover datafile 6;
    Media recovery complete.
    sys@DBTREE> alter database datafile 6 online;
    
    Database altered.
    
    sys@DBTREE> conn u_tbs_d/1
    Connected.
    
    u_tbs_d@DBTREE> select count(1) from tab_t;
    
      COUNT(1)
    ----------
         10000
    
    u_tbs_d@DBTREE> create table tab_t02 as select * from tab_t;
    
    Table created.
    
    u_tbs_d@DBTREE> select count(1) from tab_t02;
    
      COUNT(1)
    ----------
         10000

    到此步骤,数据文件恢复完成


    数据文件丢失未及时发现,实例自检时异常关闭

    1.创建实验表空间

    此步骤和上一种类型一致,不在赘述

    2.删除新创建的表空间对应的数据文件

    此步骤和上一种类型一致,不在赘述

    3.模拟实例自检时数据库异常关闭

    sys@DBTREE> alter system switch logfile;
    
    System altered.
    
    sys@DBTREE> /
    
    System altered.
    
    sys@DBTREE> /
    ERROR:
    ORA-03114: not connected to ORACLE
    
    alter system switch logfile
    *
    ERROR at line 1:
    ORA-03113: end-of-file on communication channel
    Process ID: 38296
    Session ID: 96 Serial number: 21
    
    [oracle@zabbix dbtree]$ ps -ef | grep ora_
    oracle   38404 31440  0 16:22 pts/2    00:00:00 grep --color=auto ora_

    4.利用归档日志文件重建文件

    idle> startup mount;
    ORACLE instance started.
    
    Total System Global Area 2137886720 bytes
    Fixed Size          2254952 bytes
    Variable Size         587204504 bytes
    Database Buffers     1543503872 bytes
    Redo Buffers            4923392 bytes
    Database mounted.
    idle> alter database create datafile 6;
    
    Database altered.
    
    idle> recover datafile 6;
    Media recovery complete.
    idle> alter database open;
    
    Database altered.
    
    idle> conn u_tbs_d/1
    Connected.
    u_tbs_d@DBTREE> select count(1) from tab_t;
    
      COUNT(1)
    ----------
         10000
    
    u_tbs_d@DBTREE> create table tab_t02 as select * from tab_t;
    
    Table created.
    
    u_tbs_d@DBTREE> select count(1) from tab_t02;
    
      COUNT(1)
    ----------
         10000
    

    到此步骤,数据文件恢复完成

  • 相关阅读:
    目前最大的IPV6安全风险有哪些?
    PHP中exec、system等函数调用linux命令问题
    ubuntu下LAMP环境安装
    Ubuntu配置Apache虚拟主机
    XML和YAML的区别与使用方法
    使用CURL访问站点的时候出现403的解决办法
    IPv6安装及使用手册
    SuperSlide2.1-滚动
    HTML常用手册
    关于Ajax参数的思考
  • 原文地址:https://www.cnblogs.com/hawk20110625/p/9309467.html
Copyright © 2011-2022 走看看