alert 是告警日志;trace 是详细跟踪日志。
- alert:总日志,记"出了什么事"
- trace:详细跟踪,记"具体过程和细节"
- incident :针对严重错误单独立案,记"这次事故现场"
一、先理解这几个核心点
- ADR 是 Oracle 的诊断仓库,里面统一存放 trace、dump、alert log、incident 等诊断数据;每个实例/组件都有自己的 ADR home 。在 RAC 环境下,每个数据库实例也都有各自的 ADR home。
- ADRCI 适用于单机 和 RAC 。但
SET CONTROL、PURGE这类操作都是针对当前单个 ADR home 生效,不是全局一把梭。 - TRACE 走短生命周期策略 ,不是长生命周期策略:
SHORTP_POLICY默认 720 小时 = 30 天 ,主要管 TRACE、core dump、packaging information。
- alert / incident 走长生命周期策略 :
LONGP_POLICY默认 8760 小时 = 365 天 ,主要管 alert log、incident information、incident dumps。
purge只会清理已经达到条件 的内容。
也就是说,策略定义的是"多久后具备清理资格",不是一到时间点立刻秒删。
二、定位 ADR 目录
su - oracle
# 查看实例名
echo $ORACLE_SID
# 查看 Oracle 基础目录
echo $ORACLE_BASE
# 进入 ADR 目录(现场常见)
cd /u01/app/odaorabase/oracle/diag/rdbms
# 进入具体实例目录
cd /u01/app/odaorabase/oracle/diag/rdbms/erpcdb/erpcdb1
到这个目录后,重点看这几个子目录
alert/ # XML 格式 alert 日志
trace/ # 文本 alert、.trc、.trm
incident/ # incident 信息
cdump/ # dump 信息
三、用 ADRCI 查看和切换 home
adrci
# 查看当前有哪些 ADR home
show homes
# 切到目标实例
set home diag/rdbms/erpcdb/erpcdb1
# 查看当前清理策略
show control
RAC 节点 2 示例
adrci
show homes
set home diag/rdbms/erpcdb/erpcdb2
show control
四、默认规则
# 短生命周期:30 天线
SHORTP_POLICY = 720
# 长生命周期:365 天线
LONGP_POLICY = 8760
对应关系
# 30 天线
TRACE
core dump
# 365 天线
alert log
incident
incident dump
五、按当前策略清理
# 按当前保留策略清理已到期内容
purge
注:执行后没输出也可能正常,不代表失败。
六、按类型 + 年龄清理
清理 7 天前的 TRACE
# -age 单位是分钟
# 10080 分钟 = 7 天
purge -age 10080 -type TRACE
清理 15 天前的 TRACE
# 21600 分钟 = 15 天
purge -age 21600 -type TRACE
七、修改保留策略
1)把 TRACE 保留从 30 天改成 15 天
# SHORTP_POLICY 单位是小时
# 360 小时 = 15 天
set control (SHORTP_POLICY = 360)
show control
2)把长生命周期从 365 天改成 60 天
# LONGP_POLICY 单位是小时
# 1440 小时 = 60 天
set control (LONGP_POLICY = 1440)
show control
3)改完后按新策略顺手清一次
# 按新策略清理当前已到期内容
purge
八、设置 ADR 大小策略
# 给当前 ADR home 设 20G 大小阈值
set control (SIZEP_POLICY = 20G)
show control
九、规则什么时候执行?要不要 crontab?
# 默认不需要自己配 crontab
# ADR 自己有自动清理机制
记住这两点
1. 不设置 SIZEP_POLICY:
默认大约每 24 小时自动 purge 一次
2. 设置 SIZEP_POLICY:
MMON 大约每 4 小时检查一次大小阈值
也就是说:一般不用额外配 crontab 。
只有你想固定某个时间强制清理,才考虑自己加定时任务。
十、确认清理是否成功
1)看手工清理时间
show control
重点看:
LAST_MANUPRG_TIME # 手工 purge 时间
LAST_AUTOPRG_TIME # 自动 purge 时间
十一、最简常用命令模板
su - oracle
echo $ORACLE_SID
echo $ORACLE_BASE
adrci
show homes
set home diag/rdbms/erpcdb/erpcdb1
show control
# 按当前策略清理
purge
# 清理 7 天前的 TRACE
purge -age 10080 -type TRACE
# TRACE 保留改 15 天
set control (SHORTP_POLICY = 360)
show control
# alert / incident 保留改 60 天
set control (LONGP_POLICY = 1440)
show control
# 设 20G 大小策略
set control (SIZEP_POLICY = 20G)
show control