1 查询数据库中所有的表空间以及表空间所占空间的大小
SELECTtablespace_name,sum( bytes ) / 1024 / 1024
FROMdba_data_files
GROUP BYtablespace_name;
2 Oracle查询表空间大小及每个表所占空间的大小
SELECTtablespace_name,file_id,file_name,round( bytes / ( 1024 * 1024 ), 0 ) total_space
FROMdba_data_files
ORDER BYtablespace_name;
3 查询所有表空间以及每个表空间的大小,已用空间,剩余空间,使用率和空闲率,直接执行语句就可以.
SELECTa.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
WHEREa.tablespace_name = b.tablespace_name
ORDER BYa.tablespace_name;
4 查询某个具体的表所占空间的大小,把 TABLE_NAME 换成具体要查询的表的名称就可以了
SELECTt.segment_name,t.segment_type,sum( t.bytes / 1024 / 1024 ) "占用空间(M)"
FROMdba_segments t
WHEREt.segment_type = 'TABLE' AND t.segment_name = 'TABLE_NAME'
GROUP BYOWNER,t.segment_name,t.segment_type;