首页 > 代码库 > rm-rf 误操作的恢复过程

rm-rf 误操作的恢复过程

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


一、登陆SQLPLUS,并启动数据库

[oracle@ora10g ~]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 25 12:37:50 2014


Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to an idle instance.


SQL> startup
ORACLE instance started.


Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              96470608 bytes
Database Buffers          184549376 bytes
Redo Buffers                2973696 bytes
Database mounted.
Database opened.


--查看实例初始化状态
SQL> select status from v$instance;


STATUS
------------
OPEN


--查看实例名
SQL> show parameter name;


NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      ora10g
db_unique_name                       string      ora10g
global_names                         boolean     FALSE
instance_name                        string      ora10g
lock_name_space                      string
log_file_name_convert                string
service_names                        string      ora10g
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options


二、模拟rm -rf误操作


[oracle@ora10g ~]$ cd  /u01/app/oracle/oradata
[oracle@ora10g oradata]$ ll
total 4
drwxr-x--- 2 oracle oinstall 4096 Aug 25 11:15 ora10g
[oracle@ora10g oradata]$ pwd
/u01/app/oracle/oradata
[oracle@ora10g oradata]$ rm -rf ora10g
[oracle@ora10g oradata]$ exit
logout


[root@ora10g ~]# su - oracle
[oracle@ora10g ~]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 25 12:43:58 2014


Copyright (c) 1982, 2005, Oracle.  All rights reserved.




Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options


SQL> select count(*) from dba_objects;
select count(*) from dba_objects
                     *
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-01116: error in opening database file 1
ORA-01110: data file 1: ‘/u01/app/oracle/oradata/ora10g/system01.dbf‘
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3




SQL> select count(*) from dba_segments;
select count(*) from dba_segments
                     *
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-01116: error in opening database file 1
ORA-01110: data file 1: ‘/u01/app/oracle/oradata/ora10g/system01.dbf‘
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3


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


--查看alert.log日志文件
[root@ora10g ~]# tailf /u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log 
ARCH shutting down
ARC2: Archival stopped
Mon Aug 25 12:45:38 2014
Errors in file /u01/app/oracle/admin/ora10g/bdump/ora10g_j000_3037.trc:
ORA-12012: error on auto execute of job 1
ORA-01116: error in opening database file 2
ORA-01110: data file 2: ‘/u01/app/oracle/oradata/ora10g/undotbs01.dbf
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
Mon Aug 25 12:46:43 2014
Errors in file /u01/app/oracle/admin/ora10g/bdump/ora10g_j000_3070.trc:
ORA-12012: error on auto execute of job 1
ORA-01116: error in opening database file 2
ORA-01110: data file 2: ‘/u01/app/oracle/oradata/ora10g/undotbs01.dbf
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3


--查看dbwr进程,判断需要恢复文件句柄所在目录
SQL> !ps -ef|grep ora_dbw
oracle    2912     1  0 12:37 ?        00:00:00 ora_dbw0_ora10g
oracle    3078  3032  0 12:48 pts/3    00:00:00 /bin/bash -c ps -ef|grep ora_dbw
oracle    3080  3078  0 12:48 pts/3    00:00:00 grep ora_dbw


其实这个时候,所有oracle的进程都还在,都是以ora_开头的都是oracle的后台进程:
SQL> !ps -ef|grep ora_
oracle    2906     1  0 12:37 ?        00:00:00 ora_pmon_ora10g
oracle    2908     1  0 12:37 ?        00:00:00 ora_psp0_ora10g
oracle    2910     1  0 12:37 ?        00:00:00 ora_mman_ora10g
oracle    2912     1  0 12:37 ?        00:00:00 ora_dbw0_ora10g
oracle    2914     1  0 12:37 ?        00:00:00 ora_lgwr_ora10g

oracle    2916     1  0 12:37 ?        00:00:00 ora_ckpt_ora10g
oracle    2918     1  0 12:38 ?        00:00:01 ora_smon_ora10g
oracle    2920     1  0 12:38 ?        00:00:00 ora_reco_ora10g
oracle    2922     1  0 12:38 ?        00:00:00 ora_cjq0_ora10g
oracle    2924     1  0 12:38 ?        00:00:01 ora_mmon_ora10g
oracle    2926     1  0 12:38 ?        00:00:00 ora_mmnl_ora10g
oracle    2928     1  0 12:38 ?        00:00:00 ora_d000_ora10g
oracle    2930     1  0 12:38 ?        00:00:00 ora_s000_ora10g
oracle    2934     1  0 12:38 ?        00:00:00 ora_arc0_ora10g
oracle    2936     1  0 12:38 ?        00:00:00 ora_arc1_ora10g
oracle    2941     1  0 12:38 ?        00:00:00 ora_qmnc_ora10g
oracle    2943     1  0 12:38 ?        00:00:00 ora_q000_ora10g
oracle    2945     1  0 12:38 ?        00:00:00 ora_q001_ora10g
oracle    3077     1  0 12:48 ?        00:00:00 ora_j000_ora10g
oracle    3085  3032  0 12:49 pts/3    00:00:00 /bin/bash -c ps -ef|grep ora_
oracle    3087  3085  0 12:49 pts/3    00:00:00 /bin/bash -c ps -ef|grep ora_


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


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


