Oracle undo还原表空间

还原表空间的功能介绍看这里:https://www.cnblogs.com/lijiaman/p/7617351.html
在RAC集群数据库情况下,每个节点上的实例都需要有自己单独的还原表空间,该表空间放在共享存储中,通过参数文件中 undo_tablespace 参数来定义,下面的 spfile 参数表明

orcl1 使用 undotbs1, 而 orcl2 使用 undotbs2:

orcl1.undo_tablespace='undotbs1'
orcl2.undo_tablespace='undotbs2'

注:一个时刻只能使用一个还原表空间

一. 查看还原表空间

--查看系统下一共有几个还原表空间(一般单机一个,rac会有两个,每个节点一个)
select tablespace_name,contents from dba_tablespaces where contents='UNDO';
--查看所有节点 (rac) 还原表空间及对应的文件
select tablespace_name , file_name  from dba_data_files where tablespace_name like '%UNDO%' ;

--查看本节点还原表空间
show parameter undo 

--查看回滚段使用情况,哪个用户正在使用回滚资源
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;

--检查UNDO Segment状态,查看还原表空间里还有多少个回滚对像
select usn,xacts,rssize/1024/1024/1024,hwmsize/1024/1024/1024,shrinks from v$rollstat order by rssize;

--查看控制文件位置
select name from v$controlfile;

二. 新建增加还原表空间

一般不用新建,但说不好啥时这个undo表空间坏了,如下列情况:

SQL> shutdown immediate
ORA-00600: internal error code, arguments: [2032], [12587038], [12587038],
[8192], [2], [255], [0], [767], [], [], [], []

并且插入数据的时候出现:
ORA-01110: 数据文件 3: '/data/Oracle/ORCL/undotbs01.dbf' 语句:insert into xxx(
xxx) values(xxx)
[2014-02-11 16:09:58] Connection::ExecSQL错误:ORA-01578: ORACLE数据块损坏 (文件号 3,块号 4126)

一般出现这个情况下就是undo表空间损坏导致,需要新建一个来替换

 新建过程:

--查看现有表空间及对应文件
SQL> show parameter undo
SQL> select tablespace_name , file_name  from dba_data_files where tablespace_name like '%UNDO%' ;

--查看还原表空间大小
SQL> select sum(bytes)/1024/1024 "current undo size(M)" from dba_data_files where tablespace_name='UNDOTBS1';    -- 或 UNDOTBS2
SQL> select tablespace_name, file_name,bytes/1024/1024 from dba_data_files where tablespace_name like 'UNDOTBS%' order by 1;

--创建新的还原表空间
SQL> create undo tablespace undo02 datafile '/data/oracle/ORCL/undotbs02.dbf' size 2800M;

--更改设置 undo02 为还原表空间
SQL> alter system set undo_tablespace=undo02  scope=both; 

--再次查看已更换
SQL> show parameter undo
SQL> select tablespace_name,contents from dba_tablespaces where contents='UNDO';
SQL> select sum(bytes)/1024/1024 "current undo size(M)" from dba_data_files where tablespace_name='UNDOTBS1';

验证:
关库重启应该不报错了:
shutdown immediate;
starup;

三. RAC下新建还原表空间方法

说明:RAC下每个节点使用自己的还原表空间,如果都要新建要指定分配

--创建两个还原表空间
create undo tablespace undotbs3  '/data/oracle/ORCL/undotbs03.dbf' size 2800M;
create undo tablespace undotbs4  '/data/oracle/ORCL/undotbs04.dbf' size 2800M;

--分别分配给rac1和rac2
alter system set undo_tablespace=undotbs3 scope=both sid='rac1';
alter system set undo_tablespace=undotbs4 scope=both sid='rac2';

--然后分别在rac1和rac2上查看
show parameter undo

--也可以在原undo表空间扩容,以下是添加建好的裸设备

alter tablespace UNDOTBS1 add datafile '/dev/rr10g_099' size 32767M;
alter tablespace UNDOTBS2 add datafile '/dev/rr10g_100' size 32767M;

posted @ 2020-06-10 19:00  莫让年华付水流  阅读(835)  评论(0)    收藏  举报