Oracle中臨時(shí)表空間作用 |
發(fā)布時(shí)間: 2012/8/30 17:22:42 |
Oracle臨時(shí)表空間主要用來(lái)做查詢和存放一些緩沖區(qū)數(shù)據(jù)。臨時(shí)表空間消耗的主要原因是需要對(duì)查詢的中間結(jié)果進(jìn)行排序。重啟數(shù)據(jù)庫(kù)可以釋放臨時(shí)表空間,如果不能重啟實(shí)例,而一直保持問(wèn)題sql語(yǔ)句的執(zhí)行,temp表空間會(huì)一直增長(zhǎng) Oracle臨時(shí)表空間主要用來(lái)做查詢和存放一些緩沖區(qū)數(shù)據(jù)。臨時(shí)表空間消耗的主要原因是需要對(duì)查詢的中間結(jié)果進(jìn)行排序。 - 重啟數(shù)據(jù)庫(kù)可以釋放臨時(shí)表空間,如果不能重啟實(shí)例,而一直保持問(wèn)題sql語(yǔ)句的執(zhí)行,temp表空間會(huì)一直增長(zhǎng)。直到耗盡硬盤(pán)空間。 網(wǎng)上有人猜測(cè)在磁盤(pán)空間的分配上,oracle使用的是貪心算法,如果上次磁盤(pán)空間消耗達(dá)到1GB,那么臨時(shí)表空間就是1GB。也就是說(shuō)當(dāng)前臨時(shí)表空間文件的大小是歷史上使用臨時(shí)表空間最大的大小。 臨時(shí)表空間的主要作用: 索引create或rebuild Order by 或 group by Distinct 操作 Union 或 intersect 或 minus Sort-merge joins analyze 查看臨時(shí)表空間大小 查看臨時(shí)表文件大小和已使用空間 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 groupby 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%' groupby tablespace_name ) t1, ( selecttablespace, round(sum(blocks)*8/1024) "Used (G)" from v$sort_usage groupbytablespace ) t2 where t1."Tablespace"=t2.tablespace(+) 查看當(dāng)前臨死表使用空間大小與正在占用臨時(shí)表空間的sql語(yǔ)句 select sess.SID, segtype, blocks*8/1000 "MB" ,sql_text from v$sort_usage sort, v$session sess,v$sql sql wheresort.SESSION_ADDR = sess.SADDR andsql.ADDRESS = sess.SQL_ADDRESS orderby 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(+) groupby d.tablespace_name) s, v$database; 修改臨時(shí)文件大小 select'ALTER database TEMPFILE ' || file_name || ' resize 100M ;' from dba_temp_files where tablespace_name = 'ONLYDWTEMP'; ALTER database TEMPFILE '/oradata/ONLYDWTEMP06.dbf' resize 100M ; ALTER database TEMPFILE '/oradata/ONLYDWTEMP07.dbf' resize 100M ; ALTER database TEMPFILE '/oradata/ONLYDWTEMP08.dbf' resize 100M ; ALTER database TEMPFILE '/oradata/ONLYDWTEMP09.dbf' resize 100M ; ALTER database TEMPFILE '/oradata/ONLYDWTEMP10.dbf' resize 100M ; ALTER database TEMPFILE '/oradata/ONLYDWTEMP01.dbf' resize 100M ; ALTER database TEMPFILE '/oradata/ONLYDWTEMP02.dbf' resize 100M ; ALTER database TEMPFILE '/oradata/ONLYDWTEMP03.dbf' resize 100M ; ALTER database TEMPFILE '/oradata/ONLYDWTEMP04.dbf' resize 100M ; ALTER database TEMPFILE '/oradata/ONLYDWTEMP05.dbf' resize 100M ; SQL> ALTER database TEMPFILE '/oradata/ONLYDWTEMP09.dbf' resize 100M ; ALTER database TEMPFILE '/oradata/ONLYDWTEMP09.dbf' resize 100M ORA-03297: file contains used data beyond requested RESIZE value 創(chuàng)建新的臨時(shí)表空間 SQL> create temporary tablespace TEMP1 TEMPFILE '/oradata/TEMP1_01.dbf' size 100M; Tablespace created SQL> create temporary tablespace TEMP2 TEMPFILE '/oradata/TEMP2_01.dbf' size 100M; Tablespace created 將當(dāng)前臨時(shí)表空間指定為新的臨時(shí)表空間 SQL> alter database default temporary tablespace TEMP1; Database altered 本文出自:億恩科技【1tcdy.com】 服務(wù)器租用/服務(wù)器托管中國(guó)五強(qiáng)!虛擬主機(jī)域名注冊(cè)頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM] |