Oracle 暫存資料表空間過大問題解決

來源:互聯網
上載者:User

    查詢Oracle資料庫伺服器時,探索資料程式庫伺服器磁碟使用空間達到了98%,分析總共的資料檔案也不可能達到如此大,經過查詢發現原來暫存資料表空間的使用方式達到了 32G,導致磁碟空間使用緊張。搜尋了相應的文檔與資料後,查出暫存資料表空間主要使用在:

    - 索引建立或重建立。

    - ORDER BY or GROUP BY (這個是‘罪魁禍首’)

    - DISTINCT 操作。

    - UNION & INTERSECT & MINUS - Sort-Merge joins. - Analyze 操作

    - 有些異常將會引起temp暴漲(這個也很有可能)

    下面是重新建立一個暫存資料表空間,把原來的預設暫存資料表空間drop掉(包括裡面的臨時資料檔案)再重建立立

SQL> create temporary tablespace temp2
2 tempfile '/home/oracle/oracle/product/10.2.0/oradata/hatest/temp02.pdf' size 512M reuse
3 autoextend on next 640k maxsize unlimited;

Tablespace created.

SQL> alter database default temporary tablespace temp2;

Database altered.

SQL> drop tablespace temp including contents and datafiles;

Tablespace dropped.
(注意:由於暫存資料表空間的資料檔案比較大,所以這步可能會花費比較長的時間)
SQL> create temporary tablespace temp
2 tempfile '/home/oracle/oracle/product/10.2.0/oradata/hatest/temp01.pdf' size 512M reuse
3 autoextend on next 640K maxsize unlimited;

Tablespace created.

SQL> alter database default temporary tablespace temp;

Database altered.

SQL> drop tablespace temp2 including contents and datafiles;

Tablespace dropped.

SQL> exit


    以上的方法只是暫時釋放了暫存資料表空間的磁碟佔用空間,是治標但不是治本的方法,真正的治本的方法是找出資料庫中消耗資源比較大的sql語句,然後對其進行最佳化處理。下面是查詢在sort排序區使用的執行耗時的SQL

Select se.username,se.sid,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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.