使用: truncate table tablename DROP STORAGE;

創(chuàng)新互聯(lián)專注于企業(yè)成都營(yíng)銷網(wǎng)站建設(shè)、網(wǎng)站重做改版、安州網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5響應(yīng)式網(wǎng)站、購(gòu)物商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為安州等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
解釋: 直接刪除表,并且釋放存儲(chǔ)空間。truncate的意思是清空表數(shù)據(jù), “DROP STORAGE”是釋放存儲(chǔ)空間。
解決方案
執(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.
注意:因?yàn)閍lter table jk_test move 是通過(guò)消除行遷移,清除空間碎片,刪除空閑空間,實(shí)現(xiàn)縮小所占的空間,但會(huì)導(dǎo)致此表上的索引無(wú)效(因?yàn)镽OWID變了,無(wú)法找到),所以執(zhí)行 move 就需要重建索引。
找到表對(duì)應(yīng)的索引
select?index_name,table_name,tablespace_name,index_type,status??from?dba_indexes??where?table_owner='SCOTT'
根據(jù)status 的值,重建無(wú)效的就行了。sql='alter index '||index_name||' rebuild'; 使用存儲(chǔ)過(guò)程執(zhí)行,稍微安慰。
還要注意alter table move過(guò)程中會(huì)產(chǎn)生鎖,應(yīng)該避免在業(yè)務(wù)高峰期操作!
另外說(shuō)明:truncate table jk_test 會(huì)執(zhí)行的更快,而且其所占的空間也會(huì)釋放,應(yīng)該是truncate 語(yǔ)句執(zhí)行后是不會(huì)進(jìn)入oracle回收站(recylebin)的緣故。如果drop 一個(gè)表加上purge 也不會(huì)進(jìn)回收站(在此里面的數(shù)據(jù)可以通過(guò)flashback找回)。
不管是delete還是truncate 相應(yīng)數(shù)據(jù)文件的大小并不會(huì)改變,如果想改變數(shù)據(jù)文件所占空間大小可執(zhí)行如下語(yǔ)句:
alter?database?datafile?'filename'?resize?8g
重定義數(shù)據(jù)文件的大小(不能小于該數(shù)據(jù)文件已用空間的大小)。
另補(bǔ)充一些PURGE知識(shí)
Purge操作:
1). Purge tablespace tablespace_name : 用于清空表空間的Recycle Bin
2). Purge tablespace tablespace_name user user_name: 清空指定表空間的Recycle Bin中指定用戶的對(duì)象
3). Purge recyclebin: 刪除當(dāng)前用戶的Recycle Bin中的對(duì)象。
4). Purge dba_recyclebin: 刪除所有用戶的Recycle Bin中的對(duì)象,該命令要sysdba權(quán)限
5). Drop table table_name purge:??刪除對(duì)象并且不放在Recycle Bin中,即永久的刪除,不能用Flashback恢復(fù)。
6). Purge index recycle_bin_object_name: 當(dāng)想釋放Recycle bin的空間,又想能恢復(fù)表時(shí),可以通過(guò)釋放該對(duì)象的index所占用的空間來(lái)緩解空間壓力。 因?yàn)樗饕强梢灾亟ǖ摹?/p>
二、如果某些表占用了數(shù)據(jù)文件的最后一些塊,則需要先將該表導(dǎo)出或移動(dòng)到其他的表空間中,然后刪除表,再進(jìn)行收縮。不過(guò)如果是移動(dòng)到其他的表空間,需要重建其索引。
1、
SQL?alter?table?t_obj?move?tablespace?t_tbs1;???---移動(dòng)表到其它表空間
也可以直接使用exp和imp來(lái)進(jìn)行
2、
SQLalter?owner.index_name?rebuild;?????--重建索引
3、刪除原來(lái)的表空間
重新創(chuàng)建一個(gè)臨時(shí)表空間,把原來(lái)的默認(rèn)臨時(shí)表空間drop掉(包括里面的臨時(shí)數(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í)表空間的數(shù)據(jù)文件比較大,所以這步可能會(huì)花費(fèi)比較長(zhǎng)的時(shí)間)
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
1、刪除用戶和數(shù)據(jù),磁盤空間不會(huì)釋放,因?yàn)閿?shù)據(jù)文件大小已定。
2、解決方法最直接的就是:導(dǎo)出數(shù)據(jù), 重建數(shù)據(jù)文件、表空間, 重新導(dǎo)入數(shù)據(jù)。
分享名稱:oracle如何釋放空間,oracle空間釋放空間
鏈接URL:http://chinadenli.net/article43/dseepes.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、服務(wù)器托管、微信小程序、動(dòng)態(tài)網(wǎng)站、網(wǎng)站策劃、虛擬主機(jī)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)