Oracle的UNDOTBS01.DBF文件太大的解决办法

1. 启动SQLPLUS,并用sys登陆到 数据库
#su - oracle  
$>sqlplus / as sysdba 
 
2. 查找数据库的UNDO表空间名,确定当前例程正在使用的UNDO表空间,及undo保留周期undo_retention为10800秒:
<!--StartFragment -->
SQL> show parameter undo

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_management                   string      AUTO
undo_retention                       integer      10800
undo_tablespace                      string      UNDOTBS1
 
3. 确认UNDO表空间;
SQL> select name from v$tablespace;  
NAME  
------------------------------  
UNDOTBS1 
 
4. 检查数据库UNDO表空间占用空间情况以及数据文件存放位置;
select file_name, bytes / 1024 / 1024 / 1024
  from dba_data_files
 where tablespace_name like 'UNDOTBS%';
 
5. 查看回滚段的使用情况,哪个用户正在使用回滚段的资源,如果有用户最好更换时间(特别是生产环境)。
select s.username, u.name
  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;
查询结果为空的话就能删除。
 
6. 检查UNDO Segment状态;
select usn,xacts,rssize / 1024 / 1024 / 1024,hwmsize / 1024 / 1024 / 1024,shrinks
  from v$rollstat
 order by rssize;
USN  XACTS  RSSIZE/1024/1024/1024  HWMSIZE/1024/1024/1024  SHRINKS
800.000175476074218753.11521148681641700
300.000236511230468753.22954559326172632
000.000358581542968750.000358581542968750
100.002067565917968753.04867553710938920
1000.002067565917968750.648170471191406819
700.002311706542968753.94835662841797730
400.003044128417968752.00011444091797651
1100.006950378417968752.26921844482422740
900.007926940917968752.07530975341797773
600.007926940917968751.31906890869141775
200.008903503417968753.13677215576172699
501.968338012695313.99906921386719267
这还原表空间中还存在12个回滚的对象。
 
7. 创建新的UNDO表空间,并设置自动扩展参数;
create undo tablespace undotbs2 datafile '/u02/pnrdb/undotbs2_01.dbf' size 100m reuse autoextend on next 100m maxsize unlimited;
 
8. 切换UNDO表空间为新的UNDO表空间 , 动态更改spfile配置文件;
alter system set undo_tablespace=undotbs2 scope=both;  
 
9.验证当前数据库的 UNDO表空间
SQL> show parameter undo
NAME                                 TYPE        VALUE
------------------------------------ ----------- --------------
undo_management                      string      AUTO
undo_retention                       integer     900
undo_tablespace                      string      UNDOTBS2
9. 等待原UNDO表空间所有UNDO SEGMENT OFFLINE;
select usn, xacts, status,rssize / 1024 / 1024,hwmsize / 1024 / 1024,shrinks
  from v$rollstat
 order by rssize;
 
select usn, xacts, status,rssize / 1024 / 1024,hwmsize / 1024 / 1024,shrinks
  from v$rollstat
 order by rssize;
select t.segment_name, t.tablespace_name, t.segment_id, t.status
  from dba_rollback_segs t;
SEGMENT_NAME      TABLESPACE_NAME SEGMENT_ID   STATUS
_SYSSMU1$UNDOTBS11OFFLINE
_SYSSMU2$UNDOTBS12OFFLINE
_SYSSMU3$UNDOTBS13OFFLINE
_SYSSMU4$UNDOTBS14OFFLINE
_SYSSMU5$UNDOTBS15OFFLINE
_SYSSMU6$UNDOTBS16OFFLINE
_SYSSMU7$UNDOTBS17OFFLINE
_SYSSMU8$UNDOTBS18OFFLINE
_SYSSMU9$UNDOTBS19OFFLINE
_SYSSMU10$UNDOTBS110OFFLINE
_SYSSMU11$UNDOTBS111OFFLINE
_SYSSMU12$UNDOTBS112OFFLINE
_SYSSMU13$UNDOTBS113OFFLINE
_SYSSMU14$UNDOTBS114OFFLINE
_SYSSMU15$UNDOTBS115OFFLINE
_SYSSMU16$UNDOTBS116OFFLINE
_SYSSMU17$UNDOTBS117OFFLINE
_SYSSMU18$UNDOTBS118OFFLINE
_SYSSMU19$UNDOTBS119OFFLINE
_SYSSMU20$UNDOTBS120OFFLINE
_SYSSMU21$UNDOTBS121OFFLINE
_SYSSMU22$UNDOTBS122OFFLINE
_SYSSMU23$UNDOTBS123OFFLINE
_SYSSMU24$UNDOTBS124OFFLINE
_SYSSMU25$UNDOTBS125OFFLINE
_SYSSMU26$UNDOTBS126OFFLINE
_SYSSMU27$UNDOTBS127OFFLINE
_SYSSMU28$UNDOTBS128OFFLINE
_SYSSMU29$UNDOTBS129OFFLINE
_SYSSMU30$UNDOTBS130OFFLINE
_SYSSMU31$UNDOTBS131OFFLINE
_SYSSMU32$UNDOTBS132OFFLINE
_SYSSMU33$UNDOTBS133OFFLINE
_SYSSMU34$UNDOTBS134OFFLINE
_SYSSMU35$UNDOTBS135OFFLINE
上面对应的UNDOTBS1还原表空间所对应的回滚段均为OFFLINE
 
10.到$ORACLE_HOME/dbs/init$ORACLE_SID.ora如下内容是否发生变更:
#cat $ORACLE_HOME/dbs/initddptest.ora
……
*.undo_management=’AUTO’
*.undo_retention=10800
*.undo_tablespace=’UNDOTBS2’
……
 
如果没有发生变更请执行如下语句:
SQL> create pfile from spfile;
File created.
 
11. 删除原有的UNDO表空间;
drop tablespace undotbs1 including contents and datafiles;
 
12. os级别释放undo数据文件;
到root下执行
lsof |grep /u02/pnrdb/undotbs01.dbf
lsof |grep /u02/pnrdb/undotbs01.dbf |awk '{printf"kill -9 "$2"\n"}'

你可能感兴趣的:(oracle)