Oracle查询表空间大小

 1 查询数据库中所有的表空间以及表空间所占空间的大小

SELECT
    tablespace_name,
    sum( bytes ) / 1024 / 1024 
FROM
    dba_data_files 
GROUP BY
    tablespace_name;

2 Oracle查询表空间大小及每个表所占空间的大小

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 dba_free_space 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;

你可能感兴趣的:(oracle)