Oracle Scratchpad

March 27, 2015

ASH

Filed under: Infrastructure,Oracle,Troubleshooting — Jonathan Lewis @ 9:41 am GMT Mar 27,2015

There was a little conversation on the Oracle-L list server about ASH (active session history) recently which I thought worth highlighting – partly because it raised a detail that I had got wrong until Tim Gorman corrected me a few years ago.

Once every second the dynamic performance view v$active_session_history copies information about active sessions from v$session. (There are a couple of exceptions to the this rule – for example if a session has called dbms_lock.sleep() it will appear in v$session as status = ‘ACTIVE’ and state = ‘WAITING’ but at present it will not be recorded in v$active_session_history.) Each of these snapshots is referred to as a “sample” and is given a sample_id and sample_time and a sample may hold zero, one, or many rows.

The rows collected in every tenth sample are flagged for copying into the AWR (automatic workload repository) where, once they’ve been copied into the underlying table, they can be seen in the view dba_hist_active_sess_history.  This is where a common misunderstanding occurs: it is not every 10th row from v$active_session_history that is copied it’s every 10th second/sample; and if a sample happens to be empty that’s still the sample that is selected (which means there will be a gap in the output from dba_hist_active_sess_history). In effect dba_hist_active_sess_history holds copies of the information you’d get from v$session if you sampled it once every 10 seconds instead of once per second.

It’s possible to corroborate this through a fairly simple query because the rows that are going to be dumped from v$active_session_history to the AWR are flagged as they are created:


select
        distinct case is_awr_sample when 'Y' then 'Y' end flag,
        sample_id,
        sample_time
from
        v$active_session_history
where
        sample_time > sysdate - 1/1440
order by
        2,1
;

F  SAMPLE_ID SAMPLE_TIME
- ---------- --------------------------------
     3435324 26-MAR-15 05.52.53.562 PM
     3435325 26-MAR-15 05.52.54.562 PM
     3435326 26-MAR-15 05.52.55.562 PM
     3435327 26-MAR-15 05.52.56.562 PM
     3435328 26-MAR-15 05.52.57.562 PM
     3435329 26-MAR-15 05.52.58.562 PM
     3435330 26-MAR-15 05.52.59.562 PM
     3435331 26-MAR-15 05.53.00.562 PM
Y    3435332 26-MAR-15 05.53.01.562 PM
     3435333 26-MAR-15 05.53.02.572 PM
     3435334 26-MAR-15 05.53.03.572 PM
     3435335 26-MAR-15 05.53.04.572 PM
     3435336 26-MAR-15 05.53.05.572 PM
     3435337 26-MAR-15 05.53.06.572 PM
     3435338 26-MAR-15 05.53.07.572 PM
     3435339 26-MAR-15 05.53.08.572 PM
     3435340 26-MAR-15 05.53.09.572 PM
     3435341 26-MAR-15 05.53.10.582 PM
Y    3435342 26-MAR-15 05.53.11.582 PM
     3435343 26-MAR-15 05.53.12.582 PM
     3435344 26-MAR-15 05.53.13.582 PM
     3435345 26-MAR-15 05.53.14.582 PM
     3435346 26-MAR-15 05.53.15.582 PM
     3435347 26-MAR-15 05.53.16.582 PM
     3435348 26-MAR-15 05.53.17.582 PM
     3435349 26-MAR-15 05.53.18.592 PM
     3435350 26-MAR-15 05.53.19.592 PM
     3435351 26-MAR-15 05.53.20.592 PM
Y    3435352 26-MAR-15 05.53.21.602 PM
     3435355 26-MAR-15 05.53.24.602 PM
     3435358 26-MAR-15 05.53.27.612 PM
     3435361 26-MAR-15 05.53.30.622 PM
     3435367 26-MAR-15 05.53.36.660 PM
     3435370 26-MAR-15 05.53.39.670 PM
     3435371 26-MAR-15 05.53.40.670 PM
     3435373 26-MAR-15 05.53.42.670 PM
     3435380 26-MAR-15 05.53.49.700 PM
     3435381 26-MAR-15 05.53.50.700 PM
Y    3435382 26-MAR-15 05.53.51.700 PM
     3435383 26-MAR-15 05.53.52.700 PM

40 rows selected.

