undo表空间里保持的是数据修改的镜像,对应于专用的undo segment来存储,Oracle用他来实现transaction的rollback,同时也是用来保持一致性读(consistent read)的,保持事务间的数据读取。以及事务恢复(recovery transaction)。在10g里 undo表空间还有特殊的功能就是做table级别的flashback(闪回)。 undo表空间也不知道是不是自动收缩,有文档说这个将有Oracle数据库体系管理,但是现实中undo表空间的一味扩展有时会占用大量的存储空间,这样有时也会对我们的系统造成崩溃性的伤害,作为管理员,我们必须把一切危害数据库健康的因数都排除掉。那么我们该如何示范过度占用的undo表空间了。

 

 

随着我们一起来看看吧。

1. 确认表空间名
SQL>show parameter undo_tablespace;
NAME TYPE VALUE
———————————— ———– ——————————
undo_tablespace string UNDOTBS1

2. 查找表空间datafile
SQL>select * from dba_data_files where tablespace_name = ‘UNDOTBS1′;
FILE_NAME TABLESPACE_NAME BYTES
——————————————————————————– —————————— ———-
/opt/oracle/oradata/undotbs01.dbf UNDOTBS1 209715200

SQL> 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
———- ———- ——————— ———————- ———-
0 0 0.00035858154296875 0.00035858154296875 0
2 0 0.00109100341796875 0.00304412841796875 2
4 0 0.00109100341796875 0.00304412841796875 2
10 0 0.00109100341796875 0.00206756591796875 1
5 0 0.00109100341796875 0.00206756591796875 1
7 0 0.00109100341796875 0.00206756591796875 1
1 0 0.00206756591796875 0.00206756591796875 1
3 0 0.00206756591796875 0.00304412841796875 1
8 0 0.00206756591796875 0.00304412841796875 1
9 0 0.00206756591796875 0.00304412841796875 1
6 0 0.00218963623046875 0.00218963623046875 1

3. 创建新的undo表空间
SQL> create undo tablespace undotbs2 datafile ‘/opt/oracle/oradata/undotbs02.dbf ‘ size 50M autoextend on next 50M maxsize 200M extent management local;

4. 切换udon表空间至新表空间
SQL> alter system set undo_tablespace=undotbs2 scope=both;

5. 查询切换后的表空间
SQL>show parameter undo_tablespace;
NAME TYPE VALUE
———————————— ———– ——————————
undo_tablespace string UNDOTBS2

SQL> select usn,xacts,rssize/1024/1024/1024,hwmsize/1024/1024/1024,shrinks from v$rollstat order by rssize;
SQL> 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
———- ———- ——————— ———————- ———-
11 0 0.00011444091796875 0.00011444091796875 0
12 0 0.00011444091796875 0.00011444091796875 0
13 0 0.00011444091796875 0.00011444091796875 0
15 0 0.00011444091796875 0.00011444091796875 0
17 0 0.00011444091796875 0.00011444091796875 0
19 0 0.00011444091796875 0.00011444091796875 0
20 0 0.00011444091796875 0.00011444091796875 0
18 0 0.00011444091796875 0.00011444091796875 0
16 0 0.00011444091796875 0.00011444091796875 0
14 0 0.00011444091796875 0.00011444091796875 0
0 0 0.00035858154296875 0.00035858154296875 0

6. drop掉原来的表空间
SQL>drop tablespace undotbs1 including contents and datafiles;






===============================================================

Inthirties关注Oracle数据库 维护,优化,安全,备份,恢复,迁移,故障处理

 

QQ群:  85837884(注明:数据库)