Archived redo logfiles(归档重做日志)

因为在线重做日志的运行机制(循环使用的机制),会导致日志被覆盖,
为了保证日志不被覆盖,更长时间的保留,那么,在线重做日志切换之后,
将写满的在线重做日志,保存在另外一个存储位置,这种机制,称之为归档;

ARCn这个进程负责归档操作;

如果想要采用归档机制,那么必须将数据库置为归档模式;

如何查询当前数据库的归档模式?
SYS@orcl11g> archive log list;
Database log mode              No Archive Mode -- 数据库日志模式(非归档)
Automatic archival             Disabled  -- 自动归档
Archive destination            USE_DB_RECOVERY_FILE_DEST --归档存储位置
Oldest online log sequence     0  -- 最老的在线重做日志的序列号
Current log sequence           29 -- 当前日志序列号

SYS@orcl11g> select log_mode from v$database;

LOG_MODE
------------
NOARCHIVELOG

如何设置数据库为归档模式?

 1.一致性关闭数据库
  shutdown immediate;

 2.将数据库启动到mount状态

  startup mount;

 3.修改数据库日志模式
SYS@orcl11g> alter database archivelog;
SYS@orcl11g> alter database noarchivelog; --归档模式,转换为非归档模式
 4.打开数据库
  alter database open;

 5.查看日志模式:
SYS@orcl11g> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     0
Next log sequence to archive   29  -- 下一个要被归档的日志序列号
Current log sequence           29

归档模式的设置和管理;
 设置归档的相关参数:
 查看归档位置:
SYS@orcl11g> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST -- 默认的归档位置:闪回恢复区
Oldest online log sequence     0
Next log sequence to archive   29
Current log sequence           29
SYS@orcl11g> show parameter db_recovery_file_dest;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ----------------------------------
db_recovery_file_dest                string      /u01/app/oracle/fast_recovery_area

db_recovery_file_dest_size           big integer 4122M

可以手动修改归档位置:
SYS@orcl11g> show parameter log_archive_dest_

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_1                   string      (null)
log_archive_dest_10                  string      (null)
log_archive_dest_11                  string      (null)
log_archive_dest_12                  string      (null)

。。。。。
ORACLE11G版本,一共可以设置31个归档位置;

Oracle10g版本,一共可以设置10个归档位置

这么多的归档位置,主要是用于oracle的灾备软件:DATAGUARD

******************************
如何手动设置归档位置:

SYS@orcl11g> alter system set log_archive_dest_1='location=/u01/app/oracle/arch';

 System altered.

SYS@orcl11g> host ls /u01/app/oracle/arch

SYS@orcl11g> alter system switch logfile; 

System altered.

SYS@orcl11g> host ls /u01/app/oracle/arch
1_30_816622368.dbf

归档位置状态参数:
SYS@orcl11g> show parameter log_archive_dest_state_1;

 NAME                                 TYPE        VALUE
 ------------------------------------ ----------- ------------------------------
 log_archive_dest_state_1             string      enable

Values:
 ■ enable
 Specifies that a valid log archive destination can be used for a subsequent
 archiving operation (automatic or manual). This is the default.
 ■ defer
 Specifies that valid destination information and attributes are preserved, but the
 destination is excluded from archiving operations until re-enabled.
 ■ alternate
 Specifies that a log archive destination is not enabled but will become enabled if
 communications to another destination fail.

defer:
SYS@orcl11g> alter system set log_archive_dest_state_2=defer; 

 System altered.

SYS@orcl11g> alter system switch logfile;

 System altered.

SYS@orcl11g> host ls /u01/app/oracle/arch*
 /u01/app/oracle/arch:
 1_30_816622368.dbf  1_31_816622368.dbf  1_32_816622368.dbf

 /u01/app/oracle/arch2: 
 1_31_816622368.dbf

alternate:备胎

SYS@orcl11g> alter system set log_archive_dest_state_2=alternate;

 System altered.

SYS@orcl11g> show parameter log_archive_dest_2;

 NAME                                 TYPE        VALUE
 ------------------------------------ ----------- ------------------------------
 log_archive_dest_2                   string      location=/u01/app/oracle/arch2

SYS@orcl11g> alter system set 
  log_archive_dest_1='location=/u01/app/oracle/arch mandatory noreopen alternate=log_archive_dest_2';

 System altered.

 [root@db253 mnt]# chown root.root /u01/app/oracle/arch
 [root@db253 mnt]# ll -d /u01/app/oracle/arch
 drwxr-xr-x 2 root root 4096 Jun 17 10:49 /u01/app/oracle/arch

SYS@orcl11g> alter system switch logfile;

System altered.

SYS@orcl11g> host ls /u01/app/oracle/arch*
/u01/app/oracle/arch:
1_30_816622368.dbf  1_32_816622368.dbf
1_31_816622368.dbf  1_33_816622368.dbf

/u01/app/oracle/arch2:
1_31_816622368.dbf  1_34_816622368.dbf