As you can see at the beginning of the output the samples have a sample_time that increases one second at a time (with a little slippage), and the flagged samples appear every 10 seconds at 5.53.01, 5.53.11 and 5.53.21; but then the instance becomes fairly idle and there are several samples taken over the next 20 seconds or so where we don’t capture any active sessions; in particular there are no rows in the samples for 5.53.31, and 5.53.41; but eventually the instance gets a little busy again and we see that we’ve had active sessions in consecutive samples for the last few seconds, and we can see that we’ve flagged the sample at 5.53.51 for dumping into the AWR.

You’ll notice that I seem to be losing about 1/100th second every few seconds; this is probably a side effect of virtualisation and having a little CPU-intensive work going on in the background. If you see periods where the one second gap in v$active_session_history or 10 second gap in dba_hist_active_sess_history has been stretched by several percent you can assume that the CPU was under pressure over that period. The worst case I’ve seen to date was a report showing gaps of 12 to 13 seconds in dba_hist_active_sess_history.  The “one second” algorithm is “one second since the last snapshot was captured” so if the process that’s doing the capture doesn’t get to the top of the run queue in a timely fashion the snapshots slip a little.

When the AWR snapshot is taken, the flagged rows from v$active_session_history are copied to the relevant AWR table. It probably won’t be much of a surpise to learn that you can adjust the frequency of sampling for both v$active_session_history, and dba_hist_active_sess_history; there are hidden parameters to control both: _ash_sampling_interval (1,000 milliseconds) and _ash_disk_filter_ratio (10). There’s also a parameter controlling how much memory should be reserved in the shared pool to hold v$active_session_history: _ash_size (1048618 bytes per session in my case).  The basic target is to keep one hour’s worth of data in memory but if there’s no pressure for memory you can find that the v$active_session_history holds more than the hour; conversely, if there’s heavy demand for memory and lots of continuously active sessions you may find that Oracle does “emergency flushes” (visible in v$ash_info) of v$active_session_history between the normal AWR snapshots. I have heard of people temporarily increasing the memory and reducing the interval and ratio – but I haven’t yet felt the need to do it myself.

Footnote

Remember that v$active_session_history is part of the separately licensed (and very expensive) diagnostic and performance option and you shouldn’t be using it unless you are licensed. In the older versions of Oracle it was possible for an individual to use the feature without realising the financial consequences but in later versions of 11g you can protect against accidental use by setting the parameter control_management_pack_access to ‘NONE’ and restarting the instance.

One convenience about this is that it’s then possible to recognise which other performance related views don’t require a licence, for example v$sysmetric_history is still populated when ASH is disabled. On the other hand v$sql_plan_monitor (which is used to populate the execution plan monitoring screen in OEM) stays empty.

 

4 Comments »

  1. […] Oracle uses to capture a snapshot once every second of what each currently active session is doing; every 10th snapshot is then echoed down into the Automatic Workload Repository (AWR) by a process that runs every hour […]

    Pingback by Trouble-shooting | Oracle Scratchpad — December 4, 2015 @ 7:22 am GMT Dec 4,2015 | Reply

  2. If we are taking hundreds or thousands of calls per second, So ASH will missing information by the same rule?
    Is the tracing with 10046 event will help for in-depth analysis from a process monitoring perspective?
    What are ASH pro’s and cons’s over trace?

    Comment by Anil — October 6, 2016 @ 6:26 pm BST Oct 6,2016 | Reply

  3. […] the performance and diagnostic licences: some of the available performance information comes from v$active_session_history, and the report is generated by a call to the dbms_sqltune […]

    Pingback by SQL Monitor | Oracle Scratchpad — November 8, 2018 @ 8:42 am GMT Nov 8,2018 | Reply

  4. […] have solved this by removing APEX_UTIL.PAUSE. After going though this https://jonathanlewis.wordpress.com/2015/03/27/ash/ i understood that if session goes to sleep it will appear in v$session as status = ‘ACTIVE’ and […]

    Pingback by Oracle End To End metrics with Jooq - Tutorial Guruji — October 4, 2021 @ 9:44 am BST Oct 4,2021 | Reply


RSS feed for comments on this post. TrackBack URI

Comments and related questions are welcome.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Website Powered by WordPress.com.