Oracle数据库如何删除归档日志文件
前言
Oracle启用归档日志的状态下,会在指定的归档日志目录生成大量的日志文件,而且这些日志文件默认是不会定期清理。长时间运行下,会占用大量的存储空间,最终可能导致Oracle没有足够的空间维持启动状态。
在Oracle的控制文件中记录着每一个归档日志文件得相关信息。当手动删除了归档日志的物理文件后,控制文件中依然记录着已删除的归档日志信息。所以当我们删除归档日志文件时,不仅需要删除物理文件,还要删除控制文件中对应的信息。
一、切换Oracle用户
[root@ea9446c43596 /]# su - oracle
二、查看归档日志路径
归档日志路径不一定相同,如果不清楚归档日志在哪,可以通过命令find / -name *.dbf
查找
[oracle@ea9446c43596 ~]$ cd /home/oracle/app/oracle/oradata/archlogs/ [oracle@ea9446c43596 archlogs]$ ls 1_10_900206934.dbf 1_12_900206934.dbf 1_14_900206934.dbf 1_5_900206934.dbf 1_7_900206934.dbf 1_9_900206934.dbf 1_11_900206934.dbf 1_13_900206934.dbf 1_4_900206934.dbf 1_6_900206934.dbf 1_8_900206934.dbf
三、方法一:删除归档日志物理文件
如果之前手动删除过物理文件,可以查看这个方法,将控制文件中归档日志记录删除
1 删除物理文件
删除物理文件:1_4_900206934.dbf
[oracle@ea9446c43596 archlogs]$ rm -f 1_4_900206934.dbf
2 查看控制文件
通过如下命令查看Oracle控制文件记录归档日志信息,发现"1_4_900206934.dbf"还存在
rman target /
rman登录命令
list archivelog all;
查看所有的归档日志
[oracle@ea9446c43596 archlogs]$ rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Mon Dec 12 10:01:18 2022 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: HELOWIN (DBID=1384114315) RMAN> list archivelog all; using target database control file instead of recovery catalog List of Archived Log Copies for database with db_unique_name HELOWIN ===================================================================== Key Thrd Seq S Low Time ------- ---- ------- - --------- 3 1 4 A 07-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_4_900206934.dbf 4 1 5 A 07-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_5_900206934.dbf 5 1 6 A 08-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_6_900206934.dbf 6 1 7 A 09-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_7_900206934.dbf 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 9 1 10 A 10-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_10_900206934.dbf 10 1 11 A 10-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_11_900206934.dbf 11 1 12 A 11-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_12_900206934.dbf 12 1 13 A 11-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_13_900206934.dbf 13 1 14 A 11-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_14_900206934.dbf
3 对比检查归档日志物理文件和控制文件一致性
如果你之前已经删除过物理文件,并没有删除控制文件中的信息,请看如下操作:
crosscheck archivelog all;
优先使用这个命令,核验比对物理文件和归档日志记录信息一致性
list expired archivelog all;
crosscheck
后,可以使用这个命令,查看有哪些过期的日志文件
RMAN> crosscheck archivelog all; allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=772 device type=DISK validation failed for archived log archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_4_900206934.dbf RECID=3 STAMP=1122847256 validation succeeded for archived log archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_5_900206934.dbf RECID=4 STAMP=1122894018 validation succeeded for archived log archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_6_900206934.dbf RECID=5 STAMP=1122948041 validation succeeded for archived log archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_7_900206934.dbf RECID=6 STAMP=1122980424 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 Crosschecked 11 objects RMAN> list expired archivelog all; List of Archived Log Copies for database with db_unique_name HELOWIN ===================================================================== Key Thrd Seq S Low Time ------- ---- ------- - --------- 3 1 4 X 07-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_4_900206934.dbf
4 删除过期文件
delete expired archivelog all;
删除过期日志文件,在执行命令后,会提示你将要删除哪些过期的日志文件
RMAN> delete expired archivelog all; released channel: ORA_DISK_1 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=772 device type=DISK List of Archived Log Copies for database with db_unique_name HELOWIN ===================================================================== Key Thrd Seq S Low Time ------- ---- ------- - --------- 3 1 4 X 07-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_4_900206934.dbf Do you really want to delete the above objects (enter YES or NO)? yes deleted archived log archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_4_900206934.dbf RECID=3 STAMP=1122847256 Deleted 1 EXPIRED objects
四、方法二:rman删除归档日志
这种方法,可以将控制文件中记录信息和物理文件同步删除,更为方便。
1 查看控制文件记录
rman target /
登录rman
list archivelog all;
查看所有归档日志信息
[oracle@ea9446c43596 archlogs]$ rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Mon Dec 12 10:14:25 2022 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: HELOWIN (DBID=1384114315) RMAN> list archivelog all; using target database control file instead of recovery catalog List of Archived Log Copies for database with db_unique_name HELOWIN ===================================================================== Key Thrd Seq S Low Time ------- ---- ------- - --------- 4 1 5 A 07-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_5_900206934.dbf 5 1 6 A 08-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_6_900206934.dbf 6 1 7 A 09-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_7_900206934.dbf 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 9 1 10 A 10-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_10_900206934.dbf 10 1 11 A 10-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_11_900206934.dbf 11 1 12 A 11-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_12_900206934.dbf 12 1 13 A 11-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_13_900206934.dbf 13 1 14 A 11-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_14_900206934.dbf
2 删除指定日期前日志
delete archivelog all completed before 'SYSDATE - 3';
删除3天前的归档日志,在删除控制文件记录的同时,也会将物理文件删除。
RMAN> delete archivelog all completed before 'SYSDATE - 3'; allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=772 device type=DISK List of Archived Log Copies for database with db_unique_name HELOWIN ===================================================================== Key Thrd Seq S Low Time ------- ---- ------- - --------- 4 1 5 A 07-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_5_900206934.dbf 5 1 6 A 08-DEC-22 Name: /home/oracle/app/oracle/oradata/archlogs/1_6_900206934.dbf Do you really want to delete the above objects (enter YES or NO)? yes deleted archived log archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_5_900206934.dbf RECID=4 STAMP=1122894018 deleted archived log archived log file name=/home/oracle/app/oracle/oradata/archlogs/1_6_900206934.dbf RECID=5 STAMP=1122948041 Deleted 2 objects
3 查看物理文件
在上一步中删除了1_5_900206934.dbf
和1_6_900206934.dbf
文件,观察物理文件列表后,可以看到物理文件也会被同步删除。
[oracle@ea9446c43596 archlogs]$ ls 1_10_900206934.dbf 1_12_900206934.dbf 1_14_900206934.dbf 1_8_900206934.dbf 1_11_900206934.dbf 1_13_900206934.dbf 1_7_900206934.dbf 1_9_900206934.dbf
五、使用到的命令集合
登录rman
rman target /
查看所有归档日志
list archivelog all;
对比控制文件、物理文件
crosscheck archivelog all;
查看过期归档日志
list expired archivelog all;
删除过期归档日志
delete expired archivelog all;
删除指定日期归档日志
delete archivelog all completed before 'SYSDATE - n';
退出rman
exit;
总结
到此这篇关于Oracle数据库如何删除归档日志文件的文章就介绍到这了,更多相关Oracle删除归档日志文件内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
Oracle SQL Developer脚本输出中文显示乱码的解决方法
我们在测试Oracle Select AI(自然语言查询数据库)时,发现Run Statement中文显示正常,而Run Script中文显示乱码,所以本文给大家介绍了Oracle SQL Developer脚本输出中文显示乱码的解决方法,需要的朋友可以参考下2024-05-05ORACLE DATAGUARD中手工处理日志v$archive_GAP的方法
从9i以后,oracle dataguard 备库一般都不需要手工处理丢失的日志,FAL自动会帮我们处理,本文主要通过个案例来讲下手工处理丢失的日志的方法。2014-08-08Oracle 11g+windows 环境下Ecology7系统安装过程
这篇文章主要介绍了Oracle 11g+windows 环境下Ecology7系统安装,安装步骤是以管理员模式运行Oracle setup.exe文件,根据提示安装Oracle,创建数据库,注意修改连接数,本文给大家详细讲解,需要的朋友可以参考下2022-10-10
最新评论