oracle-查看sql执行统计信息

简介:
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
set linesize 260 pagesize 10000
set long 10000
col module for a40;
col sql_id for a20;
col LAST_ACTIVE_TIME for a20
col last_load_time for a20 
col PLAN_TABLE_OUTPUT for a200
col instance_number format 9
col sql_text for a200
variable sql_id varchar2(64);
exec :sql_id:='&sql_id';
variable cursor_number number;

prompt **********************************************************
prompt                        SQL TEXT
prompt **********************************************************
select sql_text
from (
  select  distinct sql_text,piece
  from v$sqltext
  where sql_id = :sql_id
  order by piece)
/

prompt **********************************************************
prompt                        SQL PARENT CURSOR STAT
prompt **********************************************************
set linesize 500 pagesize 10000
col fetches for 999999999
col executions for 999999999
col loads for 9999
col invalidations for 9999
col version_count for 9999
col shared_pool_MB for 9999
col module for a30
col SQL_PROFILE for a30
col SQL_PLAN_BASELINE for a30
col prog_line for a20
col first_load_time for a20;
col last_load_time for a20;
col last_active_time for a20;
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
select fetches,
       executions,
       loads,
       invalidations,
       version_count,
       trunc(SHARABLE_MEM/1024/1024) shared_pool_MB,
       parse_calls,
       disk_reads,
       buffer_gets,
       ROWS_PROCESSED,
       elapsed_time/1000 elas_ms,
       cpu_time/1000 cpu_ms,
       first_load_time,
       last_load_time,
       last_active_time,
       module,
       decode(executions, 0, disk_reads, disk_reads / executions) reads_per,
       decode(executions, 0, buffer_gets, buffer_gets / executions) cr_per,
       decode(executions, 0, ROWS_PROCESSED, ROWS_PROCESSED / executions) row_per,
       decode(executions,
              0,
              elapsed_time / 1000000,
              elapsed_time / (executions * 1000)) elas_ms_per,
       decode(executions,
              0,
              cpu_time / 1000000,
              cpu_time / (executions * 1000)) cpu_ms_per,
       decode(executions,
              0,
              APPLICATION_WAIT_TIME / 1000000,
              APPLICATION_WAIT_TIME / (executions * 1000)) app_ms_per,
       decode(executions,
              0,
              CONCURRENCY_WAIT_TIME / 1000000,
              CONCURRENCY_WAIT_TIME / (executions * 1000)) concur_ms_per,
       decode(executions,
              0,
              CLUSTER_WAIT_TIME / 1000000,
              CLUSTER_WAIT_TIME / (executions * 1000)) clu_ms_per,
       decode(executions,
              0,
              USER_IO_WAIT_TIME / 1000000,
              USER_IO_WAIT_TIME / (executions * 1000)) IO_ms_per,
       SQL_PROFILE,
       SQL_PLAN_BASELINE,
       PROGRAM_ID||'-'||PROGRAM_LINE# prog_line
  from v$sqlarea
 where sql_id=:sql_id;

prompt **********************************************************
prompt                        SQL CHILD CURSOR STAT
prompt **********************************************************

SELECT
    sql_id,
    child_number,
    executions,
    loads,
    invalidations,
    plan_hash_value,
    last_active_time,
    first_load_time,
    last_load_time,
    decode(executions,0,buffer_gets,buffer_gets/executions) per_exec_buffer,
    decode(executions,0,elapsed_time/1000,elapsed_time/executions/1000) per_exec_ela_ms
    from v$sql
WHERE
    sql_id =:sql_id
ORDER BY
    last_active_time;

prompt **********************************************************
prompt                        SQL CURSOR LAST PLAN
prompt **********************************************************

declare
begin
select child_number into :cursor_number from 
(select child_number from v$sql where sql_id=:sql_id order by last_active_time desc)
where rownum=1;
end;
/

select * from table(dbms_xplan.display_cursor(:sql_id,:cursor_number,'ADVANCED'));

prompt **********************************************************
prompt                        SQL CURSOR AWR
prompt **********************************************************


