溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Linux系統(tǒng)Oracle Temp01.dbf不斷變大應(yīng)該這樣解決

發(fā)布時(shí)間:2020-07-14 04:43:40 來源:網(wǎng)絡(luò) 閱讀:916 作者:xiaoxiongmao8 欄目:數(shù)據(jù)庫

Oracle安裝在centos系統(tǒng)上,系統(tǒng)磁盤空間本身不是很大,運(yùn)行一段時(shí)間后發(fā)現(xiàn)Oracle的臨時(shí)表空間占用磁盤越來越大,以至于系統(tǒng)處于崩潰的邊緣,解決該問題的方法如下:


第一步:
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;
第三步:
select d.file_name, d.file_id, d.tablespace_name, d.bytes
from dba_temp_files d;
第四步:
alter database tempfile '/opt/oracle/oradata/orcl/temp01.dbf' autoextend off;
(只是為了解決小問題,不深究。)
 
正常來說,在完成Select語句、create index等一些使用TEMP表空間的排序操作后,Oracle是會(huì)自動(dòng)釋放掉臨時(shí)段a的。但有些有侯我們則會(huì)遇到臨時(shí)段沒有被釋放,TEMP表空間幾乎滿的狀況,甚至是我們重啟了數(shù)據(jù)庫仍沒有解決問題


在檢查centos系統(tǒng)的磁盤空間時(shí),發(fā)現(xiàn)臨時(shí)表空間所在臨時(shí)數(shù)據(jù)文件已經(jīng)達(dá)到35G,已經(jīng)占用了100%。

因?yàn)槭钦綌?shù)據(jù)庫服務(wù)器,不能隨便重啟數(shù)據(jù)庫。

以下的操作是用數(shù)據(jù)庫的sys超級(jí)用戶操作

剛開始打算把臨時(shí)表空間的數(shù)據(jù)文件重新縮小就好了

執(zhí)行:

SQL> alter database tempfile '/opt/oracle/oradata/orcl/temp01.dbf' resize 10240M;

數(shù)據(jù)庫報(bào)錯(cuò),重新設(shè)置的空間大小不能滿足需要。

看來需要重新建立新的臨時(shí)表空間替換當(dāng)前的表空間了

1、首先查看當(dāng)前的數(shù)據(jù)庫默認(rèn)表空間:

SQL>select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE';

確認(rèn)當(dāng)前的臨時(shí)表空間為TEMP

2、查看目前臨時(shí)表空間的大?。?br />
SQL>select file_name,tablespace_name,bytes/1024/1024 "MB",autoextensible from dba_temp_files;

3、創(chuàng)建新的臨時(shí)表空間:

SQL> create temporary tablespace temp02 tempfile '/opt/oracle/oradata/orcl/temp02.dbf' size 512M;

4、把新建的臨時(shí)表空間卻換成數(shù)據(jù)庫的默認(rèn)臨時(shí)表空間

SQL> alter database default temporary tablespace temp02;

5、確認(rèn)目前數(shù)據(jù)庫的默認(rèn)臨時(shí)表空間

SQL>select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE';

確認(rèn)temp02為當(dāng)前的數(shù)據(jù)庫默認(rèn)表空間

6、在刪除temp臨時(shí)表空間之前,先把運(yùn)行在temp臨時(shí)表空間的sql語句kill掉,這樣的sql語句多為排序的語句

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;

查詢出來之后,kill掉這些sql語句:

SQL>alter system kill session '524,778'; (假如某一條運(yùn)行的sql語句的SID為524,serial#為778)

確認(rèn)在temp臨時(shí)表空間中沒有運(yùn)行的sql語句之后,則可以刪除temp臨時(shí)表空間數(shù)據(jù)文件了

7、刪除temp臨時(shí)表空間

SQL> drop tablespace temp including contents and datafiles;

這樣很快就可以刪除了臨時(shí)表空間的數(shù)據(jù)文件

8、現(xiàn)在temp02臨時(shí)表空間占據(jù)了別人的磁盤空間,需要重新把臨時(shí)表空間建立在原來的位置,重新建立temp臨時(shí)表空間

SQL> create temporary tablespace temp tempfile '/opt/oracle/oradata/orcl/temp01.dbf' size 512M autoextend on maxsize 15G;


新建一個(gè)512M的自動(dòng)擴(kuò)展臨時(shí)表空間,最大的擴(kuò)展為15G。

查看新建的temp臨時(shí)表空間是否正確:

SQL>select file_name,tablespace_name,bytes/1024/1024,maxbytes/1024/1024,autoextensible from dba_temp_files;


9、把新建的temp臨時(shí)表空間卻換成數(shù)據(jù)庫的默認(rèn)臨時(shí)表空間

SQL> alter database default temporary tablespace temp;

10、確認(rèn)目前數(shù)據(jù)庫的默認(rèn)臨時(shí)表空間

SQL>select * from database_properties

where property_name='DEFAULT_TEMP_TABLESPACE';

確認(rèn)temp為當(dāng)前的數(shù)據(jù)庫默認(rèn)表空間

11、目前把原來的temp臨時(shí)表空間變成了512M,把剩余的磁盤空間空了出來,temp02臨時(shí)表空間就沒有用了,刪除temp02臨時(shí)表空間
SQL> drop tablespace temp02 including contents and datafiles;


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI