oracle 數(shù)據(jù)庫(kù)里查看表空間使用狀況;
oracle表空間的事情狀況要經(jīng)常查看,一般空閑比例過(guò)低的時(shí)候就應(yīng)該考慮增大表看空間了。查看方法如下SQL:
方法一:
select dbf.tablespace_name,
dbf.totalspace "總量(M)",
dbf.totalblocks as 總塊數(shù),
dfs.freespace "剩余總量(M)",
dfs.freeblocks "剩余塊數(shù)",
(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
當(dāng)發(fā)現(xiàn)有的表空間不夠的錯(cuò)誤時(shí),處理如下:
1:找出該表空間對(duì)應(yīng)的數(shù)據(jù)文件及路徑
select * from dba_data_files t
where t.tablespace_name = 'ARD'
2:增大數(shù)據(jù)文件
alter database datafile '全路徑的數(shù)據(jù)文件名稱(chēng)' resize ***M
3:增加數(shù)據(jù)文件
alter tablespace 表空間名稱(chēng)
add datafile '全路徑的數(shù)據(jù)文件名稱(chēng)' ***M
注解:表空間盡量讓free百分比保持在10%以上,如果低于10%就增加datafile或者resizedatafile,一般數(shù)據(jù)文件不要超過(guò)2G聯(lián)系客服