1.startup --启动数据库
2.create temporary tablespace TEMP2 TEMPFILE '/home2/oracle/oradata/sysmon/temp02.dbf' SIZE 512M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED; --创建中转临时表空间
3.alter database default temporary tablespace temp2; --改变缺省临时表空间 为刚刚创建的新临时表空间temp2
4.drop tablespace temp including contents and datafiles;--删除原来临时表空间
5.create temporary tablespace TEMP TEMPFILE '/home2/oracle/oradata/sysmon/temp01.dbf' SIZE 512M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED; --重新创建临时表空间
6.alter database default temporary tablespace temp; --重置缺省临时表空间为新建的temp表空间
7.drop tablespace temp2 including contents and datafiles;--删除中转用临时表空间
8.alter user roll temporary tablespace temp; --重新指定用户表空间为重建的临时表空间
回滚段表空间也可以如法炮制,语句写法如下:
SQL> create undo tablespace undotbs2 datafile '/oracle/app/oradata/smscdb/undotbs2.dbf' size 1000M;
SQL> alter system set undo_tablespace=undotbs2;
SQL> drop tablespace undotbs1 including contents and datafiles;
另外,有时我们发现表空间大小远大于实际使用的大小,希望缩小设置表空间的大小,但是直接 resize的话会报
ORA-03297 file contains used data beyond requested RESIZE value 错误。此时也可以考虑上面的方法(但是这种方法不能保存原始数据)
注: resize失败是因为oracle数据存储不是连续的,所以就算我们resize后的值比实际使用的值大,但是减少的那部分空间中可能包含已使用数据的部分,所以可能会失败
比较准确的计算表空间可以压缩范围的方法如下,假设表空间example原有300M,执行下面的语句:
SQL> SELECT * FROM DBA_FREE_SPACE where tablespace_name='EXAMPLE' order by BLOCK_ID;
TABLESPACE_NAME FILE_ID BLOCK_ID BYTES BLOCKS RELAT
IVE_FNO
------------------------------ ---------- ---------- ---------- ---------- -----
-------
EXAMPLE 5 9 148111360 18080
5
EXAMPLE 5 18097 196608 24
5
EXAMPLE 5 18129 196608 24
5
EXAMPLE 5 18185 1048576 128
5
EXAMPLE 5 18345 65536 8
5
EXAMPLE 5 18361 65536 8
5
EXAMPLE 5 19025 158728192 19376
5
可以看到该表空间在最后一个block_ID 19025 上还有158728192byte的空余空间,大约151.5M。 所以可以将表空间resize到149M
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7104/viewspace-133916/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7104/viewspace-133916/