Search notes:

DBA_HIST_ACTIVE_SESS_HISTORY: Query begin and end of sessions

The following query selects the begin and end of sessions that have at least one entry in dba_hist_active_sess_history.
Unfortunately, it seems not possible to select to OS user with the DBA_HIST views.
select
   to_char(min(ash.sample_time), 'dd hh24:mi:ss')    start_,
   to_char(max(ash.sample_time),    'hh24:mi:ss')    end_,
   min(ash.sample_id)                                min_id,
   max(ash.sample_id)                                max_id,
   nvl(ash.qc_session_id     , ash.session_id     )  ses_id,
   nvl(ash.qc_session_serial#, ash.session_serial#)  ses_ser,
   usr.username                                      user_name,
   vdb.name                                          db_name
from
   v$database                   vdb                                    join
   dba_hist_active_sess_history ash on vdb.dbid     = ash.dbid    left join
   dba_users                    usr on ash.user_id  = usr.user_id
where
   ash.sample_time >= sysdate - 1
group by
   nvl(ash.qc_session_id     , ash.session_id     ),
   nvl(ash.qc_session_serial#, ash.session_serial#),
   usr.username,
   vdb.name
order by
   start_ desc
;

Index