当前位置: 首页 > news >正文

50-Oracle awr报告生成-实操

一、AWR技术原理与核心架构

Automatic Workload Repository(AWR)​​ 是Oracle 10g引入的核心性能诊断工具,通过自动化数据收集机制构建数据库性能数据仓库。其技术架构包含三大核心组件:
  • 快照机制(Snapshots)​
    后台进程MMON(Manageability Monitor)默认每小时自动捕获一次系统性能快照,MMNL辅助处理轻量级任务。快照内容涵盖600+项性能指标,包括SQL执行统计、等待事件、系统负载等。
  • 数据存储(SYSAUX表空间)​
    所有快照数据持久化存储在SYSAUX表空间内,以WRM$_*(元数据)和WRH$_*(历史数据)格式存储。存储空间占用公式约为:空间(MB) = 快照数量 × 1.2(需预留冗余)。
  • 报告引擎(Report Generator)​
    通过对比两个快照生成差异化分析报告(TXT/HTML格式),使用DBMS_WORKLOAD_REPOSITORY包实现数据处理。
​​关键进程解析​:
  • - ​MMON​:负责快照调度、阈值警报、SQL统计信息更新
  • - ​MMNL​:当内存缓冲区(ASH)满时,将会话历史数据写入磁盘
  • - ​CKPT​:确保检查点期间数据一致性

 二、版本演进与功能增强

​版本​

​快照保留策略​

​关键改进​

​报告格式变化​

​Oracle 10g​

默认7天

取代Statspack,引入自动化快照

基础表格布局,无OS信息

​Oracle 11g​

默认8天

增加TOP SQL分析维度

新增操作系统类型显示

​11.2.0.4​

-

报告结构重构

新增"Wait Classes"、"IO Profile"章节,TOP 5事件扩展为TOP 10

​Oracle 12c​

-

多租仓支持

引入全局报告(Global Report),整合RAC多节点数据

​Oracle 19c​

可定制保留期

ADDM集成增强

HTML5优化,支持时间范围对比

三、各版本操作指南与脚本

​基础配置管理
-- 查看当前配置
SELECT snap_interval, retention 
FROM dba_hist_wr_control;-- 调整快照间隔(20分钟)和保留期(30天)
BEGINdbms_workload_repository.modify_snapshot_settings(interval => 20, retention => 30 * 24 * 60);
END;
/
生成AWR报告通用步骤
  • 连接数据库:sqlplus / as sysdba
  • oracle用户下运行,报告生成保存位置默认在/home/oracle/XXX.html 或是text
  • sql下面执行报告脚本: 注意是在sqlplus登录后
@awrrpt.sql        -- 单实例
@awrgrpt.sql       -- RAC全局报告
@awrrpti.sql       -- 指定实例报告(RAC)
运维脚本手动版​

​1. 手动创建快照(准备测试前后)​

-- 压测前
EXEC dbms_workload_repository.create_snapshot;-- 压测后
EXEC dbms_workload_repository.create_snapshot;

 ​2. 基线管理(性能对比基准)​

-- 创建基线
BEGINdbms_workload_repository.create_baseline(start_snap_id => 100,end_snap_id => 110,baseline_name => 'PEAK_LOAD_BASELINE');
END;
/-- 删除基线
EXEC dbms_workload_repository.drop_baseline('PEAK_LOAD_BASELINE');

​3. Shell自动化脚本(Linux环境)​ 

#!/bin/bash
ORACLE_SID=ORCLCDB --注意自己的ORACLE_SID
ORACLE_HOME=/u01/app/oracle/product/19.3/dbhome_1
REPORT_FILE="awr_$(date +%Y%m%d).html"sqlplus -s / as sysdba <<EOF
set pages 0 lin 200 feed off
spool $REPORT_FILE
SELECT dbms_workload_repository.awr_report_html((SELECT dbid FROM v$database),(SELECT instance_number FROM v$instance),(SELECT MAX(snap_id)-1 FROM dba_hist_snapshot),(SELECT MAX(snap_id) FROM dba_hist_snapshot)
) FROM dual;
spool off
EOF
echo "Report generated: $REPORT_FILE" 

