Oracle 查询占用临时表空间大的历史会话和SQL

来源:这里教程网 时间:2026-03-03 17:38:46 作者:

alter 日志中报 ORA-1652: unable to extend temp segment by 128 in tablespace                 TEMP。 可通过下面方式定为到历史sql: --占用临时表空大的历史会话和sql查询:select to_char(a.sample_time, 'yyyy-mm-dd hh24'),       a.session_id,       u.username,       a.sql_id  from gv$active_session_history a, dba_users u where u.user_id = a.user_id   and to_char(a.sample_time, 'yyyy-mm-dd hh24:mi:ss') >       '2021-05-25 20:30:00'   and to_char(a.sample_time, 'yyyy-mm-dd hh24:mi:ss') <       '2021-05-25 20:40:59'   and a.temp_space_allocated > 10000000   and sql_id is not null group by to_char(a.sample_time, 'yyyy-mm-dd hh24'),          a.session_id,          u.username,          a.sql_id order by a.sql_id, a.session_id desc; select to_char(a.sample_time, 'yyyy-mm-dd hh24'),       a.session_id,       u.username,       a.sql_id  from dba_hist_active_sess_history a, dba_users u where u.user_id = a.user_id   and to_char(a.sample_time, 'yyyy-mm-dd hh24:mi:ss') >       '2020-07-09 11:00:00'   and to_char(a.sample_time, 'yyyy-mm-dd hh24:mi:ss') <       '2020-07-09 11:10:00'   and a.temp_space_allocated > 1000000000   and sql_id is not null group by to_char(a.sample_time, 'yyyy-mm-dd hh24'),          a.session_id,          u.username,          a.sql_id order by a.sql_id, a.session_id desc; --查看sql占用临时表空间最大值: select max(a.temp_space_allocated / 1024 / 1024 / 1024) g   from gv$active_session_history a  where a.sql_id = '6uk7dr0n12f9n'; --查询当前占用临时表空间高的SQLselect se.username,       se.sid,       su.extents,       su.blocks * to_number(rtrim(p.value)) / 1024 / 1024 as used_G,       tablespace,       segtype,       s.sql_id,       s.sql_text  from v$sort_usage su, v$parameter p, v$session se, v$sql s where p.name = 'db_block_size'   AND su.session_addr = se.saddr   AND s.hash_value = su.sqlhash   AND s.address = su.sqladdr   and su.blocks > 1000 order by su.blocks desc;

相关推荐