王炸科技头像

rm

来源:
       

  很多DBA一定对rm-rf深恶痛绝吧,没准哪天自己一个犯迷糊就把数据库给消灭了,然后,就没有然后了那万一真的发生了这样的不幸,是否真的就无药可救了吗?未必,还是有解决方法的,也许某天当你不幸遇到,就可以用来救自己了。这里做恢复操作的前提是没有可用

  很多DBA一定对rm-rf深恶痛绝吧,没准哪天自己一个犯迷糊就把数据库给消灭了,然后,就没有然后了……那万一……真的发生了这样的不幸,是否真的就无药可救了吗?未必,还是有解决方法的,也许某天当你不幸遇到,就可以用来救自己了。这里做恢复操作的前提是没有可用的rman备份,或者数据库冷备份等,也就是说,没有任何备份。

  一、登陆SQLPLUS,并启动数据库[oracle@ora10g~]$sqlplus/assysdba

  SQLPlus:Release10.2.0.1.0-ProductiononMonAug2512:37:502014

  Copyright(c)1982,2005,Oracle.Allrightsreserved.

  Connectedtoanidleinstance.

  SQL>startup

  ORACLEinstancestarted.

  TotalSystemGlobalArea285212672bytes

  FixedSize1218992bytes

  VariableSize96470608bytes

  DatabaseBuffers184549376bytes

  RedoBuffers2973696bytes

  Databasemounted.

  Databaseopened.

  --查看实例初始化状态

  SQL>selectstatusfromv$instance;

  STATUS

  ------------

  OPEN

  --查看实例名

  SQL>showparametername;

  NAMETYPEVALUE

  -----------------------------------------------------------------------------

  db_file_name_convertstring

  db_namestringora10g

  db_unique_namestringora10g

  global_namesbooleanFALSE

  instance_namestringora10g

  lock_name_spacestring

  log_file_name_convertstring

  service_namesstringora10g

  SQL>exit

  DisconnectedfromOracleDatabase10gEnterpriseEditionRelease10.2.0.1.0-Production

  WiththePartitioning,OLAPandDataMiningoptions

  二、模拟rm-rf误操作[oracle@ora10g~]$cd/u01/app/oracle/oradata

  [oracle@ora10goradata]$ll

  total4

  drwxr-x---2oracleoinstall4096Aug2511:15ora10g

  [oracle@ora10goradata]$pwd

  /u01/app/oracle/oradata

  [oracle@ora10goradata]$rm-rfora10g

  [oracle@ora10goradata]$exit

  logout

  [root@ora10g~]#su-oracle

  [oracle@ora10g~]$sqlplus/assysdba

  SQLPlus:Release10.2.0.1.0-ProductiononMonAug2512:43:582014

  Copyright(c)1982,2005,Oracle.Allrightsreserved.

  Connectedto:

  OracleDatabase10gEnterpriseEditionRelease10.2.0.1.0-Production

  WiththePartitioning,OLAPandDataMiningoptions

  SQL>selectcount()fromdba_objects;

  selectcount()fromdba_objects

  ERRORatline1:

  ORA-00604:erroroccurredatrecursiveSQLlevel1

  ORA-01116:errorinopeningdatabasefile1

  ORA-01110:datafile1:'/u01/app/oracle/oradata/ora10g/system01.dbf'

  ORA-27041:unabletoopenfile

  LinuxError:2:Nosuchfileordirectory

  Additionalinformation:3

  SQL>selectcount()fromdba_segments;

  selectcount()fromdba_segments

  ERRORatline1:

  ORA-00604:erroroccurredatrecursiveSQLlevel1

  ORA-01116:errorinopeningdatabasefile1

  ORA-01110:datafile1:'/u01/app/oracle/oradata/ora10g/system01.dbf'

  ORA-27041:unabletoopenfile

  LinuxError:2:Nosuchfileordirectory

  Additionalinformation:3

  由于数据文件都被删除,其中包括system01.dbf,是存放数据字典的容器,想要再访问数据字典中得视图,当然是不可能的了,所以这里会报错,找不到文件,故障出现

  --查看alert.log日志文件

  [root@ora10g~]#tailf/u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log

  ARCHshuttingdown

  ARC2:Archivalstopped

  MonAug2512:45:382014

  Errorsinfile/u01/app/oracle/admin/ora10g/bdump/ora10g_j000_3037.trc:

  ORA-12012:erroronautoexecuteofjob1

  ORA-01116:errorinopeningdatabasefile2

  ORA-01110:datafile2:'/u01/app/oracle/oradata/ora10g/undotbs01.dbf'

  ORA-27041:unabletoopenfile

  LinuxError:2:Nosuchfileordirectory

  Additionalinformation:3

  MonAug2512:46:432014

  Errorsinfile/u01/app/oracle/admin/ora10g/bdump/ora10g_j000_3070.trc:

  ORA-12012:erroronautoexecuteofjob1

  ORA-01116:errorinopeningdatabasefile2

  ORA-01110:datafile2:'/u01/app/oracle/oradata/ora10g/undotbs01.dbf'

  ORA-27041:unabletoopenfile

  LinuxError:2:Nosuchfileordirectory

  Additionalinformation:3

  --查看dbwr进程,判断需要恢复文件句柄所在目录

  SQL>!ps-ef|grepora_dbw

  oracle29121012:37?00:00:00ora_dbw0_ora10g

  oracle30783032012:48pts/300:00:00/bin/bash-cps-ef|grepora_dbw

  oracle30803078012:48pts/300:00:00grepora_dbw

  其实这个时候,所有oracle的进程都还在,都是以ora_开头的都是oracle的后台进程:

  SQL>!ps-ef|grepora_

  oracle29061012:37?00:00:00ora_pmon_ora10g

  oracle29081012:37?00:00:00ora_psp0_ora10g

  oracle29101012:37?00:00:00ora_mman_ora10g

  oracle29121012:37?00:00:00ora_dbw0_ora10g

  oracle29141012:37?00:00:00ora_lgwr_ora10g

  oracle29161012:37?00:00:00ora_ckpt_ora10g

  oracle29181012:38?00:00:01ora_smon_ora10g

  oracle29201012:38?00:00:00ora_reco_ora10g

  oracle29221012:38?00:00:00ora_cjq0_ora10g

  oracle29241012:38?00:00:01ora_mmon_ora10g

  oracle29261012:38?00:00:00ora_mmnl_ora10g

  oracle29281012:38?00:00:00ora_d000_ora10g

  oracle29301012:38?00:00:00ora_s000_ora10g

  oracle29341012:38?00:00:00ora_arc0_ora10g

  oracle29361012:38?00:00:00ora_arc1_ora10g

  oracle29411012:38?00:00:00ora_qmnc_ora10g

  oracle29431012:38?00:00:00ora_q000_ora10g

  oracle29451012:38?00:00:00ora_q001_ora10g

  oracle30771012:48?00:00:00ora_j000_ora10g

  oracle30853032012:49pts/300:00:00/bin/bash-cps-ef|grepora_

  oracle30873085012:49pts/300:00:00/bin/bash-cps-ef|grepora_

  由此可知,我们需要的被删除的文件句柄在/proc/2912/fd下

  三、开始恢复误删除的文件

  --恢复数据文件和控制文件

  SQL>exit

  DisconnectedfromOracleDatabase10gEnterpriseEditionRelease10.2.0.1.0-Production

  WiththePartitioning,OLAPandDataMiningoptions

  [oracle@ora10g~]$cd/proc/2912

  [oracle@ora10g2912]$ll

  total0

  dr-xr-xr-x2oracleoinstall0Aug2512:51attr

  -r--------1oracleoinstall0Aug2512:51auxv

  -r--r--r--1oracleoinstall0Aug2512:48cmdline

  -rw-r--r--1oracleoinstall0Aug2512:51coredump_filter

  -r--r--r--1oracleoinstall0Aug2512:51cpuset

  lrwxrwxrwx1oracleoinstall0Aug2512:51cwd->/u01/app/oracle/product/10.2.0/db_1/dbs

  -r--------1oracleoinstall0Aug2512:51environ

  lrwxrwxrwx1oracleoinstall0Aug2512:51exe->/u01/app/oracle/product/10.2.0/db_1/bin/oracle

  dr-x------2oracleoinstall0Aug2512:51fd

  -r--------1oracleoinstall0Aug2512:51limits

  -rw-r--r--1oracleoinstall0Aug2512:51loginuid

  -r--r--r--1oracleoinstall0Aug2512:37maps

  -rw-------1oracleoinstall0Aug2512:51mem

  -r--r--r--1oracleoinstall0Aug2512:51mounts

  -r--------1oracleoinstall0Aug2512:51mountstats

  -rw-r--r--1oracleoinstall0Aug2512:51oom_adj

  -r--r--r--1oracleoinstall0Aug2512:51oom_score

  lrwxrwxrwx1oracleoinstall0Aug2512:51root->/

  -r--r--r--1oracleoinstall0Aug2512:51schedstat

  -r--------1oracleoinstall0Aug2512:51smaps

  -r--r--r--1oracleoinstall0Aug2512:37stat

  -r--r--r--1oracleoinstall0Aug2512:51statm

  -r--r--r--1oracleoinstall0Aug2512:48status

  dr-xr-xr-x3oracleoinstall0Aug2512:51task

  -r--r--r--1oracleoinstall0Aug2512:51wchan

  [oracle@ora10g2912]$cdfd

  [oracle@ora10gfd]$ls-ltr

  total0

  lr-x------1oracleoinstall64Aug2512:510->/dev/null

  l-wx------1oracleoinstall64Aug2512:516->/u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log

  l-wx------1oracleoinstall64Aug2512:515->/u01/app/oracle/admin/ora10g/udump/ora10g_ora_2904.trc

  lr-x------1oracleoinstall64Aug2512:514->/dev/null

  lr-x------1oracleoinstall64Aug2512:513->/dev/null

  lr-x------1oracleoinstall64Aug2512:512->/dev/null

  lr-x------1oracleoinstall64Aug2512:511->/dev/null

  lrwx------1oracleoinstall64Aug2512:519->/u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat

  l-wx------1oracleoinstall64Aug2512:518->/u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log

  lrwx------1oracleoinstall64Aug2512:517->/u01/app/oracle/product/10.2.0/db_1/dbs/lkinstora10g(deleted)

  lrwx------1oracleoinstall64Aug2512:5123->/u01/app/oracle/oradata/ora10g/temp01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2512:5122->/u01/app/oracle/oradata/ora10g/example01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2512:5121->/u01/app/oracle/oradata/ora10g/users01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2512:5120->/u01/app/oracle/oradata/ora10g/sysaux01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2512:5119->/u01/app/oracle/oradata/ora10g/undotbs01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2512:5118->/u01/app/oracle/oradata/ora10g/system01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2512:5117->/u01/app/oracle/oradata/ora10g/control03.ctl(deleted)

  lrwx------1oracleoinstall64Aug2512:5116->/u01/app/oracle/oradata/ora10g/control02.ctl(deleted)

  lrwx------1oracleoinstall64Aug2512:5115->/u01/app/oracle/oradata/ora10g/control01.ctl(deleted)

  lrwx------1oracleoinstall64Aug2512:5114->/u01/app/oracle/product/10.2.0/db_1/dbs/lkORA10G

  lrwx------1oracleoinstall64Aug2512:5113->/u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat

  lr-x------1oracleoinstall64Aug2512:5112->/dev/zero

  lr-x------1oracleoinstall64Aug2512:5111->/dev/zero

  lrwx------1oracleoinstall64Aug2512:5110->/u01/app/oracle/admin/ora10g/adump/ora_2904.aud

  [oracle@ora10gfd]$

