sqlplus查詢oracle數據庫數據容量
登錄sqlplus:
cmd命令行登錄:sqlplus orcl/orcl as sysdba
查詢表空間使用率
select b.file_id 文件ID,
b.tablespace_name 表空間,
b.file_name 物理文件名,
b.bytes 總字節數,
(b.bytes-sum(nvl(a.bytes,0))) 已使用,
sum(nvl(a.bytes,0)) 剩余,
sum(nvl(a.bytes,0))/(b.bytes)*100 剩余百分比
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.file_id,b.bytes
order by b.tablespace_name
select tablespace_name, segment_name, bytes / 1024 / 1024 from user_segments where segment_type = ‘TABLE‘ and tablespace_name = ‘VNOX‘ order by bytes desc ;
查詢表空間總大小(DBA_DATA_FILES和DBA_SEGMENTS,DBA_FREE_SPACE區別)
1, dba_data_files,dba_segments,dba_free_space
得出結論:一般情況下(沒有drop表的時候):dba_data_files bytes = (dba_segments bytes + dba_free_space bytes)
實驗:
SQL> Select sum(bytes)/1024/1024/1024 from dba_segments;
SUM(BYTES)/1024/1024/1024
-------------------------
1.58441162
SQL> select sum(bytes)/1024/1024/1024 from dba_free_space;
SUM(BYTES)/1024/1024/1024
-------------------------
.323669434
SQL> select sum(bytes)/1024/1024/1024 from dba_data_files;
SUM(BYTES)/1024/1024/1024
-------------------------
1.9140625
sqlplus查詢oracle數據庫數據容量