Oracle学习笔记:redo重做日志

redo重做日志对于oracle来说犹如 肝脏 那么重要,是oracle机能中的排毒恢复健康的重要部件!!

相关的基本概念:

  1.scn

  2.日志序列号

  3.日志组 和 日志 成员,尤其是日志文件的尺寸(影响ckpt自动发出);日志写入等待;

  4.lgwr

  5.ckpt

  6.dbwr

  7.log_buffer、fast_start_mttr_target、log_checkpoint_interval、log_checkpoit_timeout 初始化参数

基本管理

  1.切换日志:alter system switch logfile;

  2.手工发出检查点:alter sysem checkpoit;

  3.增加日志组:alter database add logfile [group n] file-spec 

  4.增加日志组成员:alter database add logfile member file-spec to group n

  5.删除日志组:alter database drop logfile group n

  6.删除日志组成员:alter database drop logfile member file-spec

  7.重新初始化日志组或日志组成员:alter database clear logfile {group n|file-spec|(file-spec,file-spec...)}

  8.查看当前的日志文件组及成员:select * from v$logfile;  select * from v$log;

  9.移动或|和重命名日志组成员文件:alter database rename file file-spec to file-spec

archivelog和noarchivelog模式

  noarchivelog模式是oracle的默认模式,相当于sqlserver恢复模型的“简单”模式,只能用于防止例程失效 和 smon的启动恢复

  noarchivelog的特点:

    1.简单,redo日志组不归档,只要要足够的size,完全不用考虑redo日志空间的占用问题

    2.备份数据库有要求:必须保证数据库的一致性,不能使用shutdown abort模式;而且必须和控制文件一并备份

    3.数据库无法还原到某个scn、time或日志序列

  archivelog模式是最重要、主要的模式,一般的情况下,我们应该采用该种模式。

  archivelog的特点:

    1.具有额外的归档进程,需要相应的归档目录和磁盘空间

    2.具有完全的数据库保护功能:只要有备份和之后的redo归档日志,可以还原到某个scn、time或日志序列

    3.管理方便:在数据库处于open状态时,可以备份、还原!!!

  archivelog和noarchivelog模式的切换:mount状态下,alter database {archivelog|noarchivelog}

  配置archivelog归档日志的位置

    默认的位置是:%oracle_home%\rdbms

    默认的文件格式为:ARC%S_%R.%T(格式符合的意思分别是:日志序列号、resetlogs的id号、arch线程号)

    可以通过修改初始化参数来自定义本地归档日志的位置:log_archive_dest、log_archive_duplex_dest

    可以通过修改初始化参数来自定义本地或远程归档日志的位置:log_archive_dest_n(1-10)。注意和上面的配置方式是互斥的!

      特别的:这种配置在设置的字符串值里需要指定是location还是service:{ LOCATION=path_name | SERVICE=service_name }

      而且还有一大堆的选项

LOG_ARCHIVE_DEST_[1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10] =
 { null_string | LOCATION=path_name | SERVICE=service_name }  --path_name可以设置成USE_DB_RECOVERY_FILE_DEST
 [ { MANDATORY | OPTIONAL } ]  --通过使用MANDATORY可以强制rts服务进程必须等待目标standby归档日志传输成功才可切换日志
 [ REOPEN[=seconds] ]  --Specifies the minimum number of seconds before the archiver processes (ARCn) or the log writer process (LGWR) should try again to access a previously failed destination. The default is 300 seconds.
 [ DELAY[=minutes] ]  --cannot set the DELAY attribute for a logical standby database destination,default is 30 minutes
 [ NOREGISTER ]
 [ TEMPLATE=template] ]
 [ ALTERNATE=destination ]  --格式LOG_ARCHIVE_DEST_n
 [ DEPENDENCY=destination ]  ----格式LOG_ARCHIVE_DEST_n
 [ MAX_FAILURE=count ]
 [ ARCH | LGWR ]
 [ SYNC | ASYNC ]  --network I/O is to be done synchronously or asynchronously when archival is performed using the log writer process (LGWR) and the network server (LNSn) processes.
 [ AFFIRM | NOAFFIRM ]  --synchronous or asynchronous disk I/O
 [ NET_TIMEOUT=seconds ]  --The default is 180 seconds.
 [ VALID_FOR=(redo_log_type,database_role) ]
 [{ DB_UNIQUE_NAME }]  --Specifies a unique name for the database at this destination.
 [ VERIFY ]  --Indicates if an archiver (ARCn) process should scan and verify the correctness of the contents of a completed archived redo log file, either local or remote, after successfully completing the archival operation. By default, archived redo log files are not verified.
 }

    与log_archive_dest_n配合的log_archive_dest_state_n用来决定归档位置的可用性:enable(可用)、defer(不可用)、alternate(候补)    

    我们可以通过log_archive_config初始化参数配置oracle是否发送、接受远程oracle服务器的事务日志,定义data guard。这个参数可能影响服务器的性能!

LOG_ARCHIVE_CONFIG =
 {
 [ SEND | NOSEND ]
 [ RECEIVE | NORECEIVE ]
 [ DG_CONFIG=(remote_db_unique_name1 [, ... remote_db_unique_name9) | NODG_CONFIG ]
 }

  查看archivelog模式的相关信息

    1.在sqlplus下: archive log list

    2.显示归档历史:select * from v$archived_log; select * from v$loghist;

    3.显示归档日志的位置:select * from v$archive_dest; 其他可以使用show parameters log_archive;    

原文地址:https://www.cnblogs.com/jinzhenshui/p/1397364.html