select *
  from (select to_char(begin_interval_time,'yyyy-mm-dd hh24:mi:ss') begin_time, 
  to_char(end_interval_time,'yyyy-mm-dd hh24:mi:ss') end_time, 
               a.instance_number,
               module,
               plan_hash_value,
               EXECUTIONS_DELTA exec,
               decode(EXECUTIONS_DELTA,
                      0,
                      buffer_gets_deltA,
                      round(BUFFER_GETS_DELTA / EXECUTIONS_DELTA)) per_get,
               decode(EXECUTIONS_DELTA,
                      0,
                      ROWS_PROCESSED_DELTA,
                      round(ROWS_PROCESSED_DELTA / EXECUTIONS_DELTA, 3)) per_rows,
               decode(EXECUTIONS_DELTA,
                      0,
                      ELAPSED_TIME_DELTA,
                      round(ELAPSED_TIME_DELTA / EXECUTIONS_DELTA / 1000,
                            2)) time_ms,
               decode(EXECUTIONS_DELTA,
                      0,
                      DISK_READS_DELTA,
                      round(DISK_READS_DELTA / EXECUTIONS_DELTA, 2)) per_read
          from dba_hist_sqlstat a, DBA_HIST_SNAPSHOT b
         where a.snap_id = b.snap_id
           and a.instance_number = b.instance_number
           and a.sql_id = :sql_id 
         order by 1 desc)
 where rownum < 50;

prompt **********************************************************
prompt                        SQL CURSOR ASH 
prompt **********************************************************

select * from (
SELECT
    SQL_PLAN_HASH_VALUE,
    sql_plan_line_id, 
    nvl(event,'ON CPU'),
    COUNT(*)
FROM
    v$active_session_history
WHERE
    sql_id = :sql_id 
    AND sample_time > SYSDATE-30/1440
GROUP BY
    SQL_PLAN_HASH_VALUE,sql_plan_line_id,nvl(event,'ON CPU')
ORDER BY
    count(*) DESC)
where rownum<=20;

prompt **********************************************************
prompt                        SQL CURSOR MONITOR
prompt **********************************************************

SET LONG 1000000
SET LONGCHUNKSIZE 1000000
SET LINESIZE 1000
SET PAGESIZE 0
SET TRIM ON
SET TRIMSPOOL ON
SET ECHO OFF
SET FEEDBACK OFF
SELECT DBMS_SQLTUNE.REPORT_SQL_MONITOR(
  SQL_ID       => :sql_id,
  TYPE         => 'TEXT',
  REPORT_LEVEL => 'ALL') AS REPORT
FROM dual;












目录
相关文章
|
2月前
|
XML SQL 数据格式
XML动态sql查询当前时间之前的信息报错
XML动态sql查询当前时间之前的信息报错
46 2
|
3天前
|
SQL Java
使用java在未知表字段情况下通过sql查询信息
使用java在未知表字段情况下通过sql查询信息
11 1
|
2月前
|
SQL 流计算
Flink SQL 在快手实践问题之由于meta信息变化导致的state向前兼容问题如何解决
Flink SQL 在快手实践问题之由于meta信息变化导致的state向前兼容问题如何解决
39 1
|
2月前
|
SQL JSON Go
Go - 基于 GORM 获取当前请求所执行的 SQL 信息
Go - 基于 GORM 获取当前请求所执行的 SQL 信息
41 3
|
3月前
|
SQL 缓存 关系型数据库
面试题MySQL问题之实现覆盖索引如何解决
面试题MySQL问题之实现覆盖索引如何解决
43 1
|
3月前
|
SQL 机器学习/深度学习 分布式计算
MaxCompute产品使用合集之怎么使用SQL查询来获取ODPS中所有的表及字段信息
MaxCompute作为一款全面的大数据处理平台,广泛应用于各类大数据分析、数据挖掘、BI及机器学习场景。掌握其核心功能、熟练操作流程、遵循最佳实践,可以帮助用户高效、安全地管理和利用海量数据。以下是一个关于MaxCompute产品使用的合集,涵盖了其核心功能、应用场景、操作流程以及最佳实践等内容。
|
3月前
|
SQL Oracle 关系型数据库
|
3月前
|
SQL Oracle 关系型数据库
MySQL、SQL Server和Oracle数据库安装部署教程
数据库的安装部署教程因不同的数据库管理系统(DBMS)而异,以下将以MySQL、SQL Server和Oracle为例,分别概述其安装部署的基本步骤。请注意,由于软件版本和操作系统的不同,具体步骤可能会有所变化。
165 3
|
3月前
|
SQL 存储 Oracle
TDengine 3.3.2.0 发布:新增 UDT 及 Oracle、SQL Server 数据接入
**TDengine 3.3.2.0 发布摘要** - 开源与企业版均强化性能,提升WebSocket、stmt模式写入与查询效率,解决死锁,增强列显示。 - taos-explorer支持geometry和varbinary类型。 - 企业版引入UDT,允许自定义数据转换。 - 新增Oracle和SQL Server数据接入。 - 数据同步优化,支持压缩,提升元数据同步速度,错误信息细化,支持表名修改。 - 扩展跨平台支持,包括麒麟、Euler、Anolis OS等。
94 0
|
3月前
|
Oracle 关系型数据库
oracle收集统计信息,游标失效时间
Dbms_stats Invalidates Cursors in Auto_invalidate mode
33 0
下一篇
无影云桌面