Oracle定时删除归档日志文件

Posted DATA数据猿

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 RMAN删除归档日志脚本

Oracle RMAN删除归档日志脚本

Linux下设置定时任务删除归档日志

设置定时任务用rman删除归档日志脚本

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

oracle 11g生产环境清理归档日志脚本