1. 首页
  2. IT资讯

恢复被rm意外删除的数据文件

一.模拟数据文件删除

[oracle@node1 ~]$ sqlplus /assysdba
SQL*Plus: Release 11.2.0.3.0 ProductiononSatDec31 22:00:52 2011
Copyright (c) 1982, 2011, Oracle.Allrights reserved.
–数据库版本
Connectedto:
OracleDatabase11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
Withthe Partitioning, Oracle Label Security, OLAP, Data Mining,
OracleDatabaseVaultandRealApplication Testing options
–所有数据文件
SQL>selectnamefromv$datafile;
NAME
——————————————————————————–
/opt/oracle/oradata/ora11g/system01.dbf
/opt/oracle/oradata/ora11g/sysaux01.dbf
/opt/oracle/oradata/ora11g/undotbs01.dbf
/opt/oracle/oradata/ora11g/users01.dbf
/opt/oracle/oradata/ora11g/example01.dbf
–删除example01.dbf数据文件
SQL> !rm /opt/oracle/oradata/ora11g/example01.dbf
SQL> !ls -l /opt/oracle/oradata/ora11g/example01.dbf
ls: /opt/oracle/oradata/ora11g/example01.dbf: 没有那个文件或目录
–因为数据文件被删除,创建表失败
SQL>createtablet_xifenfei tablespace example
2asselect*fromdba_tables;
asselect*fromdba_tables
*
ERRORatline 2:
ORA-01116: errorinopeningdatabasefile 5
ORA-01110: data file 5:’/opt/oracle/oradata/ora11g/example01.dbf’
ORA-27041: unabletoopenfile
Linux-x86_64 Error: 2:Nosuch fileordirectory
Additional information: 3

二.找回数据文件

–查找dbw进程spid
[oracle@node1 ~]$ps-ef|grepdbw|grep-vgrep
oracle 18387 1 0 Dec22 ? 00:00:12 ora_dbw0_ora11g
–查看该进程所有文件句柄
[oracle@node1 ~]$ ll/proc/18387/fd
总计 0
lr-x—— 1 oracle oinstall 64 12-31 22:03 0 ->/dev/null
l-wx—— 1 oracle oinstall 64 12-31 22:03 1 ->/dev/null
lr-x—— 1 oracle oinstall 64 12-31 22:03 10 ->/dev/zero
lr-x—— 1 oracle oinstall 64 12-31 22:03 11 ->/dev/zero
lr-x—— 1 oracle oinstall 64 12-31 22:03 12 ->/opt/oracle/product/11.2.0/db_1/rdbms/mesg/orazhs.msb
lrwx—— 1 oracle oinstall 64 12-31 22:03 13 ->/opt/oracle/product/11.2.0/db_1/dbs/hc_ora11g.dat
lr-x—— 1 oracle oinstall 64 12-31 22:03 14 ->/proc/18387/fd
lr-x—— 1 oracle oinstall 64 12-31 22:03 15 ->/dev/zero
lr-x—— 1 oracle oinstall 64 12-31 22:03 16 ->/opt/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb
lrwx—— 1 oracle oinstall 64 12-31 22:03 17 ->/opt/oracle/product/11.2.0/db_1/dbs/hc_ora11g.dat
lrwx—— 1 oracle oinstall 64 12-31 22:03 18 ->/opt/oracle/product/11.2.0/db_1/dbs/lkORA11G
lr-x—— 1 oracle oinstall 64 12-31 22:03 19 ->/opt/oracle/product/11.2.0/db_1/rdbms/mesg/orazhs.msb
l-wx—— 1 oracle oinstall 64 12-31 22:03 2 ->/dev/null
lr-x—— 1 oracle oinstall 64 12-31 22:03 20 ->/opt/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb
lrwx—— 1 oracle oinstall 64 12-31 22:03 21 -> socket:[441562]
lrwx—— 1 oracle oinstall 64 12-31 22:03 256 ->/opt/oracle/oradata/ora11g/control01.ctl
lrwx—— 1 oracle oinstall 64 12-31 22:03 257 ->/opt/oracle/oradata/ora11g/system01.dbf
lrwx—— 1 oracle oinstall 64 12-31 22:03 258 ->/opt/oracle/oradata/ora11g/sysaux01.dbf
lrwx—— 1 oracle oinstall 64 12-31 22:03 259 ->/opt/oracle/oradata/ora11g/undotbs01.dbf
lrwx—— 1 oracle oinstall 64 12-31 22:03 260 ->/opt/oracle/oradata/ora11g/users01.dbf
lrwx—— 1 oracle oinstall 64 12-31 22:03 261 ->/opt/oracle/oradata/ora11g/example01.dbf (deleted)
lrwx—— 1 oracle oinstall 64 12-31 22:03 262 ->/opt/oracle/oradata/ora11g/temp01.dbf
lr-x—— 1 oracle oinstall 64 12-31 22:03 3 ->/dev/null
lr-x—— 1 oracle oinstall 64 12-31 22:03 4 ->/dev/null
lrwx—— 1 oracle oinstall 64 12-31 22:03 5 ->/opt/oracle/product/11.2.0/db_1/dbs/hc_ora11g.dat
lr-x—— 1 oracle oinstall 64 12-31 22:03 6 ->/dev/null
lr-x—— 1 oracle oinstall 64 12-31 22:03 7 ->/dev/null
lr-x—— 1 oracle oinstall 64 12-31 22:03 8 ->/dev/null
lr-x—— 1 oracle oinstall 64 12-31 22:03 9 ->/dev/null
–通过句柄恢复数据文件[被删除数据文件会被标示(deleted)]
[oracle@node1 ~]$cp/proc/18387/fd/261/opt/oracle/oradata/ora11g/example01.dbf
–确认该数据文件已经恢复成功
[oracle@node1 ~]$ ll/opt/oracle/oradata/ora11g/example01.dbf
-rw-r—– 1 oracle oinstall 362422272 12-31 22:05/opt/oracle/oradata/ora11g/example01.dbf

三.数据文件online SQL>alterdatabasedatafile 5 offline;

Databasealtered.
SQL> recover datafile 5;
Media recovery complete.
SQL>alterdatabasedatafile 5 online;
Databasealtered.
SQL>createtablet_xifenfei tablespace example
2asselect*fromdba_tables;
Tablecreated.

四.补充说明 在意外使用os命令删除掉数据文件时,千万不要慌张重启数据库或者操作系统,可以通过dbwn进程相关句柄找回数据文件

如果是unix系统,可能需要先通过lsof找到句柄,然后通过cp实现

[root@node1 ~]# lsof -p 18387 |grep deleted
oracle 18387 oracle 261uW REG 8,6 362422272 13598733/opt/oracle/oradata/ora11g/example01.dbf (deleted)
cd/proc/18387/fd/
cp261/opt/oracle/oradata/ora11g/example01.dbf

lsof安装

[root@xifenfei ~]# tar xjf lsof_4.86.tar.bz2
[root@xifenfei lsof_4.86]# tar xvf lsof_4.86_src.tar
[root@xifenfei lsof_4.86_src]# ./Configure
No target dialect was specified.
Usage: Configure <options> <target-dialect>
<options>: -clean : clean up previous configuration
-d|-dialects : display a list of supported dialect versions
-h|-help : display help information
-n : avoid AFS, customization, and inventory checks
<target-dialect> (****USE -d TO GET TESTED DIALECT VERSION NUMBERS****):
aix|aixgcc : IBM AIX xlc (aix) or gcc (aixgcc)
darwin : Apple Darwin
decosf : DEC OSF/1
digital_unix|du: Digital UNIX
freebsd : FreeBSD
hpux|hpuxgcc : HP-UX cc (hpux) or gcc (hpuxgcc)
linux : Linux
netbsd : NetBSD
nextstep|next|ns|nxt : NEXTSTEP
openbsd : OpenBSD
openstep|os : OPENSTEP
osr|sco : SCO OpenServer < 6.0.0, SCO devloper’s compiler
osrgcc|scogcc : SCO OpenServer < 6.0.0, gcc compiler
osr6 : SCO OpenServer 6.0.0, SCO compiler
solaris|solariscc : Solaris gcc (solaris) or cc (solariscc)
tru64 : Tru64 UNIX
unixware|uw : SCO|Caldera UnixWare
[root@xifenfei lsof_4.86_src]# ./Configure linux
[root@xifenfei lsof_4.86_src]# make
[root@xifenfei lsof_4.86_src]# make install

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29578568/viewspace-2143311/,如需转载,请注明出处,否则将追究法律责任。

主题测试文章,只做测试使用。发布者:布吉卡,转转请注明出处:http://www.cxybcw.com/195234.html

联系我们

13687733322

在线咨询:点击这里给我发消息

邮件:1877088071@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code