log_archive_dest_n:参数的配置

 LOCATION=path_name -- location=/u01/app/oracle/arch

 MANDATORY  -- 强制的,表示这个归档位置,必须要归档成功

 REOPEN[=seconds] -- 如果某个归档路径出现问题,那么,几秒钟重试


SYS@orcl11g> alter system set log_archive_dest_3='location=/u01/app/oracle/arch3 mandatory reopen=5';

System altered.

SYS@orcl11g> alter system switch logfile;

System altered.

SYS@orcl11g> host ls /u01/app/oracle/arch*
/u01/app/oracle/arch:
1_30_816622368.dbf  1_32_816622368.dbf
1_31_816622368.dbf  1_33_816622368.dbf

/u01/app/oracle/arch2:
1_31_816622368.dbf  1_35_816622368.dbf  1_37_816622368.dbf
1_34_816622368.dbf  1_36_816622368.dbf

/u01/app/oracle/arch3:
1_37_816622368.dbf

 root#chown root.root /u01/app/oracle/arch3

 SQL> alter system switch logfile;
SYS@orcl11g> host ls /u01/app/oracle/arch*
/u01/app/oracle/arch:
1_30_816622368.dbf  1_32_816622368.dbf
1_31_816622368.dbf  1_33_816622368.dbf

/u01/app/oracle/arch2:
1_31_816622368.dbf  1_35_816622368.dbf  1_37_816622368.dbf
1_34_816622368.dbf  1_36_816622368.dbf  1_38_816622368.dbf

/u01/app/oracle/arch3:
1_37_816622368.dbf

SYS@orcl11g> select group#,sequence#,status,archived from v$log;

    GROUP#  SEQUENCE# STATUS           ARC
---------- ---------- ---------------- ---
         1         39 CURRENT          NO
         2         38 ACTIVE           NO
         3         37 ACTIVE           YES

 多次切换之后,数据库hang住;
 如果将数据库置为归档模式,但是,在线重做日志却没有被归档,那么,数据库hang住;

 重新修改mandatory,reopen属性的归档位置,数据库继续正常运行;


表示归档成功位置的最小个数:
SYS@orcl11g> show parameter min_succeed

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_min_succeed_dest         integer     1

归档进程设置参数:
SYS@orcl11g> show parameter log_archive_max_processes

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_max_processes            integer     4

[oracle@db253 ~]$ ps -ef | grep ora_ | grep arc
oracle   23330     1  0 10:29 ?        00:00:00 ora_arc0_orcl11g
oracle   23362     1  0 10:29 ?        00:00:00 ora_arc1_orcl11g
oracle   23365     1  0 10:29 ?        00:00:00 ora_arc2_orcl11g
oracle   23368     1  0 10:29 ?        00:00:00 ora_arc3_orcl11g

SYS@orcl11g> show parameter log_archive_format

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_format                   string      %t_%s_%r.dbf

归档相关的数据字典:
 v$archived_log;

SYS@orcl11g> desc v$archived_log;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 RECID                                              NUMBER
 STAMP                                              NUMBER
 NAME                                               VARCHAR2(513)
 DEST_ID                                            NUMBER
 THREAD#                                            NUMBER
 SEQUENCE#                                          NUMBER
 RESETLOGS_CHANGE#                                  NUMBER
 RESETLOGS_TIME                                     DATE
 RESETLOGS_ID                                       NUMBER
 FIRST_CHANGE#                                      NUMBER
 FIRST_TIME                                         DATE
 NEXT_CHANGE#                                       NUMBER
 NEXT_TIME                                          DATE
 BLOCKS                                             NUMBER
 BLOCK_SIZE                                         NUMBER
 CREATOR                                            VARCHAR2(7)
 REGISTRAR                                          VARCHAR2(7)
 STANDBY_DEST                                       VARCHAR2(3)
 ARCHIVED                                           VARCHAR2(3)
 APPLIED                                            VARCHAR2(9)
 DELETED                                            VARCHAR2(3)
 STATUS                                             VARCHAR2(1)
 COMPLETION_TIME                                    DATE
 DICTIONARY_BEGIN                                   VARCHAR2(3)
 DICTIONARY_END                                     VARCHAR2(3)
 END_OF_REDO                                        VARCHAR2(3)
 BACKUP_COUNT                                       NUMBER
 ARCHIVAL_THREAD#                                   NUMBER
 ACTIVATION#                                        NUMBER
 IS_RECOVERY_DEST_FILE                              VARCHAR2(3)
 COMPRESSED                                         VARCHAR2(3)
 FAL                                                VARCHAR2(3)
 END_OF_REDO_TYPE                                   VARCHAR2(10)
 BACKED_BY_VSS                                      VARCHAR2(3)

SYS@orcl11g> select sequence#,name from v$archived_log order by 1;

 SEQUENCE#   NAME
----------  --------------------------------------------------------------------------------
        29  /u01/app/oracle/fast_recovery_area/ORCL11G/archivelog/2013_06_17/o1_mf_1_29_8vwxglwq_.arc

        30  /u01/app/oracle/arch/1_30_816622368.dbf