概述:使用adrci工具删除oracle的监听告警日志,在日常维护中监听的警告日志有可能占用磁盘的空间大需要进行清理。

ADRCI 作用

ADR中的诊断数据查看
Oracle Support
诊断信息包含:
 incident , problem, trace files, dumps, health monitor reports等


最近发现oracle的监听告警日志alert目录下日志非常大(log.xml log[0-9].xml文件)就达到7G左右,监听日志log.xml log[0-9].xml日志放文件在了$ORACLE_BASE/diag/tnslsnr/机器名/listener/alert目录下

image.png

1、切换到oracle 用户.
# su – oracle

2、adrci (运行该命令)

$ adrci
ADRCI: Release 11.2.0.4.0 - Production on Thu Jul 18 13:46:19 2019
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
ADR base = "/u01/app/oracle"
adrci>


3、 使用ADRCI命令先需要设置Homepath

查看control,不然有些会报如下错误
adrci> SHOW CONTROL
DIA-48448: This command does not support multiple ADR homes

adrci> show homes   ---若非我们想要的目录,可以指定set homepath diag/tnslsnr/2018/listener
ADR Homes: 
diag/rdbms/test/test
diag/tnslsnr/hostname/listener

adrci> set homepath diag/tnslsnr/hostname/listener


4、清除日志

adrci> help purge   --查看purge帮助命令
  Usage: PURGE [[-i  |  ] | 
               [-age  [-type ALERT|INCIDENT|TRACE|CDUMP|HM|UTSCDMP]]]: 
  Purpose: Purge the diagnostic data in the current ADR home. If no
           option is specified, the default purging policy will be used.
  Options:
    [-i id1 | id1 id2]: Users can input a single incident ID, or a 
    range of incidents to purge.
    [-age ]: Users can specify the purging policy either to all
    the diagnostic data or the specified type. The data older than 
    ago will be purged
    [-type ALERT|INCIDENT|TRACE|CDUMP|HM|UTSCDMP]: Users can specify what type of 
    data to be purged.
  Examples:  
    purge 
    purge -i 123 456
    purge -age 60 -type incident


如果上面有多个数据库,在运行命令之前先设定home
adrci> set homepath diag/tnslsnr/hostname/listener

adrci> show home( show homepath)       --设置home后在次查看,已设置ok
ADR Homes: 
diag/tnslsnr/y2018/listener


adrci> PURGE -age 1440 -type ALERT  # 删除一天前的alert log[删除(24h X 60s=1440)1天之前的日志,purge默认的是分钟]

5、设置日志保留时间

包含两个属性SHORTP_POLICY、LONGP_POLICY

SHORTP_POLICY
Trace files
Core dump files
Packaging information

LONGP_POLICY
Incident information
Incident dumps
Alert logs


查看control

adrci> show control 

ADR Home = /u01/app/oracle/diag/tnslsnr/y2018/listener:

*************************************************************************

ADRID                SHORTP_POLICY        LONGP_POLICY         LAST_MOD_TIME                            LAST_AUTOPRG_TIME                        LAST_MANUPRG_TIME                        ADRDIR_VERSION       ADRSCHM_VERSION      ADRSCHMV_SUMMARY     ADRALERT_VERSION     CREATE_TIME                              

-------------------- -------------------- -------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- -------------------- -------------------- -------------------- -------------------- ---------------------------------------- 

2422723473           720                  8760                 2018-04-27 12:27:13.758790 +08:00                                                                                          1                    2                    80                   1                    2018-04-27 12:27:13.758790 +08:00


关于control的设置,除了默认的SHORTP_POLICY为720小时(即30天),LONGP_POLICY为8760小时(即365天)外,

我们可以修改这2个属性的时间: 

adrci> set control (SHORTP_POLICY = 360) 
adrci> set control (LONGP_POLICY = 2160) 

adrci> show control 

ADR Home = /u01/app/oracle/diag/tnslsnr/y2018/listener:

*************************************************************************

ADRID                SHORTP_POLICY        LONGP_POLICY         LAST_MOD_TIME                            LAST_AUTOPRG_TIME                        LAST_MANUPRG_TIME                        ADRDIR_VERSION       ADRSCHM_VERSION      ADRSCHMV_SUMMARY     ADRALERT_VERSION     CREATE_TIME                              

-------------------- -------------------- -------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- -------------------- -------------------- -------------------- -------------------- ---------------------------------------- 

2422723473           360                  2160                 2018-04-27 12:27:13.758790 +08:00                                                                                          1                    2                    80                   1                    2018-04-27 12:27:13.758790 +08:00  


这样就改成了tracefiles保留360小时,即15天,incident file保留2160小时,即90天。 
上述就是oracle自己保留日志的期限,我们也可以通过purge这个命令来手工的清空。



退出ADRCI: 

adrci>>exit或者quit  回车