4. 查看当前临时表使用空间大小与正在占用临时表空间的sql语句
-->使用临时段的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;
-->下面的查询也可以查询谁正在使用临时段
col username format a15
col machine format a15
col program format a30
col tablespace format a15
set linesize 160
SELECT s.username
,s.sid
,s.serial#
,s.sql_address
,s.machine
,s.program
,su.tablespace
,su.segtype
,su.contents
FROM v$session s, v$sort_usage su
WHERE s.saddr = su.session_addr;
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;
3. 修改默认的临时表空间
alter database default temporary tablespace tablespace_name;
4. 对于过度使用临时表空间,在允许的情况下,可以杀掉其session
alter system kill session 'sid,serial#';
三、临时表空间故障
前面已提到,临时表空间不需要备份,如果对临时表空间备份将收到错误提示
SQL> alter tablespace temp begin backup;
alter tablespace temp begin backup
*
ERROR at line 1:
ORA-03217: invalid option for alter of TEMPORARY TABLESPACE
SQL> alter temporary tablespace temp begin backup;
alter temporary tablespace temp begin backup
*
ERROR at line 1:
ORA-00940: invalid ALTER command
临时表空间出错的错误提示(位于告警日志中alert_orcl.log)
Errors in file /u01/app/Oracle/admin/orcl/bdump/orcl_dbw0_2230.trc:
ORA-01186:file 3 failed verification tests
ORA-01157:cannot identify/lock data file 3 - see DBWR trace file
ORA-01110:data file 3:'/u01/app/oracle/oradata/orcl/temp01.dbf'
