1.查询oracle表空间的使用情况
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 表空间,
TO_CHAR(ROUND(BYTES / 1024, 2), ‘99990.00’) || ‘’ 实有,
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)
–WHERE TABLESPACE_NAME LIKE ‘CDR%’
ORDER BY FLOOR(10000 * USED / BYTES) DESC;