數據環境: SQL select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production PL/SQL Release 11.2.0.1.0 - Production CO
數據環境:SQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production TNS for Linux: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production
什么是歸檔重做日志:An archived redo log file is a copy of one of the filled members of a redo log group. It includes the redo entries and the unique log sequence number of the identical member of the redo log group. For example, if you are multiplexing your redo log, and if group 1 contains identical member files a_log1 andb_log1, then the archiver process (ARCn) will archive one of these member files. Should a_log1 become corrupted, then ARCn can still archive the identical b_log1. The archived redo log contains a copy of every group created since you enabled archiving.歸檔重做日志:就是在歸檔模式下,對非活動重做日志進行備份。有后臺ARCn進程進行歸檔備份
[oracle@localhost orcl]$ ps -ef|grep arcoracle 3835 1 0 01:26 ? 00:00:01 ora_arc0_orcloracle 3837 1 0 01:26 ? 00:00:01 ora_arc1_orcloracle 3839 1 0 01:26 ? 00:00:01 ora_arc2_orcloracle 3841 1 0 01:26 ? 00:00:00 ora_arc3_orcl
2. 歸檔和非歸檔模式切換
模式切換需要在mount狀態才可切換
SQL> startup mount;
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 92
Next log sequence to archive 94
Current log sequence 94
歸檔模式切換到非歸檔模式:
SQL> alter database noarchivelog; Database altered.
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 92
Current log sequence 94
非歸檔模式切換到歸檔模式:
SQL> alter database archivelog;
Database altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 93
Next log sequence to archive 95
Current log sequence 95
如果非歸檔模式切換到歸檔模式,報ORA-00265: instance recovery required, cannot set ARCHIVELOG mode
SQL> alter database archivelog;
alter database archivelog
*
ERROR at line 1:
ORA-00265: instance recovery required, cannot set ARCHIVELOG mode
錯誤原因:在非歸檔模式下,直接用shutdown abort關閉數據,導致ora-00265錯誤
解決方法:把數據啟動到open狀態,然后shutdown immediate關閉數據,重新把數據庫啟動mount狀態
3. 配置歸檔進程
oracle 11g 默認歸檔進程是4
SQL> show parameter log_archive_max_processes;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_max_processes integer 4
后臺進程:
[oracle@localhost ~]$ ps -ef|grep arc
oracle 9164 1 0 17:12 ? 00:00:00 ora_arc0_orcl
oracle 9166 1 1 17:12 ? 00:00:00 ora_arc1_orcl
oracle 9168 1 1 17:12 ? 00:00:00 ora_arc2_orcl
oracle 9170 1 1 17:12 ? 00:00:00 ora_arc3_orcl
修改歸檔進程數量:
例如開啟10個歸檔進程
SQL> alter system set log_archive_max_processes=10;
System altered.
SQL> show parameter log_archive_max_processes;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_max_processes integer 10
[oracle@localhost ~]$ ps -ef|grep arc
oracle 9164 1 0 17:12 ? 00:00:00 ora_arc0_orcl
oracle 9166 1 0 17:12 ? 00:00:00 ora_arc1_orcl
oracle 9168 1 0 17:12 ? 00:00:00 ora_arc2_orcl
oracle 9170 1 0 17:12 ? 00:00:00 ora_arc3_orcl
oracle 9198 1 0 17:16 ? 00:00:00 ora_arc4_orcl
oracle 9200 1 0 17:16 ? 00:00:00 ora_arc5_orcl
oracle 9202 1 0 17:16 ? 00:00:00 ora_arc6_orcl
oracle 9204 1 0 17:16 ? 00:00:00 ora_arc7_orcl
oracle 9206 1 0 17:16 ? 00:00:00 ora_arc8_orcl
oracle 9208 1 0 17:16 ? 00:00:00 ora_arc9_orcl
4 配置歸檔文件格式
默認格式:%t_%s_%r.arc
SQL> show parameter log_archive_format;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_format string %t_%s_%r.dbf
修改歸檔文件格式,修改完成以后需要重啟數據庫才會生效
SQL> alter system set log_archive_format='%t_%s_%r.arc' scope=spfile;
System altered.
log_archive_format參數說明:
(歸檔文件格式必須包含以下幾個參數:%s, %t and %r,否則啟動數據庫會報錯
SQL> startup open;
ORA-19905: log_archive_format must contain %s, %t and %r
)
%s log sequence number
%S log sequence number, zero filled
%t thread number
%T thread number, zero filled
%a activation ID
%d database ID
%r resetlogs ID that ensures unique names are constructed for the archived log files across multiple incarnations of the database
5. 修改歸檔文件目錄
歸檔日志存默認路徑:受DB_RECOVERY_FILE_DEST參數控制
SQL> select dest_id,dest_name,destination from v$archive_dest;
DEST_ID DEST_NAME DESTINATION
---------- -------------------- --------------------------------------------------
1 LOG_ARCHIVE_DEST_1 USE_DB_RECOVERY_FILE_DEST
SQL> show parameter db_recovery_file_dest;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string /home/oracle/app/oracle/flash_
recovery_area
語法:alter system set log_archive_dest_n='location=文件路徑' scope=spfile
說明:a.文件存放路徑必須本地需要用location指定,遠程需要service指定,另外重啟數據庫才會生效。
b. 初始化參數LOG_ARCHIVE_DEST_n 不能與初始化參數LOG_ARCHIVE_DEST和LOG_ARCHIVE_DUPLEX_DEST同時使用.
(oracle官方文檔說明:如果是企業,將不在推薦使用log_archive_duplex_dest參數
If you are using Oracle Enterprise Edition, this parameter is deprecated in favor of the LOG_ARCHIVE_DEST_n parameters.
If Oracle Enterprise Edition is not installed or it is installed but you have not specified any LOG_ARCHIVE_DEST_n parameters, this parameter is valid)
c.LOG_ARCHIVE_DEST_n參數
OPTIONAL:該選項是默認選項.使用該選項時,無論歸檔是否成功,都可以覆蓋重做日志. MANDATORY:強制歸檔.使用該選項時,只有在歸檔成功之后,重做日志才能被覆蓋. REOPEN:該屬性用于指定重新歸檔的時間間隔,默認值為300秒,必須跟在MANDATORY后.
SQL> alter system set log_archive_dest_1='location=/home/oracle/app/oracle' scope=spfile;
System altered
SQL> select dest_id,dest_name,destination from v$archive_dest;
DEST_ID DEST_NAME DESTINATION
---------- -------------------- --------------------------------------------------
1 LOG_ARCHIVE_DEST_1 /home/oracle/app/oracle
SQL> alter system archive log current; (手動強制歸檔)
System altered.
[oracle@localhost oracle]$ ls -ls /home/oracle/app/oracle
總計 244
208 -rw-r----- 1 oracle oinstall 207872 12-10 18:26 4bc445e1_1_102_818781763.arc
歸檔日志已經在相應的目錄下生成
知識擴展:
ALTER SYSTEM SWITCH LOGFILE 是強制日志切換,不一定就歸檔當前的重做日志文件(若自動歸檔打開,就歸檔前的重做日志,若自動歸檔沒有打開,就不歸檔當前重做日志。)
ALTER SYSTEM ARCHIVE LOG CURRENT 是歸檔當前的重做日志文件,如果自動歸檔有沒有打開,將報ORA-00258錯誤。
alter system archive log all;--歸檔所有已填滿的聯機日志(只能在非歸檔模式下起作用,如果在歸檔模式下運行,會報ORA-00271: there are no logs that need archiving)
主要的區別在于
ALTER SYSTEM SWITCH LOGFILE 對單實例數據庫或RAC中的當前實例執行日志切換。
ALTER SYSTEM ARCHIVE LOG CURRENT 會對數據庫中的所有實例執行日志切換
設置:log_archive_duplex_dest參數
SQL> alter system set log_archive_duplex_dest='/home/oracle/app/oracle/archiveduplex' scope=spfile;
取消歸檔文件路徑
alter system set log_archive_dest_n='' scope=spfile
alter system set log_archive_duplex_dest='' scope=spfile
禁用某個歸檔日志路徑
語法:
SQL> alter system set log_archive_dest_state_2=defer;--禁用
5. 歸檔涉及到視圖
v$archive_dest:查詢歸檔所在的目錄(重要字段是:dest_id , dest_name , destination)
v$loghist:顯示日志歷史信息
v$archive_processes:歸檔進程信息
v$archived_log:顯示歸檔信息(重要字段:name, sequence#, first_change#)
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com