Oracle 數據庫裡查看表空間使用狀況;
Oracle表空間的事情狀況要經常查看,一般空閒比例過低的時候就應該考慮增大表看空間了。查看方法如下SQL:
方法一:
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)
方法二:
SELECT Total.name "Tablespace Name",
Free_space, (total_space-Free_space) Used_space, total_space
FROM
(select tablespace_name, sum(bytes/1024/1024) Free_Space
from sys.dba_free_space
group by tablespace_name
) Free,
(select b.name, sum(bytes/1024/1024) TOTAL_SPACE
from sys.v_$datafile a, sys.v_$tablespace B
where a.ts# = b.ts#
group by b.name
) Total
WHERE Free.Tablespace_name = Total.name
當發現有的表空間不夠的錯誤時,處理如下:
1:找出該表空間對應的數據文件及路徑
select * from dba_data_files t
where t.tablespace_name = 'ARD'
2:增大數據文件
alter database datafile '全路徑的數據文件名稱' resize ***M
3:增加數據文件
alter tablespace 表空間名稱
add datafile '全路徑的數據文件名稱' ***M
注解:表空間盡量讓free百分比保持在10%以上,如果低於10%就增加datafile或者resizedatafile,一般數據文件不要超過2G