oracle

关注公众号 jb51net

关闭
首页 > 数据库 > oracle > Oracle删除归档日志文件

Oracle数据库如何删除归档日志文件

作者:DATA数据猿

这篇文章主要给大家介绍了关于Oracle数据库如何删除归档日志文件的相关资料,当Oracle中的归档日志空间满时,则需要把它清空,否则将会影响数据库正常运行,将无法正常登入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"还存在

[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 对比检查归档日志物理文件和控制文件一致性

如果你之前已经删除过物理文件,并没有删除控制文件中的信息,请看如下操作:

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 删除过期文件

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 查看控制文件记录

[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 删除指定日期前日志

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.dbf1_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

五、使用到的命令集合

总结 

到此这篇关于Oracle数据库如何删除归档日志文件的文章就介绍到这了,更多相关Oracle删除归档日志文件内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文