阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Oracle SQL Tuning Health-Check(SQLHC)

123次阅读
没有评论

共计 4240 个字符,预计需要花费 11 分钟才能阅读完成。

一条 sql 语句的性能主要依赖于好的物理结构, 准确的系统统计数据, 准确的对象统计数据, 合理的查询优化器参数, 合理的系统参数. 这些数据也就是 CBO 计算的基本参数,SQLHC(文档 ID 1366133.1) 正是为用户提供 sql 的这些数据, 来辅助 sql 调优. 特别适合无法在客户环境中调优的情况,SQLHC 虽然没有 SQLT(文档 ID 215187.1) 更强大, 但不需要在采集的库上建用户, 会被更多的客户所接受.

以下演示:
os:CentOS 6.6
db:Oracle 11.2.0.4
#sqlhc.zip 在 mos 文档 ID 1366133.1 下载

# 解压 sqlhc.zip
[oracle@ct6604 ~]$ unzip sqlhc.zip
Archive:  sqlhc.zip
  creating: sqlhc/
  inflating: sqlhc/sqlhc.sql
  inflating: sqlhc/sqldx.sql
  inflating: sqlhc/sqlhcxec.sql
[oracle@ct6604 ~]$ cd sqlhc
[oracle@ct6604 sqlhc]$ ls
sqldx.sql  sqlhc.sql  sqlhcxec.sql

# 运行测试 sql
[oracle@ct6604 sqlhc]$ ORACLE_SID=ctdb
[oracle@ct6604 sqlhc]$ sqlplus / as sysdba
#sql 中的 gather_plan_statistics 是为了在生成的报告中显示 a -row.
#sql 中的 monitor 是为了生成 sql_monitor 报告.
SQL> select /*+gather_plan_statistics monitor */a.* from scott.emp a,scott.dept b where a.deptno=b.deptno and b.dname=’SALES’;
/*

*/

SQL> select sql_text,sql_id from v$sql where sql_text like ‘select /*+gather_plan_statistics monitor */a.* from scott.emp a%’;
/*
SQL_TEXT
——————————————————————————–
SQL_ID
————-
select /*+gather_plan_statistics monitor */a.* from scott.emp a,scott.dept b whe
re a.deptno=b.deptno and b.dname=’SALES’
9pq9f4vkb9fvb
*/

# 生成 SQLHC 报告
SQL> start sqlhc.sql T 9pq9f4vkb9fvb

/*

Archive:  sqlhc_20160516_145204_9pq9f4vkb9fvb.zip
  Length      Date    Time    Name
———  ———- —–  —-
    7756  05-16-2016 14:52  sqlhc_20160516_145204_9pq9f4vkb9fvb_1_health_check.html
  119553  05-16-2016 14:52  sqlhc_20160516_145204_9pq9f4vkb9fvb_2_diagnostics.html
    7938  05-16-2016 14:52  sqlhc_20160516_145204_9pq9f4vkb9fvb_3_execution_plans.html
    50903  05-16-2016 14:52  sqlhc_20160516_145204_9pq9f4vkb9fvb_4_sql_detail.html
  449937  05-16-2016 14:52  sqlhc_20160516_145204_9pq9f4vkb9fvb_9_log.zip
    6018  05-16-2016 14:52  sqlhc_20160516_145204_9pq9f4vkb9fvb_5_sql_monitor.zip
  147123  05-16-2016 14:52  sqlhc_20160516_145204_9pq9f4vkb9fvb_6_10053_trace_from_cursor.trc
    56808  05-16-2016 14:52  sqlhc_20160516_145204_9pq9f4vkb9fvb_8_sqldx.zip
———                    ——-
  846036                    8 files
*/

#SQLHC 报告说明
1_health_check.html
    Observations: 显示 health-checks 输出的可能存在问题的项目, 确认是否需要更改. 例如: 对象统计信息过旧
    SQL Text: 要检查的 sql 文本
    Tables Summary: 显示相关表的统计信息大概
    Indexes Summary: 显示相关索引的统计信息大概
