在数据库运行过程中,会碰到各种各样的问题,导致数据库崩溃,例如有时候遇到数据文件会因为某些原因损坏导致数据库故障无法启动,通过os系统上vim 数据文件里面去写入字符串来模拟数据文件的损坏,然后对其进行恢复
实验之前先备份以及做好快照准备。
1.先建测试表空间以及在表空间上建立测试表
SQL>create tablespace TEST datafile '/u01/app/oracle/oradata/ORACLE11G/datafile/test01.dbf' size 50M;
SQL>create table test as select * from dba_objects;
SQL>alter table test move tablespace TEST;
SQL>select count(*) from test;
COUNT(*)
----------
86427
2.vim编辑test数据文件
vi /u01/app/oracle/oradata/ORACLE11G/datafile/test01.dbf
随便输入字符串
wq退出
3.关闭数据库实例
SQL> shutdown immediate
ORA-03113: end-of-file on communication channel
Process ID: 2974
Session ID: 140 Serial number: 59
4.启动数据库实例报错
SQL> startup
ORACLE instance started.Total System Global Area 1586708480 bytes
Fixed Size 2253624 bytes
Variable Size 939527368 bytes
Database Buffers 637534208 bytes
Redo Buffers 7393280 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 14 - see DBWR trace file
ORA-01110: data file 14:
'/u01/app/oracle/oradata/ORACLE11G/datafile/test01.dbf'
数据文件不能验证或锁定数据文件14,并且此时数据库处于mount状态
5.先将损坏数据文件设置offline,并打开数据库实例
SQL>alter database datafile '/u01/app/oracle/oradata/ORACLE11G/datafile/test01.dbf' offline;
Database altered.
SQL> alter database open;
Database altered.
6.创建同名表空间
SQL>alter database create datafile '/u01/app/oracle/oradata/ORACLE11G/datafile/test01.dbf';
Database altered.
7.恢复数据文件14
SQL> recover datafile 14;
Media recovery complete.
SQL> alter database datafile 14 online;Database altered.
8.验证数据文件恢复效果
SQL> set line 200
SQL> col FILE# for a10
SQL> col NAME for a80
SQL> col STATUS for a20
SQL> select FILE#,NAME,STATUS from v$datafile where FILE#=14;FILE# NAME STATUS
---------- -------------------------------------------------------------------------------- -------
########## /u01/app/oracle/oradata/ORACLE11G/datafile/test01.dbf ONLINESQL> select count(*) from test;
COUNT(*)
----------
86427
结束~~~