【转】Undo Tablespace 切换注意事项

来源:互联网 发布:淘宝老司机搜索关键词 编辑:程序博客网 时间:2024/05/06 03:51

转来的,原贴地址: http://blog.csdn.net/lwei_998/article/details/6537066#



oracle中经常遇到undo表空间不释放,如果设置了unod表空间自动扩展AUTOEXTEND ON则还有可能把磁盘撑爆。当undo被撑满了,经常会选择重建undo表空间,进行切换。虽然切换undo比较容易,但如果要在生产切换undo还是考虑的周到一些比较好。

 

注意事项:

1.       检查系统使用的参数文件是pfile还是spfile

    如果用pfile记得修改pfile中的undo_tablespace参数。否则容易导致下次重启数据库时找不到历史的undo表空间而启动失败。

select  name , value from v$parameter  where name='spfile';

 

2.     切换undo时检查是否还有事务存在。如果有事务,在删除旧undo时可能会遇到ORA-30013的错误。

select  count(*) from  v$transaction;

 

3.     检查undo对应的数据文件是否被真正删除。

摘自:How to Shrink the datafile of Undo Tablespace [ID 268870.1]

NOTE: Dropping the old tablespace may give ORA-30013 : undo tablespace '%s' is currently in use. This error indicates you must wait for the undo tablespace to become unavailable. In other words, you must wait for existing transaction to commit or rollback.    Also be aware that on some platforms, disk space is not freed to the OS until the database is restarted.  The disk space will remain "allocated" from the OS perspective until the database restart.

 

4.     虽然可以在线切换undo,但切换后如果能重启一下最好。以免留下后患。或者选择在可以重启的时候去切换undo。

 

 

 切换undo的步骤:

一、检查undo设置

SQL> show parameter undo

 

二、查看undo表空间的大小

SELECT D.TABLESPACE_NAME,D.FILE_NAME, SUM(D.BYTES) / 1024 / 1024 MB
  FROM DBA_DATA_FILES D
 WHERE D.TABLESPACE_NAME LIKE 'UNDO%'
 GROUP BY D.TABLESPACE_NAME,D.FILE_NAME;

 

三、检查参数文件类型

select  name , value from v$parameter  where name='spfile';

 

四、创建undo表空间

SQL> create undo tablespace UNDOTBS2 datafile 'D:/ORACLE/PRODUCT/10.2.0/ORADATA/ORCL2/UNDOTBS02.DBF' size 500M;

 

五、等待原undo表空间UNDO SEGMENT OFFLINE后可以切换undo

SQL> SELECT USN,

  2           XACTS,

  3           STATUS,

  4           RSSIZE / 1024 / 1024 / 1024 RSSIZE,

  5           HWMSIZE / 1024 / 1024 / 1024 HWMSIZE,

  6           SHRINKS

  7      FROM V$ROLLSTAT

  8     ORDER BY RSSIZE;

 

六、切换UNDO表空间

SQL>alter system set undo_tablespace=undotbs2 scope=both;

 

七、删除UNDO表空间及数据文件

SQL>drop tablespace UNDOTBS1 including contents and datafiles;

 

Metalink中记录了一种切换undo比较稳妥的方法,可以参考一下:

How to Change the Existing Undo Tablespace to a New Undo Tablespace [ID 431652.1]

原创粉丝点击