Using ASH to Monitor Temporary Tablespace Usage
To use ASH (Active Session History) to monitor temporary tablespace usage use SQL similar to the query below. Detect the space used by queries.
SELECT ASH.inst_id, ASH.user_id, ASH.session_id sid, ASH.session_serial# serial#, ASH.sql_id, ASH.sql_exec_id, ASH.sql_opname, ASH.module, MIN(sample_time) sql_start_time, MAX(sample_time) sql_end_time, ((CAST(MAX(sample_time) AS DATE)) - (CAST(MIN(sample_time) AS DATE))) * (3600*24) etime_secs , ((CAST(MAX(sample_time) AS DATE)) - (CAST(MIN(sample_time) AS DATE))) * (60*24) etime_mins , MAX(temp_space_allocated)/(1024*1024) max_temp_mb FROM gv$active_session_history ASH WHERE ASH.session_type = 'FOREGROUND' AND ASH.sql_id IS NOT NULL --AND sample_time BETWEEN to_timestamp('01-04-2019 10:00', 'DD-MM-YYYY HH24:MI') AND to_timestamp('13-04-2019 12:00', 'DD-MM-YYYY HH24:MI') AND sample_time > systimestamp - 3 GROUP BY ASH.inst_id, ASH.user_id, ASH.session_id, ASH.session_serial#, ASH.sql_id, ASH.sql_opname, ASH.sql_exec_id, ASH.module HAVING MAX(temp_space_allocated) > 10000 order by 9 desc