如何解決Oracle臨時表空間過大

2022-07-24 11:39:12 字數 3871 閱讀 2453

方案一:增加臨時表空間的大小

--1.臨時表空間的使用情況題

select d.tablespace_name,

space "sum_space(m)",

blocks "sum_blocks",

used_space "used_space(m)",

round(nvl(used_space, 0) / space * 100, 2) "used_rate(%)",

space - used_space "free_space(m)"

from (select tablespace_name,

round(sum(bytes) / (1024 * 1024), 2) space,

sum(blocks) blocks

from dba_temp_files

group by tablespace_name) d,

(select tablespace,

round(sum(blocks * 8192) / (1024 * 1024), 2) used_space

from v$sort_usage

group by tablespace) f

where d.tablespace_name = f.tablespace(+)

and d.tablespace_name like 'temp%';

--檢視臨時表空間的總大小和最大擴充套件大小(能看到資料檔案)

select file_name,

tablespace_name,

bytes / 1024 / 1024 mb,

autoextensible,

maxbytes / 1024 / 1024 max_mb

from dba_temp_files;

--增加臨時表空間的大小

alter tablespace temp1 add tempfile '/data/prod/proddata/temp013.dbf' size 4g;

alter tablespace temp2 add tempfile '/data/prod/proddata/temp024.dbf' size 4g;

方案二:重建臨時表空間,解決臨時表空間過大的問題。

--0.檢視目前預設的臨時表空間

select *

from database_properties

where property_name = 'default_temp_tablespace';

--1.建立中轉臨時表空間

create temporary tablespace te*** tempfile '/data/prod/proddata/te***1.dbf' size 4g tablespace group temp;

create temporary tablespace temp4 tempfile '/data/prod/proddata/temp41.dbf' size 4g tablespace group temp;

--2.刪除原臨時表空間組中的臨時表空間

--2.1從預設臨時表空間組temp中移除temp1和temp2;

alter tablespace temp1 tablespace group '';

alter tablespace temp2 tablespace group '';

--2.2刪除臨時表空間temp1和temp2

drop tablespace temp1 including contents and datafiles;

drop tablespace temp2 including contents and datafiles;

--2.3如果刪除表空間的時候,hang住的話,可以使用下列語句,先把執行在temp臨時表空間的sql語句kill掉,這樣的sql語句多為排序的語句

select se.username,

se.sid,

se.serial#,

su.extents,

su.blocks * to_number(rtrim(p.value)) as space,

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

order by se.username, se.sid;

--2.4 kill相關程序

alter system kill session '584,23181';

alter system kill session '196,64972';

alter system kill session '262,19832';

alter system kill session '324,40273';

alter system kill session '326,38967';

alter system kill session '1266,54596';

or--重啟db

--關閉應用-->關閉監聽-->shutdown immediate

--startup-->啟動監聽-->執行以下操作後開啟應用

--2.5 建立臨時表空間,並加入臨時表空間組temp

create temporary tablespace temp1 tempfile '/data/prod/proddata/temp11.dbf' size 4g tablespace group temp;

create temporary tablespace temp2 tempfile '/data/prod/proddata/temp21.dbf' size 4g tablespace group temp;

--2.6 給臨時表空間組temp的成員temp1,temp2,te***,temp4 各增加乙個成員。

alter tablespace temp1 add tempfile '/data/prod/proddata/temp12.dbf' size 4g;

alter tablespace temp2 add tempfile '/data/prod/proddata/temp22.dbf' size 4g;

alter tablespace te*** add tempfile '/data/prod/proddata/te***2.dbf' size 4g;

alter tablespace temp4 add tempfile '/data/prod/proddata/temp42.dbf' size 4g;

--2.7檢視臨時表空間組temp

select * from dba_tablespace_groups;

--3 臨時表空間組仍然使用99.98%,

--3.1為每個臨時表空間新增4g空間

alter tablespace temp1 add tempfile '/data/prod/proddata/temp13.dbf' size 4g;

alter tablespace temp2 add tempfile '/data/prod/proddata/temp23.dbf' size 4g;

alter tablespace te*** add tempfile '/data/prod/proddata/te***3.dbf' size 4g;

alter tablespace temp4 add tempfile '/data/prod/proddata/temp43.dbf' size 4g;

如何解決Oracle臨時表空間過大

解決oracle臨時表空間過大有兩種方法,方法一增加臨時表空間的大小,方法二重建臨時表空間,解決臨時表空間過大的問題。方案一 增加臨時表空間的大小 1.臨時表空間的使用情況題 select d.tablespace name,space sum space m blocks sum blocks u...

Oracle臨時表空間

oracle臨時表空間主要是用來做查詢和存放一些快取的資料的,磁碟消耗的乙個主要原因是需要對查詢的結果進行排序,如果沒有猜錯的話,在磁碟空間的 記憶體 的分配上,oracle使用的是貪心演算法,如果上次磁碟空間消耗達到1gb,那麼臨時表空間就是1gb,如果還有增長,那麼依此類推,臨時表空間始終保持在...

Oracle 臨時表空間

我多表查詢大概五十萬條資料的檢視引發了乙個錯誤,報空間記憶體不足,開始思考分析還有哪些情況下是會使用到temp臨時表空間,在海量資料的情況下表空間不足是常見的問題 ora 01114 將塊寫入檔案 201 時出現 io 錯誤 塊 3136640 ora 27072 檔案 i o 錯誤 additio...