一、删除archivelog方法:
1、配置RMAN自动管理ARCHIVELOG。也可在RMAN中将数据备份到磁带上,然后将过期的ARCHIVELOG删除;
2、可以手工来处理,步骤如下
1)将/oracle下的相关ARCHIVELOG日志文件移到别的文件系统下(保留一段时间的ARCHIVELOG日志即可,其他的可移走,用系统命令mv移走)。然后打包、压缩,备份到介质上,此时可将这些移出的文件删除。注意:别在原来的/oracle打包了,否则空间占满了就有些麻烦了。
2)以oracle用户登录,执行rman target /。如有多个实例此时执行rman target 用户名/密码@实例名,进入rman
3)在rman中执行
RMAN>list archivelog all; /*列出所有的归档日志文件
RMAN>crosscheck archivelog all; /*与物理归档日志文件保持同步,之前移走了一部分文件,因此执行此命令后会在/oracle目录下找不到的归档日志标记为expired
RMAN>list expired archivelog all; /*列出所有expired(过期)的归档日志文件,此时你就可看到移走的归档日志文件均被标记为expired
RMAN>delete expired archivelog all; /*在oracle中删除所有过期的expired文件
RMAN>list archivelog all; /*再列出所有的归档日志文件,就可发现移走的日志文件被删掉了
RMAN>exit /*退出
注意:为确保安全,建议将移走的归档日志文件备份出来。
三、实例:
Rman Crosscheck删除失效归档当手工删除了归档日志以后,Rman备份会检测到日志缺失,从而无法进一步继续执行。 $ rman target / 2.使用delete expired archivelog all 命令删除所有过期归档日志: RMAN> delete expired archivelog all; 3.简要介绍一下report obsolete命令 使用report obsolete命令报告过期备份 RMAN> report obsolete; 4.使用delete obsolete命令删除过期备份: RMAN> delete obsolete; -The End-
四、参考文档:
今天在启动自己windowns下的oracle时,遇到如下的情况:
Microsoft Windows XP [版本 5.1.2600] (C) 版权所有 1985-2001 Microsoft Corp. D:/Documents and Settings/Administrator>sqlplus /nolog SQL*Plus: Release 10.2.0.1.0 - Production on 星期日 11月 9 20:59:04 2008 Copyright (c) 1982, 2005, Oracle. All rights reserved. SQL> connect / as sysdba 已连接。 步骤1: SQL> shutdown immediate ORA-01109: 数据库未打开 已经卸载数据库。 ORACLE 例程已经关闭。 SQL> startup mount; ORACLE 例程已经启动。 Total System Global Area 1593835520 bytes Fixed Size 1251508 bytes Variable Size 536872780 bytes Database Buffers 1048576000 bytes Redo Buffers 7135232 bytes 数据库装载完毕。 步骤2: SQL> alter database open; alter database open * 第 1 行出现错误: ORA-16038: 日志 1 序列号 74 无法归档 ORA-19809: 超出了恢复文件数的限制 ORA-00312: 联机日志 1 线程 1: 'C:/ORACLE/PRODUCT/10.2.0/ORADATA/ORCL/REDO01.LOG' 查了一下错误信息 ORA-19809: limit exceeded for recovery files Cause: The limit for recovery files specified by the DB_RECOVERY_FILE_DEST_SIZE was exceeded. Action: The error is accompanied by 19804. See message 19804 for further details. 解决方法: 方法1、 1)将归档设置到其他目录 修改alter system set log_archive_dest = 其他路径 2)转移或者删除闪回恢复区里的归档日志。 方法2、 也可以使用增大闪回恢复区的方法来解决 SQL> show parameter db_recovery_file_dest_size NAME TYPE VALUE db_recovery_file_dest_size big integer 2G 下面是我的解决该问题的全部过程:(使用方法1来解决的) 首先试图只使用CLEAR LOGFILE命令来试图转移或者删除闪回恢复区里的归档日志,文档描述如下: Use the CLEAR LOGFILE clause to reinitialize an online redo log, optionally without archiving the redo log. CLEAR LOGFILE is similar to adding and dropping a redo log, except that the statement may be issued even if there are only two logs for the thread and may be issued for the current redo log of a closed thread. You must specify UNARCHIVED if you want to reuse a redo log that was not archived. 首先,执行下面的语句看看group1是不是current日志组 SQL> select group#,sequence#,archived,status from v$log; GROUP# SEQUENCE# ARC STATUS 1 74 NO INACTIVE 3 75 NO INACTIVE 2 76 NO CURRENT SQL> alter database clear logfile group 1; alter database clear logfile group 1 * 第 1 行出现错误: ORA-00350: 日志 1 (实例 orcl 的日志, 线程 1) 需要归档 ORA-00312: 联机日志 1 线程 1: 'C:/ORACLE/PRODUCT/10.2.0/ORADATA/ORCL/REDO01.LOG' 总结: 日志文件组的状态 current: 当前正在使用的工作组 inactive: 非活动组 active : 归档还没有完成 unused : 还没有使用,一般新建的工组组都是这个状态 视图使用 clear unarchived logfile,使用UNARCHIVED会在重做日志不再需要归档的情况下可以定义UNARCHIVED。 SQL> alter database clear unarchived logfile group 1;
|
五、附脚本
前两天备库的归档日志尚未应用,结果被脚本给压缩了,导致备库向主库再次请求归档日志时主库的归档日志也被压缩而找不到相应文件,结果报错.因以前的压缩及删除归档的脚本存在过多弊端,故重新写了一个通用版的压缩并删除归档程序.
程序要求: 主库或备库部署相同的脚本,并在磁盘上尽可能多的保留归档日志,在空间紧张时删除最早的日志,达到空间循环使用的目的.
脚本如下:
####################压缩脚本####################
#!/bin/sh
#fuction gzip archivelog
#created by qds 20100804
. /oracle9/.profile 2>/dev/null;
ORACLE_SID='para';
ARCH_HOME='/oracle9/app/oracle/product/9.2.0/dbs/arch';
ARCH_POSTFIX='arc';
cd /oracle9/maindb/dbshell;
function get_role {
sqlplus -S "/as sysdba" > ./log/get_role.txt <<EOF
set head off
set echo off
select database_role from v/$database;
exit;
EOF
db_role=`sed '/^$/d' ./log/get_role.txt`
if [ "$db_role" == "PRIMARY" ]; then
return 1;
elif [ "$db_role" == "PHYSICAL STANDBY" ]; then
return 2;
else
return 3;
fi;
}
if [ `ps -ef |grep gzip_archive.sh|wc -l` -ge 3 ]; then
echo "the process has been running";
return;
fi;
get_role;
myflag=$?;
if [ $myflag -eq 1 ]; then
echo "this database is primary database";
#find $ARCH_HOME/ -name "*.$ARCH_POSTFIX" -type f -cmin +60 -exec ls -l {} /;
#find $ARCH_HOME/ -name "*.$ARCH_POSTFIX" -type f -cmin +60 -exec gzip {} /;
ls -lt $ARCH_HOME/*.$ARCH_POSTFIX 2>/dev/null|awk '{if(NR>3) print $NF}' >./log/gzip_archive.txt
for i in `cat ./log/gzip_archive.txt`
do
echo `ls -l $i`;
gzip $i;
done;
return;
elif [ $myflag -eq 2 ]; then
echo "this database is standby database";
sqlplus -S "/as sysdba" > ./log/db_archived_log.txt <<EOF
set head off
set echo off
set feedback off
select name from v/$archived_log where applied='YES' and deleted='NO' and first_time>trunc(sysdate-90);
EOF
ls ${ARCH_HOME}/*.$ARCH_POSTFIX 1> ./log/sys_archived_log.txt 2>/dev/null
for i in `cat ./log/db_archived_log.txt`
do
for j in `cat ./log/sys_archived_log.txt`
do
if [ $i == $j ]; then
echo `ls -l $i` ;
gzip $i;
continue;
fi;
done;
done;
return;
else
echo "WARNING:this database is not the monitor type";
return;
fi;
####################删除脚本####################
#!/bin/sh
#fuction gzip and delete the archivelogs
#created by qds 20100803
ARCH_HOME='/oracle9/app/oracle/product/9.2.0/dbs/arch';
OS_TYPE=`uname`;
SPACE_LIMIT=60;
ARCH_POSTFIX='arc.gz';
DEL_ARC_DAYS=60;
DEL_ARC_INTERVAL=2;
SPACE_USED=0;
cd /oracle9/maindb/dbshell;
ARCH_ROOT=`echo "$ARCH_HOME"|awk -F / '{ print "/"$2}'`;
function get_space_used {
if [ $OS_TYPE='AIX' ]; then
SPACE_USED=`df -g |grep $ARCH_ROOT|awk '{print $4}'|sed 's/%//g'`
elif [ $OS_TYPE='Linux' ];then
SPACE_USED=`df -h |grep $ARCH_ROOT|awk '{print $5}'|sed 's/%//g'`
fi;
echo $SPACE_USED
}
if [ `ps -ef |grep del_archive.sh|wc -l` -ge 3 ]; then
echo "the process has been running";
return;
fi;
while [ "`get_space_used`" -ge $SPACE_LIMIT ]
do
#ls -lrt $ARCH_HOME/*.$ARCH_POSTFIX|awk '{if(NR<10) print $NF}'|xargs rm -f;
find $ARCH_HOME -name "*$ARCH_POSTFIX" -type f -ctime +$DEL_ARC_DAYS -exec ls -l {} /;
find $ARCH_HOME -name "*$ARCH_POSTFIX" -type f -ctime +$DEL_ARC_DAYS -exec rm {} /;
DEL_ARC_DAYS=`expr $DEL_ARC_DAYS - $DEL_ARC_INTERVAL`;
if [ $DEL_ARC_DAYS -le 1 ]; then
break;
fi;
done;
注:由于Aix5.2中不支持find的cmin查找,故注释掉,使用了ls的方式.
写该脚本时曾参考meco的http://www.easyora.net/blog/dg_scripts_list.html#comment-307脚本