Saturday 19 January 2013

How many SQL's are actually captured and displayed by AWR ?

While looking into a performance problem, we generally take an AWR report and directly look at the top resource consuming SQL statements. But what do you do when the most expensive SQL is missing from the AWR report ?
How do I check if my AWR report is complete and has captured all or most of the SQL statements ?

Let us have a look at this section of the AWR report.

WORKLOAD REPOSITORY report for

DB NameDB IdInstanceInst numReleaseRACHost
VISHAL-TEST9999999999VISHAL-TEST410.2.0.4.0YESabcd.host.com
Snap IdSnap TimeSessionsCursors/Session
Begin Snap:1830507-Jan-13 15:00:30381.6
End Snap:1830607-Jan-13 16:00:05381.6
Elapsed:59.59 (mins)
DB Time:58.40 (mins)

SQL ordered by Executions

  • Total Executions: 9,914
  • Captured SQL account for 68.9% of Total
ExecutionsRows ProcessedRows per ExecCPU per Exec (s)Elap per Exec (s)SQL IdSQL ModuleSQL Text
3,989420.010.000.00c4nhd1ntptxq7select message_level, sequenc...
71500.000.000.006ssrk2dqj7jbxselect job, nvl2(last_date, ...
2382381.000.000.00gj5r9jj2xad7fJDBC Thin ClientSELECT 1, status, '', arch...
1141141.000.000.000ws7ahf1d78qaselect SYS_CONTEXT('USERENV', ...
1141141.000.000.00459f3z9u4fb3uselect value$ from props$ wher...
1041,87218.000.000.000h6b2sajwb74nselect privilege#, level from ...
1041041.000.000.000k8522rmdzg4kselect privilege# from sysauth...
10400.000.000.001uzhrfn574t12sqlplus@vcd01024.ute.fedex.com (TNS V1-V3)SELECT ATTRIBUTE, SCOPE, NUMER...
1041041.000.000.005qgz1p0cut7mxsqlplus@vcd01024.ute.fedex.com (TNS V1-V3)BEGIN DBMS_OUTPUT.DISABLE; END...
1041041.000.000.005ur69atw3vfhjselect decode(failover_method,...
10400.000.000.00c4pc3jhzjcmc7sqlplus@vcd01024.ute.fedex.com (TNS V1-V3)SELECT CHAR_VALUE FROM SYSTEM....
1041041.000.000.00d6vwqbw6r2ffksqlplus@vcd01024.ute.fedex.com (TNS V1-V3)SELECT USER FROM DUAL
1041041.000.000.00dyk4dprp70d74SQL*PlusSELECT DECODE('A', 'A', '1', '...
1041041.000.000.00g4y6nw3tts7ccsqlplus@vcd01024.ute.fedex.com (TNS V1-V3)BEGIN DBMS_APPLICATION_INFO.SE...

It is very important to understand this section of the AWR report. 

Well, there are two things to consider.

1. How much data is being captured in the AWR repository ?
2. How much data is being displayed in the AWR report ?

Looking at this AWR report, I see total executions at 9914. (This number comes from DBA_HIST_SYSSTAT ). 68.9 % of this 9914 = 6830 executions were captured in the AWR repository.

What happened to the other SQL statements ? Why did Oracle fail to capture them ?
Could be the case where these missing SQL statements might have consumed a lot of CPU and that information is now lost.

By default AWR captues a snap every 1 hour. It takes a snap of V$SQL every hour and keeps this data safe in DBA_HIST_SQLSTAT and other related tables. Let us consider this scenario

At 10 AM - You take an AWR snap . S1
At 10.15 AM - You run a resource intensive SQL statement
At 10.45 AM -  SQL execution got completed. It has done a lot of damage by now.
At 10.50 AM - You flush the shared pool manually. / SQL gets aged out of shared pool automatically.
At 11 AM - You take another AWR snap S2

Now, if you generate an AWR report between these two snaps. You would see that the SQL which you ran is missing ! That's an interesting takeaway. AWR base tables are populated through V$SQL and if there is something missing in V$SQL, AWR too would miss the same.

Coming back to our AWR report, 
Total executions were - 9914
6830 executions were actually captured by the AWR repository.

Rest is lost ! ( Well, not completely, we will talk about ASH a little later. ASH takes samples every  second and may give us some more information )

Now lets us add up the numbers in the "executions" column of this AWR report. 

3989 + 715 + 238 + ... = 6106

AWR told us it captured 6830 executions, but when I add up these numbers I get 6106.
Well, this is quite simple. AWR does not display everything that is present in DBA_HIST_SQLSTAT
You can directly query DBA_HIST_SQLSTAT if you want to get a list of all the SQLs.

From 11.2 it is possible to control the number of SQL statements displayed in the AWR report. It defaults to 30 and can be altered using the following procedure.

SQL> exec dbms_workload_repository.awr_set_report_thresholds(top_n_sql=>50,top_n_sql_max=>50);





4 comments:

  1. Hi,
    Can i know AWR used which SQL query to capture information from V$SQL?

    ReplyDelete
    Replies
    1. Yes. Enable a 10046 trace on dbms_workload_repository.create_snapshot and you get all the SQL statements Oracle uses to populate DBA_HIST_SQLSTAT.

      Delete
    2. Nice presentation Vishal...Its really helps to know more about AWR in depth...Plz keep posting

      Delete
  2. This comment has been removed by the author.

    ReplyDelete

19c Multitenant RAC- Default service disables parallelism

We recently upgraded one of our RAC databases from 11.2 to 19.10 on Exadata. And to everyone's surprise, almost everything on the system...