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

news/2025/9/19 15:33:13/文章来源:https://www.cnblogs.com/www-htz-pw/p/19100956

我们的文章会在微信公众号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.mzph.cn/news/907862.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

k8s学习笔记8——Service

k8s学习笔记8——Service容器带来的问题自动调度: 在Pod创建之前,用户无法预知Pod所在节点以及Pod的IP地址 一个已经存在的Pod在运行过程中,出现故障,Pod也会在新的节点使用新的IP进行部署 应用程序访问服务时,地址是不…

逆向分析之if语句与循环语句的分析

前言 本次我们要介绍if语句,for循环编译后的反汇编内容,以C/C++编写的可执行程序为例进行分析 一只Demo 首先是一只Demo,是我们本次分析对象的源码 #include <stdio.h>void if_demo(int v) {if (v > 5)pri…

读书笔记:索引组织表(IOT):让数据库查询飞起来的黑科技

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

AI 自动化智能体训练营

课程背景与解决的问题 你是否也有这样的困扰? 每天被大量重复劳动占据时间? 报表、PPT、文案写得慢,效率低? 想用 AI 提高效率,却不知道从哪入手? 想做副业/创业,但缺乏技术与工具? 👉 这门训练营,将带你从…

ROMA-iOS适配深色模式总结

一、背景深色模式在低光环境下(如夜间使用)可以显著减少屏幕发出的蓝光,降低眼睛疲劳,减轻视觉压力。深色背景配合浅色文字能提供更好的对比度和可读性,减少眩光,让内容更易于阅读。深色模式还可以显著节省电量,…

本地(或自下载)浏览器插件 安装指南

1 首先准备好安装包 通过不用渠道下载所要安装插件的压缩包 2 安装流程 第一步 解压 解压压缩包至文件夹中,请确保您的电脑上已安装解压工具,否则会解压失败 1)mac系统中,双击压缩包即可完成解压。 2)win系统解压…

Docker是什么?最全Docker使用教程(小白到高手) - 实践

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

408学习之c语言(结构体) - 教程

408学习之c语言(结构体) - 教程pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco&q…

路由查看命令

路由查看命令多网卡,软路由设置route print //查看当前路由表route print -4 //查看当前IPv4路由表网络目标,网络掩码,网关,跃点数route print //查看当前路由表route print -4 //查看当前IPv4路由表route delete …

Linux 基础命令01

一、线上查询及帮助命令 1.1 man root@ubuntu2204:~/test 14:28:16 # man ls1.2 help root@ubuntu2204:~/test 14:30:00 # ls --help1.3 info root@ubuntu2204:~/test 14:30:47 # info ls二、文件和目录操作命令 2.1 l…

Git 指令笔记 - 详解

Git 指令笔记 - 详解pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "…

Syntax Error: TypeError: eslint.CLIEngine is not a constructor 解决方案

Syntax Error: TypeError: eslint.CLIEngine is not a constructor 解决方案 删除 package-lock.json 然后 删除 node_modules 从新 npm install 然后再revert package-lock.json (别动项目文件)(如果按新包了,再区…

TDMQ CKafka 版客户端实战指南系列之一:生产最佳实践

TDMQ CKafka 版客户端实战指南系列之一:生产最佳实践导语 在当今数字化时代,数据的产生和流动呈爆发式增长,消息队列作为一种高效的数据传输和处理工具,在各种应用场景中发挥着关键作用。TDMQ CKafka 版作为一款分…

【ACM出版】2025年人工智能、虚拟现实与交互设计国际学术会议(AIVRID 2025)

2025年人工智能、虚拟现实与交互设计国际学术会议(AIVRID 2025)将于2025年10月17-19日在中国广东省东莞市召开。【ACM出版社出版-高录用,快检索-最快见刊后1个月EI & Scopus检索】 【海内外高校、IEEE Fellow等…

《sklearn机器学习——特征提取》 - 指南

《sklearn机器学习——特征提取》 - 指南pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "M…

Windows 10 11 Boot Fix

修復啟動程式碼Bootrec.exe 例如主開機記錄、開機設定資料儲存 (BCD) 和開機磁區。 更新主開機記錄和開機磁區程式碼來修復問題。修復引導程式碼 步驟1.按「Windows + S」開啟搜尋框。然後,在其中鍵入cmd 或命令提示符…

ubuntu 安装 milvus

docker 是 引擎,是底层的基础工具。它用于管理单个容器(Container)的生命周期(构建、运行、停止、删除)。 docker-compose 是 编排工具,是上层的操作界面。它用于定义和运行由多个容器组成的、相互关联的整套应用…

完整教程:MySQL并发问题解析

完整教程:MySQL并发问题解析2025-09-19 15:02 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important…

面向多模态检索的向量数据库对比分析和技术选型:Elasticsearch、Milvus、Pinecone、FAISS、Chroma、PGVector、Weaviate、Qdrant

目录1.向量数据库1.1 Elasticsearch 1.2 Milvus 1.3 Pinecone 1.4 FAISS 1.5 Chroma 1.6 PGVector 1.7 Weaviate 1.8 Qdrant2.向量数据库对比分析 3.多模态大规模图文检索选型3.1需求分析 3.2推荐方案 3.3实施建议 1.…

SI/PI学习笔记1 -20250911

SI/PI学习笔记1 -20250911作为硬件测试工程师,随着信号传输速度的迭代升级,分析信号和电源完整性将成为一个必然的趋势。SI全称为Signal Integrity 信号完整性,PI全称为Power Integrity 电源完整性。 从测试方面来…