實驗環境:RHEL 5.4 + Oracle 11.2.0.3
現象:日誌切換後沒找到歸檔日誌目錄。api
開啓歸檔模式後,若是不設置歸檔目錄,能夠看到默認的歸檔路徑爲$ORACLE_HOME/dbs/arch:bash
SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch Oldest online log sequence 11 Next log sequence to archive 13 Current log sequence 13
手工切換日誌,驗證歸檔日誌可否成功歸檔:網絡
SQL> alter system switch logfile; System altered. SQL> / System altered. SQL> / System altered.
咦?!這個歸檔的目錄竟然都不存在?oracle
[oracle@edbjr2p1 oracle]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch -bash: cd: /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch: No such file or directory
退到上一層目錄下,發現歸檔是正常生成的,只不過將arch當成了命名前綴:app
[oracle@edbjr2p1 oracle]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/dbs [oracle@edbjr2p1 dbs]$ ls -lrth -rw-r----- 1 oracle oinstall 1.5M May 25 15:48 arch1_13_1008804696.dbf -rw-r----- 1 oracle oinstall 1.0K May 25 15:48 arch1_14_1008804696.dbf -rw-r----- 1 oracle oinstall 1.5K May 25 15:48 arch1_15_1008804696.dbf
下面就驗證下若是要是存在這個歸檔目錄,Oracle會怎麼處理呢?日誌
[oracle@edbjr2p1 oracle]$ mkdir /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch SQL> set lines 180 SQL> select * from v$log; GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME ---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ --------- 1 1 16 52428800 512 1 NO CURRENT 2373438 25-MAY-19 2.8147E+14 2 1 14 52428800 512 1 YES INACTIVE 2373431 25-MAY-19 2373434 25-MAY-19 3 1 15 52428800 512 1 YES INACTIVE 2373434 25-MAY-19 2373438 25-MAY-19 SQL> alter system switch logfile; System altered.
能夠看到若是實際存在這個目錄,歸檔就會正常存到這個目錄下,而不會再把它做爲前綴處理,這仍是比較符合咱們正常人的思惟的:code
[oracle@edbjr2p1 arch]$ pwd /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch [oracle@edbjr2p1 arch]$ ls -lrth total 16K -rw-r----- 1 oracle oinstall 16K May 25 15:50 1_16_1008804696.dbf
這個知識點雖然看起來有點無聊哈,不過既然遇到了,仍是要記錄下來給初學者參考。ci
實際通常咱們開啓歸檔後,都會顯示設置LOG_ARCHIVE_DEST_n參數去指定規劃的歸檔目錄。rem
n is an integer from 1 to 31. Archive destinations 1 to 10 are available for local or remote locations. Archive destinations 11 to 31 are available for remote locations only.it
而設置的具體路徑能夠是文件系統目錄、ASM磁盤組、遠端(經過網絡服務名)。具體根據實際需求來定。好比:
LOG_ARCHIVE_DEST_1 = 'LOCATION=/disk1/arc'
LOG_ARCHIVE_DEST_2 = 'LOCATION=+DGROUP1/orcl/arc_1'
LOG_ARCHIVE_DEST_3 = 'SERVICE=standby1'
LOG_ARCHIVE_DEST_n = 'LOCATION=USE_DB_RECOVERY_FILE_DEST'
The keyword USE_DB_RECOVERY_FILE_DEST to indicate the Fast Recovery Area
If you configure a Fast Recovery Area (by setting the DB_RECOVERY_FILE_DEST and DB_RECOVERY_FILE_DEST_SIZE parameters) and do not specify any local archive destinations, the database automatically selects the Fast Recovery Area as a local archive destination and sets LOG_ARCHIVE_DEST_1 to USE_DB_RECOVERY_FILE_DEST.
此外,能夠經過設置LOG_ARCHIVE_FORMAT這個參數自定義歸檔日誌的名稱(默認爲%t_%s_%r.dbf,好比可修改成arc_%t_%s_%r.dbf)
Optionally, set the LOG_ARCHIVE_FORMAT initialization parameter, using %t to include the thread number as part of the file name, %s to include the log sequence number, and %r to include the resetlogs ID (a timestamp value represented in ub4). Use capital letters (%T, %S, and %R) to pad the file name to the left with zeroes.
經過設置LOG_ARCHIVE_DEST_STATE_n參數來控制LOG_ARCHIVE_DEST_n的可用狀態:
The LOG_ARCHIVE_DEST_STATE_n (where n is an integer from 1 to 31) initialization parameter lets you control the availability state of the specified destination (n).
- ENABLE indicates that the database can use the destination.
- DEFER indicates that the location is temporarily disabled.
- ALTERNATE indicates that the destination is an alternate. The availability state of an alternate destination is DEFER. If its parent destination fails, the availability state of the alternate becomes ENABLE. ALTERNATE cannot be specified for destinations LOG_ARCHIVE_DEST_11 to LOG_ARCHIVE_DEST_31.