|
 |
|
What SQL is included in AWR tables?
Oracle Database Tips by Donald BurlesonJanuary 22, 2015
|
Question: I am running
queries against my AWR tables to analyze historical SQL, and I don't
see all of the SQL in the AWR report.
I know that Oracle has a top-n threshold, but I
don't understand how Oracle chooses the SQL that gets moved from v$sql
into the AWR SQL table. Can you please explain how Oracle
determines what SQL gets into the AWR table?
I notice you have a script (rpt_sql.ksh) that
will report from the statspack tables… does it behave the same way?
Answer: AWR uses a "Top N" method which defaults to
collect the Top-30 SQL statements for each SQL category (statistics_level=typical).
If you set statistics_level = all, AWR will collect the
top 100 SQL statements.
The snap process collects information from v$sqlarea for SQL
statements (this part is wrapped code, and you can not see it).
If the library cache no longer has the SQL statement in it, then
it will not get snapped.
If
the SQL statement is not snapped on both the begin snap and end
snaps, Oracle will not be able to report on it. This can be seen
in the sprepins.sql script, which is the real body of
spreport.sql. An example of one of the SQL reports is seen
below. Note the sections marked in red. The SQL must exist in
stats$sql_summary table, and must be in this table for both the begin
and end snap value.
select aa, hv
from ( select /*+ ordered use_nl (b st) */
decode( st.piece
, 0
, lpad(to_char((e.buffer_gets -
nvl(b.buffer_gets,0))
,'99,999,999,999')
,15)||' '||
lpad(to_char((e.executions -
nvl(b.executions,0))
,'999,999,999')
,12)||' '||
lpad((to_char(decode(e.executions -
nvl(b.executions,0)
,0, to_number(null)
,(e.buffer_gets -
nvl(b.buffer_gets,0)) /
(e.executions -
nvl(b.executions,0)))
,'999,999,990.0'))
,14) ||' '||
lpad((to_char(100*(e.buffer_gets -
nvl(b.buffer_gets,0))/:gets
,'990.0'))
, 6) ||' '||
lpad( nvl(to_char( (e.cpu_time -
nvl(b.cpu_time,0))/1000000
, '9990.00')
, ' '),8) || ' ' ||
lpad( nvl(to_char( (e.elapsed_time -
nvl(b.elapsed_time,0))/1000000
, '99990.00')
, ' '),9) || ' ' ||
lpad(e.old_hash_value,10)||''||
decode(e.module,null,st.sql_text
,rpad('Module:
'||e.module,80)||st.sql_text)
, st.sql_text) aa
, e.old_hash_value hv
from stats$sql_summary e
, stats$sql_summary b
, stats$sqltext st
where b.snap_id(+) = :bid
and b.dbid(+) = e.dbid
and b.instance_number(+) = e.instance_number
and b.old_hash_value(+) = e.old_hash_value
and b.address(+) = e.address
and b.text_subset(+) = e.text_subset
and e.snap_id = :eid
and e.dbid = :dbid
and e.instance_number = :inst_num
and e.old_hash_value = st.old_hash_value
and e.text_subset = st.text_subset
and st.piece <= &&num_rows_per_hash
and e.executions > nvl(b.executions,0)
and 100*(e.buffer_gets - nvl(b.buffer_gets,0))/:gets >
&&top_pct_sql
order by (e.buffer_gets - nvl(b.buffer_gets,0)) desc,
e.old_hash_value, st.piece
)
where rownum < &&top_n_sql;

|
|