1. 程式人生 > >ORACLE資料庫儲存空間使用情況查詢

ORACLE資料庫儲存空間使用情況查詢

使用系統sys或者dba許可權的賬戶建立檢視如下:

  1. 主要從資料庫的表dba_data_files,dba_segments兩張表中獲取。
  2. 預設資料庫儲存的是byte單位,轉換關係如下:
    1024bytes = 1kb
    1024KB = 1M
    1024M = 1G
CREATE OR REPLACE VIEW V_GET_DISKSPACE AS
 SELECT A.TABLESPACE_NAME,
 A.USE "USED (MB)",
 (B.TOTAL-A.USE) "FREE (MB)",
 B.TOTAL "TOTAL (MB)",
 round((B.TOTAL-A.USE)/B.TOTAL,5
)*100||'%' "PER_FREE" FROM ( select TABLESPACE_NAME,sum(bytes)/(1024*1024) as USE from dba_segments /*where tablespace_name NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2')*/ GROUP BY TABLESPACE_NAME ) A , ( WITH TABLESPACE_TOTAL AS ( SELECT tablespace_name,sum(MAXBYTES)/(1024*1024) TOTAL FROM
DBA_DATA_FILES T WHERE /*T.TABLESPACE_NAME NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2') AND*/ T.AUTOEXTENSIBLE='YES' group by tablespace_name UNION ALL SELECT tablespace_name,sum(bytes) TOTAL FROM DBA_DATA_FILES T WHERE /*T.TABLESPACE_NAME NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2'
) AND*/ T.AUTOEXTENSIBLE='NO' group by tablespace_name ) SELECT TABLESPACE_NAME,SUM(TOTAL) TOTAL FROM TABLESPACE_TOTAL GROUP BY TABLESPACE_NAME ) B WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME;

LINUX伺服器查詢

  1. du -sch * 使用該命令查詢當前目錄下資料夾佔用的空間的情況

  2. df -hl 查詢磁碟剩餘空間