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

SQL脚本:查询指定SQL的统计信息(cursor,awr)

我们的文章会在微信公众号IT民工的龙马人生和博客网站( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢!
由于博客中有大量代码,通过页面浏览效果更佳。

SQL脚本:查询指定SQL的统计信息(cursor,awr)

1,从cursor中查询指定sql的统计信息

set echo off
set lines 300
set verify off

欢迎大家加入ORACLE超级群:17115662 免费解决各种ORACLE问题,以后BLOG将迁移到http://www.htz.pw

set serveroutput on
set feedback off
set lines 300
set pages 10000
set long 100000
set lines 300
set echo off
set verify off
col sql_id for a18
col i_mem for 999999 heading ‘SHARED|Mem KB’
col sorts for 99999999
col version_count for 999 heading ‘VER|NUM’
col executions for 999999 heading ‘EXEC|NUM’
col parse_calls for 999999 heading ‘PARSE|CALLS’
col disk_reads for 999999 heading ‘DISK|READ’
col direct_writes for 999999 heading ‘DIRECT|WRITE’
col buffer_gets for 99999999999999
col avg_disk_reads for 99999 heading ‘AVG|DISK|READ’
col avg_direct_writes for 99999 heading ‘AVG|DIRECT|WRITE’
col avg_buffer_gets for 9999999 heading ‘AVG|BUFFER|GET’
col sql_profile for a14
col ROWS_PROCESSED for 999999999 heading ‘ROW|PROC’
col avg_rows_processed for 99999999 heading ‘AVG|ROW|PROC’
col  avg_fetches for 999999 heading ‘AVG|FETCH’
col AVG_ELAPSED_TIME  for 9999999 heading ‘AVG|ELAPSED|TIME’
col AVG_CPU_TIME for 9999999 heading ‘AVG|CPU_TIME’
col PARSING_SCHEMA_NAME  for a15 heading ‘PARSING|SCHEMA_NAME’
SELECTplan_hash_value,parsing_schema_name,(executions) executions,(elapsed_time) elapsed_time,TRUNC ( (elapsed_time) / DECODE ( (executions), 0, 1, (executions)))avg_elapsed_time,(cpu_time) cpu_time,TRUNC ( (cpu_time) / DECODE ( (executions), 0, 1, (executions)))avg_cpu_time,(buffer_gets) buffer_gets,TRUNC ( (buffer_gets) / DECODE ( (executions), 0, 1, (executions)))avg_buffer_gets,(disk_reads) disk_reads,TRUNC ( (disk_reads) / DECODE ( (executions), 0, 1, (executions)))avg_disk_reads,(direct_writes) direct_writes,TRUNC ( (direct_writes) / DECODE ( (executions), 0, 1, (executions)))avg_direct_writes,(rows_processed) rows_processed,TRUNC ( (rows_processed) / DECODE ( (executions), 0, 1, (executions)))avg_rows_processed,(fetches) fetches,TRUNC ( (fetches) / DECODE ( (executions), 0, 1, (executions)))avg_fetches
from table(DBMS_SQLTUNE.SELECT_CURSOR_CACHE(‘sql_id = ”&sql_id”’));undefine begin_snap;
undefine sql_id;
undefine end_snap;
undefine sort_type;
undefine topn;

2,从awr中查询指定sql的统计信息

set echo off
set lines 300
set verify off
set serveroutput on
set feedback off
set lines 300
set pages 10000
set long 100000
@awr_snapshot_info.sql
set lines 300
set echo off
set verify off
col sql_id for a18
col i_mem for 999999 heading ‘SHARED|Mem KB’
col sorts for 99999999
col version_count for 999 heading ‘VER|NUM’
col executions for 999999 heading ‘EXEC|NUM’
col parse_calls for 999999 heading ‘PARSE|CALLS’
col disk_reads for 999999 heading ‘DISK|READ’
col direct_writes for 999999 heading ‘DIRECT|WRITE’
col buffer_gets for 99999999999999
col avg_disk_reads for 99999 heading ‘AVG|DISK|READ’
col avg_direct_writes for 99999 heading ‘AVG|DIRECT|WRITE’
col avg_buffer_gets for 9999999 heading ‘AVG|BUFFER|GET’
col sql_profile for a14
col ROWS_PROCESSED for 999999999 heading ‘ROW|PROC’
col avg_rows_processed for 99999999 heading ‘AVG|ROW|PROC’
col  avg_fetches for 999999 heading ‘AVG|FETCH’
col AVG_ELAPSED_TIME  for 9999999 heading ‘AVG|ELAPSED|TIME’
col AVG_CPU_TIME for 9999999 heading ‘AVG|CPU_TIME’
col PARSING_SCHEMA_NAME  for a15 heading ‘PARSING|SCHEMA_NAME’
SELECTplan_hash_value,parsing_schema_name,(executions) executions,(elapsed_time) elapsed_time,TRUNC ( (elapsed_time) / DECODE ( (executions), 0, 1, (executions)))avg_elapsed_time,(cpu_time) cpu_time,TRUNC ( (cpu_time) / DECODE ( (executions), 0, 1, (executions)))avg_cpu_time,(buffer_gets) buffer_gets,TRUNC ( (buffer_gets) / DECODE ( (executions), 0, 1, (executions)))avg_buffer_gets,(disk_reads) disk_reads,TRUNC ( (disk_reads) / DECODE ( (executions), 0, 1, (executions)))avg_disk_reads,(direct_writes) direct_writes,TRUNC ( (direct_writes) / DECODE ( (executions), 0, 1, (executions)))avg_direct_writes,(rows_processed) rows_processed,TRUNC ( (rows_processed) / DECODE ( (executions), 0, 1, (executions)))avg_rows_processed,(fetches) fetches,TRUNC ( (fetches) / DECODE ( (executions), 0, 1, (executions)))avg_fetchesFROM TABLE (DBMS_SQLTUNE.select_workload_repository (&begin_id,&end_id,‘sql_id=”&sqlid”’));
undefine begin_id;
undefine sqlid;
undefine end_id;

3,从sqlset中查看统计信息

set echo off
set lines 300
set verify off
set serveroutput on
set feedback off
set lines 300
set pages 10000
set long 100000
set lines 300
set echo off
set verify off
col sql_id for a15
col executions for 999999 heading ‘EXEC|NUM’
col parse_calls for 999999 heading ‘PARSE|CALLS’
col disk_reads for 999999 heading ‘DISK|READ’
col direct_writes for 999999 heading ‘DIRECT|WRITE’
col buffer_gets for 9999999999
col avg_disk_reads for 99999 heading ‘AVG|DISK|READ’
col avg_direct_writes for 99999 heading ‘AVG|DIRECT|WRITE’
col avg_buffer_gets for 999999 heading ‘AVG|BUFFER|GET’
col sql_profile for a14
col ROWS_PROCESSED for 999999 heading ‘ROW|PROC’
col avg_rows_processed for 99999 heading ‘AVG|ROW|PROC’
col avg_fetches for 99999 heading ‘AVG|FETCH’
col fetches for 9999999 heading ‘AVG|FETCH’
col AVG_ELAPSED_TIME  for 999999 heading ‘AVG|ELAPSED|TIME’
col AVG_CPU_TIME for 9999999 heading ‘AVG|CPU_TIME’
col PARSING_SCHEMA_NAME  for a15 heading ‘PARSING|SCHEMA_NAME’
col plan_hash_value for 99999999999 heading ‘PLAN|HASH_VALUE’col name for a30
col owner for a15
col description for a50
col sqlset_name for a20
SELECT a.id,a.name,a.owner,a.description,to_char(a.created,’yy-mm-dd’) created,to_char(a.last_modified,’yy-mm-dd hh24:mi’) last_modified,a.statement_count sql_countFROM dba_sqlset a
order by a.id/
SELECT sqlset_name,sql_id,plan_hash_value,parsing_schema_name,(executions) executions,(elapsed_time) elapsed_time,TRUNC ( (elapsed_time) / DECODE ( (executions), 0, 1, (executions)))avg_elapsed_time,(cpu_time) cpu_time,TRUNC ( (cpu_time) / DECODE ( (executions), 0, 1, (executions)))avg_cpu_time,(buffer_gets) buffer_gets,TRUNC ( (buffer_gets) / DECODE ( (executions), 0, 1, (executions)))avg_buffer_gets,(disk_reads) disk_reads,TRUNC ( (disk_reads) / DECODE ( (executions), 0, 1, (executions)))avg_disk_reads,(direct_writes) direct_writes,TRUNC ( (direct_writes) / DECODE ( (executions), 0, 1, (executions)))avg_direct_writes,(rows_processed) rows_processed,TRUNC ( (rows_processed) / DECODE ( (executions), 0, 1, (executions)))avg_rows_processed,(fetches) fetches,TRUNC ( (fetches) / DECODE ( (executions), 0, 1, (executions)))avg_fetchesFROM DBA_SQLSET_STATEMENTS
WHERE     sqlset_name = NVL (UPPER (‘&sqlset_name’), sqlset_name)AND sql_id = NVL (‘&sql_id’, sql_id);
undefine begin_snap;
undefine sql_id;
undefine end_snap;
undefine sort_type;
undefine topn;

------------------作者介绍-----------------------
姓名:黄廷忠
现就职:Oracle中国高级服务团队
曾就职:OceanBase、云和恩墨、东方龙马等
电话、微信、QQ:18081072613
个人博客: (http://www.htz.pw)
CSDN地址: (https://blog.csdn.net/wwwhtzpw)
博客园地址: (https://www.cnblogs.com/www-htz-pw)

http://www.rkmt.cn/news/8015.html

相关文章:

  • 本地(或自下载)浏览器插件 安装指南
  • 路由查看命令
  • Linux 基础命令01
  • 面向多模态检索的向量数据库对比分析和技术选型:Elasticsearch、Milvus、Pinecone、FAISS、Chroma、PGVector、Weaviate、Qdrant
  • 终结AI幻觉:Amazon Bedrock如何用形式化方法重塑可信AI
  • 技术解读 | OceanBase 数据库诊断与调优的关键技术与方法
  • 我代表编程导航,向大家道歉!
  • cf div2 1051 E(视角转换,构造+思维)
  • openHarmony之开源三方库zlib适配讲解 - 实践
  • phoenix 导出sql执行结果到文件中
  • LK32V12A 过压/过流保护开关芯片 OVP过压45V 过流2.2A电流 SOT-23L
  • 深入解析:HTML元素周期表
  • APP 内测分发的核心逻辑与流程,虾分发让效率翻倍
  • 深入解析:【vue+exceljs+file-saver】纯前端:下载excel和上传解析excel
  • 解码C语言关键字
  • Windows环境中安装Zookeeper
  • ​​电流探头选型技术指南:精准捕获电流信号的艺术​​
  • slurm启动验证命令
  • 实用指南:LeetCode //C - 836. Rectangle Overlap
  • 深入解析:[Android] 安卓手机翻页时钟Flip Clock - World Clock v1.5.0.0
  • 深入解析:多模态大模型3:TAViS
  • 基于STM32F103C8T6与DS18B20的温度测量系统
  • Oxygen Forensic Detective 18.0 发布,新增功能简介
  • Windows如何美化cmd窗口
  • MX Round 7 解题报告
  • 实用指南:售价3499美元,英伟达Jetson Thor实现机器人与物理世界的实时智能交互
  • 逻辑回归 vs 支持向量机 vs 随机森林:哪个更适合小数据集? - 指南
  • 券多多系统-开发记录
  • US$189 Yanhua Mini ACDP Module3 Read amp; Write BMW DME ISN Code by OBD
  • React 状态丢失:组件 key 用错引发的渲染异常 - 指南