Oracle在开启了归档模式后,会在指定的archive目录下产生很多的archivelog文件,
而且默认是不会定期清除的,时间长久了,该文件夹会占用很大的空间。
数据库开启归档模式之后,虽然可以保障数据的完整性,然而一定程度上会消耗系统性能,
另一个比较关键的地方就是,增加了维护的成本,因此需要做好管理工作,实际生产环境中有很多由于开启了日志归档,没有做好管理工作导致出现各种故障。
很多人直接在archive目录下删除文件,这样其实不能达到在Oracle CLF文件中删除文件记录的效果。
常用的管理方法,有两种:
1、配置RMAN自动管理ARCHIVELOG。也可在RMAN中将数据备份到备份服务器或者磁带上,然后将过期的ARCHIVELOG删除;
删除归档脚本:/home/oracle/backup/rman_backup/rman_script/deletearch.sh
RMAN_LOG_FILE=/home/oracle/backup/rman_backup/rman_script/deletearch.outif [-f "$RMAN_LOG_FILE"]
thenrm-f "$RMAN_LOG_FILE"
fi
echo>>$RMAN_LOG_FILE
chmod666$RMAN_LOG_FILE
echo Script $0 >>$RMAN_LOG_FILE
echo==== started on `date` ==== >>$RMAN_LOG_FILE
echo>>$RMAN_LOG_FILE
ORACLE_USER=oracle
export ORACLE_SID=ENMOEDU
export ORACLE_HOME=/u01/oracle/product/11.2.0/db_1
$ORACLE_HOME/bin/rman target / msglog $RMAN_LOG_FILE append<
run {delete noprompt archivelog until time 'sysdate-7';
crosscheck archivelogall;
}
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 /*退出
###################
有用的查询脚本:
1.查询每日归档备份大小情况:
SELECT TRUNC(FIRST_TIME) "日期", TRUNC(SUM(BLOCKS*BLOCK_SIZE)/1024/1024/1024,2) "大小(GB/DAY)" FROM V$ARCHIVED_LOG GROUP BY TRUNC(FIRST_TIME) ORDER BY 1 DESC;
2.查看归档空间占用情况:
SQL> col name fora60
SQL> select NAME,SPACE_LIMIT/1024/1024/1024,SPACE_USED/1024/1024/1024,NUMBER_OF_FILES fromV$RECOVERY_FILE_DEST;
NAME SPACE_LIMIT/1024/1024/1024 SPACE_USED/1024/1024/1024NUMBER_OF_FILES------------------------------------------------------------ -------------------------- ------------------------- ---------------
/home/oracle/u01/app/oracle/account_flashback_area 5 .09765625 2
3.查询系统使用的是哪一组日志文件:
SQL> select * from v$log;GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------- ------------ -------------------
1 1 7 52428800 512 1 YES INACTIVE 979398 2017-06-30 14:20:02 980053 2017-06-30 14:29:07
2 1 8 52428800 512 1 YES INACTIVE 980053 2017-06-30 14:29:07 990274 2017-06-30 17:38:43
3 1 9 52428800 512 1 NO CURRENT 990274 2017-06-30 17:38:43 2.8147E+14
4.查询正在使用的组所对应的日志文件:
SQL> col MEMBER fora60
SQL> select * fromv$logfile;GROUP# STATUS TYPE MEMBER IS_---------- ------- ------- ------------------------------------------------------------ ---
3 ONLINE /home/oracle/u01/app/oracle/oradata/orcl/redo03.logNO2 ONLINE /home/oracle/u01/app/oracle/oradata/orcl/redo02.logNO1 ONLINE /home/oracle/u01/app/oracle/oradata/orcl/redo01.log NO
5.强制日志切换:
alter system switch logfile;
6.查询历史日志:
SQL> select * fromv$log_history;
RECID STAMP THREAD# SEQUENCE# FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# RESETLOGS_CHANGE# RESETLOGS_TIME---------- ---------- ---------- ---------- ------------- ------------------- ------------ ----------------- -------------------
1 947091134 1 1 925702 2017-06-19 16:50:54 925918 925702 2017-06-19 16:50:54
2 947091237 1 2 925918 2017-06-19 16:52:14 930555 925702 2017-06-19 16:50:54
3 947091304 1 3 930555 2017-06-19 16:53:56 949834 925702 2017-06-19 16:50:54
4 947091545 1 4 949834 2017-06-19 16:55:03 962092 925702 2017-06-19 16:50:54
5 947092728 1 5 962092 2017-06-19 16:59:05 972833 925702 2017-06-19 16:50:54
6 948032402 1 6 972833 2017-06-19 17:18:47 979398 925702 2017-06-19 16:50:54
7 948032947 1 7 979398 2017-06-30 14:20:02 980053 925702 2017-06-19 16:50:54
8 948044323 1 8 980053 2017-06-30 14:29:07 990274 925702 2017-06-19 16:50:54
8 rows selected.
7.查询日志的归档模式:
SQL> select dbid,name,created,log_mode from v$database;
DBID NAME CREATED LOG_MODE---------- ------------------------------------------------------------ ------------------- ------------
1474871786 ORCL 2017-06-19 16:50:50 ARCHIVELOG
8.查询归档日志的信息:
SQL> col name fora100
SQL> select recid,stamp,thread#,sequence#,name fromv$archived_log;
RECID STAMP THREAD# SEQUENCE# NAME---------- ---------- ---------- ---------- ----------------------------------------------------------------------------------------------------
1 948032402 1 6 /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_6_947091054.dbf2 948032947 1 7 /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/archarchive_1_7_947091054.log
3 948044324 1 8 /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch_1_8_947091054.log
9.增加与删除日志文件组
alter database add logfile group 1 ('/home1/oracle/oradata/ora/log1a.log'),'/home2/oracle/oradata/ora/log1b.log') size 100M;alter database drop logfile group 1;
10.增加与删除日志成员
alter database add logfile member '/home1/oracle/oradata/ora/log1a.log' to group 1,'/home1/oracle/oradata/ora/log2a.log' to group 2;alter database drop logfile member '/home1/oracle/oradata/ora8i/log1a.log' ;
11.日志文件移动
alter database rename file '/home1/oracle/oradata/ora/log1a.log' to '/home2/oracle/oradata/ora/log1a.log';
执行该命令之前必须保证该日志文件物理上已经移动到新目录
12.清除日志文件
alter database clear logfile '/home1/oracle/oradata/ora/log1a.log';
该命令不能用删除组及组成员命令删除日志时使用。