创建表空间
SQL> create tablespace test datafile '/u01/app/oracle/oradata/test/test.dbf' size 100m;
Tablespace created.
查看数据文件状态
SQL> select file_id,file_name,tablespace_name,status,ONLINE_STATUS from dba_data_files;
FILE_ID FILE_NAME TABLESPACE_NAME STATUS ONLINE_
---------- -------------------------------------------------- ------------------------------ --------- -------
4 /u01/app/oracle/oradata/test/users01.dbf USERS AVAILABLE ONLINE
3 /u01/app/oracle/oradata/test/undotbs01.dbf UNDOTBS1 AVAILABLE ONLINE
2 /u01/app/oracle/oradata/test/sysaux01.dbf SYSAUX AVAILABLE ONLINE
1 /u01/app/oracle/oradata/test/system01.dbf SYSTEM AVAILABLE SYSTEM
5 /u01/app/oracle/oradata/test/test.dbf TEST AVAILABLE ONLINE
创建用户插入数据
SQL> create user test identified by test default tablespace test;
User created.
SQL> grant dba to test;
Grant succeeded.
SQL> conn test/test
Connected.
SQL> create table test (a int);
Table created.
SQL> insert into test select rownum from dba_objects;
86259 rows created.
SQL> commit;
删除归档
[oracle@test test]$ rm -rf redo0*
强制关库
Commit complete.
SQL> shutdown abort
SQL> startup
ORACLE instance started.
Total System Global Area 1653518336 bytes
Fixed Size 2253784 bytes
Variable Size 1006636072 bytes
Database Buffers 637534208 bytes
Redo Buffers 7094272 bytes
Database mounted.
ORA-00313: open failed for members of log group 2 of thread 1
ORA-00312: online log 2 thread 1: '/u01/app/oracle/oradata/test/redo02.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
添加隐含参数
SQL> alter system set "_allow_resetlogs_corruption"=true scope=spfile;
System altered.
SQL> set linesize 120
SQL> col name for a30
SQL> col value for a20
SQL> col describ for a60
SQL> SELECT x.ksppinm NAME,y.ksppstvl VALUE,x.ksppdesc describ
2 FROM SYS.x$ksppi x,SYS.x$ksppcv y
3 WHERE x.inst_id=USERENV('Instance')
4 AND y.inst_id=USERENV('Instance')
5 AND x.indx=y.indx
6 AND x.ksppinm LIKE '%&par%'
7 /
Enter value for par: _allow_resetlogs_corruption
old 6: AND x.ksppinm LIKE '%&par%'
new 6: AND x.ksppinm LIKE '%_allow_resetlogs_corruption%'
NAME VALUE DESCRIB
------------------------------ -------------------- ------------------------------------------------------------
_allow_resetlogs_corruption TRUE allow resetlogs even if it will cause corruption
做recover
SQL> recover database until cancel;
ORA-00279: change 951706 generated at 12/05/2018 10:40:06 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/TEST/archivelog/2018_12_05/o1_mf_1_2_%u_.arc
ORA-00280: change 951706 for thread 1 is in sequence #2
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/app/oracle/oradata/test/system01.dbf'
ORA-01112: media recovery not started
开库显示test表空间的数据文件要recover
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01248: file 5 was created in the future of incomplete recovery
ORA-01110: data file 5: '/u01/app/oracle/oradata/test/test.dbf'
转存控制文件
SQL> alter database backup controlfile to trace as '/home/oracle/cf.trc';
Database altered.
offline数据文件
SQL> alter database datafile '/u01/app/oracle/oradata/test/test.dbf' offline;
Database altered.
开库
SQL> alter database open resetlogs;
Database altered.
查看转出的控制文件发现有 '/u01/app/oracle/oradata/test/test.dbf'
[oracle@test ~]$ cat cf.trc
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "TEST" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/test/redo01.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/u01/app/oracle/oradata/test/redo02.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/u01/app/oracle/oradata/test/redo03.log' SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/test/system01.dbf',
'/u01/app/oracle/oradata/test/sysaux01.dbf',
'/u01/app/oracle/oradata/test/undotbs01.dbf',
'/u01/app/oracle/oradata/test/users01.dbf',
'/u01/app/oracle/oradata/test/test.dbf'
CHARACTER SET WE8MSWIN1252
;
转储新的数控制文件
SQL> alter database backup controlfile to trace as '/home/oracle/cfnew.trc';
Database altered.
发现test数据文件没了
[oracle@test ~]$ cat cfnew.trc
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "TEST" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/test/redo01.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/u01/app/oracle/oradata/test/redo02.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/u01/app/oracle/oradata/test/redo03.log' SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/test/system01.dbf',
'/u01/app/oracle/oradata/test/sysaux01.dbf',
'/u01/app/oracle/oradata/test/undotbs01.dbf',
'/u01/app/oracle/oradata/test/users01.dbf'
CHARACTER SET WE8MSWIN1252
;
查看表空间、数据文件状态和用户都没有了
SQL> select file_id,file_name,tablespace_name,status,ONLINE_STATUS from dba_data_files;
FILE_ID FILE_NAME TABLESPACE_NAME STATUS ONLINE_
---------- -------------------------------------------------- ------------------------------ --------- -------
4 /u01/app/oracle/oradata/test/users01.dbf USERS AVAILABLE ONLINE
3 /u01/app/oracle/oradata/test/undotbs01.dbf UNDOTBS1 AVAILABLE ONLINE
2 /u01/app/oracle/oradata/test/sysaux01.dbf SYSAUX AVAILABLE ONLINE
1 /u01/app/oracle/oradata/test/system01.dbf SYSTEM AVAILABLE SYSTEM
SQL> select username from dba_users where username='TEST';
no rows selected
第二次
新建表空间用户插入数据
SQL> create tablespace test datafile '/u01/app/oracle/oradata/test/test.dbf' size 100m reuse;
Tablespace created.
SQL> create user test identified by test default tablespace test;
User created.
SQL>
SQL> grant dba to test;
Grant succeeded.
SQL> conn test/test
Connected.
SQL> create table test(a int);
Table created.
SQL> insert into test select rownum from dba_objects;
86259 rows created.
SQL> commit;
Commit complete.
做ckpt
SQL> alter system checkpoint;
System altered.
SQL> shutdown abort
ORACLE instance shut down.
删除redo
[oracle@test test]$ rm -rf redo0*
SQL> startup
ORACLE instance started.
Total System Global Area 1653518336 bytes
Fixed Size 2253784 bytes
Variable Size 1006636072 bytes
Database Buffers 637534208 bytes
Redo Buffers 7094272 bytes
Database mounted.
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/test/redo01.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
开库
SQL> alter system set "_allow_resetlogs_corruption"=true scope=spfile;
System altered.
SQL> recover database until cancel;
ORA-00279: change 954694 generated at 12/05/2018 15:22:35 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/fast_recovery_area/TEST/archivelog/2018_12_05/o1_mf_1_1_%u_.arc
ORA-00280: change 954694 for thread 1 is in sequence #1
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/app/oracle/oradata/test/system01.dbf'
ORA-01112: media recovery not started
SQL> alter database open resetlogs;
Database altered.
发现数据文件和用户都还在
SQL> select file_id,file_name,tablespace_name,status,ONLINE_STATUS from dba_data_files;
FILE_ID FILE_NAME TABLESPACE_NAME STATUS ONLINE_
---------- -------------------------------------------------- ------------------------------ --------- -------
4 /u01/app/oracle/oradata/test/users01.dbf USERS AVAILABLE ONLINE
3 /u01/app/oracle/oradata/test/undotbs01.dbf UNDOTBS1 AVAILABLE ONLINE
2 /u01/app/oracle/oradata/test/sysaux01.dbf SYSAUX AVAILABLE ONLINE
1 /u01/app/oracle/oradata/test/system01.dbf SYSTEM AVAILABLE SYSTEM
5 /u01/app/oracle/oradata/test/test.dbf TEST AVAILABLE ONLINE
SQL> select count(*) from test.test;
COUNT(*)
----------
86259
删除redo没落盘的信息会丢失。