Oracle实用小技巧:UNDO 100%占用不释放解决办法

表现是UNDO 100%占用不释放,其实原因是因为本地磁盘没有空间了,没办法让UNDO继续自动扩展了,同时现有的UNDO也有点大了,想要清理一下。

1、问题现像

起因是客户存储没空间了,目前RAC1节点UNDOTBS1占用200多G,想要把UNDO释放一下。

我这边undo_retention设置的是900,按说不应该增长到很大才对,以前确实没有注意,只是加 过几次undo数据文件。

数据库的版本为12CR2,操作系统为solaris 11。

查看发现有大量unexpired

Oracle Undo段中区3种状态(DBA_UNDO_EXTENTS的STATUS列):ACTIVE、EXPIRED和UNEXPIRED:

  • ACTIVE即未提交的Undo信息(活动):表示事物还在活动,该值对应的Undo段的DBA_ROLLBACK_SEGS.STATUS一定是ONLINE状态,一旦没有活动的事务在使用Undo段,那么对应的Undo段就变成OFFLINE状态。ACTIVE状态的Undo区不会被覆盖。
  • EXPIRED即过期的Undo信息(过期):表示事务已经提交且超过了UNDO_RETENTION指定时间,该状态可以被覆盖使用。
  • UNEXPIRED即提交的Undo信息(未过期):表示事务已经提交但是还没有超过UNDO_RETENTION指定时间,该状态可以被覆盖使用。

2、解决UNDO过大的问题

2.1、修改隐藏参数关闭autotune

查看隐藏参数_undo_autotune默认状态为true:

SELECT ksppinm, ksppstvl, ksppdesc FROM x$ksppi x, x$ksppcv y WHERE x.indx = y.indx AND ksppinm = '_undo_autotune';

修改隐藏参数来限制undo这里有2个方法

方法1:限制undoretention最大时间,就是在自动调整的结果上强制限制最大时间(试了效果不大)。

alter system set "_highthreshold_undoretention"=50000 scope=spfile;

方法2:直接关闭autotune(这个更干脆)

关于autotune可以查看官方文档Automatic Tuning of Undo Retention Common Issues (Doc ID 1579779.1)

alter system set "_undo_autotune"=false;

创建PDB参数文件

改完效果

再检查undo情况

隔了一天再检查

再检查状态基本都为expired状态

select status, count(*) Num_Extents, sum(blocks) Num_Blocks, round((sum(bytes)/1024/1024),2) MB from dba_undo_extents group by status order by status;

2.2、切换UNDO方法

我这边的数据库版本是12.2版本。默认使用LOCAL UNDO

先切换到PDB

SQL> alter session set container=pdb;
Session altered.

动之前再确认是否开启本地UNDO

SQL> select property_name, property_value from database_properties where property_name='LOCAL_UNDO_ENABLED';

PROPERTY_NAME PROPERTY_VALUE
----------------------- ---------------
LOCAL_UNDO_ENABLED TRUE

创建undo_01表空间

CREATE UNDO TABLESPACE UNDO_1 datafile '+DATA' size 10G autoextend on;

PDB修改下原来11G基本一样,也要指定下SID(这里不是写数据库的实例名)

alter system set undo_tablespace=UNDO_01 sid='orcl1' scope=both;

然后使用如下SQL查看,回滚段是否己经切换到undo_01里。

select dr.tablespace_name, dr.segment_name, vr.status from dba_rollback_segs dr, v$rollstat vr where dr.segment_id=vr.usn;

确实无误后执行删除原有UNDOTBS1。

drop tablespace UNDOTBS1 including contents and datafiles;

再次查看。

SELECT * FROM DBA_DATA_FILES;

3、关于为啥node2上的undo表空间不叫undotbs2而叫undo_2

第2个节点的名称挺奇怪,原来11g的时候都是undotbs1和undotbs2

在PDB里显示为1节点是undotbs1,2节点是undo_2。这个在12CR2的版本里是正常现像,RAC环境创建PDB的第2个节点就是默认叫这个名,可以参照官方文档说明。

With Local Undo Enabled and RAC Environment,The UNDO Tablespace of a PDB is UNDO_2 (Doc ID 2971554.1)

如果你觉得别扭,可以手动创建个undotbs2进行切换,具体方法参照官方文档,这里我贴出来

 If you need to change the UNDO tablespace of the PDB on node 2 from UNDO_2, do the following in the target PDB on node2:

Check the current UNDO tablespace. -- Connect to and execute the PDB on the target node.
alter session set container=;

show con_name

-- Check the current UNDO tablespace.

show parameter undo_tablespace 

If there is no UNDO tablespace to change to, create a new UNDO tablespace.
CREATE UNDO TABLESPACE SIZE AUTOEXTEND ON ;

example:

CREATE UNDO TABLESPACE UNDOTBS2 datafile SIZE 10M AUTOEXTEND ON ;

Verify that the undo tablespace that you want to change has been created.

SELECT * FROM DBA_DATA_FILES;

 Change the UNDO tablespace.
alter system set undo_tablespace= container=current  sid='' scope=spfile ;example:

alter system set undo_tablespace=UNDOTBS2 container=current  sid='orcl2' scope=spfile ;

Restart the PDB and confirm that you have switched to the new tablespace.
Restart the PDB:shutdown

startupPlease confirm that you have switched to the new tablespace.

See if the segment for the old undo tablespace (UNDO_2) disappears.

select dr.tablespace_name, dr.segment_name, vr.status from dba_rollback_segs dr, v$rollstat vr where dr.segment_id=vr.usn;

 Drop the old UNDO tablespace.
drop tablespace UNDO_2 including contents and datafiles;

Verify that the original undo tablespace has been dropped.

SELECT * FROM   DBA_DATA_FILES;

4、参考

Document 1578639.1 (oracle.com)

也欢迎关注我的公众号【徐sir的IT之路】,一起学习!

————————————————————————————
公众号:徐sir的IT之路
优快云 :徐sir(徐慧阳)-优快云博客
墨天轮:徐sir的个人主页 - 墨天轮
PGFANS:PGFans问答社区:全球唯一的PostgreSQL中文技术交流社区

————————————————————————————

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐sir(徐慧阳)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值