ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Oracle TOP Sql

Oracle TOP Sql

原创 Linux操作系统 作者:hicxlj 时间:2010-07-22 14:25:56 0 删除 编辑
--top 10 sql
SELECT   *
    FROM (SELECT   b.username username,
                     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 b.username = 'ZYK'
          ORDER BY rds_exec_ratio DESC)
   WHERE ROWNUM < 11
ORDER BY rds_exec_ratio DESC 



1.       识别’低效执行’的SQL语句
用下列SQL工具找出低效SQL:
SELECT EXECUTIONS , DISK_READS, BUFFER_GETS,
        ROUND((BUFFER_GETS-DISK_READS)/BUFFER_GETS,2) Hit_radio,
        ROUND(DISK_READS/EXECUTIONS,2) Reads_per_run,
        SQL_TEXT
FROM   V$SQLAREA
WHERE  EXECUTIONS>0
AND     BUFFER_GETS > 0 
AND (BUFFER_GETS-DISK_READS)/BUFFER_GETS < 0.8 
ORDER BY 4 DESC;

2.查找单条语句的内存占用率
alter system set pga_aggregate_target=10m
alter system set workarea_size_policy=auto;
select distinct * from a where rownum<500000;

select sql_text,operation_type,policy,(last_memory_used/1024/1024),
last_execution,last_tempseg_size
from v$sql i,v$sql_workarea a
where i.hash_value=a.hash_value
and sql_text='select distinct * from a where rownum<500000';


Top 10 by Buffer Gets:

set linesize 100
set pagesize 100
SELECT * FROM
(SELECT substr(sql_text,1,40) sql,
buffer_gets, executions, buffer_gets/executions "Gets/Exec",
hash_value,address
FROM V$SQLAREA
WHERE buffer_gets > 10000
ORDER BY buffer_gets DESC)
WHERE rownum <= 10
;

Top 10 by Physical Reads:

set linesize 100
set pagesize 100
SELECT * FROM
(SELECT substr(sql_text,1,40) sql,
disk_reads, executions, disk_reads/executions "Reads/Exec",
hash_value,address
FROM V$SQLAREA
WHERE disk_reads > 1000
ORDER BY disk_reads DESC)
WHERE rownum <= 10
;

Top 10 by Executions:

set linesize 100
set pagesize 100
SELECT * FROM
(SELECT substr(sql_text,1,40) sql,
executions, rows_processed, rows_processed/executions "Rows/Exec",
hash_value,address
FROM V$SQLAREA
WHERE executions > 100
ORDER BY executions DESC)
WHERE rownum <= 10
;

Top 10 by Parse Calls:

set linesize 100
set pagesize 100
SELECT * FROM
(SELECT substr(sql_text,1,40) sql,
parse_calls, executions, hash_value,address
FROM V$SQLAREA
WHERE parse_calls > 1000
ORDER BY parse_calls DESC)
WHERE rownum <= 10
;

Top 10 by Sharable Memory:

set linesize 100
set pagesize 100
SELECT * FROM 
(SELECT substr(sql_text,1,40) sql,
sharable_mem, executions, hash_value,address
FROM V$SQLAREA
WHERE sharable_mem > 1048576
ORDER BY sharable_mem DESC)
WHERE rownum <= 10
;

Top 10 by Version Count:

set linesize 100
set pagesize 100
SELECT * FROM 
(SELECT substr(sql_text,1,40) sql,
version_count, executions, hash_value,address
FROM V$SQLAREA
WHERE version_count > 20
ORDER BY version_count DESC)
WHERE rownum <= 10
;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/52280/viewspace-668740/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-09-10

  • 博文量
    19
  • 访问量
    46788