如何删除oracle的归档日志

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何删除oracle的归档日志相关的知识,希望对你有一定的参考价值。

su - oracle //进入oracle账户
sqlplus / as sysdba //以操作系统权限认证的oracle sys管理员登陆
archive log list //查看数据库的归档模式
注意:输入archive log list会显示出USE_DB_RECOVERY_FILE_DEST
select * from V$RECOVERY_FILE_DEST; //查询归档日志空间大小及路径
show parameter recover; //显示归档文件路径
退出到oracle账户根目录然后进入rman输入以下命令进入rman
rman target sys/password
RMAN> crosscheck archivelog all; //验证的DB的归档日志
RMAN> delete expired archivelog all; //删除所有归档日志
RMAN>DELETE ARCHIVELOG ALL COMPLETED BEFORE ‘SYSDATE-7’; //保留7天的归档日志
再查
SQL> select * from V$RECOVERY_FILE_DEST;
修改大小
SQL> alter system set db_recovery_file_dest_size=5G scope=both;
关闭归档
SQL> alter system set log_archive_start=false scope=spfile; #禁用自归档

SQL> shutdown immediate; //强制关闭数据库
SQL> startup mount; //重启数据库到mount模式
SQL> alter database noarchivelog; //修改为非归档模式
SQL> alter database open; //打数据文件
SQL> archive log list; //再次查看前归档模式
参考技术A 我们都都知道在controlfile中记录着每一个archivelog的相关信息,当然们在OS下把这些物理文件delete掉后,在我们的
controlfile中仍然记录着这些archivelog的信息,在oracle的OEM管理器中有可视化的日志展现出,当我们手工清除archive目录下的文件后,这些记录并没有被我们从controlfile中清除掉,也就是oracle并不知道这些文件已经不存在了!这时候我们要做手工的清除的话,下面我经过实验,可以尝试这种方法:

1. 进入rman
2. connect target /
3. crosscheck archivelog all;
4. delete expired archivelog all;
这时候我们再去OEM中看就一定看不到,如果你的从来没有做过这个动作的话,我们可以比较从这个动作前的controlfile后动作后的controlfile的大小!
ORACLE正确删除归档并回收空间的方法

ORACLE正确删除归档并回收空间的方法
一个ORACLE归档日志经常满,表现为/oraarchive 这个文件空间占用100%大家一定抱怨ORACLE为何没有归档维护工具,很多人直接删除了事,错了,ORACLE有,而且很智能,可以正确的删除归档和FLASHBACK,不过切记,ORACLE归档日志对于ORACLE的数据恢复和备份非常重要,不到万不得已不要删除归档日志。
删除归档日志的过程
以ORACLE用户身份登录到数据库服务器主机或通过网络连接
进入ORACLE数据备份工具
rman target/
或rman target/@orcl
在命令窗口里面执行
DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7';
说明
SYSDATA-7,表明当前的系统时间7天前,before关键字表示在7天前的归档日志,如果使用了闪回功能,也会删除闪回的数据。
同样道理,也可以删除从7天前到现在的全部日志,不过这个命令要考虑清楚,做完这个删除,最好马上进行全备份数据库
DELETE ARCHIVELOG FROM TIME 'SYSDATE-7'; 删除从7天前到现在的全部日志,慎用
UNIX/LINUX下也可以通过FIND找到7天前的归档数据,使用EXEC子操作删除
find /oraarchive -xdev -mtime +7 -name "*.dbf" -exec rm -f ;
这样做仍然会在RMAN里留下未管理的归档文件
仍需要在RMAN里执行下面2条命令
crosscheck archivelog all;
delete expired archivelog all;
所以还不如上面的方法好用,不过用FIND的好处就是,可以在条件上,和EXEC子项上做很多操作,实现更复杂的功能
3.简要介绍一下report obsolete命令
使用report obsolete命令报告过期备份
RMAN> report obsolete;
RMAN retention policy will be applied to the commandRMAN retention policy is set to redundancy 1Report of obsolete backups and copiesType Key Completion Time Filename/Handle-------------------- ------ ------------------ --------------------Backup Set 125 01-NOV-04Backup Piece 125 01-NOV-04 /data1/oracle/orabak/full_1_541045804Backup Set 131 04-NOV-04Backup Piece 131 04-NOV-04 /data1/oracle/orabak/full_AVATAR2_20041104_131....Backup Set 173 06-DEC-04Backup Piece 173 06-DEC-04 /data1/oracle/orabak/full_AVATAR2_20041206_173Backup Set 179 11-DEC-04Backup Piece 179 11-DEC-04 /data1/oracle/orabak/arch544588206.arc.....Backup Piece 189 17-DEC-04 /data1/oracle/orabak/arch545106606.arcBackup Set 190 17-DEC-04Backup Piece 190 17-DEC-04 /data1/oracle/orabak/arch545106665.arcBackup Set 191 20-DEC-04Backup Piece 191 20-DEC-04 /data1/oracle/orabak/arch_AVATAR2_20041220_194Archive Log 2973 20-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2985.dbfArchive Log 2971 20-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2984.dbf.....Archive Log 2705 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2717.dbfArchive Log 2704 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2716.dbfArchive Log 2703 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2715.dbfArchive Log 2702 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2714.dbf