rm-第1张图片

  分析:可以看句柄7,15-23的文件末尾被标记(deleted),这是由刚才的rm-rf操作所导致的,误删除后只要Oracle数据库未重启,进程就不会停止,那么就可以通过/proc/#oracle进程号/fd目录中的文件句柄号,来对这些被delete的文件进行恢复,方法就是cp文件句柄到原路径,注意一点这里如果不是在fd目录,那就要用绝对路径来指定文件句柄,如果删除文件后就,又对数据库进行了关闭操作,那就无解了--手动创建ora10g实例名命名的目录并cp句柄到具体路径

  [oracle@ora10gfd]$mkdir/u01/app/oracle/oradata/ora10g/

  [oracle@ora10gfd]$cp7/u01/app/oracle/product/10.2.0/db_1/dbs/lkinstora10g

  [oracle@ora10gfd]$cp23/u01/app/oracle/oradata/ora10g/temp01.dbf

  [oracle@ora10gfd]$cp22/u01/app/oracle/oradata/ora10g/example01.dbf

  [oracle@ora10gfd]$cp21/u01/app/oracle/oradata/ora10g/users01.dbf

  [oracle@ora10gfd]$cp20/u01/app/oracle/oradata/ora10g/sysaux01.dbf

  [oracle@ora10gfd]$cp19/u01/app/oracle/oradata/ora10g/undotbs01.dbf

  [oracle@ora10gfd]$cp18/u01/app/oracle/oradata/ora10g/system01.dbf

  [oracle@ora10gfd]$cp17/u01/app/oracle/oradata/ora10g/control03.ctl

  [oracle@ora10gfd]$cp16/u01/app/oracle/oradata/ora10g/control02.ctl

  [oracle@ora10gfd]$cp15/u01/app/oracle/oradata/ora10g/control01.ctl

  注意,这里一定要注意权限问题,要用oracle用户去cp,如果用root去cp出来的文件,oracle进程是没有权限操作的,当然,你也可以在用root恢复完后,再chown一下:

  [root@ora10gfd]#chownoracle.oinstall/u01/app/oracle-R

  但是一定要注意,必须等全部数据文件恢复后才可以做chown操作,因为一旦执行了该操作,原来的ora_进程会停止!!!你再也无法恢复丢失的数据了!!!这也是为什么推荐用oralce用户来cp的原因

  [root@ora10gfd]#ps-ef|grepora_dbw

  oracle34701013:50?00:00:02ora_dbw0_ora10g

  root40123825015:15pts/300:00:00grepora_dbw

  [root@ora10gfd]#chownoracle.oinstall/u01/-R

  [root@ora10gfd]#cd/proc/3470

  -bash:cd:/proc/3470:Nosuchfileordirectory

  [root@ora10gfd]#ps-ef|grepora_dbw

  root40263825015:18pts/300:00:00grepora_dbw

  [root@ora10gfd]#ps-ef|grepora_

  root40363825015:22pts/300:00:00grepora_

  [root@ora10gfd]#

  --再次查看fd目录下得文件状态[oracle@ora10gfd]$ls-ltr

  total0

  lr-x------1oracleoinstall64Aug2512:510->/dev/null

  l-wx------1oracleoinstall64Aug2512:516->/u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log

  l-wx------1oracleoinstall64Aug2512:515->/u01/app/oracle/admin/ora10g/udump/ora10g_ora_2904.trc

  lr-x------1oracleoinstall64Aug2512:514->/dev/null

  lr-x------1oracleoinstall64Aug2512:513->/dev/null

  lr-x------1oracleoinstall64Aug2512:512->/dev/null

  lr-x------1oracleoinstall64Aug2512:511->/dev/null

  lrwx------1oracleoinstall64Aug2512:519->/u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat

  l-wx------1oracleoinstall64Aug2512:518->/u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log

  lrwx------1oracleoinstall64Aug2512:517->/u01/app/oracle/product/10.2.0/db_1/dbs/lkinstora10g(deleted)

  lrwx------1oracleoinstall64Aug2512:5123->/u01/app/oracle/oradata/ora10g/temp01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2512:5122->/u01/app/oracle/oradata/ora10g/example01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2512:5121->/u01/app/oracle/oradata/ora10g/users01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2512:5120->/u01/app/oracle/oradata/ora10g/sysaux01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2512:5119->/u01/app/oracle/oradata/ora10g/undotbs01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2512:5118->/u01/app/oracle/oradata/ora10g/system01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2512:5117->/u01/app/oracle/oradata/ora10g/control03.ctl(deleted)

  lrwx------1oracleoinstall64Aug2512:5116->/u01/app/oracle/oradata/ora10g/control02.ctl(deleted)

  lrwx------1oracleoinstall64Aug2512:5115->/u01/app/oracle/oradata/ora10g/control01.ctl(deleted)

  lrwx------1oracleoinstall64Aug2512:5114->/u01/app/oracle/product/10.2.0/db_1/dbs/lkORA10G

  lrwx------1oracleoinstall64Aug2512:5113->/u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat

  lr-x------1oracleoinstall64Aug2512:5112->/dev/zero

  lr-x------1oracleoinstall64Aug2512:5111->/dev/zero

  lrwx------1oracleoinstall64Aug2512:5110->/u01/app/oracle/admin/ora10g/adump/ora_2904.aud

  对文件进行恢复以后,直接查询fd目录下的文件状态,依然可以看到是(deleted)的,但是没关系,实际上文件已经恢复成功了

  --开启另一个session查看文件是否已经恢复

  [root@ora10g~]#su-oracle

  [oracle@ora10g~]$cd/u01/app/oracle/oradata/ora10g

  [oracle@ora10gora10g]$ll

  total914656

  -rw-r-----1oracleoinstall7061504Aug2513:03control01.ctl

  -rw-r-----1oracleoinstall7061504Aug2513:03control02.ctl

  -rw-r-----1oracleoinstall7061504Aug2513:03control03.ctl

  -rw-r-----1oracleoinstall104865792Aug2513:00example01.dbf

  -rw-r-----1oracleoinstall251666432Aug2513:01sysaux01.dbf

  -rw-r-----1oracleoinstall503324672Aug2513:02system01.dbf

  -rw-r-----1oracleoinstall20979712Aug2512:59temp01.dbf

  -rw-r-----1oracleoinstall31465472Aug2513:01undotbs01.dbf

  -rw-r-----1oracleoinstall5251072Aug2513:00users01.dbf

  [oracle@ora10gora10g]$pwd

  /u01/app/oracle/oradata/ora10g

  [oracle@ora10gora10g]$

  --恢复在线日志文件

  [oracle@ora10gfd]$ps-ef|grepora_lgwr

  oracle29141012:37?00:00:01ora_lgwr_ora10g

  oracle32552999013:09pts/200:00:00grepora_lgwr

  [oracle@ora10gfd]$cd/proc/2914/fd

  [oracle@ora10gfd]$ls-ltr

  total0

  lr-x------1oracleoinstall64Aug2513:090->/dev/null

  l-wx------1oracleoinstall64Aug2513:095->/u01/app/oracle/admin/ora10g/udump/ora10g_ora_2904.trc

  lr-x------1oracleoinstall64Aug2513:094->/dev/null

  lr-x------1oracleoinstall64Aug2513:093->/dev/null

  l-wx------1oracleoinstall64Aug2513:092->/u01/app/oracle/admin/ora10g/bdump/ora10g_lgwr_2914.trc

  lr-x------1oracleoinstall64Aug2513:091->/dev/null

  lrwx------1oracleoinstall64Aug2513:099->/u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat

  l-wx------1oracleoinstall64Aug2513:098->/u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log

  lrwx------1oracleoinstall64Aug2513:097->/u01/app/oracle/product/10.2.0/db_1/dbs/lkinstora10g(deleted)

  l-wx------1oracleoinstall64Aug2513:096->/u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log

  lrwx------1oracleoinstall64Aug2513:0926->/u01/app/oracle/oradata/ora10g/temp01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2513:0925->/u01/app/oracle/oradata/ora10g/example01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2513:0924->/u01/app/oracle/oradata/ora10g/users01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2513:0923->/u01/app/oracle/oradata/ora10g/sysaux01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2513:0922->/u01/app/oracle/oradata/ora10g/undotbs01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2513:0921->/u01/app/oracle/oradata/ora10g/system01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2513:0920->/u01/app/oracle/oradata/ora10g/redo03.log(deleted)

  lrwx------1oracleoinstall64Aug2513:0919->/u01/app/oracle/oradata/ora10g/redo02.log(deleted)

  lrwx------1oracleoinstall64Aug2513:0918->/u01/app/oracle/oradata/ora10g/redo01.log(deleted)

  lrwx------1oracleoinstall64Aug2513:0917->/u01/app/oracle/oradata/ora10g/control03.ctl(deleted)

  lrwx------1oracleoinstall64Aug2513:0916->/u01/app/oracle/oradata/ora10g/control02.ctl(deleted)

  lrwx------1oracleoinstall64Aug2513:0915->/u01/app/oracle/oradata/ora10g/control01.ctl(deleted)

  lrwx------1oracleoinstall64Aug2513:0914->/u01/app/oracle/product/10.2.0/db_1/dbs/lkORA10G

  lrwx------1oracleoinstall64Aug2513:0913->/u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat

  lr-x------1oracleoinstall64Aug2513:0912->/dev/zero

  lr-x------1oracleoinstall64Aug2513:0911->/dev/zero

  lrwx------1oracleoinstall64Aug2513:0910->/u01/app/oracle/admin/ora10g/adump/ora_2904.aud

  [oracle@ora10gfd]$

  可以看到,根据ora_lgwr进程找到的/proc/2914/fd目录下,也有刚才恢复过得数据文件句柄,但句柄的编号,和刚才在/proc/2912/fd下面是不一致的,这也就说明,这些进程在运行的时候,各自有各自的文件句柄编号,互不影响,由于刚才已经对数据文件和控制文件进行了恢复,此时,只需要再对onlineredologfile进行恢复即可

  --开始恢复onlineredologfile

  [oracle@ora10gfd]$cp20/u01/app/oracle/oradata/ora10g/redo03.log

  [oracle@ora10gfd]$cp19/u01/app/oracle/oradata/ora10g/redo02.log

  [oracle@ora10gfd]$cp18/u01/app/oracle/oradata/ora10g/redo01.log

  --在另一个session中查看onlineredolog是否已经恢复

  [oracle@ora10gora10g]$ll

  total1068436

  -rw-r-----1oracleoinstall7061504Aug2513:03control01.ctl

  -rw-r-----1oracleoinstall7061504Aug2513:03control02.ctl

  -rw-r-----1oracleoinstall7061504Aug2513:03control03.ctl

  -rw-r-----1oracleoinstall104865792Aug2513:00example01.dbf

  -rw-r-----1oracleoinstall52429312Aug2513:12redo01.log

  -rw-r-----1oracleoinstall52429312Aug2513:12redo02.log

  -rw-r-----1oracleoinstall52429312Aug2513:12redo03.log

  -rw-r-----1oracleoinstall251666432Aug2513:01sysaux01.dbf

  -rw-r-----1oracleoinstall503324672Aug2513:02system01.dbf

  -rw-r-----1oracleoinstall20979712Aug2512:59temp01.dbf

  -rw-r-----1oracleoinstall31465472Aug2513:01undotbs01.dbf

  -rw-r-----1oracleoinstall5251072Aug2513:00users01.dbf

  [oracle@ora10gora10g]$

  --重新登录数据库,进行dml操作

  [oracle@ora10gfd]$sqlplus/assysdba

  SQLPlus:Release10.2.0.1.0-ProductiononMonAug2513:14:252014

  Copyright(c)1982,2005,Oracle.Allrightsreserved.

  Connectedto:

  OracleDatabase10gEnterpriseEditionRelease10.2.0.1.0-Production

  WiththePartitioning,OLAPandDataMiningoptions

  SQL>selectcount()fromdba_objects;

  COUNT()

  ----------

  50314

  此时数据库可以正常dml了,但是关闭后再开启数据库,会报600错误:

  SQL>shutdownimmediate

  Databaseclosed.

  Databasedismounted.

  ORACLEinstanceshutdown.

  SQL>startup

  ORACLEinstancestarted.

  TotalSystemGlobalArea285212672bytes

  FixedSize1218992bytes

  VariableSize96470608bytes

  DatabaseBuffers184549376bytes

  RedoBuffers2973696bytes

  Databasemounted.

  ORA-00600:internalerrorcode,arguments:[kcratr1_lastbwr],[],[],[],[],

  [],[],[]

  --查看alert.log

  MonAug2513:19:162014

  ALTERDATABASEMOUNT

  MonAug2513:19:202014

  Settingrecoverytargetincarnationto2

  MonAug2513:19:212014

  Successfulmountofredothread1,withmountid4175423764

  MonAug2513:19:212014

  DatabasemountedinExclusiveMode

  Completed:ALTERDATABASEMOUNT

  MonAug2513:19:212014

  ALTERDATABASEOPEN

  MonAug2513:19:212014

  Beginningcrashrecoveryof1threads

  MonAug2513:19:212014

  Startedredoscan

  MonAug2513:19:212014

  Errorsinfile/u01/app/oracle/admin/ora10g/udump/ora10g_ora_3320.trc:

  ORA-00600:internalerrorcode,arguments:[kcratr1_lastbwr],[],[],[],[],[],[],[]

  MonAug2513:19:222014

  Abortingcrashrecoveryduetoerror600--终止实例恢复

  根据MetalinknoteID:[393984.1]文档的说明,出现该问题的原因是oracle不能执行实例恢复,手工完成介质恢复后即可以打开

  SQL>shutdownimmediate

  ORA-01109:databasenotopen

  Databasedismounted.

  ORACLEinstanceshutdown.

  SQL>startupmount

  ORACLEinstancestarted.

  TotalSystemGlobalArea285212672bytes

  FixedSize1218992bytes

  VariableSize96470608bytes

  DatabaseBuffers184549376bytes

  RedoBuffers2973696bytes

  Databasemounted.

  SQL>recoverdatabase

  Mediarecoverycomplete.

  SQL>alterdatabaseopen;

  Databasealtered.

  SQL>selectcount()fromdba_objects;

  COUNT()

  ----------

  50314

  SQL>

  --再次验证数据文件

  SQL>!ps-ef|grepora_

  oracle34641013:50?00:00:00ora_pmon_ora10g

  oracle34661013:50?00:00:00ora_psp0_ora10g

  oracle34681013:50?00:00:00ora_mman_ora10g

  oracle34701013:50?00:00:00ora_dbw0_ora10g

  oracle34721013:50?00:00:00ora_lgwr_ora10g

  oracle34741013:50?00:00:01ora_ckpt_ora10g

  oracle34761013:50?00:00:01ora_smon_ora10g

  oracle34781013:50?00:00:00ora_reco_ora10g

  oracle34801013:50?00:00:01ora_cjq0_ora10g

  oracle34821013:50?00:00:01ora_mmon_ora10g

  oracle34841013:50?00:00:00ora_mmnl_ora10g

  oracle34861013:50?00:00:00ora_d000_ora10g

  oracle34881013:50?00:00:00ora_s000_ora10g

  oracle34931013:50?00:00:00ora_arc0_ora10g

  oracle34951013:50?00:00:00ora_arc1_ora10g

  oracle34991013:51?00:00:00ora_qmnc_ora10g

  oracle35131013:51?00:00:00ora_q000_ora10g

  oracle35151013:51?00:00:00ora_q001_ora10g

  oracle35651014:04?00:00:00ora_j000_ora10g

  oracle35683278014:04pts/500:00:00/bin/bash-cps-ef|grepora_

  SQL>!ls-ltr/proc/3472/fd

  total0

  lrwx------1oracleoinstall64Aug2514:049->/u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat

  l-wx------1oracleoinstall64Aug2514:048->/u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log

  lrwx------1oracleoinstall64Aug2514:047->/u01/app/oracle/product/10.2.0/db_1/dbs/lkinstora10g(deleted)

  l-wx------1oracleoinstall64Aug2514:046->/u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log

  l-wx------1oracleoinstall64Aug2514:045->/u01/app/oracle/admin/ora10g/udump/ora10g_ora_3462.trc

  lr-x------1oracleoinstall64Aug2514:044->/dev/null

  lr-x------1oracleoinstall64Aug2514:043->/dev/null

  l-wx------1oracleoinstall64Aug2514:042->/u01/app/oracle/admin/ora10g/bdump/ora10g_lgwr_3472.trc

  lrwx------1oracleoinstall64Aug2514:0413->/u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat

  lr-x------1oracleoinstall64Aug2514:0412->/dev/zero

  lr-x------1oracleoinstall64Aug2514:0411->/dev/zero

  lrwx------1oracleoinstall64Aug2514:0410->/u01/app/oracle/admin/ora10g/adump/ora_3462.aud

  lr-x------1oracleoinstall64Aug2514:041->/dev/null

  lr-x------1oracleoinstall64Aug2514:040->/dev/null

  lrwx------1oracleoinstall64Aug2514:0426->/u01/app/oracle/oradata/ora10g/temp01.dbf

  lrwx------1oracleoinstall64Aug2514:0425->/u01/app/oracle/oradata/ora10g/example01.dbf

  lrwx------1oracleoinstall64Aug2514:0424->/u01/app/oracle/oradata/ora10g/users01.dbf

  lrwx------1oracleoinstall64Aug2514:0423->/u01/app/oracle/oradata/ora10g/sysaux01.dbf

  lrwx------1oracleoinstall64Aug2514:0422->/u01/app/oracle/oradata/ora10g/undotbs01.dbf

  lrwx------1oracleoinstall64Aug2514:0421->/u01/app/oracle/oradata/ora10g/system01.dbf

  lrwx------1oracleoinstall64Aug2514:0420->/u01/app/oracle/oradata/ora10g/redo03.log

  lrwx------1oracleoinstall64Aug2514:0419->/u01/app/oracle/oradata/ora10g/redo02.log

  lrwx------1oracleoinstall64Aug2514:0418->/u01/app/oracle/oradata/ora10g/redo01.log

  lrwx------1oracleoinstall64Aug2514:0417->/u01/app/oracle/oradata/ora10g/control03.ctl

  lrwx------1oracleoinstall64Aug2514:0416->/u01/app/oracle/oradata/ora10g/control02.ctl

  lrwx------1oracleoinstall64Aug2514:0415->/u01/app/oracle/oradata/ora10g/control01.ctl

  lrwx------1oracleoinstall64Aug2514:0414->/u01/app/oracle/product/10.2.0/db_1/dbs/lkORA10G

  SQL>

  此时数据文件都已经正常了,每次启动数据库实例后,进程都会再/proc下生成一个相应的以进程号命名的目录,存放操作中涉及到的文件句柄,此时lgwr进程对应的目录已经变为3472,而原来的2914目录已经不存在了

  --------------------------------------------------------------------------------------

  第2次测试(创建完表并插入2条数据后,不提交,直接删除/u01/app/oracle/oradata/ora10g/下的全部文件)

  [oracle@ora10gfd]$sqlplus/assysdba

  SQLPlus:Release10.2.0.1.0-ProductiononMonAug2515:57:572014

  Copyright(c)1982,2005,Oracle.Allrightsreserved.

  Connectedto:

  OracleDatabase10gEnterpriseEditionRelease10.2.0.1.0-Production

  WiththePartitioning,OLAPandDataMiningoptions

  SQL>selectcount()fromdba_objects;

  COUNT()

  ----------

  50314

  SQL>createuseraaron8219identifiedbyoracle;

  Usercreated.

  SQL>grantdbatoaaron8219;

  Grantsucceeded.

  SQL>connaaron8219/oracle

  Connected.

  SQL>createtabletest1(intnumber);

  Tablecreated.

  SQL>selectcount()fromdba_objects;

  COUNT()

  ----------

  50315

  SQL>insertintotest1values(1);

  1rowcreated.

  SQL>insertintotest1values(2);

  1rowcreated.

  SQL>selectfromtest1;

  INT

  ----------

  1

  2

  SQL>selectgroup#,status,membersfromv$log;

  GROUP#STATUSMEMBERS

  ------------------------------------

  1CURRENT1

  2UNUSED1

  3INACTIVE1

  SQL>exit--注意,这里执行exit会触发隐式提交,也就是说,insert的语句已经从buffer中写入了redo01.log中

  DisconnectedfromOracleDatabase10gEnterpriseEditionRelease10.2.0.1.0-Production

  WiththePartitioning,OLAPandDataMiningoptions

  [oracle@ora10gfd]$cd/u01/app/oracle/oradata

  [oracle@ora10goradata]$cdora10g

  [oracle@ora10gora10g]$ll

  total1068440

  -rw-r-----1oracleoinstall7061504Aug2516:01control01.ctl

  -rw-r-----1oracleoinstall7061504Aug2516:01control02.ctl

  -rw-r-----1oracleoinstall7061504Aug2516:01control03.ctl

  -rw-r-----1oracleoinstall104865792Aug2515:52example01.dbf

  -rw-r-----1oracleoinstall52429312Aug2516:01redo01.log

  -rw-r-----1oracleoinstall52429312Aug2515:52redo02.log

  -rw-r-----1oracleoinstall52429312Aug2515:52redo03.log

  -rw-r-----1oracleoinstall251666432Aug2516:01sysaux01.dbf

  -rw-r-----1oracleoinstall503324672Aug2515:57system01.dbf

  -rw-r-----1oracleoinstall20979712Aug2515:50temp01.dbf

  -rw-r-----1oracleoinstall31465472Aug2515:57undotbs01.dbf

  -rw-r-----1oracleoinstall5251072Aug2515:52users01.dbf

  --删除数据库文件,模拟故障

  [oracle@ora10gora10g]$rm-rf.

  [oracle@ora10gora10g]$ll

  total0

  [oracle@ora10gora10g]$ps-ef|grepora_lgwr

  oracle45661015:52?00:00:01ora_lgwr_ora10g

  oracle67842999016:02pts/200:00:00grepora_lgwr

  [oracle@ora10gora10g]$cd/proc/4566/fd

  [oracle@ora10gfd]$ll

  total0

  lr-x------1oracleoinstall64Aug2516:020->/dev/null

  lr-x------1oracleoinstall64Aug2516:021->/dev/null

  lrwx------1oracleoinstall64Aug2516:0210->/u01/app/oracle/admin/ora10g/adump/ora_4556.aud

  l-wx------1oracleoinstall64Aug2516:0211->/u01/app/oracle/product/10.2.0/db_1/cfgtoollogs/dbca/ora10g/mkplug_v3_ora10g.log

  lr-x------1oracleoinstall64Aug2516:0212->/dev/zero

  lr-x------1oracleoinstall64Aug2516:0213->/dev/zero

  lrwx------1oracleoinstall64Aug2516:0214->/u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat

  lrwx------1oracleoinstall64Aug2516:0215->/u01/app/oracle/product/10.2.0/db_1/dbs/lkORA10G

  lrwx------1oracleoinstall64Aug2516:0216->/u01/app/oracle/oradata/ora10g/control01.ctl(deleted)

  lrwx------1oracleoinstall64Aug2516:0217->/u01/app/oracle/oradata/ora10g/control02.ctl(deleted)

  lrwx------1oracleoinstall64Aug2516:0218->/u01/app/oracle/oradata/ora10g/control03.ctl(deleted)

  lrwx------1oracleoinstall64Aug2516:0219->/u01/app/oracle/oradata/ora10g/redo01.log(deleted)

  l-wx------1oracleoinstall64Aug2516:022->/u01/app/oracle/admin/ora10g/bdump/ora10g_lgwr_4566.trc

  lrwx------1oracleoinstall64Aug2516:0220->/u01/app/oracle/oradata/ora10g/redo02.log(deleted)

  lrwx------1oracleoinstall64Aug2516:0221->/u01/app/oracle/oradata/ora10g/redo03.log(deleted)

  lrwx------1oracleoinstall64Aug2516:0222->/u01/app/oracle/oradata/ora10g/system01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2516:0223->/u01/app/oracle/oradata/ora10g/undotbs01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2516:0224->/u01/app/oracle/oradata/ora10g/sysaux01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2516:0225->/u01/app/oracle/oradata/ora10g/users01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2516:0226->/u01/app/oracle/oradata/ora10g/example01.dbf(deleted)

  lrwx------1oracleoinstall64Aug2516:0227->/u01/app/oracle/oradata/ora10g/temp01.dbf(deleted)

  lr-x------1oracleoinstall64Aug2516:023->/dev/null

  lr-x------1oracleoinstall64Aug2516:024->/dev/null

  l-wx------1oracleoinstall64Aug2516:025->/u01/app/oracle/admin/ora10g/udump/ora10g_ora_4556.trc

  l-wx------1oracleoinstall64Aug2516:026->/u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log

  lrwx------1oracleoinstall64Aug2516:027->/u01/app/oracle/product/10.2.0/db_1/dbs/lkinstora10g(deleted)

  l-wx------1oracleoinstall64Aug2516:028->/u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log

  lrwx------1oracleoinstall64Aug2516:029->/u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat

  --恢复数据库文件

  [oracle@ora10gfd]$cp7/u01/app/oracle/product/10.2.0/db_1/dbs/lkinstora10g

  [oracle@ora10gfd]$cp16/u01/app/oracle/oradata/ora10g/control01.ctl

  [oracle@ora10gfd]$cp17/u01/app/oracle/oradata/ora10g/control02.ctl

  [oracle@ora10gfd]$cp18/u01/app/oracle/oradata/ora10g/control03.ctl

  [oracle@ora10gfd]$cp19/u01/app/oracle/oradata/ora10g/redo01.log

  [oracle@ora10gfd]$cp20/u01/app/oracle/oradata/ora10g/redo02.log

  [oracle@ora10gfd]$cp21/u01/app/oracle/oradata/ora10g/redo03.log

  [oracle@ora10gfd]$cp22/u01/app/oracle/oradata/ora10g/system01.dbf

  [oracle@ora10gfd]$cp23/u01/app/oracle/oradata/ora10g/undotbs01.dbf

  [oracle@ora10gfd]$cp24/u01/app/oracle/oradata/ora10g/sysaux01.dbf

  [oracle@ora10gfd]$cp25/u01/app/oracle/oradata/ora10g/users01.dbf

  [oracle@ora10gfd]$cp26/u01/app/oracle/oradata/ora10g/example01.dbf

  [oracle@ora10gfd]$cp27/u01/app/oracle/oradata/ora10g/temp01.dbf

  --恢复数据库相关文件后登陆sqlplus,进行dml操作

  [oracle@ora10gfd]$sqlplus/assysdba

  SQLPlus:Release10.2.0.1.0-ProductiononMonAug2516:10:032014

  Copyright(c)1982,2005,Oracle.Allrightsreserved.

  Connectedto:

  OracleDatabase10gEnterpriseEditionRelease10.2.0.1.0-Production

  WiththePartitioning,OLAPandDataMiningoptions

  SQL>selectcount()fromdba_objects;

  COUNT()

  ----------

  50315

  SQL>selectfromaaron8219.test1;

  INT

  ----------

  1

  2

  SQL>selectgroup#,status,membersfromv$log;

  GROUP#STATUSMEMBERS

  ------------------------------------

  1CURRENT1

  2UNUSED1

  3INACTIVE1

  当前在线日志文件和恢复前一致,是redo01.log

  SQL>archiveloglist

  DatabaselogmodeArchiveMode

  AutomaticarchivalEnabled

  ArchivedestinationUSE_DB_RECOVERY_FILE_DEST

  Oldestonlinelogsequence1

  Nextlogsequencetoarchive2

  Currentlogsequence2

  SQL>altersystemswitchlogfile;

  Systemaltered.

  SQL>archiveloglist

  ORA-03113:end-of-fileoncommunicationchannel

  切换一次日志后,实例被终止,可以从alert.log中看到:

  [root@ora10goradata]#tailf/u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log

  ...

  MonAug2516:13:052014

  Thread1advancedtologsequence3

  Currentlog#2seq#3mem#0:/u01/app/oracle/oradata/ora10g/redo02.log

  MonAug2516:13:052014

  Errorsinfile/u01/app/oracle/admin/ora10g/bdump/ora10g_arc0_4586.trc:

  ORA-00322:Message322notfound;Nomessagefileforproduct=RDBMS,facility=ORA;arguments:[1][1]

  ORA-00312:Message312notfound;Nomessagefileforproduct=RDBMS,facility=ORA;arguments:[1][1][/u01/app/oracle/oradata/ora10g/redo01.log]

  MonAug2516:13:052014

  Errorsinfile/u01/app/oracle/admin/ora10g/bdump/ora10g_arc0_4586.trc:

  ORA-00322:Message322notfound;Nomessagefileforproduct=RDBMS,facility=ORA;arguments:[1][1]

  ORA-00312:Message312notfound;Nomessagefileforproduct=RDBMS,facility=ORA;arguments:[1][1][/u01/app/oracle/oradata/ora10g/redo01.log]

  MonAug2516:13:052014

  ARC0:Failedtoarchivethread1sequence2(0)

  ARCH:Archivalstopped,erroroccurred.Willcontinueretrying

  MonAug2516:13:052014

  ORACLEInstanceora10g-ArchivalError

  MonAug2516:13:052014

  ORA-16038:Message16038notfound;Nomessagefileforproduct=RDBMS,facility=ORA;arguments:[1][2]

  ORA-00312:Message312notfound;Nomessagefileforproduct=RDBMS,facility=ORA;arguments:[1][1][/u01/app/oracle/oradata/ora10g/redo01.log]

  MonAug2516:13:052014

  Errorsinfile/u01/app/oracle/admin/ora10g/bdump/ora10g_arc0_4586.trc:

  ORA-16038:Message16038notfound;Nomessagefileforproduct=RDBMS,facility=ORA;arguments:[1][2]

  ORA-00312:Message312notfound;Nomessagefileforproduct=RDBMS,facility=ORA;arguments:[1][1][/u01/app/oracle/oradata/ora10g/redo01.log]

  MonAug2516:13:082014

  ATTENTION:

  ThecontrolfileheaderblockreturnedbytheOS

  hasasequencenumberthatistooold.

  Thecontrolfilemightbecorrupted.

  PLEASEDONOTATTEMPTTOSTARTUPTHEINSTANCE

  withoutfollowingthestepsbelow.

  RE-STARTINGTHEINSTANCECANCAUSESERIOUSDAMAGE

  TOTHEDATABASE,ifthecontrolfileistrulycorrupted.

  Inordertore-starttheinstancesafely,

  pleasedothefollowing:

  (1)Saveallcopiesofthecontrolfileforlater

  analysisandcontactyourOSvendorandOraclesupport.

  (2)Mounttheinstanceandissue:

  ALTERDATABASEBACKUPCONTROLFILETOTRACE;

  (3)Unmounttheinstance.

  (4)Usethescriptinthetracefileto

  RE-CREATETHECONTROLFILEandopenthedatabase.

  InstanceterminatedbyUSER,pid=6994

  --关闭实例,重新启动

  SQL>shutdownimmediate

  ORA-24324:servicehandlenotinitialized

  ORA-01041:internalerror.hostdefextensiondoesn'texist

  SQL>exit

  DisconnectedfromOracleDatabase10gEnterpriseEditionRelease10.2.0.1.0-Production

  WiththePartitioning,OLAPandDataMiningoptions

  [oracle@ora10gfd]$sqlplus/assysdba

  SQLPlus:Release10.2.0.1.0-ProductiononMonAug2516:17:052014

  Copyright(c)1982,2005,Oracle.Allrightsreserved.

  Connectedtoanidleinstance.

  SQL>startup

  ORACLEinstancestarted.

  TotalSystemGlobalArea285212672bytes

  FixedSize1218992bytes

  VariableSize92276304bytes

  DatabaseBuffers188743680bytes

  RedoBuffers2973696bytes

  Databasemounted.

  Databaseopened.

  SQL>selectfromaaron8219.test1;

  INT

  ----------

  1

  2

  SQL>

  可以看到,这次数据并没有丢失,insert的2条数据由于exit退出SQLPLUS时触发了隐式提交,已经被写入数据文件中,而现在又通过操作系统文件句柄的方式恢复出来了,如果要避免隐式提交,可以在另一个session中对数据库文件进行删除

  总结:当我们进行Linux操作系统命令rm的时候,切忌不可随意加-rf参数,就算一定要用,也要确定再三后才能执行,否则对于数据库而言,可以说是灾难性的。这里只是测试了一下删除/u01/app/oracle/oradata/下的全部文件,试想一下,如果你当初执行的是rm-rf/u01呢?可能情况就要更加复杂一点了,恢复需要的步骤也就更多了。

  由于是在数据库open状态下直接进行了破坏性操作,对于redobuffer还来不及写入onlineredologfile的那部分操作,肯定是会丢失的,(在我的第2次测试中,并没有丢失未提交数据,是因为触发了隐式提交),因为我们通过文件句柄号恢复出来的日志文件中,并不一定包含数据库的最新变更,即便如此,对于rm-rf误操作的恢复,还是有一定意义的,至少可以在你没有任何备份的情况下,多提供了一根救命稻草来拯救你的数据库,再次强调一下,rm-rf后,千万不要着急地关闭数据库重启!!!否则就等着哭吧!!!