标签:enc 完整 prompt ash 步骤 实例 lte dbf backup
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.out
if [ -f "$RMAN_LOG_FILE" ]
then
rm -f "$RMAN_LOG_FILE"
fi
echo >> $RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
echo Script $0 >> $RMAN_LOG_FILE
echo ==== started on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
export ORACLE_BASE=/home/oracle/u01/app/oracle
export ORACLE_HOME=${ORACLE_BASE}/product/11.2.0/dbhome_1
export ORACLE_PATH=${ORACLE_HOME}/rdbms/admin
export ORACLE_SID=orcl
export PATH=${PATH}:${ORACLE_HOME}/bin::~/local/bin
ORACLE_USER=oracle
$ORACLE_HOME/bin/rman target / log $RMAN_LOG_FILE append<< all; archivelog crosscheck ?sysdate-7?; time until noprompt delete { run>
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 for a60
SQL> select NAME,SPACE_LIMIT/1024/1024/1024,SPACE_USED/1024/1024/1024,NUMBER_OF_FILES from V$RECOVERY_FILE_DEST;
NAME SPACE_LIMIT/1024/1024/1024 SPACE_USED/1024/1024/1024 NUMBER_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 for a60
SQL> select * from v$logfile;
GROUP# STATUS TYPE MEMBER IS_
---------- ------- ------- ------------------------------------------------------------ ---
3 ONLINE /home/oracle/u01/app/oracle/oradata/orcl/redo03.log NO
2 ONLINE /home/oracle/u01/app/oracle/oradata/orcl/redo02.log NO
1 ONLINE /home/oracle/u01/app/oracle/oradata/orcl/redo01.log NO
5.强制日志切换:
alter system switch logfile;
6.查询历史日志:
SQL> select * from v$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 for a100
SQL> select recid,stamp,thread#,sequence#,name from v$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.dbf
2 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/ora8i/log1a.log‘),‘/home2/oracle/oradata/ora8i/log1b.log‘) size 100M;
alter database drop logfile group 1;
10.增加与删除日志成员
alter database add logfile member ‘/home1/oracle/oradata/ora8i/log1a.log‘ to group 1,‘/home1/oracle/oradata/ora8i/log2a.log‘ to group 2;
alter database drop logfile member ‘/home1/oracle/oradata/ora8i/log1a.log‘ ;
11.日志文件移动
alter database rename file ‘/home1/oracle/oradata/ora8i/log1a.log‘ to ‘/home2/oracle/oradata/ora8i/log1a.log‘;
执行该命令之前必须保证该日志文件物理上已经移动到新目录
12.清除日志文件
alter database clear logfile ‘/home1/oracle/oradata/ora8i/log1a.log‘;
该命令不能用删除组及组成员命令删除日志时使用
标签:enc 完整 prompt ash 步骤 实例 lte dbf backup
原文地址:http://www.cnblogs.com/hellojesson/p/7182219.html