4.使用delete obsolete命令删除过期备份:
RMAN> delete obsolete;RMAN retention policy will be applied to the commandRMAN retention policy is set to redundancy 1using channel ORA_DISK_1Deleting the following obsolete backups and copies:Type Key Completion Time Filename/Handle-------------------- ------ ------------------ --------------------Backup Set 125 01-NOV-04Backup Piece 125 01-NOV-04 /data1/oracle/orabak/full_1_541045804....Archive Log 2704 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2716.dbfArchive Log 2703 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2715.dbfArchive Log 2702 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2714.dbfDo you really want to delete the above objects (enter YES or NO)? yesdeleted backup piecebackup piece handle=/data1/oracle/orabak/full_AVATAR2_20041206_173 recid=173 stamp=544156241.....deleted archive logarchive log filename=/opt/oracle/oradata/avatar2/archive/1_2715.dbf recid=2703 stamp=545108268deleted archive logarchive log filename=/opt/oracle/oradata/avatar2/archive/1_2714.dbf recid=2702 stamp=545107659Deleted 286 objectsRMAN> crosscheck archivelog all;released channel: ORA_DISK_1allocated channel: ORA_DISK_1channel ORA_DISK_1: sid=19 devtype=DISKspecification does not match any archive log in the recovery catalog

5 在rman中用crosscheck检查归档日志,2个归档日志都是失败的:
RMAN> crosscheck archivelog all;
释放的通道: ORA_DISK_1
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: sid=14 devtype=DISK
对归档日志的验证失败
存档日志文件名 =D:ORACLEORADATATESTARCHIVE1_47.DBF 记录 ID=1 时间戳 =572866
683
对归档日志的验证失败
存档日志文件名 =D:ORACLEORADATATESTARCHIVE11_48.DBF 记录 ID=2 时间戳 =57286
6931
已交叉检验的 2 对象
6 试着同步一下,看行不行,结果不行,crosscheck还是失败:
RMAN> resync catalog;
正在启动全部恢复目录的 resync
完成全部 resync
RMAN> crosscheck archivelog all;
释放的通道: ORA_DISK_1
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: sid=14 devtype=DISK
对归档日志的验证失败
存档日志文件名 =D:ORACLEORADATATESTARCHIVE1_47.DBF 记录 ID=1 时间戳 =572866
683
对归档日志的验证失败
存档日志文件名 =D:ORACLEORADATATESTARCHIVE11_48.DBF 记录 ID=2 时间戳 =57286
6931
已交叉检验的 2 对象
7 用list expired看看是否有失效的archive log,证明没有失效的archive log:
RMAN> list expired archivelog all;
说明与恢复目录中的任何存档日志均不匹配
8 更改语言环境试试,结果再次crosscheck,2个archive log 都成功了:
RMAN> exit

恢复管理器完成。
C:>set nls_lang=american_america.zhs16gbk
C:>rman catalogrman/rman@safetarget /
Recovery Manager: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database: TEST (DBID=1870953724)
connected to recovery catalog database
RMAN> crosscheck archivelog all;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=9 devtype=DISK
validation succeeded for archived log
archive log filename=D:ORACLEORADATATESTARCHIVE1_47.DBF recid=1 stamp=57286
6683
validation succeeded for archived log
archive log filename=D:ORACLEORADATATESTARCHIVE11_48.DBF recid=2 stamp=5728
66931
Crosschecked 2 objects
参考技术B 建议是使用rman先备份归档日志文件,然后让再自动删除备份后的归档文件。
如果使用手动删除,在删除完归档后,再在rman下使用以下两个语句:
crosscheck archivelog all;
delete expired archivelog all;
第一条语句的做用就是检查控制文件和实际物理文件的差别;
第二条语句的做用就是同步控制文件的信息和实际物理文件的信息。在controlfile中记录着每一个archivelog的相关信息,当我们在OS下把这些物理文件delete掉或异常变动后,在controlfile中仍然记录着这些archivelog的信息,所以当我们手工清除archive目录下的文件后,这些记录并没有被我们从controlfile中清除掉,需要使用这条语句来更新controlfile。

