日期:2014-05-16  浏览次数:20415 次

删除current redo log的恢复

? 近日测试删除current redo log的恢复,却不知引发一系列案中案,特记录如下(CentOS 6.3,Oracle 11.2.0).

SQL> select * from v$log;

??? GROUP#??? THREAD#? SEQUENCE#????? BYTES? BLOCKSIZE??? MEMBERS ARC STATUS?????????? FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------
???????? 1????????? 1???????? 22?? 52428800??????? 512????????? 1 YES INACTIVE?????????????? 1819273 08-SEP-13????? 1839279 08-SEP-13
???????? 2????????? 1???????? 23?? 52428800??????? 512????????? 1 NO? CURRENT??????????????? 1839279 08-SEP-13?? 2.8147E+14
???????? 3????????? 1???????? 21?? 52428800??????? 512????????? 1 YES INACTIVE?????????????? 1798901 08-SEP-13????? 1819273 08-SEP-13

SQL>insert into t(txt) values('aa');

SQL>commit;

-- commit后,oracle将脏数据写入到redo.log,些时未有switch logfile,故data未写入datafile和archived logfile.此时删除redo02.log,不shutdown

SQL> host rm /db/oracle/app/oracle/oradata/pvm/redo02.log;

SQL>alter system switch logfile;

-- 此时仍可switch logfile,因为switch logfile触发checkpoint,data会写入到datafile.

-- 此时继续switch logfile,而再switch到redo02.log时,因该log已删除,故

SQL>alter system switch logfile;

--会一直停在运行的状态,ctrl+c退出运行

SQL> SQL> select * from v$log;

??? GROUP#??? THREAD#? SEQUENCE#????? BYTES? BLOCKSIZE??? MEMBERS ARC STATUS?????????? FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------
???????? 1????????? 1???????? 25?? 52428800??????? 512????????? 1 NO? CURRENT??????????????? 1851152 09-SEP-13?? 2.8147E+14
???????? 2????????? 1???????? 23?? 52428800??????? 512????????? 1 NO? INACTIVE?????????????? 1839279 08-SEP-13????? 1851142 09-SEP-13
???????? 3????????? 1???????? 24?? 52428800??????? 512????????? 1 NO? ACTIVE???????????????? 1851142 09-SEP-13????? 1851152 09-SEP-13

--redo02.log status变为inactive,但ARC=no. 因为寻址不到redo02.log,故无法archived.

-- 重建redo02.log

SQL> alter database clear unarchived logfile group 2;

Database altered.
-- 以上command是会重建redolog,但必须redo log非active及current status才可.

-- 因 redo02已写datafile,故data不会丢失,重启db,验证;

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area? 422670336 bytes
Fixed Size????????????????? 1336960 bytes
Variable Size???????????? 327158144 bytes
Database Buffers?????????? 88080384 bytes
Redo Buffers??????????????? 6094848 bytes
Database mounted.
Database opened.
SQL> select * from t;

TXT??????????????????????????????????????????????? DTE
-------------------------------------------------- ---------
aa????????????????????????????????????? 07-SEP-13

SQL>

?--以上为redo log删除后,未shutdown的情况下的恢复,若强行shutdown后,恢复就比较麻烦一些

-- 以下再测试删除redo并shutdown后的恢复

-- 同样上面的操作,insert data/commit/rm redo/switch logfile ,此时?删除的redo log status为active,然后强行shutdown abort;,再重启,报错:

SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area? 422670336 bytes
Fixed Size????????????????? 1336960 bytes
Variable Size???????????? 331352448 bytes
Database Buffers?????????? 83886080 bytes
Redo Buffers??????????????? 6094848 bytes
Database mounted.
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/db/oracle/app/oracle/oradata/pvm/redo01.log'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
-- 考虑不完全恢复,并用alter database open resetlogs来重建redo log:

SQL> recover database