閃回與歸檔的相關測試 參考博客:http://www.cnblogs.com/hellojesson/p/7050097.htmlhtml
數據庫在歸檔模式下的管理 參考博客:http://www.cnblogs.com/hellojesson/p/7182219.html數據庫
場景描述:oracle
本地數據庫 當前運行在非歸檔模式 沒有開啓閃回功能!!!app
咱們要作的操做是將:數據庫切換在歸檔模式 ,開啓數據庫的閃回功能;測試
而且:自定義閃回恢復區路徑以及大小 自定義歸檔日誌存放路徑。spa
補充一個操做說明:其實能夠參照oracle默認的配置,將歸檔日誌存放在閃回區的指定路徑中,這裏是爲了說明,歸檔是能夠本身定義指定目錄存放的,所以下文中的操做,將歸檔日誌放在了和閃回不一樣的目錄!!!操作系統
在ORACLE10g和11g版本,ORACLE默認的日誌歸檔路徑爲閃回恢復區($ORACLE_BASE/flash_recovery_area)。對於這個路徑,ORACLE有一個限制,就是默認只有2G的空間,並且不僅是歸檔日誌的默認路徑,也是備份文件和閃回日誌的默認地址,
這樣的話歸檔日誌所使用的空間就達不到2G,在沒有設置好這個路徑大小的狀況下,不少系統都遇到過歸檔日誌滿,沒法歸檔而致使數據庫夯住的問題。雖然閃回恢復區ORACLE會自動管理,即閃回恢復區空間不足就會清理掉沒用的數據,可是若是備份策略不是很完善,數據庫很是繁忙的狀況下,仍是有可能遇到沒法歸檔致使數據庫夯住的問題,這時候一般須要修改歸檔日誌的路徑,將歸檔日誌放到其餘不受限制的路徑下來解決這個問題,這種狀況下就可經過下面操做來實現。日誌
確認當前系統環境: 沒有開啓歸檔 沒有開啓閃回code
SQL> archive log list Database log mode No Archive Mode Automatic archival Disabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 6 Current log sequence 8 SQL> select flashback_on from v$database; FLASHBACK_ON ------------------ NO
(1) 首先設置 歸檔日誌路徑 設置歸檔日誌存放格式orm
SQL> alter system set log_archive_dest_1='location=/home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch'; System altered. SQL> archive log list Database log mode No Archive Mode Automatic archival Disabled Archive destination /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch Oldest online log sequence 6 Current log sequence 8
打開歸檔模式
SQL> alter database archivelog; Database altered.
修改日誌文件命名格式:
SQL> alter system set log_archive_max_processes = 5; SQL> alter system set log_archive_format = "%t_%s_%r.dbf" scope=spfile; --- 注意: 上方的%t_%s_%r.dbf命名格式,10g以後必須包含%t %s %r不然後續會報錯!!! 出現:「ORA-19905:log_archive_format must contain %s,%t and %r」錯誤,實例將沒法啓動。 SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch Oldest online log sequence 6 Next log sequence to archive 8 Current log sequence 8
(2) 開啓閃回:
SQL> alter database flashback on; alter database flashback on * ERROR at line 1: ORA-38706: Cannot turn on FLASHBACK DATABASE logging. ORA-38709: Recovery Area is not enabled. ---若是出現上述 報錯 須要先在數據庫層面建立:閃回的路徑 並指定空間大小 (有網友說這塊必須得先設置空間大小再指定路徑,不然報錯,我這塊暫沒有遇到這種狀況,若是提示相關錯誤的話,下方的操做,就先設置閃回空間大小,再指定路徑), 另外還須要在操做系統層面建立相應的目錄; 參考下方相關操做!!!而後再回來執行上述打開閃回的命令。
(3) 而後 設置閃迴路徑 設置閃迴路徑大小 設置閃回保存策略
設置閃回區位置:
SQL> alter system set db_recovery_file_dest='/home/oracle/u01/app/oracle/flashback_area' scope=spfile;
操做系統層面建立閃回相關目錄:
[oracle@dbserver oracle]$ mkdir -p /home/oracle/u01/app/oracle/flashback_area
設置閃迴路徑大小
alter system set db_recovery_file_dest_size=30g scope=spfile;
設置閃回目標爲5天,以分鐘爲單位,oracle默認1440分鐘,即一天)
SQL> alter system set db_flashback_retention_target=7200 scope=spfile; SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch Oldest online log sequence 6 Next log sequence to archive 8 Current log sequence 8 SQL> select open_mode,flashback_on from v$database; OPEN_MODE FLASHBACK_ON -------------------- ------------------ MOUNTED YES
(4) 重啓數據庫
查看相關配置是否生效
SQL> select open_mode,flashback_on from v$database; OPEN_MODE FLASHBACK_ON -------------------- ------------------ MOUNTED YES SQL> alter database open; SQL> shutdown immediate SQL> startup SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch Oldest online log sequence 6 Next log sequence to archive 8 Current log sequence 8 SQL> select open_mode,flashback_on from v$database; OPEN_MODE FLASHBACK_ON -------------------- ------------------ READ WRITE YES
查看閃回恢復區的配置
SQL> show parameter db_recovery NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_recovery_file_dest string /home/oracle/u01/app/oracle/account_flashback_area db_recovery_file_dest_size big integer 5G
檢查flash recovery area的使用狀況,查看archivelog
SQL> set linesize 200 SQL> set pagesize 80 SQL> select * from V$FLASH_RECOVERY_AREA_USAGE; FILE_TYPE PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES -------------------- ------------------ ------------------------- --------------- CONTROL FILE 0 0 0 REDO LOG 0 0 0 ARCHIVED LOG 0 0 0 BACKUP PIECE 0 0 0 IMAGE COPY 0 0 0 FLASHBACK LOG 1.95 0 2 FOREIGN ARCHIVED LOG 0 0 0 7 rows selected.
計算flash recovery area已經佔用的空間
SQL> select sum(percent_space_used)*3/100 from v$flash_recovery_area_usage; SUM(PERCENT_SPACE_USED)*3/100 ----------------------------- .0585 SQL> select archiver from v$instance; ARCHIVE ------- STARTED SQL> select name from v$archived_log; NAME ----------------------------------------------------------------------------- /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_6_947091054.dbf
強制切換歸檔:
SQL> alter system switch logfile; System altered. SQL> select name from v$archived_log; NAME -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_6_947091054.dbf /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch_1_8_947091054.log SQL> show parameter db_recover NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_recovery_file_dest string /home/oracle/u01/app/oracle/fl ashback_area db_recovery_file_dest_size big integer 30G
補充個發現:
當選擇oracle默認的配置,將歸檔日誌存放在閃回區以後,生成的歸檔日誌,是以日期爲文件夾,而且日誌後綴名爲.arc,
而若是歸檔日誌是自定義指定的存放路徑,那麼歸檔日誌文件是以定義的日誌格式存放的,後綴名爲.bdf。
SQL> col name for a100 SQL> select recid, name, first_time from v$archived_log; RECID NAME FIRST_TIME ---------- ---------------------------------------------------------------------------------------------------- ------------------- 1 /home/oracle/u01/app/oracle/archivelog/1_6_950980202.dbf 2017-08-02 17:10:47 2 /home/oracle/u01/app/oracle/archivelog/1_7_950980202.dbf 2017-08-03 10:13:28 3 /home/oracle/u01/app/oracle/archivelog/1_8_950980202.dbf 2017-08-03 11:48:58 4 /home/oracle/u01/app/oracle/archivelog/1_9_950980202.dbf 2017-08-03 11:49:47 5 /home/oracle/u01/app/oracle/flashback_area/ORCL/archivelog/2017_08_03/o1_mf_1_10_dr5lkd29_.arc 2017-08-03 14:44:51 6 /home/oracle/u01/app/oracle/flashback_area/ORCL/archivelog/2017_08_03/o1_mf_1_11_dr5lm0og_.arc 2017-08-03 15:01:00 7 /home/oracle/u01/app/oracle/flashback_area/ORCL/archivelog/2017_08_03/o1_mf_1_12_dr5lqxsh_.arc 2017-08-03 15:01:52 8 /home/oracle/u01/app/oracle/flashback_area/ORCL/archivelog/2017_08_03/o1_mf_1_13_dr5lstob_.arc 2017-08-03 15:04:29