恢复被rm意外删除的数据文件
一.模拟数据文件删除
二.找回数据文件
--查找dbw进程spid [oracle@node1 ~]$ ps -ef|grepdbw|grep -v grep 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> alterdatabase datafile 5 offline; Database altered.
SQL> recover datafile 5; Media recovery complete.
SQL> alterdatabase datafile 5 online; Database altered.
SQL> createtable t_xifenfei tablespace example 2 as select* from dba_tables; Table created.
四.补充说明
在意外使用os命令删除掉数据文件时,千万不要慌张重启数据库或者操作系统,可以通过dbwn进程相关句柄找回数据文件
如果是unix系统,可能需要先通过lsof找到句柄,然后通过cp实现
[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