咦?Oracle歸檔文件存哪了?


實驗環境: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.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM