SELECT
tablespace_name,
file_id,
file_name,
round( bytes / ( 1024 * 1024 ), 0 ) total_space
FROM
dba_data_files
ORDER BY
tablespace_name;
3 查询所有表空间以及每个表空间的大小,已用空间,剩余空间,使用率和空闲率,直接执行语句就可以.
复制代码
SELECT
a.tablespace_name,
total,
free,
total - free AS used,
substr( free / total * 100, 1, 5 ) AS "FREE%",
substr( ( total - free ) / total * 100, 1, 5 ) AS "USED%"
FROM
(SELECT tablespace_name, sum( bytes ) / 1024 / 1024 AS total FROM dba_data_files GROUP BY tablespace_name) a,
(SELECT tablespace_name, sum( bytes ) / 1024 / 1024 AS free FROM https://zhida.zhihu.com/search?content_id=231075085&content_type=Article&match_order=1&q=dba_free_space&zd_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ6aGlkYV9zZXJ2ZXIiLCJleHAiOjE3NDg1NzI1MTYsInEiOiJkYmFfZnJlZV9zcGFjZSIsInpoaWRhX3NvdXJjZSI6ImVudGl0eSIsImNvbnRlbnRfaWQiOjIzMTA3NTA4NSwiY29udGVudF90eXBlIjoiQXJ0aWNsZSIsIm1hdGNoX29yZGVyIjoxLCJ6ZF90b2tlbiI6bnVsbH0.6BaRKjgOV7zPbI0l6UZ-I3Xgn_BZtbQZhh1JUNP--74&zhida_source=entity GROUP BY tablespace_name) b
WHERE
a.tablespace_name = b.tablespace_name
ORDER BY
a.tablespace_name;
4 查询某个具体的表所占空间的大小,把 TABLE_NAME 换成具体要查询的表的名称就可以了
复制代码
SELECT
t.segment_name,
t.segment_type,
sum( t.bytes / 1024 / 1024 ) "占用空间(M)"
FROM
dba_segments t
WHERE
t.segment_type = 'TABLE'
AND t.segment_name = 'TABLE_NAME'
GROUP BY
OWNER,
t.segment_name,
t.segment_type;