目錄
一、擴容:參考?https://blog.csdn.net/weixin_40841731/article/details/134931289
二、清理數據
1、查詢文件大小情況(管理員賬號)
2、查詢表的大小(使用該表空間的用戶)
3、清理數據(使用該表空間的用戶)
報錯:
1、0RA-01653:表aaa.xxx無法通過1024(在表空間aaa中)擴展
2、ORA-01144:文件大小(4352000塊)超出4194303塊的最大數
處理方式:
一、擴容:參考?https://blog.csdn.net/weixin_40841731/article/details/134931289
二、清理數據
1、查詢文件大小情況(管理員賬號)
select dbf.tablespace_name,
dbf.totalspace "總量(M)",
dbf.totalblocks as 總塊數,
dfs.freespace "剩余總量(M)",
dfs.freeblocks "剩余塊數",
(dfs.freespace / dbf.totalspace) * 100 "空閑比例"
from (select t.tablespace_name,
sum(t.bytes) / 1024 / 1024 totalspace,
sum(t.blocks) totalblocks
from dba_data_files t
group by t.tablespace_name) dbf,
(select tt.tablespace_name,
sum(tt.bytes) / 1024 / 1024 freespace,
sum(tt.blocks) freeblocks
from dba_free_space tt
group by tt.tablespace_name) dfs
where trim(dbf.tablespace_name) = trim(dfs.tablespace_name) and dfs.tablespace_name='aaa'
2、查詢表的大小(使用該表空間的用戶)
select segment_name, bytes / 1024 / 1024
from user_segments
where segment_type = 'TABLE' order by bytes desc;
3、清理數據(使用該表空間的用戶)
a.重建表
創建一個新表,將舊表的數據插入到新表中,再刪除舊表,這種方法可以徹底釋放空間,但如果表空間不足以創建新表再插入數據時,這種方法是不可行的。
CREATE TABLE new_table AS SELECT * FROM your_table WHERE 1=0;
INSERT INTO new_table SELECT * FROM your_table;
DROP TABLE your_table;
ALTER TABLE new_table RENAME TO your_table;
b.使用TRUNCATE命令
如果你只是想刪除表中的所有數據而不是結構本身,可以使用TRUNCATE命令。這將會刪除表中的所有數據,并且會釋放占用的空間:
TRUNCATE TABLE your_table;
c、刪除表數據
Oracle數據庫使用了一種可稱為“可變長記錄”的存儲結構,這意味著即使刪了表數據,原來的空間也仍然被保留以供將來可能相同記錄的大小使用。這種方式是為了提高數據庫操作的效率,避免頻繁的釋放存儲空間。
通過shrink space收縮表,釋放空間
--刪除數據
delete from table_aa where ab='xx';--打開行移動
alter table table_aa enable row movement;
--下調HWM
alter table table_aa shrink space;
--關閉行移動
alter table table_aa disable row movement;