Anyone familiar with Oracle performance tuning knows about ASH , aka active session history. ASH saves a history of every session that is active every collection, which by default is once per second. Once per second is fast enough to give a clear view of database load.
The ASH data comes from v$session which is a structure that contains information on every connection and shows which connections are active, what SQL they are running (SQL_ID) and if they are runnable on CPU or waiting on a wait_event for some resource like an I/O to complete or a lock or latch. It’s a pretty simple select query on v$session to select who is active, their wait_event and SQL_ID.
On Oracle that gives us a query like:
select sid||':'||serial# session_id, username, s.sql_id||':'||sql_child_number sqlid, decode(state, 'WAITING', wait_class||':'||event, 'CPU') event from v$session s where (( s.wait_time != 0 /* on CPU */ …[Read more]