Oracle定时删除归档日志文件

Oracle定时删除归档日志文件

Oracle如何删除归档日志文件?

一、定时删除脚本

  • crosscheck检查物理文件和归档日志
  • delete expired删除过期归档日志
  • delete …unitl…删除指定日期之前的日志
[oracle@ea9446c43596 oradata]$ vi delete_arc.sh
[oracle@ea9446c43596 oradata]$ chmod +x delete_arc.sh
  • 脚本内容
#! /bin/bash
source ~/.bash_profile
exec >> /home/oracle/app/oracle/oradata/deletelogs/del_arch`date +%F-%H`.log
$ORACLE_HOME/bin/rman target / <<EOF

crosscheck archivelog all;

delete noprompt expired archivelog all;

delete noprompt archivelog until time 'sysdate-7';
exit;
EOF

二、root用户下启动cron

[root@ea9446c43596 oradata]# service crond start
Starting crond:                                            [  OK  ]


三、Oracle用户下部署定时任务

  • 切换用户
[root@ea9446c43596 oradata]# su - oracle
  • 部署定时任务
[oracle@ea9446c43596 ~]$ crontab -e
0 2 * * * /home/oracle/app/oracle/oradata/delete_arc.sh
  • 查看定时任务
[oracle@ea9446c43596 ~]$ crontab -l
0 2 * * * /home/oracle/app/oracle/oradata/delete_arc.sh

四、几天后…

  通过日志del_arch2022-12-17-02.log可以看到,2022年12月17号2点的日志文件中,定时删除了七天前的1_8_900206934.dbf1_9_900206934.dbf两个日志文件。

[oracle@ea9446c43596 deletelogs]$ cat del_arch2022-12-17-02.log

Recovery Manager: Release 11.2.0.1.0 - Production on Sat Dec 17 02:00:01 2022

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: HELOWIN (DBID=1384114315)

RMAN>
RMAN>
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=775 device type=DISK
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_8_900206934.dbf RECID=7 STAMP=1123029988
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_9_900206934.dbf RECID=8 STAMP=1123066818
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_10_900206934.dbf RECID=9 STAMP=1123095615
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_11_900206934.dbf RECID=10 STAMP=1123124827
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_12_900206934.dbf RECID=11 STAMP=1123153640
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_13_900206934.dbf RECID=12 STAMP=1123184937
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_14_900206934.dbf RECID=13 STAMP=1123211251
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_15_900206934.dbf RECID=14 STAMP=1123243645
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_16_900206934.dbf RECID=15 STAMP=1123300833
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_17_900206934.dbf RECID=16 STAMP=1123326019
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_18_900206934.dbf RECID=17 STAMP=1123376427
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_19_900206934.dbf RECID=18 STAMP=1123412416
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_20_900206934.dbf RECID=19 STAMP=1123455608
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_21_900206934.dbf RECID=20 STAMP=1123498814
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_22_900206934.dbf RECID=21 STAMP=1123502886
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_23_900206934.dbf RECID=22 STAMP=1123560383
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_24_900206934.dbf RECID=23 STAMP=1123585220
validation succeeded for archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_25_900206934.dbf RECID=24 STAMP=1123599642
Crosschecked 18 objects


RMAN>
RMAN>
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=775 device type=DISK
specification does not match any archived log in the repository

RMAN>
RMAN>
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=775 device type=DISK
List of Archived Log Copies for database with db_unique_name HELOWIN
=====================================================================

Key     Thrd Seq     S Low Time
------- ---- ------- - ---------
7       1    8       A 09-DEC-22
        Name: /home/oracle/app/oracle/oradata/archlogs/1_8_900206934.dbf

8       1    9       A 10-DEC-22
        Name: /home/oracle/app/oracle/oradata/archlogs/1_9_900206934.dbf

deleted archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_8_900206934.dbf RECID=7 STAMP=1123029988
deleted archived log
archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_9_900206934.dbf RECID=8 STAMP=1123066818
Deleted 2 objects


RMAN>

Recovery Manager complete.

以上是关于如何删除oracle的归档日志的主要内容,如果未能解决你的问题,请参考以下文章

Oracle如何删除归档日志文件?

如何正确删除Oracle 归档日志文件

oracle 如何关闭打开归档日志的方法

Oracle定时删除归档日志文件

如何解决Oracle数据库归档日志占满磁盘空间

如何查看rman备份集的归档日志信息