您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

归档日志管理

2024/3/29 0:29:26发布4次查看
数据环境: 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
1. 归档日志概念什么是归档重做日志: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指定,另外重启数据库才会生效。
配置远程归档位置时,service选项需要指定远程数据库的网络服务名(在tnsnames.ora文件中配置) 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
禁用某个归档日志路径
语法:
alter system set log_archive_dest_state_n = { enable | defer | alternate }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#)
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录