1. 程式人生 > >oracle啟用歸檔日誌

oracle啟用歸檔日誌

不同的 oba scope _for iat alt pre 參數 imm

1、查看歸檔信息

SQL> archive log list
Database log mode           No Archive Mode
Automatic archival           Disabled
Archive destination           USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     244
Current log sequence           246

當前數據庫未開啟歸檔

2、設置歸檔目錄

oracle默認使用閃回恢復區DB_RECOVERY_FILE_DEST作為歸檔路徑

SQL> show parameter DB_RECOVERY_FILE_DEST

NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest             string     /u01/app/oracle/flash_recovery_area
db_recovery_file_dest_size         big integer 3882M

閃回恢復區在安裝過程中有限制其大小,如果閃回恢復區滿了,歸檔日誌會無法寫入而導致數據庫hang住,解決辦法可以增加閃回區大小或者修改歸檔路徑

3、修改歸檔路徑

修改log_archive_dest_1參數可修改歸檔日誌路徑(pfile/spfile中參數db_recovery_file_dest指定的目錄將無效)

實際上從Oracle 10g開始,可以生成多份一樣的日誌,保存多個位置,以防不測。多個位置通過設置不同的log_archive_dest_n 參數實現,archive log list輸出中的Archive destination路徑只顯示最新修改的路徑。

SQL>
show parameter log_archive_dest_1 NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ log_archive_dest_1 string log_archive_dest_10 string log_archive_dest_11 string log_archive_dest_12 string log_archive_dest_13 string log_archive_dest_14 string log_archive_dest_15 string log_archive_dest_16 string log_archive_dest_17 string log_archive_dest_18 string log_archive_dest_19 string

修改歸檔路徑為/u01/app/oracle/archive_log

SQL> alter system set log_archive_dest_1=location=/u01/app/oracle/archive_log scope=spfile;

System altered.

重啟生效

4、修改歸檔日誌格式

SQL> alter system set log_archive_format=ARC%S_%R.%T_%D.dbf scope=spfile;

System altered.

重啟生效

5、開啟歸檔

需要在mount狀態下開啟數據庫歸檔

重啟至mount

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

Total System Global Area 1603411968 bytes
Fixed Size            2213776 bytes
Variable Size          989857904 bytes
Database Buffers      603979776 bytes
Redo Buffers            7360512 bytes
Database mounted.

開啟數據庫歸檔

SQL> alter database archivelog;

Database altered.

查看歸檔情況

SQL> archive log list
Database log mode           Archive Mode
Automatic archival           Enabled
Archive destination           /u01/app/oracle/archive_log
Oldest online log sequence     244
Next log sequence to archive   246
Current log sequence           246

ALTER DATABASE FORCE LOGGING;
開啟強制歸檔

打開數據庫

SQL> alter database open;

Database altered.

6、確認數據庫為歸檔模式

SQL> select log_mode from v$database;

LOG_MODE
------------
ARCHIVELOG

SQL> select archiver from v$instance;

ARCHIVE
-------
STARTED

7、強制日誌切換

先查看當前歸檔日誌視圖和歸檔日誌路徑:

SQL> select name from v$archived_log;

no rows selected
[oracle@zml-rhel6 archive_log]$ ll
total 0

沒有歸檔日誌

下面執行強制日誌切換

SQL> alter system switch logfile;

System altered.

再次查看視圖

SQL> select name from v$archived_log;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/archive_log/ARC0000000246_0963417259.0001_6833bc69.dbf

有歸檔日誌產生,驗證成功

//TODO

RMAN歸檔日誌清理

oracle啟用歸檔日誌