oracle重构undo表空间

3 篇文章 0 订阅
1 篇文章 0 订阅

在日常的数据库维护和数据库编程中经常会遇到犹豫对大数据量做DML操作后是得ORACLE的undo表空间扩展到十几个G或者几十个G 但是这些表空间的所占用磁盘的物理空间又不会被oracle所释放,经过个人整理经过如下操作可以重构undo表空间,同样temp表空间也可能在你查询大数据或则创建索引的时候无限扩大导致磁盘空间不足,同样可以用如下方式解决此问题:

1. 查看各表空间名称

select name from v$tablespace

2. 查看某个表空间信息

select file_name,bytes/1024/1024 from dba_data_files where tablespace_name = 'UNDOTBS1';
select file_name,bytes/1024/1024 from dba_data_files where tablespace_name like 'UNDOTBS1';

3. 查看回滚段的使用情况,

哪个用户正在使用回滚段的资源,如果有用户最好更换时间(特别是生产环境)。

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; 

4. 检查UNDO Segment状态

select usn,xacts,rssize/1024/1024/1024,hwmsize/1024/1024/1024,shrinks from v$rollstat order by rssize;

5. 创建新的UNDO表空间,并设置自动扩展参数;

create undo tablespace undotbs2 datafile '/u01/app/oracle/oradata/DWHDB1/datafile/UNDOTBS02.DBF' size 10m reuse autoextend on next 100m maxsize unlimited;

6. 动态更改spfile配置文件;

alter system set undo_tablespace=undotbs2 scope=both;

7. 等待原UNDO表空间所有UNDO SEGMENT OFFLINE;

select usn,xacts,status,rssize/1024/1024/1024,hwmsize/1024/1024/1024,shrinks from v$rollstat order by rssize;

8. 再执行看UNDO表空间所有UNDO SEGMENT ONLINE;

select usn,xacts,status,rssize/1024/1024/1024,hwmsize/1024/1024/1024,shrinks from v$rollstat order by rssize;

9. 此时数据库处于静止状态,无任何DML操作,查看UNDOTBS1已经处于OFFLINE状态

select tablespace_name , status , count(*) from dba_rollback_segs group by tablespace_name , status;

10. 检查确认UNDOTBS1中没有ONLINE的segment

select status,segment_name from dba_rollback_segs where status not in ('OFFLINE') and tablespace_name='UNDOTBS1';

11. 删除原有的UNDO表空间;

  drop tablespace undotbs1 including contents;

12. 确认删除是否成功;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值