数据库空间使用情况

“`
source /etc/profile
source ~/.bash_profile

echo “Table_space start time: ​​date +"%Y-%m-%d %H:%M:%S"​​​”
free -m
sqlplus -s smb/czty_smb@ZSMS << EOF

SELECT TABLESPACE_NAME “表空间”,
To_char(Round(BYTES / 1024, 2), ‘99990.00’) || ‘G’ “实有”,
To_char(Round(FREE / 1024, 2), ‘99990.00’) || ‘G’ “现有”,
To_char(Round((BYTES - FREE) / 1024, 2), ‘99990.00’) || ‘G’ “使用”,
To_char(Round(10000 * USED / BYTES) / 100, ‘99990.00’) || ‘%’ “比例”
FROM (SELECT A.TABLESPACE_NAME TABLESPACE_NAME,
Floor(A.BYTES / (1024 * 1024)) BYTES,
Floor(B.FREE / (1024 * 1024)) FREE,
Floor((A.BYTES - B.FREE) / (1024 * 1024)) USED
FROM (SELECT TABLESPACE_NAME TABLESPACE_NAME, Sum(BYTES) BYTES
FROM DBA_DATA_FILES
GROUP BY TABLESPACE_NAME) A,
(SELECT TABLESPACE_NAME TABLESPACE_NAME, Sum(BYTES) FREE
FROM DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) B
WHERE A.TABLESPACE_NAME = B.TABLESPACE_NAME)

ORDER BY Floor(10000 * USED / BYTES) DESC;
···