"Oracle Series" How does Oracle delete archived log files?

insert image description here

How does Oracle delete archived log files?

  When Oracle enables archived logs, a large number of log files will be generated in the specified archived log directory, and these log files will not be cleaned up regularly by default. If it runs for a long time, it will take up a lot of storage space, which may eventually cause Oracle to not have enough space to maintain the startup state.

  Information about each archived log file is recorded in the Oracle control file. After manually deleting the physical file of the archived log, the deleted archived log information is still recorded in the control file. So when we delete an archived log file, we not only need to delete the physical file, but also delete the corresponding information in the control file.

1. Switch the Oracle user

[root@ea9446c43596 /]# su - oracle

Second, view the archived log path

The archived log path is not necessarily the same, if you do not know where the archived log is, you can use the command find / -name *.dbfto find it

[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

3. Method 1: Delete the archived log physical file

如果之前手动删除过物理文件,可以查看这个方法,将控制文件中归档日志记录删除

1 Delete the physical file

删除物理文件:1_4_900206934.dbf

[oracle@ea9446c43596 archlogs]$ rm -f 1_4_900206934.dbf

2 View control files

通过如下命令查看Oracle控制文件记录归档日志信息,发现"1_4_900206934.dbf"还存在

  • rman target /

    rman login command

  • list archivelog all;

    view all archived logs

[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 Compare and check the consistency of the archived log physical file and the control file

If you have deleted the physical file before and have not deleted the information in the control file, please see the following steps:

  • crosscheck archivelog all;

    Use this command first to verify the consistency of physical files and archive log records

  • list expired archivelog all;

    crosscheckAfter that, you can use this command to see what expired log files are

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 files

  • delete expired archivelog all;

    Delete expired log files. After executing the command, you will be prompted which expired log files will be deleted

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

4. Method 2: rman deletes archived logs

这种方法,可以将控制文件中记录信息和物理文件同步删除,更为方便。

1 View control file records

  • rman target /

    login rman

  • list archivelog all;

    View all archived log messages

[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 logs before the specified date

  • delete archivelog all completed before 'SYSDATE - 3';

    When deleting the archived logs 3 days ago, the physical files will also be deleted when the control file records are deleted.

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 View physical files

Deleted 1_5_900206934.dbfand 1_6_900206934.dbffiles in the previous step, after observing the list of physical files, you can see that the physical files will also be deleted synchronously.

[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

5. The set of commands used

  • login rman

    rman target /
    
  • View all archived logs

    list archivelog all;
    
  • Compare Control Files, Physical Files

    crosscheck archivelog all;
    
  • View expired archived logs

    list expired archivelog all;
    
  • Delete expired archived logs

    delete expired archivelog all;
    
  • Delete archived logs on specified date

    delete archivelog all completed before 'SYSDATE - n';
    
  • quit rman

    exit;
    

Guess you like

Origin blog.csdn.net/m0_51197424/article/details/128293792
Recommended