--恢复数据文件和控制文件
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@ora10g ~]$ cd /proc/2912
[oracle@ora10g 2912]$ ll
total 0
dr-xr-xr-x 2 oracle oinstall 0 Aug 25 12:51 attr
-r-------- 1 oracle oinstall 0 Aug 25 12:51 auxv
-r--r--r-- 1 oracle oinstall 0 Aug 25 12:48 cmdline
-rw-r--r-- 1 oracle oinstall 0 Aug 25 12:51 coredump_filter
-r--r--r-- 1 oracle oinstall 0 Aug 25 12:51 cpuset
lrwxrwxrwx 1 oracle oinstall 0 Aug 25 12:51 cwd -> /u01/app/oracle/product/10.2.0/db_1/dbs
-r-------- 1 oracle oinstall 0 Aug 25 12:51 environ
lrwxrwxrwx 1 oracle oinstall 0 Aug 25 12:51 exe -> /u01/app/oracle/product/10.2.0/db_1/bin/oracle
dr-x------ 2 oracle oinstall 0 Aug 25 12:51 fd
-r-------- 1 oracle oinstall 0 Aug 25 12:51 limits
-rw-r--r-- 1 oracle oinstall 0 Aug 25 12:51 loginuid
-r--r--r-- 1 oracle oinstall 0 Aug 25 12:37 maps
-rw------- 1 oracle oinstall 0 Aug 25 12:51 mem
-r--r--r-- 1 oracle oinstall 0 Aug 25 12:51 mounts
-r-------- 1 oracle oinstall 0 Aug 25 12:51 mountstats
-rw-r--r-- 1 oracle oinstall 0 Aug 25 12:51 oom_adj
-r--r--r-- 1 oracle oinstall 0 Aug 25 12:51 oom_score
lrwxrwxrwx 1 oracle oinstall 0 Aug 25 12:51 root -> /
-r--r--r-- 1 oracle oinstall 0 Aug 25 12:51 schedstat
-r-------- 1 oracle oinstall 0 Aug 25 12:51 smaps
-r--r--r-- 1 oracle oinstall 0 Aug 25 12:37 stat
-r--r--r-- 1 oracle oinstall 0 Aug 25 12:51 statm
-r--r--r-- 1 oracle oinstall 0 Aug 25 12:48 status
dr-xr-xr-x 3 oracle oinstall 0 Aug 25 12:51 task
-r--r--r-- 1 oracle oinstall 0 Aug 25 12:51 wchan
[oracle@ora10g 2912]$ cd fd
[oracle@ora10g fd]$ ls -ltr
total 0
lr-x------ 1 oracle oinstall 64 Aug 25 12:51 0 -> /dev/null
l-wx------ 1 oracle oinstall 64 Aug 25 12:51 6 -> /u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log
l-wx------ 1 oracle oinstall 64 Aug 25 12:51 5 -> /u01/app/oracle/admin/ora10g/udump/ora10g_ora_2904.trc
lr-x------ 1 oracle oinstall 64 Aug 25 12:51 4 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 25 12:51 3 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 25 12:51 2 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 25 12:51 1 -> /dev/null
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 9 -> /u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat
l-wx------ 1 oracle oinstall 64 Aug 25 12:51 8 -> /u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 7 -> /u01/app/oracle/product/10.2.0/db_1/dbs/lkinstora10g (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 23 -> /u01/app/oracle/oradata/ora10g/temp01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 22 -> /u01/app/oracle/oradata/ora10g/example01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 21 -> /u01/app/oracle/oradata/ora10g/users01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 20 -> /u01/app/oracle/oradata/ora10g/sysaux01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 19 -> /u01/app/oracle/oradata/ora10g/undotbs01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 18 -> /u01/app/oracle/oradata/ora10g/system01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 17 -> /u01/app/oracle/oradata/ora10g/control03.ctl (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 16 -> /u01/app/oracle/oradata/ora10g/control02.ctl (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 15 -> /u01/app/oracle/oradata/ora10g/control01.ctl (deleted)

lrwx------ 1 oracle oinstall 64 Aug 25 12:51 14 -> /u01/app/oracle/product/10.2.0/db_1/dbs/lkORA10G
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 13 -> /u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat
lr-x------ 1 oracle oinstall 64 Aug 25 12:51 12 -> /dev/zero
lr-x------ 1 oracle oinstall 64 Aug 25 12:51 11 -> /dev/zero
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 10 -> /u01/app/oracle/admin/ora10g/adump/ora_2904.aud
[oracle@ora10g fd]$ 



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


--手动创建ora10g实例名命名的目录并cp句柄到具体路径
[oracle@ora10g fd]$ mkdir /u01/app/oracle/oradata/ora10g/
[oracle@ora10g fd]$ cp 7 /u01/app/oracle/product/10.2.0/db_1/dbs/lkinstora10g
[oracle@ora10g fd]$ cp 23 /u01/app/oracle/oradata/ora10g/temp01.dbf
[oracle@ora10g fd]$ cp 22 /u01/app/oracle/oradata/ora10g/example01.dbf
[oracle@ora10g fd]$ cp 21 /u01/app/oracle/oradata/ora10g/users01.dbf
[oracle@ora10g fd]$ cp 20 /u01/app/oracle/oradata/ora10g/sysaux01.dbf
[oracle@ora10g fd]$ cp 19 /u01/app/oracle/oradata/ora10g/undotbs01.dbf
[oracle@ora10g fd]$ cp 18 /u01/app/oracle/oradata/ora10g/system01.dbf
[oracle@ora10g fd]$ cp 17 /u01/app/oracle/oradata/ora10g/control03.ctl
[oracle@ora10g fd]$ cp 16 /u01/app/oracle/oradata/ora10g/control02.ctl

[oracle@ora10g fd]$ cp 15 /u01/app/oracle/oradata/ora10g/control01.ctl


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

[root@ora10g fd]# chown oracle.oinstall /u01/app/oracle -R

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

[root@ora10g fd]# ps -ef | grep ora_dbw
oracle    3470     1  0 13:50 ?        00:00:02 ora_dbw0_ora10g
root      4012  3825  0 15:15 pts/3    00:00:00 grep ora_dbw
[root@ora10g fd]# chown oracle.oinstall /u01/ -R
[root@ora10g fd]# cd /proc/3470
-bash: cd: /proc/3470: No such file or directory
[root@ora10g fd]# ps -ef | grep ora_dbw         
root      4026  3825  0 15:18 pts/3    00:00:00 grep ora_dbw
[root@ora10g fd]# ps -ef | grep ora_
root      4036  3825  0 15:22 pts/3    00:00:00 grep ora_
[root@ora10g fd]# 


--再次查看fd目录下得文件状态

[oracle@ora10g fd]$ ls -ltr
total 0
lr-x------ 1 oracle oinstall 64 Aug 25 12:51 0 -> /dev/null
l-wx------ 1 oracle oinstall 64 Aug 25 12:51 6 -> /u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log
l-wx------ 1 oracle oinstall 64 Aug 25 12:51 5 -> /u01/app/oracle/admin/ora10g/udump/ora10g_ora_2904.trc
lr-x------ 1 oracle oinstall 64 Aug 25 12:51 4 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 25 12:51 3 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 25 12:51 2 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 25 12:51 1 -> /dev/null
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 9 -> /u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat
l-wx------ 1 oracle oinstall 64 Aug 25 12:51 8 -> /u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 7 -> /u01/app/oracle/product/10.2.0/db_1/dbs/lkinstora10g (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 23 -> /u01/app/oracle/oradata/ora10g/temp01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 22 -> /u01/app/oracle/oradata/ora10g/example01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 21 -> /u01/app/oracle/oradata/ora10g/users01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 20 -> /u01/app/oracle/oradata/ora10g/sysaux01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 19 -> /u01/app/oracle/oradata/ora10g/undotbs01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 18 -> /u01/app/oracle/oradata/ora10g/system01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 17 -> /u01/app/oracle/oradata/ora10g/control03.ctl (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 16 -> /u01/app/oracle/oradata/ora10g/control02.ctl (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 15 -> /u01/app/oracle/oradata/ora10g/control01.ctl (deleted)

lrwx------ 1 oracle oinstall 64 Aug 25 12:51 14 -> /u01/app/oracle/product/10.2.0/db_1/dbs/lkORA10G
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 13 -> /u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat
lr-x------ 1 oracle oinstall 64 Aug 25 12:51 12 -> /dev/zero
lr-x------ 1 oracle oinstall 64 Aug 25 12:51 11 -> /dev/zero
lrwx------ 1 oracle oinstall 64 Aug 25 12:51 10 -> /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@ora10g ora10g]$ ll
total 914656
-rw-r----- 1 oracle oinstall   7061504 Aug 25 13:03 control01.ctl
-rw-r----- 1 oracle oinstall   7061504 Aug 25 13:03 control02.ctl
-rw-r----- 1 oracle oinstall   7061504 Aug 25 13:03 control03.ctl
-rw-r----- 1 oracle oinstall 104865792 Aug 25 13:00 example01.dbf
-rw-r----- 1 oracle oinstall 251666432 Aug 25 13:01 sysaux01.dbf
-rw-r----- 1 oracle oinstall 503324672 Aug 25 13:02 system01.dbf
-rw-r----- 1 oracle oinstall  20979712 Aug 25 12:59 temp01.dbf
-rw-r----- 1 oracle oinstall  31465472 Aug 25 13:01 undotbs01.dbf
-rw-r----- 1 oracle oinstall   5251072 Aug 25 13:00 users01.dbf

[oracle@ora10g ora10g]$ pwd
/u01/app/oracle/oradata/ora10g
[oracle@ora10g ora10g]$ 


--恢复在线日志文件
[oracle@ora10g fd]$ ps -ef | grep ora_lgwr
oracle    2914     1  0 12:37 ?        00:00:01 ora_lgwr_ora10g
oracle    3255  2999  0 13:09 pts/2    00:00:00 grep ora_lgwr
[oracle@ora10g fd]$ cd /proc/2914/fd
[oracle@ora10g fd]$ ls -ltr
total 0
lr-x------ 1 oracle oinstall 64 Aug 25 13:09 0 -> /dev/null
l-wx------ 1 oracle oinstall 64 Aug 25 13:09 5 -> /u01/app/oracle/admin/ora10g/udump/ora10g_ora_2904.trc
lr-x------ 1 oracle oinstall 64 Aug 25 13:09 4 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 25 13:09 3 -> /dev/null
l-wx------ 1 oracle oinstall 64 Aug 25 13:09 2 -> /u01/app/oracle/admin/ora10g/bdump/ora10g_lgwr_2914.trc
lr-x------ 1 oracle oinstall 64 Aug 25 13:09 1 -> /dev/null
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 9 -> /u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat
l-wx------ 1 oracle oinstall 64 Aug 25 13:09 8 -> /u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 7 -> /u01/app/oracle/product/10.2.0/db_1/dbs/lkinstora10g (deleted)
l-wx------ 1 oracle oinstall 64 Aug 25 13:09 6 -> /u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 26 -> /u01/app/oracle/oradata/ora10g/temp01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 25 -> /u01/app/oracle/oradata/ora10g/example01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 24 -> /u01/app/oracle/oradata/ora10g/users01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 23 -> /u01/app/oracle/oradata/ora10g/sysaux01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 22 -> /u01/app/oracle/oradata/ora10g/undotbs01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 21 -> /u01/app/oracle/oradata/ora10g/system01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 20 -> /u01/app/oracle/oradata/ora10g/redo03.log (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 19 -> /u01/app/oracle/oradata/ora10g/redo02.log (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 18 -> /u01/app/oracle/oradata/ora10g/redo01.log (deleted)

lrwx------ 1 oracle oinstall 64 Aug 25 13:09 17 -> /u01/app/oracle/oradata/ora10g/control03.ctl (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 16 -> /u01/app/oracle/oradata/ora10g/control02.ctl (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 15 -> /u01/app/oracle/oradata/ora10g/control01.ctl (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 14 -> /u01/app/oracle/product/10.2.0/db_1/dbs/lkORA10G
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 13 -> /u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat
lr-x------ 1 oracle oinstall 64 Aug 25 13:09 12 -> /dev/zero
lr-x------ 1 oracle oinstall 64 Aug 25 13:09 11 -> /dev/zero
lrwx------ 1 oracle oinstall 64 Aug 25 13:09 10 -> /u01/app/oracle/admin/ora10g/adump/ora_2904.aud
[oracle@ora10g fd]$ 


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


--开始恢复online redo logfile
[oracle@ora10g fd]$ cp 20 /u01/app/oracle/oradata/ora10g/redo03.log
[oracle@ora10g fd]$ cp 19 /u01/app/oracle/oradata/ora10g/redo02.log
[oracle@ora10g fd]$ cp 18 /u01/app/oracle/oradata/ora10g/redo01.log



--在另一个session中查看online redo log是否已经恢复
[oracle@ora10g ora10g]$ ll 
total 1068436
-rw-r----- 1 oracle oinstall   7061504 Aug 25 13:03 control01.ctl
-rw-r----- 1 oracle oinstall   7061504 Aug 25 13:03 control02.ctl
-rw-r----- 1 oracle oinstall   7061504 Aug 25 13:03 control03.ctl
-rw-r----- 1 oracle oinstall 104865792 Aug 25 13:00 example01.dbf
-rw-r----- 1 oracle oinstall  52429312 Aug 25 13:12 redo01.log
-rw-r----- 1 oracle oinstall  52429312 Aug 25 13:12 redo02.log
-rw-r----- 1 oracle oinstall  52429312 Aug 25 13:12 redo03.log
-rw-r----- 1 oracle oinstall 251666432 Aug 25 13:01 sysaux01.dbf
-rw-r----- 1 oracle oinstall 503324672 Aug 25 13:02 system01.dbf
-rw-r----- 1 oracle oinstall  20979712 Aug 25 12:59 temp01.dbf
-rw-r----- 1 oracle oinstall  31465472 Aug 25 13:01 undotbs01.dbf
-rw-r----- 1 oracle oinstall   5251072 Aug 25 13:00 users01.dbf
[oracle@ora10g ora10g]$ 


--重新登录数据库,进行dml操作
[oracle@ora10g fd]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 25 13:14:25 2014


Copyright (c) 1982, 2005, Oracle.  All rights reserved.




Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options


SQL> select count(*) from dba_objects;


  COUNT(*)
----------
     50314


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


SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.


Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              96470608 bytes
Database Buffers          184549376 bytes
Redo Buffers                2973696 bytes
Database mounted.
ORA-00600: internal error code, arguments: [kcratr1_lastbwr], [], [], [], [],
[], [], []



--查看alert.log
Mon Aug 25 13:19:16 2014
ALTER DATABASE   MOUNT
Mon Aug 25 13:19:20 2014
Setting recovery target incarnation to 2
Mon Aug 25 13:19:21 2014
Successful mount of redo thread 1, with mount id 4175423764
Mon Aug 25 13:19:21 2014
Database mounted in Exclusive Mode
Completed: ALTER DATABASE   MOUNT
Mon Aug 25 13:19:21 2014
ALTER DATABASE OPEN
Mon Aug 25 13:19:21 2014
Beginning crash recovery of 1 threads
Mon Aug 25 13:19:21 2014
Started redo scan
Mon Aug 25 13:19:21 2014
Errors in file /u01/app/oracle/admin/ora10g/udump/ora10g_ora_3320.trc:
ORA-00600: internal error code, arguments: [kcratr1_lastbwr], [], [], [], [], [], [], []
Mon Aug 25 13:19:22 2014
Aborting crash recovery due to error 600--终止实例恢复


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


SQL> shutdown immediate
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.


Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              96470608 bytes
Database Buffers          184549376 bytes
Redo Buffers                2973696 bytes
Database mounted.
SQL> recover database
Media recovery complete.
SQL> alter database open;


Database altered.


SQL> select count(*) from dba_objects;


  COUNT(*)
----------
     50314


SQL> 


--再次验证数据文件
SQL> !ps -ef | grep ora_
oracle    3464     1  0 13:50 ?        00:00:00 ora_pmon_ora10g
oracle    3466     1  0 13:50 ?        00:00:00 ora_psp0_ora10g
oracle    3468     1  0 13:50 ?        00:00:00 ora_mman_ora10g
oracle    3470     1  0 13:50 ?        00:00:00 ora_dbw0_ora10g
oracle    3472     1  0 13:50 ?        00:00:00 ora_lgwr_ora10g

oracle    3474     1  0 13:50 ?        00:00:01 ora_ckpt_ora10g
oracle    3476     1  0 13:50 ?        00:00:01 ora_smon_ora10g
oracle    3478     1  0 13:50 ?        00:00:00 ora_reco_ora10g
oracle    3480     1  0 13:50 ?        00:00:01 ora_cjq0_ora10g
oracle    3482     1  0 13:50 ?        00:00:01 ora_mmon_ora10g
oracle    3484     1  0 13:50 ?        00:00:00 ora_mmnl_ora10g
oracle    3486     1  0 13:50 ?        00:00:00 ora_d000_ora10g
oracle    3488     1  0 13:50 ?        00:00:00 ora_s000_ora10g
oracle    3493     1  0 13:50 ?        00:00:00 ora_arc0_ora10g
oracle    3495     1  0 13:50 ?        00:00:00 ora_arc1_ora10g
oracle    3499     1  0 13:51 ?        00:00:00 ora_qmnc_ora10g
oracle    3513     1  0 13:51 ?        00:00:00 ora_q000_ora10g
oracle    3515     1  0 13:51 ?        00:00:00 ora_q001_ora10g
oracle    3565     1  0 14:04 ?        00:00:00 ora_j000_ora10g
oracle    3568  3278  0 14:04 pts/5    00:00:00 /bin/bash -c ps -ef | grep ora_


SQL> !ls -ltr /proc/3472/fd
total 0
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 9 -> /u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat
l-wx------ 1 oracle oinstall 64 Aug 25 14:04 8 -> /u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 7 -> /u01/app/oracle/product/10.2.0/db_1/dbs/lkinstora10g (deleted)
l-wx------ 1 oracle oinstall 64 Aug 25 14:04 6 -> /u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log
l-wx------ 1 oracle oinstall 64 Aug 25 14:04 5 -> /u01/app/oracle/admin/ora10g/udump/ora10g_ora_3462.trc
lr-x------ 1 oracle oinstall 64 Aug 25 14:04 4 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 25 14:04 3 -> /dev/null
l-wx------ 1 oracle oinstall 64 Aug 25 14:04 2 -> /u01/app/oracle/admin/ora10g/bdump/ora10g_lgwr_3472.trc
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 13 -> /u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat
lr-x------ 1 oracle oinstall 64 Aug 25 14:04 12 -> /dev/zero
lr-x------ 1 oracle oinstall 64 Aug 25 14:04 11 -> /dev/zero
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 10 -> /u01/app/oracle/admin/ora10g/adump/ora_3462.aud
lr-x------ 1 oracle oinstall 64 Aug 25 14:04 1 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 25 14:04 0 -> /dev/null
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 26 -> /u01/app/oracle/oradata/ora10g/temp01.dbf
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 25 -> /u01/app/oracle/oradata/ora10g/example01.dbf
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 24 -> /u01/app/oracle/oradata/ora10g/users01.dbf
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 23 -> /u01/app/oracle/oradata/ora10g/sysaux01.dbf
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 22 -> /u01/app/oracle/oradata/ora10g/undotbs01.dbf
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 21 -> /u01/app/oracle/oradata/ora10g/system01.dbf
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 20 -> /u01/app/oracle/oradata/ora10g/redo03.log
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 19 -> /u01/app/oracle/oradata/ora10g/redo02.log
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 18 -> /u01/app/oracle/oradata/ora10g/redo01.log
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 17 -> /u01/app/oracle/oradata/ora10g/control03.ctl
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 16 -> /u01/app/oracle/oradata/ora10g/control02.ctl
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 15 -> /u01/app/oracle/oradata/ora10g/control01.ctl
lrwx------ 1 oracle oinstall 64 Aug 25 14:04 14 -> /u01/app/oracle/product/10.2.0/db_1/dbs/lkORA10G


SQL>


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

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


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


[oracle@ora10g fd]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 25 15:57:57 2014


Copyright (c) 1982, 2005, Oracle.  All rights reserved.




Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options


SQL> select count(*) from dba_objects;



  COUNT(*)
----------
     50314


SQL> create user aaron8219 identified by oracle;


User created.


SQL> grant dba to aaron8219;


Grant succeeded.


SQL> conn aaron8219/oracle
Connected.
SQL> create table test1(int number);


Table created.


SQL> select count(*) from dba_objects;


  COUNT(*)
----------
     50315


SQL> insert into test1 values(1);


1 row created.


SQL> insert into test1 values(2);


1 row created.


SQL> select * from test1;


       INT
----------
         1
         2


SQL> select group#,status,members from v$log;


    GROUP# STATUS              MEMBERS
---------- ---------------- ----------
         1 CURRENT                   1
         2 UNUSED                    1
         3 INACTIVE                  1


SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@ora10g fd]$ cd /u01/app/oracle/oradata
[oracle@ora10g oradata]$ cd ora10g
[oracle@ora10g ora10g]$ ll
total 1068440
-rw-r----- 1 oracle oinstall   7061504 Aug 25 16:01 control01.ctl
-rw-r----- 1 oracle oinstall   7061504 Aug 25 16:01 control02.ctl
-rw-r----- 1 oracle oinstall   7061504 Aug 25 16:01 control03.ctl
-rw-r----- 1 oracle oinstall 104865792 Aug 25 15:52 example01.dbf
-rw-r----- 1 oracle oinstall  52429312 Aug 25 16:01 redo01.log
-rw-r----- 1 oracle oinstall  52429312 Aug 25 15:52 redo02.log
-rw-r----- 1 oracle oinstall  52429312 Aug 25 15:52 redo03.log
-rw-r----- 1 oracle oinstall 251666432 Aug 25 16:01 sysaux01.dbf
-rw-r----- 1 oracle oinstall 503324672 Aug 25 15:57 system01.dbf
-rw-r----- 1 oracle oinstall  20979712 Aug 25 15:50 temp01.dbf
-rw-r----- 1 oracle oinstall  31465472 Aug 25 15:57 undotbs01.dbf
-rw-r----- 1 oracle oinstall   5251072 Aug 25 15:52 users01.dbf
[oracle@ora10g ora10g]$ rm -rf *.*
[oracle@ora10g ora10g]$ ll
total 0
[oracle@ora10g ora10g]$ ps -ef | grep ora_lgwr
oracle    4566     1  0 15:52 ?        00:00:01 ora_lgwr_ora10g
oracle    6784  2999  0 16:02 pts/2    00:00:00 grep ora_lgwr
[oracle@ora10g ora10g]$ cd /proc/4566/fd
[oracle@ora10g fd]$ ll
total 0
lr-x------ 1 oracle oinstall 64 Aug 25 16:02 0 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 25 16:02 1 -> /dev/null
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 10 -> /u01/app/oracle/admin/ora10g/adump/ora_4556.aud
l-wx------ 1 oracle oinstall 64 Aug 25 16:02 11 -> /u01/app/oracle/product/10.2.0/db_1/cfgtoollogs/dbca/ora10g/mkplug_v3_ora10g.log
lr-x------ 1 oracle oinstall 64 Aug 25 16:02 12 -> /dev/zero
lr-x------ 1 oracle oinstall 64 Aug 25 16:02 13 -> /dev/zero
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 14 -> /u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 15 -> /u01/app/oracle/product/10.2.0/db_1/dbs/lkORA10G
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 16 -> /u01/app/oracle/oradata/ora10g/control01.ctl (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 17 -> /u01/app/oracle/oradata/ora10g/control02.ctl (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 18 -> /u01/app/oracle/oradata/ora10g/control03.ctl (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 19 -> /u01/app/oracle/oradata/ora10g/redo01.log (deleted)
l-wx------ 1 oracle oinstall 64 Aug 25 16:02 2 -> /u01/app/oracle/admin/ora10g/bdump/ora10g_lgwr_4566.trc
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 20 -> /u01/app/oracle/oradata/ora10g/redo02.log (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 21 -> /u01/app/oracle/oradata/ora10g/redo03.log (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 22 -> /u01/app/oracle/oradata/ora10g/system01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 23 -> /u01/app/oracle/oradata/ora10g/undotbs01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 24 -> /u01/app/oracle/oradata/ora10g/sysaux01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 25 -> /u01/app/oracle/oradata/ora10g/users01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 26 -> /u01/app/oracle/oradata/ora10g/example01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 27 -> /u01/app/oracle/oradata/ora10g/temp01.dbf (deleted)
lr-x------ 1 oracle oinstall 64 Aug 25 16:02 3 -> /dev/null
lr-x------ 1 oracle oinstall 64 Aug 25 16:02 4 -> /dev/null
l-wx------ 1 oracle oinstall 64 Aug 25 16:02 5 -> /u01/app/oracle/admin/ora10g/udump/ora10g_ora_4556.trc
l-wx------ 1 oracle oinstall 64 Aug 25 16:02 6 -> /u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 7 -> /u01/app/oracle/product/10.2.0/db_1/dbs/lkinstora10g (deleted)
l-wx------ 1 oracle oinstall 64 Aug 25 16:02 8 -> /u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log
lrwx------ 1 oracle oinstall 64 Aug 25 16:02 9 -> /u01/app/oracle/product/10.2.0/db_1/dbs/hc_ora10g.dat
[oracle@ora10g fd]$ cp 7 /u01/app/oracle/product/10.2.0/db_1/dbs/lkinstora10g
[oracle@ora10g fd]$ cp 16 /u01/app/oracle/oradata/ora10g/control01.ctl
[oracle@ora10g fd]$ cp 17 /u01/app/oracle/oradata/ora10g/control02.ctl
[oracle@ora10g fd]$ cp 18 /u01/app/oracle/oradata/ora10g/control03.ctl
[oracle@ora10g fd]$ cp 19 /u01/app/oracle/oradata/ora10g/redo01.log
[oracle@ora10g fd]$ cp 20 /u01/app/oracle/oradata/ora10g/redo02.log
[oracle@ora10g fd]$ cp 21 /u01/app/oracle/oradata/ora10g/redo03.log
[oracle@ora10g fd]$ cp 22 /u01/app/oracle/oradata/ora10g/system01.dbf
[oracle@ora10g fd]$ cp 23 /u01/app/oracle/oradata/ora10g/undotbs01.dbf
[oracle@ora10g fd]$ cp 24 /u01/app/oracle/oradata/ora10g/sysaux01.dbf
[oracle@ora10g fd]$ cp 25 /u01/app/oracle/oradata/ora10g/users01.dbf
[oracle@ora10g fd]$ cp 26 /u01/app/oracle/oradata/ora10g/example01.dbf
[oracle@ora10g fd]$ cp 27 /u01/app/oracle/oradata/ora10g/temp01.dbf


[oracle@ora10g fd]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 25 16:10:03 2014


Copyright (c) 1982, 2005, Oracle.  All rights reserved.




Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options


SQL> select count(*) from dba_objects;


  COUNT(*)
----------
     50315


SQL> select * from aaron8219.test1;


       INT
----------
         1
         2



SQL> select group#,status,members from v$log;


    GROUP# STATUS              MEMBERS
---------- ---------------- ----------
         1 CURRENT                   1
         2 UNUSED                    1
         3 INACTIVE                  1


SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     1
Next log sequence to archive   2
Current log sequence           2
SQL> alter system switch logfile;


System altered.


SQL> archive log list
ORA-03113: end-of-file on communication channel

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

[root@ora10g oradata]# tailf /u01/app/oracle/admin/ora10g/bdump/alert_ora10g.log
...
Mon Aug 25 16:13:05 2014
Thread 1 advanced to log sequence 3
  Current log# 2 seq# 3 mem# 0: /u01/app/oracle/oradata/ora10g/redo02.log
Mon Aug 25 16:13:05 2014
Errors in file /u01/app/oracle/admin/ora10g/bdump/ora10g_arc0_4586.trc:
ORA-00322: Message 322 not found; No message file for product=RDBMS, facility=ORA; arguments: [1] [1]
ORA-00312: Message 312 not found; No message file for product=RDBMS, facility=ORA; arguments: [1] [1] [/u01/app/oracle/oradata/ora10g/redo01.log]
Mon Aug 25 16:13:05 2014
Errors in file /u01/app/oracle/admin/ora10g/bdump/ora10g_arc0_4586.trc:
ORA-00322: Message 322 not found; No message file for product=RDBMS, facility=ORA; arguments: [1] [1]
ORA-00312: Message 312 not found; No message file for product=RDBMS, facility=ORA; arguments: [1] [1] [/u01/app/oracle/oradata/ora10g/redo01.log]
Mon Aug 25 16:13:05 2014
ARC0: Failed to archive thread 1 sequence 2 (0)
ARCH: Archival stopped, error occurred. Will continue retrying
Mon Aug 25 16:13:05 2014
ORACLE Instance ora10g - Archival Error
Mon Aug 25 16:13:05 2014
ORA-16038: Message 16038 not found; No message file for product=RDBMS, facility=ORA; arguments: [1] [2]
ORA-00312: Message 312 not found; No message file for product=RDBMS, facility=ORA; arguments: [1] [1] [/u01/app/oracle/oradata/ora10g/redo01.log]
Mon Aug 25 16:13:05 2014
Errors in file /u01/app/oracle/admin/ora10g/bdump/ora10g_arc0_4586.trc:
ORA-16038: Message 16038 not found; No message file for product=RDBMS, facility=ORA; arguments: [1] [2]
ORA-00312: Message 312 not found; No message file for product=RDBMS, facility=ORA; arguments: [1] [1] [/u01/app/oracle/oradata/ora10g/redo01.log]
Mon Aug 25 16:13:08 2014
********************* ATTENTION: ******************** 
 The controlfile header block returned by the OS
 has a sequence number that is too old. 
 The controlfile might be corrupted.
 PLEASE DO NOT ATTEMPT TO START UP THE INSTANCE 
 without following the steps below.
 RE-STARTING THE INSTANCE CAN CAUSE SERIOUS DAMAGE 
 TO THE DATABASE, if the controlfile is truly corrupted.
 In order to re-start the instance safely, 
 please do the following:
 (1) Save all copies of the controlfile for later 
     analysis and contact your OS vendor and Oracle support.
 (2) Mount the instance and issue: 
     ALTER DATABASE BACKUP CONTROLFILE TO TRACE;
 (3) Unmount the instance. 
 (4) Use the script in the trace file to
     RE-CREATE THE CONTROLFILE and open the database. 
*****************************************************
Instance terminated by USER, pid = 6994


--关闭实例,重新启动

SQL> shutdown immediate
ORA-24324: service handle not initialized
ORA-01041: internal error. hostdef extension doesn‘t exist
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@ora10g fd]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 25 16:17:05 2014


Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to an idle instance.


SQL> startup
ORACLE instance started.


Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              92276304 bytes
Database Buffers          188743680 bytes
Redo Buffers                2973696 bytes
Database mounted.
Database opened.
SQL> select * from aaron8219.test1;


       INT
----------
         1
         2



SQL> 

可以看到,这次未提交的数据并没有丢失,insert的2条数据已经被写入数据文件中,而且又恢复出来了

总结:


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


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



rm-rf 误操作的恢复过程