4. 单节点和RAC环境实操,输入步骤一样,使用的sql脚本不同。 

    [root@OL97 ~]# su - oracle
    [oracle@OL97 ~]$ sqlplus / as sysdbaSQL*Plus: Release 23.0.0.0.0 - Production on Thu Jun 19 21:19:57 2025
    Version 23.8.0.25.04Copyright (c) 1982, 2025, Oracle.  All rights reserved.Connected to:
    Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
    Version 23.8.0.25.04SYS@FREE> @?/rdbms/admin/awrrpt.sqlSpecify the Report Type
    ~~~~~~~~~~~~~~~~~~~~~~~
    AWR reports can be generated in the following formats.  Please enter the
    name of the format at the prompt.  Default value is 'html'.'html'          HTML format (default)
    'text'          Text format
    'active-html'   Includes Performance Hub active reportEnter value for report_type:html
    Current Instance
    ~~~~~~~~~~~~~~~~
    DB Id          DB Name        Inst Num       Instance       Container Name
    -------------- -------------- -------------- -------------- --------------1475650002     FREE                        1 FREE           CDB$ROOTInstances in this Workload Repository schema
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~DB Id      Inst Num   DB Name      Instance     Host
    ------------ ---------- ---------    ----------   ------
    * 1475650002     1      FREE         FREE         OL97Using 1475650002 for database Id
    Using          1 for instance numberSpecify the number of days of snapshots to choose from
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Entering the number of days (n) will result in the most recent
    (n) days of snapshots being listed.  Pressing <return> without
    specifying a number lists all completed snapshots.Enter value for num_days:1179  19 Jun 2025 10:29     1180  19 Jun 2025 10:59     1181  19 Jun 2025 11:29     1182  19 Jun 2025 11:59     1183  19 Jun 2025 12:29     1184  19 Jun 2025 12:59     1185  19 Jun 2025 13:29     1186  19 Jun 2025 13:59     1187  19 Jun 2025 14:29     1188  19 Jun 2025 14:59     1189  19 Jun 2025 15:29     1190  19 Jun 2025 15:59     1191  19 Jun 2025 16:29     1192  19 Jun 2025 16:59     1193  19 Jun 2025 17:29     1194  19 Jun 2025 17:59     1195  19 Jun 2025 18:29     1196  19 Jun 2025 18:59     1197  19 Jun 2025 19:29     1198  19 Jun 2025 19:59     1199  19 Jun 2025 20:29     1200  19 Jun 2025 20:59     1Specify the Begin and End Snapshot Ids
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Enter value for begin_snap:185
    Begin Snapshot Id specified: 185Enter value for end_snap: 192
    End   Snapshot Id specified: 192Specify the Report Name
    ~~~~~~~~~~~~~~~~~~~~~~~
    The default report file name is awrrpt_1_185_192.html.  To use this name,
    press <return> to continue, otherwise enter an alternative.Enter value for report_name:23ai-free-20250619~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Additional Information----------------------Miscellaneous Information
    -------------------------
    There was no significant database activity to run the ADDM.</pre>
    <br /><a class="awr" href="#top">Back to Top</a><p />
    <p />
    <a class="awr" name="99991"></a>
    <h3 class="awr">Report Footnotes</h3>
    <ul>
    <li class="awr"> This section contains footnotes used by this report</li>
    </ul>
    <table border="0" class="tdiff" summary="Report Footnotes"><tr></tr>
    </table>
    <br /><a class="awr" name="1">[1]. The elapsed time statistic actually shows the measured database time.</a><br />
    <br />
    <br /><a class="awr" href="#top">Back to Top</a><p />
    <p />
    <p />
    <p />
    <p />
    <p />
    <p />
    <p />
    <p />
    <p />
    End of Report
    </body></html>
    Report written to 23ai-free-20250619.html
    SYS@FREE>

    四、性能分析关键

    解读AWR报告需聚焦三大核心领域:
    • 负载特征(Load Profile)​
    • Redo Size​:> 1MB/秒可能预示日志写入瓶颈
    • Logical Reads​:> 10,000/秒需检查索引效率
    • Hard Parses​:> 20/秒表明SQL重用率低
    • 等待事件分析(Top 10 Events)​

    等待事件​

    ​问题指向

    ​优化方案​

    db file sequential read

    索引扫描延迟

    优化SQL、SSD迁移

    log file sync

    提交延迟

    分批提交、闪存日志

    buffer busy waits

    热点块争用

    分区、反向索引

    • TOP SQL识别​关注指标:
    1. Elapsed Time/Exec​ > 1秒
    2. Executions​ 异常偏高
    3. Disk Reads​ 占比 > 20%
    ​诊断黄金法则​:当DB Time > Elapsed Time × CPU核心数时,表明数据库处于持续高压状态

    五、最佳实践与避坑

    • 空间管理策略
    SYSAUX空间不足是常见故障,监控脚本:
    --
    SELECT space_usage_kbytes/1024 MB_used 
    FROM v$sysaux_occupants 
    WHERE occupant_name='SM/AWR';
    --
    SELECT space_usage_kbytes/1024 MB_used2  FROM v$sysaux_occupants3  WHERE occupant_name='SM/AWR';MB_USED
    ----------472.25SYS@FREE>
    • 快照策略优化 

    ​场景​

    ​间隔​

    ​保留期​

    生产环境

    30分钟

    30天

    压测期间

    5分钟

    保留至分析结束

    开发环境

    60分钟

    7天

    • 故障排查:AWR生成失败
    1. 检查SYSAUX表空间使用率(>95%需扩容)
    2. 降低快照频率:ALTER SYSTEM SET snapshot_interval=30;
    3. 清理历史数据:EXEC dbms_workload_repository.drop_snapshot_range(low_snap_id,high_snap_id); 
    • 报告关键指标缺失
    1. 确认STATISTICS_LEVEL=TYPICAL(BASIC模式禁用AWR)
    2. 检查dba_hist_snapshot是否有对应时间段快照
    AWR作为Oracle性能分析的基石工具,其价值随着版本迭代不断提升。掌握其技术细节并配合自动化脚本,可使DBA在复杂性能问题诊断中游刃有余。建议定期创建性能基线,结合ADDM实现预测式优化,构建完整的数据库健康管理体系。
    也可以在12c+环境中使用@?/rdbms/admin/awrinfo.sql可生成包含AWR配置、空间使用、快照分布的综合性报告,格式默认txt。

     

     

    相关文章:

  • Promise静态方法 race
  • LangGraph--结构化输出(.with_structured_output() 方法)
  • 【论文笔记】【强化微调】AgentThink:思维链推理 + 工具调用
  • 高度雾实时渲染~轻松营造GIS场景真实感
  • 2025虚幻引擎文件与文件夹命名规律
  • ssh 服务和 rsync 数据同步
  • MFC中使用CRichEditCtrl控件让文本框中的内容部分加粗
  • 面试第三期
  • C#语言入门-task2 :C# 语言的基本语法结构
  • C#实现语音预处理:降噪/静音检测/自动增益
  • 河马剧场多部自制剧霸榜,短剧精品化战略持续推进
  • 二十章:ps结合插件stable diffusion
  • 【LLM学习笔记3】搭建基于chatgpt的问答系统(下)
  • CFG的前世今生
  • 拼多多商家端 anti_content 补环境分析
  • 网页后端开发(基础4--数据库MySQL)
  • Xsens动作捕捉技术用于研究机器人的运动控制、姿态调整以及人机交互
  • 不同程度多径效应影响下的无线通信网络电磁信号仿真数据生成程序
  • 【lenovo】LEGION 2020款跳过windows账号登录
  • 【MySQL篇01】补充:索引体系大总结(数据库原理篇)
  • 网站bbs备案/安徽企业网站建设
  • 青岛网站设计客服/bing搜索引擎
  • 苏州手机网站seo/seo黑帽教程视频
  • 一千元做网站/网站服务器速度对seo有什么影响
  • 电商代运营公司排行榜/班级优化大师免费下载电脑版
  • 网站怎么建立会员/网页制作