1.非归档模式下,断电重新启动导致无法锁定数据文件
SYS@huiches>startup
ORACLE 例程已经启动。
Total System Global Area 159383552 bytes
Fixed Size 1295608 bytes
Variable Size 96471816 bytes
Database Buffers 54525952 bytes
Redo Buffers 7090176 bytes
数据库装载完毕。
ORA-01157: 无法标识/锁定数据文件 6 - 请参阅 DBWR 跟踪文件
ORA-01110: 数据文件 6: 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\USERS03.DBF'
2.先用控制文件把数据库启来再说
SYS@huiches>alter database backup controlfile to trace;
数据库已更改。
已用时间: 00: 00: 00.40s
SYS@huiches>shutdown immediate;
ORA-01109: 数据库未打开
已经卸载数据库。
ORACLE 例程已经关闭。
SYS@huiches>STARTUP NOMOUNT
ORACLE 例程已经启动。
Total System Global Area 159383552 bytes
Fixed Size 1295608 bytes
Variable Size 96471816 bytes
Database Buffers 54525952 bytes
Redo Buffers 7090176 bytes
SYS@huiches>CREATE CONTROLFILE REUSE DATABASE "HUICHES" RESETLOGS FORCE LOGGING NOARCHIVELOG
2 MAXLOGFILES 16
3 MAXLOGMEMBERS 3
4 MAXDATAFILES 100
5 MAXINSTANCES 8
6 MAXLOGHISTORY 2337
7 LOGFILE
8 GROUP 4 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\REDO04.LOG' SIZE 10M,
9 GROUP 5 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\REDO05.LOG' SIZE 10M,
10 GROUP 6 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\REDO06.LOG' SIZE 10M
11 -- STANDBY LOGFILE
12 DATAFILE
13 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\SYSTEM01.DBF',
14 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\UNDODATA01.DBF',
15 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\SYSAUX01.DBF',
16 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\USERS02.DBF',
17 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\INDX01.DBF',
18 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\CATALOG.DBF'
19 CHARACTER SET AL32UTF8
20 ;
控制文件已创建。
已用时间: 00: 00: 01.11
SYS@huiches>alter database open;
alter database open
*
第 1 行出现错误:
ORA-01589: ??????????? RESETLOGS ? NORESETLOGS ??
已用时间: 00: 00: 00.20
SYS@huiches>alter database open resetlogs;
数据库已更改。
已用时间: 00: 00: 17.42
3.检查到有一个文件需要恢复
SYS@huiches>select * from v$recover_file;
FILE# ONLINE ONLINE_STATUS ERROR CHANGE# TIME
---------- -------------- -------------- ----------------------------------------------------------------- ---------- --------------
6 OFFLINE OFFLINE FILE MISSING 0
已用时间: 00: 00: 00.06
4.检查到文件丢失信息
SYS@huiches>select * from dba_data_files;
FILE_NAME FILE_ID TABLESPACE_NAME BYTES BLOCKS STATUS RELATIVE_FNO AUTOEX MAXBYTES MAXBLOCKS INCREMENT_BY USER_BYTES USER_BLOCKS ON
------------------------------------------------------------ ---------- -------------------- ---------- ---------- ------------------------------------------------------------ ------------ ------ ---------- ---------- ------------ ---------- ----------- --
D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\CATALOG.DBF 8 TOOLS 20971520 2560 AVAILABLE 8 NO 0 0 0 20905984 2552 ON
D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\INDX01.DBF 5 INDX 20971520 2560 AVAILABLE 5 YES 3.4360E+10 4194302 13 20905984 2552 ON
D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\USERS02.DBF 4 USERS 528220160 64480 AVAILABLE 4 YES 3.4360E+10 4194302 160 528154624 64472 ON
D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\SYSAUX01.DBF 3 SYSAUX 325058560 39680 AVAILABLE 3 YES 3.4360E+10 4194302 1280 324993024 39672 ON
D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\UNDODATA01.DBF 2 UNDO01 104857600 12800 AVAILABLE 2 YES 3.4360E+10 4194302 128 104792064 12792 ON
D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\SYSTEM01.DBF 1 SYSTEM 912261120 111360 AVAILABLE 1 YES 3.4360E+10 4194302 1280 912195584 111352 SY
D:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\MISSING00006 6 USERS AVAILABLE 6 RE
已选择7行。
已用时间: 00: 00: 00.12
5.尝试重命名数据文件
SYS@huiches>alter database rename datafile 'D:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\MISSING00006' to 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\USERS03.DBF';
alter database rename datafile 'D:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\MISSING00006' to 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\USERS03.DBF'
*
第 1 行出现错误:
ORA-02231: ALTER DATABASE ?????????????????????
已用时间: 00: 00: 00.03
SYS@huiches>alter database rename file 'D:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\MISSING00006' to 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\USERS03.DBF';
数据库已更改。
已用时间: 00: 00: 00.15
SYS@huiches> select * from v$recover_file;
FILE# ONLINE ONLINE_STATUS ERROR CHANGE# TIME
---------- -------------- -------------- ----------------------------------------------------------------- ---------- --------------
6 OFFLINE OFFLINE UNKNOWN ERROR 166743763 08-4? -10
已用时间: 00: 00: 00.07
6.尝试把文件6上线
SYS@huiches>alter database datafile 6 online;
alter database datafile 6 online
*
第 1 行出现错误:
ORA-01190: ??????????????????????????? 6 ?????????????????? RESETLOGS ??????
ORA-01110: ???????????? 6: 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\USERS03.DBF'
已用时间: 00: 00: 00.07
SYS@huiches>alter session set nls_language='american';
Session altered.
Elapsed: 00:00:00.01
SYS@huiches>alter database datafile 6 online;
alter database datafile 6 online
*
ERROR at line 1:
ORA-01190: control file or data file 6 is from before the last RESETLOGS
ORA-01110: data file 6: 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\USERS03.DBF'
Elapsed: 00:00:00.09
7.控制文件或文件6不在同一个resetlogs版本,尝试手动调整SCN,手动调整SCN,以后必须用resetlogs模式打开数据库,所以需要设置_allow_resetlogs_corruption=true
SYS@huiches> ALTER SESSION SET EVENTS 'IMMEDIATE TRACE NAME ADJUST_SCN LEVEL 1';
Session altered.
Elapsed: 00:00:00.45
SYS@huiches> select * from v$recover_file;
FILE# ONLINE ONLINE_STATUS ERROR CHANGE# TIME
---------- -------------- -------------- ----------------------------------------------------------------- ---------- ------------
6 OFFLINE OFFLINE UNKNOWN ERROR 166743763 08-APR-10
Elapsed: 00:00:00.06
SYS@huiches>show parameter _allow_resetlogs_corruption
SYS@huiches>alter system set "_allow_resetlogs_corruption"=true scope=spfile;
System altered.
Elapsed: 00:00:00.06
SYS@huiches>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@huiches>startup mount;
ORACLE instance started.
Total System Global Area 159383552 bytes
Fixed Size 1295608 bytes
Variable Size 96471816 bytes
Database Buffers 54525952 bytes
Redo Buffers 7090176 bytes
数据库装载完毕。
SYS@huiches>recover database until cancel;
完成介质恢复。
8.完成介质恢复. 上面这一步很重要, 虽然不做这个操作也能打开数据库,但是我们是要用RESETLOGS来打开数据库,然后将数据文件状态联机:
SYS@huiches>alter database datafile 6 online;
数据库已更改。
已用时间: 00: 00: 00.09
SYS@huiches>select * from v$recover_file;
FILE# ONLINE ONLINE_STATUS ERROR CHANGE# TIME
---------- -------------- -------------- ----------------------------------------------------------------- ---------- --------------
6 ONLINE ONLINE UNKNOWN ERROR 166743763 08-4月 -10
已用时间: 00: 00: 00.14
SYS@huiches>alter database open resetlogs;
数据库已更改。
已用时间: 00: 00: 15.04
9.数据库成功启动,一切正常
SYS@huiches>select * from v$recover_file;
未选定行
已用时间: 00: 00: 00.06
SYS@huiches>select * from dba_data_files;
FILE_NAME FILE_ID TABLESPACE_NAME BYTES BLOCKS STATUS RELATIVE_FNO AUTOEX MAXBYTES MAXBLOCKS INCREMENT_BY USER_BYTES USER_BLOCKS ON
------------------------------------------------------------ ---------- -------------------- ---------- ---------- ------------------------------------------------------------ ------------ ------ ---------- ---------- ------------ ---------- ----------- --
D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\CATALOG.DBF 8 TOOLS 20971520 2560 AVAILABLE 8 NO 0 0 0 20905984 2552 ON
D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\INDX01.DBF 5 INDX 20971520 2560 AVAILABLE 5 YES 3.4360E+10 4194302 13 20905984 2552 ON
D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\USERS02.DBF 4 USERS 528220160 64480 AVAILABLE 4 YES 3.4360E+10 4194302 160 528154624 64472 ON
D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\SYSAUX01.DBF 3 SYSAUX 325058560 39680 AVAILABLE 3 YES 3.4360E+10 4194302 1280 324993024 39672 ON
D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\UNDODATA01.DBF 2 UNDO01 104857600 12800 AVAILABLE 2 YES 3.4360E+10 4194302 128 104792064 12792 ON
D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\SYSTEM01.DBF 1 SYSTEM 912261120 111360 AVAILABLE 1 YES 3.4360E+10 4194302 1280 912195584 111352 SY
D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\USERS03.DBF 6 USERS 180879360 22080 AVAILABLE 6 NO 0 0 0 180813824 22072 ON
已选择7行。
已用时间: 00: 00: 00.14
SYS@huiches>select * from dba_temp_files;
未选定行
已用时间: 00: 00: 00.09
SYS@huiches>ALTER TABLESPACE TEMP01 ADD TEMPFILE 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\HUICHES\TEMP02.DBF' REUSE;
表空间已更改。
已用时间: 00: 00: 00.34
已用时间: 00: 00: 00.04
10.reset _allow_resetlogs_corruption
SYS@huiches>alter system reset "_allow_resetlogs_corruption" scope=spfile sid='*';
系统已更改。
已用时间: 00: 00: 00.04