• 一些性能查询的SQL 备忘


    --检查数据库的等待事件

    from v$session_wait
    where event not like 'SQL%' and event not like 'rdbms%'

    --找出系统中耗时的操作
    select b.username username,a.disk_reads reads,
           a.executions exec,a.disk_reads/decode(a.executions,0,1,a.executions)
               rds_exec_ratio,
           a.sql_text statement
    from v$sqlarea a,dba_users b
    where a.parsing_user_id=b.user_id
    and   a.disk_reads >100000
    order by a.disk_reads desc;

    --查看buffer中耗时的操作
    select * from
      (select address,rank() over( order by buffer_gets desc) as rank_bufgets,
       to_char(100*ratio_to_report(buffer_gets) over(),'999.99') pct_bufgets
       from v$sql )
      where rank_bufgets <11;

    -- 查看buffer中耗时的操作
    select * from
      (select sql_text,rank() over( order by buffer_gets desc) as rank_bufgets,
       to_char(100*ratio_to_report(buffer_gets) over(),'999.99') pct_bufgets
       from v$sql )
      where rank_bufgets <11;


    --查找前十条性能差的SQL
    select * from (select parsing_user_id
    executions,sorts,command_type,disk_reads,
    sql_text from v$sqlarea order by disk_reads desc)
    where rownum<10;

    --等待时间最多的5和系统等待事件的获取
     select * from (select *
     from v$system_event where event not like 'sql%' order by
    total_waits desc) where rownum<=5

    --检查运行很久的SQL
    column username format a12
    column opname format a16
    column progress format a8
    SELECT USERNAME,SID,OPNAME,ROUND(SOFAR*100 / TOTALWORK,0) || '%' AS
    PROGRESS,TIME_REMAINING,SQL_TEXT FROM V$SESSION_LONGOPS , V$SQL WHERE TIME_REMAINING <>
    0 AND SQL_ADDRESS=ADDRESS AND SQL_HASH_VALUE = HASH_VALUE;

    --检查消耗CPU最高的进程
    SET LINE 240
    SET VERIFY OFF
    COLUMN SID FORMAT 999
    COLUMN PID FORMAT 999
    COLUMN S_# FORMAT 999
    COLUMN USERNAME FORMAT A9 HEADING "ORA USER"
    COLUMN PROGRAM FORMAT A29
    COLUMN SQL FORMAT A60
    COLUMN OSNAME FORMAT A9 HEADING "OS USER"
    SELECT P.PID PID,S.SID SID,P.SPID SPID,S.USERNAME USERNAME,S.OSUSER OSNAME,P.SERIAL#
    S_#,P.TERMINAL,P.PROGRAM PROGRAM,P.BACKGROUND,S.STATUS,RTRIM(SUBSTR(A.SQL_TEXT, 1, 80))
    SQLFROM V$PROCESS P, V$SESSION S,V$SQLAREA A WHERE P.ADDR = S.PADDR AND S.SQL_ADDRESS
    = A.ADDRESS (+) AND P.SPID LIKE '%&1%';


    --检查碎片程度高的表
     select segment_name table_name,count(*)
    extents from dba_segments where owner not in ('sys','system')
    group by segment_name having count(*)=(select max(count(*))
    from dba_segments group by segment_name) ;

    --检查表空间的1/O比例
     select df.tablespace_name name,df.file_name "FILE",
    F.phyrds pyr,f.phyblkrd pbr,f.phywrts pyw,f.phyblkwrt pbw from v$filestat f,
    dba_data_files df
    where f.file#=df.file_id order by df.tablespace_name;


    select df.tablespace_name name,df.file_name "File"
    from v$filestat f,dba_data_files df
    where f.file#=df.file_id
    order by tablespace_name


    --检测文件系统的I/O比例

    select substr(a.file#,1,2) "#",substr(a.name,1,30) "NAME",
    a.status,a.bytes,b.phyrds,b.phywrts
    from v$datafile a,
    v$filestat b
    where a.file# = b.file#

    --检查死锁及处理
    select sid,serial#,username,schemaname,osuser,machine,
    terminal,program,owner,object_name,object_type,o.object_id
    from dba_objects o,v$locked_object l,v$session s
    where o.object_id=l.object_id and s.sid=l.session_id;

  • 相关阅读:
    Java 对象的内存布局(HotSpot 实现)
    HDFS 伪分布式环境搭建
    Java 多线程(四):锁(二)
    使用二叉树的递归套路来解决的问题
    乘积小于 K 的子数组
    Netty 学习(三):通信协议和编解码
    HDFS 分布式环境搭建
    Netty 学习(一):服务端启动 & 客户端启动
    累加和为 K 的最长子数组问题
    使用单调栈来解决的一些问题
  • 原文地址:https://www.cnblogs.com/tdskee/p/5949555.html
Copyright © 2020-2023  润新知