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_4_900206934.dbf
[oracle@ea9446c43596 archlogs]$ rm -f 1_4_900206934.dbf
通过如下命令查看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
如果你之前已经删除过物理文件,并没有删除控制文件中的信息,请看如下操作:
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
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 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
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
在上一步中删除了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;