天天看點

oracle資料庫重做日志的作用,實驗說明Oracle重做日志與歸檔日志的作用

最近在學習Oracle 歸檔日志模式的管理, 特撰寫一下學習心得,不足之處還望指出!!!

-----------------------------------------------------------

一 系統環境:

1、作業系統:Windows xp sp3

2、資料庫: Oracle 10g

二 Oracle 重做日志的作用:[模拟媒體恢複]

1. 關閉資料庫歸檔模式:

SQL> shutdown immediate

資料庫已經關閉。

已經解除安裝資料庫。

ORACLE 例程已經關閉。

SQL> startup mount

ORACLE 例程已經啟動。

Total System Global Area 608174080 bytes

Fixed Size 1250404 bytes

Variable Size 159386524 bytes

Database Buffers 440401920 bytes

Redo Buffers 7135232 bytes

資料庫裝載完畢。

SQL> alter database noarchivelog;

資料庫已更改。

2.建立測試表空間:

create tablespace test datafile

'e:\oradata\test.ora' size 5M

AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED

default storage (initial 128K next 1M pctincrease 0);

3.建立測試使用者與測試表:

drop user test cascade;

create user test identified by test default tablespace test;

grant connect,resource to test;

conn test/test

create table a(a number);

begin

for i in 1..100000 loop

insert into a values(i);

end loop;

end;

commit;

4. 拷貝test.ora為test1.ora檔案。

5. insert into a select * from a;    --20萬條

6.關閉資料庫

shutdown immediate

7. 将檔案test1.ora與test.ora名稱互換。

8. 再次啟動資料庫

startup

oracle資料庫重做日志的作用,實驗說明Oracle重做日志與歸檔日志的作用

9. 進行媒體恢複:

oracle資料庫重做日志的作用,實驗說明Oracle重做日志與歸檔日志的作用

三 Oracle 歸檔日志作用: [模拟重做日志丢失]

1.  緊接着實驗二 第9步, 我們開啟歸檔日志:

SQL> alter database archivelog;

資料庫已更改。

SQL> alter database open;

資料庫已更改。

2. 删除a表部分資料:

SQL> conn test/test

已連接配接。

SQL> delete from a where rownum<=100000;

已删除100000行。

SQL> commit;

送出完成。

3. 做重做日志歸檔操作,并清空目前線上日志檔案:

SQL> select group#, members, archived, status from v$log;

GROUP# MEMBERS ARC STATUS

---------- ---------- --- ----------------

1 1 NO CURRENT

2 1 YES INACTIVE

3 1 YES ACTIVE

SQL> alter system switch logfile;

系統已更改。

SQL> alter system checkpoint;

系統已更改。

SQL> alter database clear logfile group 1;

資料庫已更改。

SQL> shutdown immediate

資料庫已經關閉。

已經解除安裝資料庫。

ORACLE 例程已經關閉。

SQL> startup

ORACLE 例程已經啟動。

Total System Global Area  608174080 bytes

Fixed Size                  1250404 bytes

Variable Size             176163740 bytes

Database Buffers          423624704 bytes

Redo Buffers                7135232 bytes

資料庫裝載完畢。

ORA-01113: 檔案 11 需要媒體恢複

ORA-01110: 資料檔案 11: 'E:\ORADATA\TEST.ORA'

SQL> recover database

ORA-00279: 更改 3455649 (在 11/21/2012 13:23:53 生成) 對于線程 1 是必需的

ORA-00289: 建議:

E:\FLASH_RECOVERY_AREA\ORCL\ARCHIVELOG\2012_11_21\O1_MF_1_212_%U_.ARC

ORA-00280: 更改 3455649 (用于線程 1) 在序列 #212 中

指定日志: {=suggested | filename | AUTO | CANCEL}

已應用的日志。

完成媒體恢複。

SQL> alter database open;

資料庫已更改。

4. 以test使用者登入檢視a表中資料是否還原:

SQL> select count(1) from a;

COUNT(1)

----------

100000

四  心得:

Oracle 聯機重做日志(ONLINE REDO LOG FILE)主要用于資料庫的媒體恢複,比如資料檔案的損壞。

歸檔日志(ARCHIVED LOG FILE)其實就是對線上日志的備份,畢竟線上日志空間有限而僅能儲存一定時間的重做日志資料。

歸檔日志與全庫備份檔案的結合恢複效果更好。

-------------------------

present  by  dylan.