--臨時表空間空間不足解決方法
--關閉自動增長
SYS@PROD2> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production PL/SQL Release 11.2.0.3.0 - Production CORE 11.2.0.3.0 Production TNS for Linux: Version 11.2.0.3.0 - Production NLSRTL Version 11.2.0.3.0 - Production SYS@PROD2> alter database tempfile '/u01/app/oracle/oradata/PROD2/temp02.dbf' autoextend off; Database altered. SYS@PROD2> alter database tempfile '/u01/app/oracle/oradata/PROD2/temp02.dbf' resize 2m; Database altered. SCOTT@PROD2> select * from temp1 order by 1,2,3,4,5,6,7,8,9; select * from temp1 order by 1,2,3,4,5,6,7,8,9 * ERROR at line 1: ORA-01652: unable to extend temp segment by 128 in tablespace TEMP SCOTT@PROD2> set autot trace exp SCOTT@PROD2> select * from temp1 order by 1,2,3,4,5,6,7,8,9; Execution Plan ---------------------------------------------------------- Plan hash value: 3339515882 ------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | ------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 10M| 1542M| | 361K (1)| 01:12:18 | | 1 | SORT ORDER BY | | 10M| 1542M| 1904M| 361K (1)| 01:12:18 | | 2 | TABLE ACCESS FULL| TEMP1 | 10M| 1542M| | 4909 (6)| 00:00:59 | ------------------------------------------------------------------------------------ Note ----- - dynamic sampling used for this statement (level=2) 查看執行計划,發現估算需要1904M空間 SYS@PROD2> alter database tempfile '/u01/app/oracle/oradata/PROD2/temp02.dbf' resize 2000m; Database altered. SCOTT@PROD2> select * from temp1 order by 1,2,3,4,5,6,7,8,9; 54247 rows selected. --時間太長中止了 但是通過resize很難准確調整,很容易導致過度使用的問題。 11g以前只能重建表空間替換原來臨時表空間。 在11g中可以使用在線回收臨時表空間的功能。 SYS@PROD2> ho ls -lh /u01/app/oracle/oradata/PROD2/temp02.dbf --當前大小2G -rw-r----- 1 oracle oinstall 2.0G Dec 13 16:55 /u01/app/oracle/oradata/PROD2/temp02.dbf SYS@PROD2> alter tablespace temp shrink space; --使用在線回收 Tablespace altered. SYS@PROD2> ho ls -lh /u01/app/oracle/oradata/PROD2/temp02.dbf --大小縮小為139M -rw-r----- 1 oracle oinstall 139M Dec 13 17:01 /u01/app/oracle/oradata/PROD2/temp02.dbf SYS@PROD2> alter tablespace temp shrink space keep 20m; --通過KEEP語句指定回收大小 Tablespace altered. SYS@PROD2> ho ls -lh /u01/app/oracle/oradata/PROD2/temp02.dbf -rw-r----- 1 oracle oinstall 139M Dec 13 17:01 /u01/app/oracle/oradata/PROD2/temp02.dbf 發現大小並未回收,說明這部分空間正在被使用。