查詢表空間的總大小,剩余表空間,已用空間,表占用大小,某天占用的大小


引用 :http://blog.csdn.net/cosio/article/details/3978747  , https://zhidao.baidu.com/question/628524115699308364.html

block 塊
extent 區
segment 段

--增加USERS表空間500M空間
alter tablespace USERS add datafile '/data01/oradata/bidb96/USER_test30.bdf' size 500M;
select file_name , tablespace_name, t.* from dba_data_files t where tablespace_name = 'USERS' order by file_id;


--每個表占用的空間
select segment_name,sum(bytes )/1024/1024/1024 GB
from user_segments --where segment_name ='TR_GOV_WJ_XNH_D'
group by segment_name ;


--20190530這天TW層占用的空間
select count(distinct segment_name) tb_cnt,sum(bytes)/(1024*1024*1024) GB
from user_segments t
where partition_name='P_20190530'
and segment_name like 'TW%';

----查看剩余表空間  匯總
SELECT t1 表空間,z 總表空間,z-s 已用表空間,s 剩余表空間,ROUND((z-s)/z*100,2) "使用率%"
From (Select tablespace_name t1,Sum(bytes)/(1024*1024*1024) s
 From DBA_FREE_SPACE Group by tablespace_name),
 (Select tablespace_name t2,Sum(bytes)/(1024*1024*1024) z
 From DBA_DATA_FILES Group by tablespace_name) Where t1=t2;


---表空間總共的空間  
select tablespace_name,sum(bytes)/(1024*1024*1024) GB from dba_data_files
group by tablespace_name
;
--表空間剩余空間
select tablespace_name,sum(bytes)/(1024*1024*1024) GB from user_free_space
group by tablespace_name
;
--表空間占用的空間 表空間所有對象的物理占用(表,分區,索引等) 這個和DBA_DATA_FILES的大小才一樣
select tablespace_name,sum(bytes)/(1024*1024*1024) GB from user_segments
group by tablespace_name
;

----表實際使用大小  這個大小相加必定<DBA_DATA_FILES的大小,因為只有表 , 這個貌似沒有及時更新
select table_name,(num_rows * avg_row_len )/(1024*1024*1024) 該表大小GB
from user_tables 
where table_name = '表名大寫'--672699條數據 0.306965947151184GB
order by 2 desc


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM