1.2 Oracle 告警日志位置
Oracle告警日志的位置:
- Oracle 11g及之前:由background_dump_dest参数指定
- Oracle 12c及之后:位于Automatic Diagnostic Repository (ADR)中
- 默认路径:$ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/trace/
1.3 Oracle 告警日志内容
告警日志包含以下类型的信息:
- 数据库启动和关闭
- 参数变更
- 检查点信息
- 日志切换信息
- ORA错误信息
- 表空间操作
- 备份恢复信息
- Resource Manager信息
Part02-生产环境规划与建议
2.1 Oracle数据库告警监控规划
告警监控规划要点:
– 关键错误:实时监控(如ORA-00600, ORA-07445)
– 重要错误:每小时检查(如ORA-01555, ORA-04031)
– 警告信息:每天检查(如表空间警告)
– 常规信息:每周汇总(如日志切换)
# 告警级别定义
P0 – 紧急:数据库不可用
P1 – 严重:重要功能不可用
P2 – 高:性能严重下降
P3 – 中:一般性能问题
P4 – 低:信息性消息
# 通知方式
P0/P1:电话 + 短信 + 邮件
P2:短信 + 邮件
P3:邮件
P4:每日汇总邮件
2.2 Oracle数据库日志保留策略
告警日志保留建议:
– 当前告警日志:始终保留
– 最近7天的告警日志:在线可查
– 最近30天的告警日志:压缩在线
# 归档保留
– 31天-90天的告警日志:归档存储
– 91天-1年的告警日志:备份到磁带/云存储
– 1年以上的告警日志:根据法规要求保留
# 轮换策略
– 每天轮换:使用logrotate或ADRCI
– 保留30个轮换版本
– 轮换后压缩旧日志
2.3 Oracle数据库分析工具选择
常用的告警日志分析工具:
- ADRCI:Oracle自带的ADR命令行工具
- OS工具:grep, tail, awk, sed等
- Enterprise Manager:图形化查看和分析
- 第三方工具:Splunk, ELK, Zabbix等
- 自定义脚本:Shell或Python脚本
Part03-生产环境项目实施方案
3.1 Oracle数据库告警日志管理
3.1.1 查看告警日志位置
$ sqlplus / as sysdba
SQL> select value from v$diag_info where name = ‘Diag Trace’;VALUE
——————————————————————————–
/oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace
SQL> select value from v$diag_info where name = ‘Diag Alert’;VALUE
——————————————————————————–
/oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/alert
# 方法2:查看background_dump_dest参数(11g及之前)
SQL> show parameter background_dump_dest;NAME TYPE VALUE
———————————— ———– ——————————
background_dump_dest string /oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace
# 方法3:查看告警日志文件
$ cd /oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace
$ ls -lh alert_*.log
-rw-r—– 1 oracle oinstall 50M Mar 31 23:00 alert_fgedudb.log
3.1.2 使用ADRCI管理告警日志
$ adrci
ADRCI: Release 19.0.0.0.0 – Production on Wed Mar 31 23:00:00 2026
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
ADR base = “/oracle/app/oracle”
# 设置ADR根目录
adrci> set base /oracle/app/oracle
# 查看ADR目录
adrci> show homes
ADR Homes:
diag/rdbms/fgedudb/fgedudb
diag/tnslsnr/rac1/listener
# 设置ADR Home
adrci> set homepath diag/rdbms/fgedudb/fgedudb
# 查看告警日志
adrci> show alert
Choose the alert log from the following homes to view:
1: diag/rdbms/fgedudb/fgedudb
Q: to quit
Please select option: 1
Output the results to file: /tmp/alert_12345_1.dat
1: diag/rdbms/fgedudb/fgedudb
2: diag/tnslsnr/rac1/listener
# 查看最近的告警
adrci> show alert -tail 100
# 查看特定时间段的告警
adrci> show alert -p “ORIGINATING_TIMESTAMP > ‘2026-03-30 00:00:00’ AND ORIGINATING_TIMESTAMP < '2026-03-31 23:59:59'"
# 查看特定错误
adrci> show alert -p “MESSAGE_TEXT LIKE ‘%ORA-00600%'”
# 清除告警日志
adrci> purge -age 720
# 退出ADRCI
adrci> exit
3.1.3 使用OS命令查看告警日志
$ tail -100 /oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace/alert_fgedudb.log
# 实时查看告警日志
$ tail -f /oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace/alert_fgedudb.log
# 查看特定错误
$ grep “ORA-00600” /oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace/alert_fgedudb.log
# 查看最近的错误
$ grep “ORA-” /oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace/alert_fgedudb.log | tail -20
Wed Mar 31 20:00:00 2026
ORA-12012: error on auto execute of job “SYS”.”MGMT_JOB_12345″
ORA-06512: at line 1
# 统计错误类型
$ grep “ORA-” /oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace/alert_fgedudb.log | awk ‘{print $1}’ | sort | uniq -c | sort -rn
15 ORA-12012:
5 ORA-01555:
3 ORA-04031:
1 ORA-00600:
# 查看检查点信息
$ grep “Completed checkpoint” /oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace/alert_fgedudb.log | tail -10
Wed Mar 31 18:00:00 2026
Completed checkpoint up to RBA [0x123.4567.89], SCN: 123456789
Wed Mar 31 19:00:00 2026
Completed checkpoint up to RBA [0x123.5678.90], SCN: 123456790
# 查看日志切换信息
$ grep “Thread 1 advanced to log sequence” /oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace/alert_fgedudb.log | tail -10
Wed Mar 31 22:00:00 2026
Thread 1 advanced to log sequence 1001 (LGWR switch)
Wed Mar 31 22:30:00 2026
Thread 1 advanced to log sequence 1002 (LGWR switch)
3.2 Oracle数据库告警监控脚本
3.2.1 简单告警监控脚本
# alert_monitor.sh – 简单的告警日志监控脚本
# from:www.itpux.com.qq113257174.wx:itpux-com
# web `http://www.fgedu.net.cn`
ORACLE_HOME=/oracle/app/oracle/product/19c/db_1
ORACLE_SID=fgedudb
ALERT_LOG=/oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace/alert_fgedudb.log
TMP_FILE=/tmp/alert_errors.tmp
LAST_CHECK=/tmp/alert_last_check.tmp
RECIPIENTS=”dba@fgedu.net.cn”
# 检查告警日志是否存在
if [ ! -f “$ALERT_LOG” ]; then
echo “ERROR: Alert log not found at $ALERT_LOG”
exit 1
fi
# 创建上次检查时间戳文件(如果不存在)
if [ ! -f “$LAST_CHECK” ]; then
date +%s > $LAST_CHECK
exit 0
fi
# 获取上次检查时间
LAST_TIME=$(cat $LAST_CHECK)
CURRENT_TIME=$(date +%s)
# 提取新的错误
grep -A 5 “ORA-” $ALERT_LOG | while read -r line; do
# 检查时间戳(这里需要根据实际日志格式调整)
echo “$line” | grep -E “^[A-Za-z]{3} [A-Za-z]{3} [0-9]{2}” > /dev/null
if [ $? -eq 0 ]; then
# 提取时间并转换为时间戳(简化处理)
LINE_TIME=$(echo “$line” | awk ‘{print $1, $2, $3, $4}’)
# 这里可以添加更精确的时间比较逻辑
fi
echo “$line” >> $TMP_FILE
done
# 检查是否有新的错误
if [ -s “$TMP_FILE” ]; then
# 发送邮件通知
echo “New errors found in alert log:” > /tmp/alert_email.tmp
echo “====================================” >> /tmp/alert_email.tmp
cat $TMP_FILE >> /tmp/alert_email.tmp
mail -s “ALERT: Oracle Errors – $ORACLE_SID” $RECIPIENTS < /tmp/alert_email.tmp rm -f /tmp/alert_email.tmp fi # 更新最后检查时间 echo $CURRENT_TIME > $LAST_CHECK
# 清理临时文件
rm -f $TMP_FILE
echo “Alert log check completed at $(date)”
3.2.2 使用logrotate管理告警日志
# vi /etc/logrotate.d/oracle-alert
/oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace/alert_*.log {
daily
rotate 30
compress
delaycompress
missingok
notifempty
dateext
dateformat -%Y%m%d
sharedscripts
postrotate
# 使用ADRCI重新初始化告警日志
su – oracle -c “/oracle/app/oracle/product/19c/db_1/bin/adrci << EOF
set base /oracle/app/oracle
set homepath diag/rdbms/fgedudb/fgedudb
purge -age 720
exit
EOF"
endscript
}
# 测试logrotate配置
# logrotate -d /etc/logrotate.d/oracle-alert
# 手动执行轮换
# logrotate -f /etc/logrotate.d/oracle-alert
# 查看轮换后的日志
# ls -lh /oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace/alert_*.log*
3.3 Oracle数据库告警分析脚本
3.3.1 告警日志分析脚本
# alert_analysis.sh – 告警日志分析脚本
# from:www.itpux.com.qq113257174.wx:itpux-com
# web `http://www.fgedu.net.cn`
ORACLE_SID=fgedudb
ALERT_LOG=/oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace/alert_fgedudb.log
REPORT_FILE=/tmp/alert_report_$(date +%Y%m%d).txt
echo “========================================” > $REPORT_FILE
echo “Oracle Alert Log Analysis Report” >> $REPORT_FILE
echo “Date: $(date)” >> $REPORT_FILE
echo “Database: $ORACLE_SID” >> $REPORT_FILE
echo “========================================” >> $REPORT_FILE
echo “” >> $REPORT_FILE
# 1. 错误统计
echo “1. Error Statistics” >> $REPORT_FILE
echo “——————-” >> $REPORT_FILE
grep “ORA-” $ALERT_LOG | awk ‘{print $1}’ | sort | uniq -c | sort -rn >> $REPORT_FILE
echo “” >> $REPORT_FILE
# 2. 最近的严重错误
echo “2. Recent Critical Errors (last 50)” >> $REPORT_FILE
echo “———————————–” >> $REPORT_FILE
grep -B 2 -A 5 “ORA-00600\|ORA-07445” $ALERT_LOG | tail -100 >> $REPORT_FILE
echo “” >> $REPORT_FILE
# 3. 日志切换频率
echo “3. Log Switch Frequency” >> $REPORT_FILE
echo “———————-” >> $REPORT_FILE
grep “Thread 1 advanced to log sequence” $ALERT_LOG | tail -20 >> $REPORT_FILE
echo “” >> $REPORT_FILE
# 4. 检查点信息
echo “4. Checkpoint Information” >> $REPORT_FILE
echo “————————” >> $REPORT_FILE
grep “Completed checkpoint” $ALERT_LOG | tail -20 >> $REPORT_FILE
echo “” >> $REPORT_FILE
# 5. 表空间警告
echo “5. Tablespace Warnings” >> $REPORT_FILE
echo “———————” >> $REPORT_FILE
grep -i “tablespace” $ALERT_LOG | grep -i “full\|warning\|extend” | tail -20 >> $REPORT_FILE
echo “” >> $REPORT_FILE
# 6. 数据库启动/关闭记录
echo “6. Database Startup/Shutdown” >> $REPORT_FILE
echo “—————————” >> $REPORT_FILE
grep -E “Starting ORACLE instance|Shutting down instance” $ALERT_LOG | tail -20 >> $REPORT_FILE
echo “” >> $REPORT_FILE
echo “========================================” >> $REPORT_FILE
echo “Analysis Completed” >> $REPORT_FILE
echo “========================================” >> $REPORT_FILE
echo “Alert log analysis report generated: $REPORT_FILE”
cat $REPORT_FILE
Part04-生产案例与实战讲解
4.1 Oracle数据库常见告警分析
4.1.1 ORA-00600 内部错误
Wed Mar 31 20:00:00 2026
Errors in file /oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace/fgedudb_ora_1234.trc:
ORA-00600: internal error code, arguments: [ktsircinfo_num1], [], [], [], [], [], [], [], [], [], [], []
# 分析步骤
1. 查看完整的跟踪文件
$ cat /oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace/fgedudb_ora_1234.trc
2. 收集错误信息
– 错误代码:ORA-00600
– 参数:[ktsircinfo_num1]
– 数据库版本:19.3.0.0.0
– 操作系统:Linux x86_64
3. 检查Oracle Support
– 搜索My Oracle Support (MOS)
– 查找匹配的Bug和补丁
– 检查是否有已知解决方案
4. 解决方案
– 如果是已知Bug,应用对应的补丁
– 如果是首次出现,监控是否再次发生
– 如果频繁发生,联系Oracle Support
4.1.2 ORA-01555 快照过旧
Wed Mar 31 21:00:00 2026
ORA-01555: snapshot too old: rollback segment number 10 with name “_SYSSMU10_123456789$” too small
# 分析步骤
1. 检查UNDO表空间配置
SQL> show parameter undo;NAME TYPE VALUE
———————————— ———– ——————————
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS1
2. 检查UNDO表空间使用情况
SQL> select tablespace_name, status, contents, retention from dba_tablespaces where tablespace_name like ‘%UNDO%’;TABLESPACE_NAME STATUS CONTENTS RETENTION
—————————— ——— ——— ———–
UNDOTBS1 ONLINE UNDO NOGUARANTEE
3. 检查长时间运行的查询
SQL> select sid, serial#, username, program, last_call_et/60 as minutes_running
from v$session
where status = ‘ACTIVE’
and last_call_et > 600
order by last_call_et desc;4. 解决方案
– 增加undo_retention参数值
– 增加UNDO表空间大小
– 优化长时间运行的查询
– 考虑启用UNDO_RETENTION GUARANTEE
SQL> alter system set undo_retention = 3600 scope=both;System altered.
SQL> alter tablespace undotbs1 add datafile ‘/oracle/app/oracle/oradata/fgedudb/undotbs02.dbf’ size 10G autoextend on;Tablespace altered.
4.1.3 ORA-04031 内存不足
Wed Mar 31 22:00:00 2026
Errors in file /oracle/app/oracle/diag/rdbms/fgedudb/fgedudb/trace/fgedudb_ora_5678.trc:
ORA-04031: unable to allocate 4096 bytes of shared memory (“shared pool”,”unknown object”,”sga heap(1,0)”,”modification “)
# 分析步骤
1. 检查SGA配置
SQL> show parameter sga;NAME TYPE VALUE
———————————— ———– ——————————
sga_max_size big integer 1G
sga_target big integer 1G
2. 检查共享池使用情况
SQL> select pool, name, bytes/1024/1024 as mb
from v$sgastat
where pool = ‘shared pool’
order by bytes desc
fetch first 20 rows only;POOL NAME MB
———— —————————— ———-
shared pool free memory 150.23
shared pool sql area 200.56
shared pool library cache 180.78
3. 检查共享池碎片化
SQL> select request_size, count(*)
from x$ksmsp
where ksmchcls = ‘free’
group by request_size
order by request_size;4. 解决方案
– 增加shared_pool_size
– 刷新共享池(谨慎使用)
– 检查导致内存泄漏的SQL
– 考虑使用内存自动管理
SQL> alter system set shared_pool_size = 500M scope=both;System altered.
SQL> alter system flush shared_pool;System altered.
4.2 Oracle数据库告警调查流程
4.2.1 标准调查流程
1. 确认告警
– 检查告警日志中的错误信息
– 确认错误发生时间
– 收集错误上下文信息
2. 评估影响
– 判断错误的严重程度
– 评估对业务的影响
– 确定优先级
3. 收集信息
– 查看相关的跟踪文件
– 收集数据库配置信息
– 检查系统资源使用情况
– 查看历史告警信息
4. 分析原因
– 搜索Oracle Support文档
– 检查是否有已知Bug
– 分析相关日志和跟踪文件
– 尝试复现问题(测试环境)
5. 制定解决方案
– 根据分析结果制定修复方案
– 评估方案的风险
– 制定回滚计划
– 获得批准
6. 实施解决方案
– 在测试环境验证
– 在维护窗口实施
– 执行修复操作
– 监控实施结果
7. 验证修复
– 检查告警是否消失
– 验证业务功能正常
– 监控数据库性能
– 确认没有新的问题
8. 总结记录
– 记录问题现象
– 记录分析过程
– 记录解决方案
– 记录经验教训
9. 预防措施
– 更新监控阈值
– 添加预防脚本
– 更新维护文档
– 培训团队成员
4.3 Oracle数据库告警解决方案
4.3.1 表空间满解决方案
Wed Mar 31 23:00:00 2026
ORA-01653: unable to extend table FGAPP_USER.ORDERS by 128 in tablespace USERS
# 解决方案
1. 检查表空间使用情况
SQL> select tablespace_name,
round((1 – free/total)*100, 2) as used_pct,
round(total/1024/1024/1024, 2) as total_gb,
round(free/1024/1024/1024, 2) as free_gb
from (
select tablespace_name,
sum(bytes) as total,
sum(maxbytes) as max_total
from dba_data_files
group by tablespace_name
) a,
(
select tablespace_name,
sum(bytes) as free
from dba_free_space
group by tablespace_name
) b
where a.tablespace_name = b.tablespace_name
and a.tablespace_name = ‘USERS’;TABLESPACE_NAME USED_PCT TOTAL_GB FREE_GB
—————————— ———- ———- ———-
USERS 98.5 5.0 0.08
2. 添加数据文件
SQL> alter tablespace USERS add datafile ‘/oracle/app/oracle/oradata/fgedudb/users02.dbf’ size 10G autoextend on next 1G maxsize 32G;Tablespace altered.
3. 验证表空间状态
SQL> select tablespace_name,
round((1 – free/total)*100, 2) as used_pct,
round(total/1024/1024/1024, 2) as total_gb,
round(free/1024/1024/1024, 2) as free_gb
from (
select tablespace_name,
sum(bytes) as total,
sum(maxbytes) as max_total
from dba_data_files
group by tablespace_name
) a,
(
select tablespace_name,
sum(bytes) as free
from dba_free_space
group by tablespace_name
) b
where a.tablespace_name = b.tablespace_name
and a.tablespace_name = ‘USERS’;TABLESPACE_NAME USED_PCT TOTAL_GB FREE_GB
—————————— ———- ———- ———-
USERS 32.8 15.0 10.08
4. 长期解决方案
– 监控表空间增长趋势
– 定期清理历史数据
– 考虑表分区
– 建立容量规划流程
Part05-风哥经验总结与分享
5.1 Oracle数据库最佳实践
- 实时监控:配置实时告警监控,及时发现重要错误
- 定期检查:每天检查告警日志,不要堆积问题
- 日志轮换:配置告警日志轮换,避免单个文件过大
- 归档保存:归档历史告警日志,便于问题追溯
- 错误分类:建立错误分类标准,统一处理流程
- 记录完整:完整记录问题分析和解决过程
- 知识共享:建立知识库,共享解决方案
- 持续改进:定期review告警,优化监控和预防措施
5.2 Oracle数据库告警检查清单
检查项
频率
说明
检查ORA-00600错误
实时
内部错误,需要立即关注
检查ORA-07445错误
实时
系统错误,需要立即关注
检查ORA-01555错误
每小时
快照过旧,检查UNDO配置
检查ORA-04031错误
每小时
内存不足,检查SGA配置
检查表空间警告
每天
表空间使用率高
检查日志切换频率
每天
确认日志切换正常
检查检查点信息
每天
确认检查点正常
检查启动/关闭记录
每天
确认没有意外重启
生成告警分析报告
每周
汇总分析告警趋势
review告警处理记录
每月
持续改进监控流程
5.3 Oracle数据库工具推荐
1. ADRCI – ADR命令行工具
– 功能:管理ADR、查看告警日志、清除旧日志
– 优点:Oracle官方工具,功能完整
– 适用:日常管理和维护
2. Enterprise Manager
– 功能:图形化查看告警、性能分析、监控
– 优点:界面友好,功能强大
– 适用:生产环境监控和分析
# OS工具
1. grep/sed/awk
– 功能:文本搜索、过滤、处理
– 优点:快速、灵活、无需安装
– 适用:快速检查和简单分析
2. tail
– 功能:查看文件末尾、实时监控
– 优点:简单易用
– 适用:实时监控告警日志
3. logrotate
– 功能:日志轮换和管理
– 优点:系统自带,配置简单
– 适用:告警日志轮换
# 第三方工具
1. Splunk/ELK Stack
– 功能:日志收集、存储、分析、可视化
– 优点:强大的搜索和分析能力
– 适用:大型环境,集中日志管理
2. Zabbix/Nagios
– 功能:监控、告警、通知
– 优点:成熟的监控解决方案
– 适用:生产环境监控
3. OS Watcher
– 功能:系统和数据库监控
– 优点:Oracle提供的免费工具
– 适用:性能分析和故障诊断
# 自定义工具
1. Shell/Python脚本
– 功能:自定义监控和分析
– 优点:灵活、可定制
– 适用:特定需求的监控和分析
2. cron/scheduled tasks
– 功能:定时执行任务
– 优点:系统自带,配置简单
– 适用:定期检查和分析
更多学习教程公众号风哥教程itpux_com
from oracle:www.itpux.com
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
