--查看临时表文件大小和已使用空间
select t1."Tablespace" "Tablespace",
t1."Total (G)" "Total (G)",
nvl(t2."Used (G)", 0) "Used(G)",
t1."Total (G)" - nvl(t2."Used (G)", 0) "Free (G)"
from
(
select tablespace_name "Tablespace", to_char((sum(bytes/1024/1024/1024)),'99,999,990.900') "Total (G)"
from dba_temp_files
group by tablespace_name
union
select tablespace_name "Tablespace", to_char((sum(bytes/1024/1024/1024)),'99,999,990.900') "Total (G)"
from dba_data_files
where tablespace_name like'TEMP%'
group by tablespace_name
) t1,
(
select tablespace, round(sum(blocks)*8/1024) "Used (G)" from v$sort_usage
group by tablespace
) t2
where t1."Tablespace"=t2.tablespace(+)
--查看当前临时表使用空间大小与正在占用临时表空间的sql语句
select sess.SID, segtype, blocks*8/1000 "MB" ,sql_text
from v$sort_usage sort, v$session sess,v$sql sql
where sort.SESSION_ADDR = sess.SADDR
and sql.ADDRESS = sess.SQL_ADDRESS
order by blocks desc;
select'the ' || name || ' temp tablespaces ' || tablespace_name ||
' idle ' ||
round(100 - (s.tot_used_blocks / s.total_blocks) * 100, 3) ||
'% at ' || to_char(sysdate, 'yyyymmddhh24miss')
from (select d.tablespace_name tablespace_name,
nvl(sum(used_blocks), 0) tot_used_blocks,
sum(blocks) total_blocks
from v$sort_segment v, dba_temp_files d
where d.tablespace_name = v.tablespace_name(+)
group by d.tablespace_name) s,
v$database;
--查看临时表物理位置
SELECT * from dba_temp_files;
select t1."Tablespace" "Tablespace",
t1."Total (G)" "Total (G)",
nvl(t2."Used (G)", 0) "Used(G)",
t1."Total (G)" - nvl(t2."Used (G)", 0) "Free (G)"
from
(
select tablespace_name "Tablespace", to_char((sum(bytes/1024/1024/1024)),'99,999,990.900') "Total (G)"
from dba_temp_files
group by tablespace_name
union
select tablespace_name "Tablespace", to_char((sum(bytes/1024/1024/1024)),'99,999,990.900') "Total (G)"
from dba_data_files
where tablespace_name like'TEMP%'
group by tablespace_name
) t1,
(
select tablespace, round(sum(blocks)*8/1024) "Used (G)" from v$sort_usage
group by tablespace
) t2
where t1."Tablespace"=t2.tablespace(+)
--查看当前临时表使用空间大小与正在占用临时表空间的sql语句
select sess.SID, segtype, blocks*8/1000 "MB" ,sql_text
from v$sort_usage sort, v$session sess,v$sql sql
where sort.SESSION_ADDR = sess.SADDR
and sql.ADDRESS = sess.SQL_ADDRESS
order by blocks desc;
select'the ' || name || ' temp tablespaces ' || tablespace_name ||
' idle ' ||
round(100 - (s.tot_used_blocks / s.total_blocks) * 100, 3) ||
'% at ' || to_char(sysdate, 'yyyymmddhh24miss')
from (select d.tablespace_name tablespace_name,
nvl(sum(used_blocks), 0) tot_used_blocks,
sum(blocks) total_blocks
from v$sort_segment v, dba_temp_files d
where d.tablespace_name = v.tablespace_name(+)
group by d.tablespace_name) s,
v$database;
--查看临时表物理位置
SELECT * from dba_temp_files;