Oracle 如何释放数据库空间
当需要释放数据库空间的时候,通常的方案会用有truncate、delete、drop/re-creating等处理。其中truncate 后会立即释放,并且不能回滚;但delete不能立即释放数据库空间,还会产生archive log。下面就简单介绍一下:
如: Truncate table xxxx; 我们可以直接去查user_segments对应table的bytes就变小,数据库空间释放,并且不能回滚。用Truncate去删除记录比drop表再创建表效率更高。
Use the TRUNCATE
statement to remove all rows from a table or cluster. By default, Oracle Database also deallocates all space used by the removed rows except that specified by the MINEXTENTS
storage parameter and sets the NEXT
storage parameter to the size of the last extent removed from the segment by the truncation process.
Removing rows with the TRUNCATE
statement can be more efficient than dropping and re-creating a table. Dropping and re-creating a table invalidates dependent objects of the table, requires you to regrant object privileges on the table, and requires you to re-create the indexes, integrity constraints, and triggers on the table and respecify its storage parameters. Truncating has none of these effects.
Delete操作后,不能立即释放数据库空间,并且还会产生archive log(查看user_segments大小没有变化),需要做其他操作。如Oracle 10g, 11可以用下面操作来释放数据库空间。
alter table table_name shrink space cascade;
如果报ora-10636 row movement is not enabled,先执行下面语句:
alter table table_name enable row movement;
(由于是个人的一些理解,主要是总结一下,如有不对,欢迎指正)
已有 0 人发表留言,猛击->> 这里<<-参与讨论
ITeye推荐