新聞中心
在oracle數(shù)據(jù)庫中刪除表后,怎樣把占用的磁盤空間釋放
使用: truncate table tablename DROP STORAGE;
創(chuàng)新互聯(lián)專注于企業(yè)成都營銷網(wǎng)站建設(shè)、網(wǎng)站重做改版、安州網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5響應(yīng)式網(wǎng)站、購物商城網(wǎng)站建設(shè)、集團公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為安州等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
解釋: 直接刪除表,并且釋放存儲空間。truncate的意思是清空表數(shù)據(jù), “DROP STORAGE”是釋放存儲空間。
Oracle 刪除表中記錄 如何釋放表及表空間大小
解決方案
執(zhí)行
alter?table?jk_test?move
或
alter?table?jk_test?move?storage(initial?64k)
或
alter?table?jk_test?deallocate?unused
或
alter?table?jk_test?shrink?space.
注意:因為alter table jk_test move 是通過消除行遷移,清除空間碎片,刪除空閑空間,實現(xiàn)縮小所占的空間,但會導(dǎo)致此表上的索引無效(因為ROWID變了,無法找到),所以執(zhí)行 move 就需要重建索引。
找到表對應(yīng)的索引
select?index_name,table_name,tablespace_name,index_type,status??from?dba_indexes??where?table_owner='SCOTT'
根據(jù)status 的值,重建無效的就行了。sql='alter index '||index_name||' rebuild'; 使用存儲過程執(zhí)行,稍微安慰。
還要注意alter table move過程中會產(chǎn)生鎖,應(yīng)該避免在業(yè)務(wù)高峰期操作!
另外說明:truncate table jk_test 會執(zhí)行的更快,而且其所占的空間也會釋放,應(yīng)該是truncate 語句執(zhí)行后是不會進(jìn)入oracle回收站(recylebin)的緣故。如果drop 一個表加上purge 也不會進(jìn)回收站(在此里面的數(shù)據(jù)可以通過flashback找回)。
不管是delete還是truncate 相應(yīng)數(shù)據(jù)文件的大小并不會改變,如果想改變數(shù)據(jù)文件所占空間大小可執(zhí)行如下語句:
alter?database?datafile?'filename'?resize?8g
重定義數(shù)據(jù)文件的大?。ú荒苄∮谠摂?shù)據(jù)文件已用空間的大小)。
另補充一些PURGE知識
Purge操作:
1). Purge tablespace tablespace_name : 用于清空表空間的Recycle Bin
2). Purge tablespace tablespace_name user user_name: 清空指定表空間的Recycle Bin中指定用戶的對象
3). Purge recyclebin: 刪除當(dāng)前用戶的Recycle Bin中的對象。
4). Purge dba_recyclebin: 刪除所有用戶的Recycle Bin中的對象,該命令要sysdba權(quán)限
5). Drop table table_name purge:??刪除對象并且不放在Recycle Bin中,即永久的刪除,不能用Flashback恢復(fù)。
6). Purge index recycle_bin_object_name: 當(dāng)想釋放Recycle bin的空間,又想能恢復(fù)表時,可以通過釋放該對象的index所占用的空間來緩解空間壓力。 因為索引是可以重建的。
二、如果某些表占用了數(shù)據(jù)文件的最后一些塊,則需要先將該表導(dǎo)出或移動到其他的表空間中,然后刪除表,再進(jìn)行收縮。不過如果是移動到其他的表空間,需要重建其索引。
1、
SQL?alter?table?t_obj?move?tablespace?t_tbs1;???---移動表到其它表空間
也可以直接使用exp和imp來進(jìn)行
2、
SQLalter?owner.index_name?rebuild;?????--重建索引
3、刪除原來的表空間
如何釋放oracle臨時表空間
重新創(chuàng)建一個臨時表空間,把原來的默認(rèn)臨時表空間drop掉(包括里面的臨時數(shù)據(jù)文件)再重新建立
SQL create temporary tablespace temp2
2 tempfile '/home/oracle/oracle/product/10.2.0/oradata/hatest/temp02.pdf' size 512M reuse
3 autoextend on next 640k maxsize unlimited;
Tablespace created.
SQL alter database default temporary tablespace temp2;
Database altered.
SQL drop tablespace temp including contents and datafiles;
Tablespace dropped.
(注意:由于臨時表空間的數(shù)據(jù)文件比較大,所以這步可能會花費比較長的時間)
SQL create temporary tablespace temp
2 tempfile '/home/oracle/oracle/product/10.2.0/oradata/hatest/temp01.pdf' size 512M reuse
3 autoextend on next 640K maxsize unlimited;
Tablespace created.
SQL alter database default temporary tablespace temp;
Database altered.
SQL drop tablespace temp2 including contents and datafiles;
Tablespace dropped.
SQL exit
ORACLE如何清理數(shù)據(jù)可以使表空間立即釋放
1、刪除用戶和數(shù)據(jù),磁盤空間不會釋放,因為數(shù)據(jù)文件大小已定。
2、解決方法最直接的就是:導(dǎo)出數(shù)據(jù), 重建數(shù)據(jù)文件、表空間, 重新導(dǎo)入數(shù)據(jù)。
當(dāng)前題目:oracle如何釋放空間,oracle空間釋放空間
文章出自:http://www.dlmjj.cn/article/dseepes.html