搜索结果

×

搜索结果将在这里显示。

🌻 1.8 Oracle数据库alert日志检查

Oracle 的 alert 日志(alert log)是数据库的“运行日记”,记录了启动关闭、内部错误、归档切换、参数变更等关键事件。定期检查 alert 日志是 DBA 日常巡检的核心任务。以下是系统的检查方法:

一、alert 日志的位置

1. 使用 ADR(11g 及以后,默认)

-- 查询 ADR 路径
SHOW PARAMETER diagnostic_dest;
-- 日志文件位于 $DIAGNOSTIC_DEST/diag/rdbms/<dbname>/<SID>/trace/alert_<SID>.log

实际示例:

/u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log

2. 非 ADR(10g 及以前)

SHOW PARAMETER background_dump_dest;
-- 日志文件位于该路径下的 alert_<SID>.log

二、查看 alert 日志的方法

1. 操作系统命令

# 查看最后 100 行
tail -100 $ORACLE_BASE/diag/rdbms/orcl/orcl/trace/alert_orcl.log

# 实时跟踪新日志
tail -f $ORACLE_BASE/diag/rdbms/orcl/orcl/trace/alert_orcl.log

# 筛选错误
grep -i "ORA-" alert_orcl.log | tail -20
grep -i "deadlock" alert_orcl.log
grep -i "Starting ORACLE instance" alert_orcl.log   # 查看启动时间

2. 使用 ADRCI

adrci
> set homepath diag/rdbms/orcl/orcl
> show alert -tail 100
> show alert -p "message_text like '%ORA-00600%'"

3. SQL 查询(12c 及以后)

SELECT originating_timestamp, message_text
FROM v$diag_alert_ext
WHERE message_text LIKE '%ORA-%'
  AND originating_timestamp > SYSDATE - 1
ORDER BY originating_timestamp DESC;

三、alert 日志中需要重点关注的内容

错误/事件 含义 处理建议
ORA-00600 / ORA-07445 内部错误,可能为 Bug 查 MOS,应用补丁
ORA-01555 快照过旧 增加 undo 表空间,优化 SQL
ORA-01688 表空间无法扩展 添加数据文件或开启自动扩展
ORA-00257 归档空间满 清理归档,扩大 FRA
Deadlock detected 死锁 分析应用,优化事务
Thread X cannot allocate new log 日志切换慢 增加日志组大小或数量
Checkpoint not complete 检查点未完成 调优检查点参数,增加日志组
Archiver process died 归档进程异常 检查归档目标,必要时重启
Instance terminated 实例异常终止 分析原因(OOM、手动 kill)

四、日常巡检脚本示例

可将以下内容保存为 check_alert.sh,定期执行:

#!/bin/bash
ALERT_LOG=$(sqlplus -s / as sysdba <<EOF
set pages 0 feedback off
select value from v\$parameter where name='background_dump_dest';
exit
EOF
)
ALERT_LOG=${ALERT_LOG%/}/alert_$ORACLE_SID.log

if [ -f "$ALERT_LOG" ]; then
    echo "=== 最近 ORA- 错误 ==="
    tail -1000 "$ALERT_LOG" | grep -i "ORA-" | tail -10
    echo "=== 最近死锁 ==="
    tail -1000 "$ALERT_LOG" | grep -i "deadlock" | tail -5
    echo "=== 最近启动时间 ==="
    grep -i "Starting ORACLE instance" "$ALERT_LOG" | tail -1
else
    echo "Alert log not found at $ALERT_LOG"
fi

五、常见操作建议

  • 每日检查:快速浏览最近 100 行,关注 ORA-、deadlock、archiver 等关键词。
  • 周度分析:统计一周内错误频率,排查潜在隐患。
  • 归档清理:若频繁出现 ORA-00257,需设置自动清理策略(RMAN 删除过期归档)。
  • 日志轮转:ADR 会自动管理;非 ADR 需手动轮转(可配合 logrotate 或重启实例后清理)。

通过规律性检查 alert 日志,可以提前发现空间不足、硬件故障、应用错误等问题,保障数据库稳定运行。若遇到具体错误,请保留完整日志上下文,便于深入分析。

grep -i "ORA-00600" /oracle/app/oracle/diag/rdbms/lxmes/lxmes/trace/alert_lxmes.log | tail -20
grep -i "ORA-07455" /oracle/app/oracle/diag/rdbms/lxmes/lxmes/trace/alert_lxmes.log | tail -20
grep -i "ORA-01555" /oracle/app/oracle/diag/rdbms/lxmes/lxmes/trace/alert_lxmes.log | tail -20
grep -i "ORA-01688" /oracle/app/oracle/diag/rdbms/lxmes/lxmes/trace/alert_lxmes.log | tail -20
grep -i "ORA-00257" /oracle/app/oracle/diag/rdbms/lxmes/lxmes/trace/alert_lxmes.log | tail -20
grep -i "Deadlock detected" /oracle/app/oracle/diag/rdbms/lxmes/lxmes/trace/alert_lxmes.log | tail -20
grep -i "cannot allocate new log" /oracle/app/oracle/diag/rdbms/lxmes/lxmes/trace/alert_lxmes.log | tail -20
grep -i "Checkpoint not complete" /oracle/app/oracle/diag/rdbms/lxmes/lxmes/trace/alert_lxmes.log | tail -20
grep -i "Archiver process died" /oracle/app/oracle/diag/rdbms/lxmes/lxmes/trace/alert_lxmes.log | tail -20
grep -i "Instance terminated" /oracle/app/oracle/diag/rdbms/lxmes/lxmes/trace/alert_lxmes.log | tail -20

grep -i "ORA-" /oracle/app/oracle/diag/rdbms/lxmes/lxmes/trace/alert_lxmes.log

阅读:144
发布时间: