咦?Oracle歸檔檔案存哪了?

AlfredZhao發表於2019-05-25

實驗環境:RHEL 5.4 + Oracle 11.2.0.3
現象:日誌切換後沒找到歸檔日誌目錄。

1.檢視歸檔日誌路徑

開啟歸檔模式後,如果不設定歸檔目錄,可以看到預設的歸檔路徑為$ORACLE_HOME/dbs/arch:

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

2.日誌切換後並未找到歸檔目錄

手工切換日誌,驗證歸檔日誌能否成功歸檔:

SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> /

System altered.

咦?!這個歸檔的目錄居然都不存在?

[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當成了命名字首:

[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

3.建立歸檔目錄後再次觀察

下面就驗證下如果要是存在這個歸檔目錄,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.

可以看到如果實際存在這個目錄,歸檔就會正常存到這個目錄下,而不會再把它作為字首處理,這還是比較符合我們正常人的思維的:

[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

這個知識點雖然看起來有點無聊哈,不過既然遇到了,還是要記錄下來給初學者參考。

引申知識

實際一般我們開啟歸檔後,都會顯示設定LOG_ARCHIVE_DEST_n引數去指定規劃的歸檔目錄。

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.

而設定的具體路徑可以是檔案系統目錄、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.

相關文章