Home » SQL & PL/SQL » SQL & PL/SQL » How to get list of top 15 sql order by by buffer gets (11.2.0.3)
How to get list of top 15 sql order by by buffer gets [message #630491] Mon, 29 December 2014 05:10 Go to next message
kytemanaic
Messages: 55
Registered: February 2009
Member
Hi all,

I'm trying to get a list of sql ordered by buffer gets

SELECT * FROM(
SELECT ROW_NUMBER () OVER (ORDER BY sql_ordered_by_gets.BUFFER_GETS_TOTAL DESC) rn, sql_ordered_by_gets.* FROM(
SELECT DISTINCT sql.SQL_ID
,BUFFER_GETS_TOTAL
, EXECUTIONS_TOTAL
--,  BUFFER_GETS_TOTAL/EXECUTIONS_TOTAL "Gets Per Exec"
,total_buffer_gets.total_buffer_gets
, round(dhs.BUFFER_GETS_TOTAL/total_buffer_gets.total_buffer_gets*100,1) per_cent_buffer_total
,ELAPSED_TIME_TOTAL/1000000 elapsed_time
,round(CPU_TIME_TOTAL/ELAPSED_TIME_TOTAL*100,0) "%CPU"
, round(IOWAIT_TOTAL/ELAPSED_TIME_TOTAL*100,1) "%IO"
,dhs.MODULE
,sql.SQL_TEXT
FROM dba_hist_sqlstat dhs ,v$instance inst, v$sql sql
,(SELECT sum(BUFFER_GETS_TOTAL) total_buffer_gets FROM dba_hist_sqlstat dhs
JOIN v$instance inst
ON inst.INSTANCE_NUMBER = dhs.INSTANCE_NUMBER
JOIN v$sql sql
ON sql.sql_id = dhs.SQL_ID
AND dhs.INSTANCE_NUMBER=1
WHERE dhs.SNAP_ID=3482
AND dhs.EXECUTIONS_TOTAL>0
) total_buffer_gets
WHERE SNAP_ID=3482
AND dhs.INSTANCE_NUMBER=1
--AND dhs.sql_id='0a59tkkpx31vx'
AND inst.INSTANCE_NUMBER = dhs.INSTANCE_NUMBER
AND sql.sql_id= dhs.SQL_ID
--AND EXECUTIONS_TOTAL>0
) sql_ordered_by_gets
) WHERE rn>=1 and rn<=100;



when compare to AWR, it seems that my %total, i.e. %Total - Buffer Gets as a percentage of Total Buffer Gets, the figure seems to get wrong, could appreciate if someone could point out what's wrong with my sql.

thanks a lot!
Re: How to get list of top 15 sql order by by buffer gets [message #630493 is a reply to message #630491] Mon, 29 December 2014 05:39 Go to previous messageGo to next message
Roachcoach
Messages: 1576
Registered: May 2010
Location: UK
Senior Member
I'm 99(.999)% sure sql developer has reports on this which can give the sql to you.
Re: How to get list of top 15 sql order by by buffer gets [message #630500 is a reply to message #630491] Mon, 29 December 2014 06:36 Go to previous messageGo to next message
Michel Cadot
Messages: 68771
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Maybe you should first learn how to format a SQL query to make it readable and maintainable.
If you don't know how to do it, learn it using SQL Formatter.

[Updated on: Mon, 29 December 2014 06:37]

Report message to a moderator

Re: How to get list of top 15 sql order by by buffer gets [message #630508 is a reply to message #630500] Mon, 29 December 2014 08:49 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>could appreciate if someone could point out what's wrong with my sql.

use same SELECT as AWR uses
Previous Topic: LONG to VARCHAR2 conversion using dblink
Next Topic: Problem with nested FOR Loop
Goto Forum:
  


Current Time: Mon Dec 01 05:59:37 CST 2025