济宁做网站的公司,青岛网络推广教程,软件定制开发公司,seo培训优化课程一、AWR技术原理与核心架构 Automatic Workload Repository#xff08;AWR#xff09; 是Oracle 10g引入的核心性能诊断工具#xff0c;通过自动化数据收集机制构建数据库性能数据仓库。其技术架构包含三大核心组件#xff1a; 快照机制(Snapshots) 后台进程M…一、AWR技术原理与核心架构
Automatic Workload RepositoryAWR 是Oracle 10g引入的核心性能诊断工具通过自动化数据收集机制构建数据库性能数据仓库。其技术架构包含三大核心组件 快照机制(Snapshots) 后台进程MMONManageability 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 sysdbaoracle用户下运行报告生成保存位置默认在/home/oracle/XXX.html 或是textsql下面执行报告脚本 注意是在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_SIDORCLCDB --注意自己的ORACLE_SID
ORACLE_HOME/u01/app/oracle/product/19.3/dbhome_1
REPORT_FILEawr_$(date %Y%m%d).htmlsqlplus -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脚本不同。 [rootOL97 ~]# su - oracle
[oracleOL97 ~]$ 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.04SYSFREE ?/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 classawr href#topBack to Top/ap /
p /
a classawr name99991/a
h3 classawrReport Footnotes/h3
ul
li classawr This section contains footnotes used by this report/li
/ul
table border0 classtdiff summaryReport Footnotestr/tr
/table
br /a classawr name1[1]. The elapsed time statistic actually shows the measured database time./abr /
br /
br /a classawr href#topBack to Top/ap /
p /
p /
p /
p /
p /
p /
p /
p /
p /
End of Report
/body/html
Report written to 23ai-free-20250619.html
SYSFREE 四、性能分析关键
解读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识别关注指标 Elapsed Time/Exec 1秒Executions 异常偏高Disk Reads 占比 20% 诊断黄金法则当DB Time Elapsed Time × CPU核心数时表明数据库处于持续高压状态 五、最佳实践与避坑 空间管理策略 SYSAUX空间不足是常见故障监控脚本 --
SELECT space_usage_kbytes/1024 MB_used
FROM v$sysaux_occupants
WHERE occupant_nameSM/AWR;
--
SELECT space_usage_kbytes/1024 MB_used2 FROM v$sysaux_occupants3 WHERE occupant_nameSM/AWR;MB_USED
----------472.25SYSFREE
快照策略优化 场景 间隔 保留期 生产环境 30分钟 30天 压测期间 5分钟 保留至分析结束 开发环境 60分钟 7天 故障排查AWR生成失败 检查SYSAUX表空间使用率95%需扩容降低快照频率ALTER SYSTEM SET snapshot_interval30;清理历史数据EXEC dbms_workload_repository.drop_snapshot_range(low_snap_id,high_snap_id); 报告关键指标缺失 确认STATISTICS_LEVELTYPICALBASIC模式禁用AWR检查dba_hist_snapshot是否有对应时间段快照 AWR作为Oracle性能分析的基石工具其价值随着版本迭代不断提升。掌握其技术细节并配合自动化脚本可使DBA在复杂性能问题诊断中游刃有余。建议定期创建性能基线结合ADDM实现预测式优化构建完整的数据库健康管理体系。 也可以在12c环境中使用?/rdbms/admin/awrinfo.sql可生成包含AWR配置、空间使用、快照分布的综合性报告,格式默认txt。