2_diagnostics.html
    SQL Text: 要检查的 sql 文本
    SQL Plan Baselines (DBA_SQL_PLAN_BASELINES):DBA_SQL_PLAN_BASELINES 中此 sql 的 plan history
    SQL Profiles (DBA_SQL_PROFILES):DBA_SQL_PROFILES 中此 sql 的 profiles
    SQL Patches (DBA_SQL_PATCHES):DBA_SQL_PATCHES 中此 sql 的相关 patches
    Cursor Sharing and Reason:GV$SQL_SHARED_CURSOR 是此 sql 的 cursor sharing
    Cursor Sharing List:GV$SQL_SHARED_CURSOR 中此 sql 的 cursor sharing
    Current Plans Summary (GV$SQL):GV$SQL 中此 sql 的平均消耗
    Current SQL Statistics (GV$SQL):GV$SQL 中此 sql 的消耗
    Historical Plans Summary (DBA_HIST_SQLSTAT):DBA_HIST_SQLSTAT 中此 sql 的历史平均消耗
    Historical SQL Statistics – Delta (DBA_HIST_SQLSTAT):DBA_HIST_SQLSTAT 中此 sql 的历史消耗
    Historical SQL Statistics – Total (DBA_HIST_SQLSTAT):DBA_HIST_SQLSTAT 中此 sql 的历史消耗
    Active Session History by Plan (GV$ACTIVE_SESSION_HISTORY):GV$ACTIVE_SESSION_HISTORY 中此 sql 的 session state 统计
    Active Session History by Plan Line (GV$ACTIVE_SESSION_HISTORY):GV$ACTIVE_SESSION_HISTORY 中此 sql 的 plan line 统计
    AWR Active Session History by Plan (DBA_HIST_ACTIVE_SESS_HISTORY):DBA_HIST_ACTIVE_SESS_HISTORY 中此 sql 的 session state 统计
    AWR Active Session History by Plan Line (DBA_HIST_ACTIVE_SESS_HISTORY):DBA_HIST_ACTIVE_SESS_HISTORY 中此 sql 的 plan line 统计
    DBMS_STATS System Preferences:DBMS_STATS 系统参数
    Tables: 表相关的统计信息
    DBMS_STATS Table Preferences:DBMS_STATS 表参数
    Table Columns: 列相关的统计信息
    Table Partitions: 表分区相关的统计信息
    Table Constraints: 表上的约束信息
    Tables Statistics Versions: 表相关的统计信息
    Indexes: 索引相关的统计信息
    Index Columns: 索引列相关的统计信息
    Index Partitions: 索引分区相关的统计信息
    Indexes Statistics Versions: 索引相关的统计信息
    System Parameters with Non-Default or Modified Values:GV$SYSTEM_PARAMETER2 中 isdefault = ‘FALSE’ OR ismodified != ‘FALSE’ 的参数
    Instance Parameters:V$SYSTEM_PARAMETER2 中的系统参数
    Metadata: 表和索引的建立语句
3_execution_plans.html
    SQL Text: 要检查的 sql 文本
    Current Execution Plans (last execution): 按 child cursor 显示此 sql 的内存中的执行计划
    Current Execution Plans (all executions): 按 child cursor 显示此 sql 的内存中的执行计划
    Historical Execution Plans: 按 child cursor 显示此 sql 的 awr 的执行计划
4_sql_detail.html
   图形化显示 sql 的运行统计
5_sql_monitor.zip
   图形化显示 sql 的监控信息
6_10053_trace_from_cursor.trc
   显示 sql 的 10053 跟踪文件
8_sqldx.zip
   sql health check 数据来源
9_log.zip
   sql health check 生成日志

更多 Oracle 相关信息见 Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-05/131478.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计4240字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中