实验环境:OEL 5.6 oracle 11g(11.2.0.4.0)
注意:
system表空间数据文件不能在线recover,需要启动到mount状态再recover;
undo表空间数据文件可以在线recover;
用到的命令:
ps -ef |grep dbw |grep -v grep
ps -ef |grep ckpt |grep -v grep
ll /proc/7971/fd
1.恢复system表空间文件实验:
SYS@LGR> select * from v$dbfile; ---查看system数据文件的所在位置
FILE# NAME
---------- --------------------------------------------------
10 /u01/app/oracle/oradata/lgr/undotbs02.dbf
8 /u01/app/oracle/oradata/lgr/ts_idx02.dbf
7 /u01/app/oracle/oradata/lgr/ts2
6 /u01/app/oracle/oradata/lgr/ts1
4 /u01/app/oracle/oradata/lgr/users01.dbf
2 /u01/app/oracle/oradata/lgr/sysaux01.dbf
1 /u01/app/oracle/oradata/lgr/system01.dbf
[oracle@localhost ~]$ ps -ef |grep dbw |grep -v grep ---查看DBWR进程号,如果是控制文件则查看CKPT进程号
oracle 7971 1 0 Dec16 ? 00:00:01 ora_dbw0_LGR
[oracle@localhost ~]$ cd /u01/app/oracle/oradata/lgr/ ---切换到system数据文件的所在目录
[oracle@localhost lgr]$ ll
total 2399084
-rw-r----- 1 oracle oinstall 430592 Dec 9 19:37 1_16_929983013.dbf
-rw-r----- 1 oracle oinstall 11776 Dec 9 19:45 1_17_929983013.dbf
-rw-r----- 1 oracle oinstall 1536 Dec 9 19:45 1_18_929983013.dbf
-rw-r----- 1 oracle oinstall 1024 Dec 9 19:46 1_19_929983013.dbf
-rw-r----- 1 oracle oinstall 822784 Dec 9 19:49 1_20_929983013.dbf
-rw-r----- 1 oracle oinstall 334848 Dec 9 20:00 1_21_929983013.dbf
-rw-r----- 1 oracle oinstall 88064 Dec 12 20:40 1_25_929983013.dbf
-rw-r----- 1 oracle oinstall 44032 Dec 12 20:46 1_26_929983013.dbf
-rw-r----- 1 oracle oinstall 52736 Dec 12 20:50 1_27_929983013.dbf
-rw-r----- 1 oracle oinstall 15708160 Dec 12 22:52 1_28_929983013.dbf
-rw-r----- 1 oracle oinstall 356352 Dec 12 23:09 1_29_929983013.dbf
-rw-r----- 1 oracle oinstall 182272 Dec 12 23:21 1_30_929983013.dbf
-rw-r----- 1 oracle oinstall 96256 Dec 12 23:27 1_31_929983013.dbf
-rw-r----- 1 oracle oinstall 264704 Dec 12 23:33 1_32_929983013.dbf
-rw-r----- 1 oracle oinstall 85504 Dec 12 23:43 1_33_929983013.dbf
-rw-r----- 1 oracle oinstall 30996480 Dec 16 21:50 1_34_929983013.dbf
-rw-r----- 1 oracle oinstall 9846784 Dec 17 00:37 ora_control1.ctl
-rw-r----- 1 oracle oinstall 104858112 Dec 16 21:50 redo01a.log
-rw-r----- 1 oracle oinstall 104858112 Dec 9 19:49 redo01b.log
-rw-r----- 1 oracle oinstall 104858112 Dec 17 00:35 redo02a.log
-rw-r----- 1 oracle oinstall 104858112 Dec 9 19:46 redo02b.log
-rw-r----- 1 oracle oinstall 104858112 Dec 9 11:20 redo03a.log
-rw-r----- 1 oracle oinstall 340795392 Dec 17 00:35 sysaux01.dbf
-rw-r----- 1 oracle oinstall 1073750016 Dec 17 00:25 system01.dbf
-rw-r----- 1 oracle oinstall 104865792 Dec 12 23:40 tbs.dbf
-rw-r----- 1 oracle oinstall 20979712 Dec 16 22:00 temp01.dbf
-rw-r----- 1 oracle oinstall 10493952 Dec 6 10:41 temp1
-rw-r----- 1 oracle oinstall 10493952 Dec 5 22:00 temp2
-rw-r----- 1 oracle oinstall 41951232 Dec 16 21:50 ts1
-rw-r----- 1 oracle oinstall 104865792 Dec 16 21:50 ts2
-rw-r----- 1 oracle oinstall 41951232 Dec 16 21:50 ts_idx02.dbf
-rw-r----- 1 oracle oinstall 104865792 Dec 17 00:35 undotbs02.dbf
-rw-r----- 1 oracle oinstall 52436992 Dec 16 21:50 users01.db
[oracle@localhost lgr]$ rm -f system01.dbf ---删除system数据文件
system数据文件丢失后,数据库可能不会立即觉察,仍然可以做正常操作,这只会在Linux/Unix上出现,windows中不会出现。
[oracle@localhost lgr]$ ll /proc/7971/fd
total 0
lr-x------ 1 oracle oinstall 64 Dec 17 00:47 0 -> /dev/null
l-wx------ 1 oracle oinstall 64 Dec 17 00:47 1 -> /dev/null
lrwx------ 1 oracle oinstall 64 Dec 17 00:47 10 -> /u01/app/oracle/product/11.2.0/db_1/dbs/lkLGR
lr-x------ 1 oracle oinstall 64 Dec 17 00:47 11 -> /u01/app/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb
l-wx------ 1 oracle oinstall 64 Dec 17 00:47 2 -> /dev/null
lrwx------ 1 oracle oinstall 64 Dec 17 00:47 256 -> /u01/app/oracle/oradata/lgr/ora_control1.ctl
lrwx------ 1 oracle oinstall 64 Dec 17 00:47 257 -> /u01/app/oracle/oradata/lgr/system01.dbf (deleted) ---会一直闪:Hi,I'm here!
lrwx------ 1 oracle oinstall 64 Dec 17 00:47 258 -> /u01/app/oracle/oradata/lgr/sysaux01.dbf
lrwx------ 1 oracle oinstall 64 Dec 17 00:47 259 -> /u01/app/oracle/oradata/lgr/users01.dbf
lrwx------ 1 oracle oinstall 64 Dec 17 00:47 260 -> /u01/app/oracle/oradata/lgr/ts1
lrwx------ 1 oracle oinstall 64 Dec 17 00:47 261 -> /u01/app/oracle/oradata/lgr/ts2
lrwx------ 1 oracle oinstall 64 Dec 17 00:47 262 -> /u01/app/oracle/oradata/lgr/ts_idx02.dbf
lrwx------ 1 oracle oinstall 64 Dec 17 00:47 263 -> /u01/app/oracle/oradata/lgr/undotbs02.dbf
lrwx------ 1 oracle oinstall 64 Dec 17 00:47 264 -> /u01/app/oracle/oradata/lgr/temp01.dbf
[oracle@localhost lgr]$ cp /proc/7971/fd/257 /u01/app/oracle/oradata/lgr/system01.dbf ---把文件复制到system数据文件原来的位置
SYS@LGR> shutdown immediate ---关闭数据库
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@LGR> startup
ORACLE instance started. ---重启
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 536874064 bytes
Database Buffers 289406976 bytes
Redo Buffers 6565888 bytes
Database mounted.
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/u01/app/oracle/oradata/lgr/system01.dbf' ---错误提示,system数据文件需要recovery
SYS@LGR> recover datafile 1; ---recover system数据文件
Media recovery complete.
SYS@LGR> alter database open; ---启动到open
Database altered.
2.undo数据文件的恢复和system的恢复步骤基本相同,不同之处:
拷贝完数据文件后:
①:将数据文件offline
alter database datafile 6 offline;
select file#,status,name from v$datafile;
②:恢复数据文件
recover datafile 6;
③:将数据文件online
alter database datafile 6 online;
3.如果丢失的非undo/system数据文件,则可以在线恢复,步骤如下:
①:将数据文件offline
alter database datafile 6 offline;
select file#,status,name from v$datafile;
②:恢复数据文件
recover datafile 6;
③:将数据文件online
alter database datafile 6 online;
4.控制文件的恢复和system恢复基本相同,不同之处是:
①需要用到 ps -ef |grep ckpt |grep -v grep 查ckpt的进程号;
②拷贝完数据文件后,直接停启库,不需要recovery。