Oracle 安裝在磁碟空間有限的 CentOS 上時,臨時表空間可能隨運行時間增加而持續變大,甚至拖垮系統。以下提供一套以重建臨時表空間為核心的處理流程。
可先嘗試刪除舊臨時檔案、重建臨時表空間,並限制自動擴展:
alter database tempfile '/opt/oracle/oradata/orcl/temp01.dbf' drop; alter tablespace temp add tempfile '/opt/oracle/oradata/orcl/temp01.dbf' size 2048M reuse autoextend on next 100M; alter database tempfile '/opt/oracle/oradata/orcl/temp01.dbf' autoextend off;
select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE'; select file_name,tablespace_name,bytes/1024/1024 "MB",autoextensible from dba_temp_files;
create temporary tablespace temp02 tempfile '/opt/oracle/oradata/orcl/temp02.dbf' size 512M; alter database default temporary tablespace temp02;
可先查詢使用 temp 的排序型 SQL:
Select se.username,se.sid,se.serial#,su.extents,su.blocks,tablespace,segtype,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;
確認後,可針對特定 session 執行:
alter system kill session 'SID,SERIAL#';
drop tablespace temp including contents and datafiles; create temporary tablespace temp tempfile '/opt/oracle/oradata/orcl/temp01.dbf' size 512M autoextend on maxsize 15G; alter database default temporary tablespace temp; drop tablespace temp02 including contents and datafiles;
這樣可把臨時表空間重新放回原本位置,並設定合理的最大擴展上限,避免再次占滿磁碟。