ORACLE UNDO表空间回收处理

谁说胖子不能爱 提交于 2020-03-10 09:31:29

ORACLE UNDO表空间回收处理

1、首先查询当前undo表空间的使用情况
  SQL> select file_name,bytes/1024/1024 MB,autoextensible from dba_data_files where tablespace_name like 'UNDOTBS1';
   
  
  FILE_NAME                                                                                                    MB AUTOEX
  ---------------------------------------------------------------------------------------------------- ---------- ------
  +MGMT/_MGMTDB/76C3BF7AF221EFDFE0530F0B08BCEB76/DATAFILE/undotbs2.285.1034609595                            2048 NO
2、查看当前undo的参数
  SQL> show parameter undo
  
  NAME                                 TYPE                   VALUE
  ------------------------------------ ---------------------- ------------------------------
  temp_undo_enabled                    boolean                FALSE
  undo_management                      string                 AUTO
  undo_retention                       integer                900
  undo_tablespace                      string                 UNDOTBS2
3、切换undo表空间
  SQL>alter system set undo_tablespace=undotbs2 scope=both;
  SQL> show parameter undo
   
  NAME                                 TYPE        VALUE
  ------------------------------------ ----------- ------------------------------
  undo_management                      string      AUTO
  undo_retention                       integer     900
  undo_tablespace                      string      UNDOTBS1
4、新建undotbs2
   CREATE UNDO TABLESPACE UNDOTBS2 datafile  SIZE 2048M AUTOEXTEND off ;
5、查看当前的undo1 的回滚段状态
SQL>  select segment_name,tablespace_name,status from dba_rollback_segs t where tablespace_name='UNDOTBS1';
 
SEGMENT_NAME                                                 TABLESPACE_NAME           STATUS
------------------------------------------------------------ ------------------------- --------------------------------
_SYSSMU1_3338263574$                                         UNDOTBS1                  ONLINE
_SYSSMU2_97423102$                                                                     OFFLINE
_SYSSMU3_903760972$                                                                    OFFLINE
_SYSSMU4_4070352387$                                                                   OFFLINE
_SYSSMU5_2732634063$                                                                   OFFLINE
_SYSSMU6_472129223$                                                                    OFFLINE
_SYSSMU7_3778710963$                                                                   OFFLINE
_SYSSMU8_2606293711$                                                                   OFFLINE
_SYSSMU9_3450126029$                                                                   OFFLINE
_SYSSMU10_579958984$                                                                   OFFLINE
6、由于上面的两个回滚段一直处于online状态,无法直接删除undotbs1表空间和数据文件回收空间,首先试着使用命令下线回滚段
  SQL>  ALTER ROLLBACK SEGMENT "_SYSSMU1_3338263574$" OFFLINE;
 
  Rollback segment altered.
7、查询回滚段状态,一直处于pengding offline状态
SQL> SELECT s.username, u.name ,r.status FROM v$transaction t, v$rollstat r, v$rollname u, v$session s WHERE s.taddr =  t.addr AND t.xidusn = r.usn AND r.usn
 = u.usn ORDER BY s.username;
 
USERNAME                    NAME                           STATUS
--------------------------- ------------------------------ ---------------
CBS                        _SYSSMU1_3338263574$                      PENDING OFFLINE
。。。

10 rows selected.
8、查找到相关的事务ID
  SQL> SELECT s.sid,serial#, u.name ,r.status
    2  FROM v$transaction t, v$rollstat r, v$rollname u, v$session s
    3  WHERE s.taddr = t.addr AND t.xidusn = r.usn AND r.usn = u.usn and r.status='PENDING OFFLINE' ;
   
         SID    SERIAL# NAME                           STATUS
  ---------- ---------- ------------------------------ ---------------
        2311      19282 _SYSSMU1_3338263574$                       PENDING OFFLINE

9、根据上面的SID号查询该会话正在执行的操作
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; 
10、结束该会话
  alter system kill session '2311,19282';
  ALTER ROLLBACK SEGMENT "_SYSSMU1_3338263574$" OFFLINE; 
11、验证当前undotbs1 是否全部offline
select * from dba_rollback_segs t where tablespace_name='UNDOTBS'
12、删除掉undotbs1
  SQL> drop tablespace undotbs1 including contents and datafiles;

  Tablespace dropped.
  
  SQL> SELECT   tablespace_name, status, SUM (bytes) / 1024 / 1024 "Bytes(M)"
    2      FROM   dba_undo_extents
    3      GROUP BY   tablespace_name, status;
  
  TABLESPACE_NAME                                              STATUS               Bytes(M)
  ------------------------------------------------------------ ------------------ ----------
  UNDOTBS2                                                     UNEXPIRED                  20
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!