1. 程式人生 > >刪除redo測試丟資料情況(_allow_resetlogs_corruption)

刪除redo測試丟資料情況(_allow_resetlogs_corruption)

建立表空間

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;

刪除歸檔

[[email protected] 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'

[[email protected] ~]$ 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資料檔案沒了

[[email protected] ~]$ 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

[oracl[email protected] 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沒落盤的資訊會丟失。