今天在自己的实验环境上建了一个用户test,在此用户下建立了50多张表并插入了海量数据,最后发现磁盘空间几乎沾满,想做别的实验已经不可能,于是删除了用户test,使用关键词cascade删除的,但是最后发现用户虽然删除了,但是数据文件的大小依然没有变化,并且发现有大量的undo日志,undo表空间异常的大,怎么解决次问题呢???
解决思路:
查看
undo数据文件太大希望重建undo表空间,并且通过alter database datafile 'users01.dbf' resize ...修改数据文件的大小
在执行的时候遇到了问题:
问题:undo表空间不能删除
SQL> showparameter undo
NAME TYPE VALUE
----------------------------------------------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS1
SQL> create undotablespace undotbs2 datafile '/u01/app/oracle/oradata/dsg01/undotbs201.dbf'size 300M;
表空间已创建。
SQL> alter systemset undo_tblespace=undotbs2;
alter system setundo_tblespace=undotbs2
*
第 1 行出现错误:
ORA-02065: 非法的 ALTER SYSTEM 选项
SQL> alter systemset undo_tablespace=undotbs2;
系统已更改。
SQL> showparameter undo
NAME TYPE VALUE
----------------------------------------------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS2
SQL>
SQL>
SQL>
SQL> droptablespace undotbs1;
drop tablespaceundotbs1
*
第 1 行出现错误:
ORA-30013: 还原表空间 'UNDOTBS1' 当前正在使用中
SQL> alter systemswitch logfile;
系统已更改。
SQL> droptablespace undotbs1;
drop tablespaceundotbs1
*
第 1 行出现错误:
ORA-30013: 还原表空间 'UNDOTBS1' 当前正在使用中
SQL> !oerr ora30013
30013, 00000,"undo tablespace '%s' is currently in use"
// *Cause: the specified undo tablespace is currentlyused by another
// instance.
// *Action: Wait for the undo tablespace to becomeavailable or
// change to another name and reissuethe statement.
SQL> alter systemcheckpoint;
系统已更改。
SQL> droptablespace undotbs1;
drop tablespaceundotbs1
*
第 1 行出现错误:
ORA-30013: 还原表空间 'UNDOTBS1' 当前正在使用中
SQL> ^C
SQL>
SQL>
SQL> showparameter undo
NAME TYPE VALUE
----------------------------------------------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS2
SQL> droptablespace undotbs1;
drop tablespaceundotbs1
*
第 1 行出现错误:
ORA-30013: 还原表空间 'UNDOTBS1' 当前正在使用中
SQL> altertablespace undotbs1 offline;
alter tablespaceundotbs1 offline
*
第 1 行出现错误:
ORA-30042:无法使还原表空间脱机
分析:undotbs1表空间中有未处理完成的事务,那么怎么处理未完成的事务呢?
什么不能将undotbs1置为offline呢,原因当你切换tablespace后,新的事务都会使用新的untotbs,而老的事务仍然在用着老的空间,等所有老的事务都提交后(一般需要等待十分钟,你再进行置为offline即可),就你可以将老的undotbs1置为offline.
SQL> altertablespace undotbs1 offline;
表空间已更改。
SQL> droptablespace undotbs1 including contents and datafiles;
表空间已删除。
(2)重置永久表空间的大小
SQL> alter database datafile '/u01/app/oracle/oradata/dsg01/users01.dbf' resize 500M;
alter database datafile '/u01/app/oracle/oradata/dsg01/users01.dbf' resize 500M
*
第 1 行出现错误:
ORA-03297: 文件包含在请求的 RESIZE 值以外使用的数据
SQL> alter database datafile '/u01/app/oracle/oradata/dsg01/users01.dbf' resize 700M;
数据库已更改。