如何處理Oracle的UNDO資料表空間所對應的資料檔案過大

來源:互聯網
上載者:User

1 查看undo的資料表空間大小和最大值  
select   t.file_name,t.tablespace_name,  
t.bytes/1024/1024/1024 "GB",  t.maxbytes/1024/1024/1024   "Max GB" 
 from     dba_data_files     t     where    t.tablespace_name='UNDOTBS1' 
   
資料檔案為:/Oracle/oradata/undo/undotbs01.dbf  
   
2 建立一個新的undo資料表空間,用來替換原來的undo資料表空間  
create      undo     tablespace    UNDOTBS2  
datafile     '/oracle/oradata/log/undotbs02.dbf' 
size    10M    autoextend     on    maxsize    unlimited;  
3 把新的undo資料表空間設定成資料庫的undo資料表空間  
alter     system     set undo_tablespace=UNDOTBS2     scope=both;  
4 再次驗證資料庫的undo資料表空間  
 show     parameter     undo_tablespace  
5 等待原UNDO資料表空間UNDOTBS1 is OFFLINE;  
   
 SELECT    r.status    "Status",  
r.segment_name    "Name",  
r.tablespace_name     "Tablespace",  
s.extents     "Extents",  
TO_CHAR((s.bytes/1024/1024),'99999990.000')     "Size" 
FROM     sys.dba_rollback_segs      r, sys.dba_segments    s  
WHERE        r.segment_name = s.segment_name  
AND       s.segment_type IN ('ROLLBACK', 'TYPE2 UNDO')  
and       r.tablespace_name='UNDOTBS1'      and       status='ONLINE' 
如果上面有狀態online的對象,可以查詢具體對象的sid,serial#  
5.1 查看當前是什麼在使用這個復原段  
 SELECT     r.NAME,s.sid,s.serial# Serial,  
s.username ,s.machine ,  
t.start_time,t.status ,  
t.used_ublk ,  
substr(s.program, 1, 15)    "operate" 
FROM      v$session    s, v$transaction    t, v$rollname    r,v$rollstat    g  
WHERE      t.addr = s.taddr  
AND      t.xidusn = r.usn  
AND     r.usn = g.usn  
ORDER     BY     t.used_ublk desc;  
--比如:對象為:sid  474,serial  6794 
5.2 根據sid查出具體的sql  
select     sql_text    from     v$session a,v$sqltext_with_newlines     b  
  where DECODE(a.sql_hash_value, 0, prev_hash_value, sql_hash_value)=b.hash_value  
  and      a.sid=&sid    order     by     piece  
如果該sql不重要,可以直接kill該會話。  
   
5.3  kill session  
alter system kill session '474,6794';  
5.4  刪除原undo資料表空間及其系統的資料問題  
drop tablespace UNDOTBS1 including contents and datafiles;  
(在AIX系統中,雖然已經刪除了系統所對應的undo資料表空間的資料檔案,但用df -g查看,該系統空間不能釋放。  
主要是由於Oracle的一個進程在訪問該檔案。可以kill Oracle訪問進程,或者重啟資料庫後,即可釋放系統的空間。)  
   
   
6建立立UNDOTBS1資料表空間  
create     undo     tablespace    UNDOTBS1  
datafile    '/oracle/oradata/undo/undotbs01.dbf' 
size    10M    autoextend   on    maxsize 12G;  
   
7切換回UNTOTBS1  
alter system set undo_tablespace=UNDOTBS1 scope=both;  
8 等待UNDO資料表空間UNDOTBS2 is OFFLINE;  
 SELECT r.status "Status",  
r.segment_name "Name",  
r.tablespace_name "Tablespace",  
s.extents "Extents",  
TO_CHAR((s.bytes/1024/1024),'99999990.000') "Size" 
FROM sys.dba_rollback_segs r, sys.dba_segments s  
WHERE r.segment_name = s.segment_name  
AND s.segment_type IN ('ROLLBACK', 'TYPE2 UNDO')  
and r.tablespace_name='UNDOTBS2' 
ORDER BY 5 DESC;  
9 刪除  
drop    tablespace     UNDOTBS2    including    contents    and     datafiles; 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.