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 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;
相关推荐
XDHCOM19 小时前
ORA-32484重复列名错误,ORACLE数据库CYCLE子句故障修复与远程处理方案
数据库·oracle
一博一言20 小时前
Oracle高版本Version_Count问题处理排查
oracle·dba
LilySesy1 天前
【与AI+】英语day4——数据库与性能优化
数据库·oracle·性能优化·sap·abap·自动翻译
余佬学数据库1 天前
Error 57 initializing SQL*Plus Error loading message shared library
oracle
Yana.nice1 天前
MySQL 事务的四大特性(ACID)
数据库·mysql·oracle
小小程序员.¥1 天前
oracle--视图、序列、索引
服务器·数据库·oracle
zzh0811 天前
PG数据库日常应用
数据库·oracle
Trouvaille ~1 天前
【MySQL篇】表的操作:数据的容器
linux·数据库·mysql·oracle·xshell·ddl·表的操作
麦聪聊数据1 天前
数据库安全与运维管控(一):MySQL、PG与Oracle原生审计机制对比
运维·数据库·mysql·oracle
小小程序员.¥1 天前
oracle--plsql块、存储过程、存储函数
数据库·sql·oracle