Oracle查询表空间及表大小


Oracle查询表空间及表大小

一、Oracle物理表空间查询

select b.file_name phy_file_name, --(物理文件名)
       b.tablespace_name tablespace_name, --(表空间名)
       b.bytes / 1024 / 1024 || ' MB' tabspace_bytes, --(表空间大小 MB)
       (b.bytes - sum(nvl(a.bytes, 0))) / 1024 / 1024 || ' MB' USEED_SPACE, --(使用表空间大小)
       b.bytes / 1024 / 1024 -(b.bytes - sum(nvl(a.bytes, 0))) / 1024 / 1024 || ' MB'  Free_Space, --剩余表空间大小
       substr((b.bytes - sum(nvl(a.bytes, 0))) / (b.bytes) * 100, 1, 5) || '%' use_ratio --(利用率)
  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.bytes
 order by b.tablespace_name;

二、查询特定的表所在的表空间以及所在的物理文件上

select a.table_name, a.tablespace_name, b.file_name
  from user_tables a, dba_data_files b
 where a.tablespace_name = b.tablespace_name
   and a.table_name = 'CORP_RICH_ORDERTRADENIGHT';

三、更改数据库的默认表空间

Alter database  default  tablespace tablespace_name;(数据表空间)

Alter database  temporary tablespace tablespace_name;(临时数据表空间)

四、查询表大小

Select Segment_Name, Sum(bytes) / 1024 / 1024 || 'MB'
From User_Extents u where u.segment_type='TABLE'
Group By Segment_Name;

文章作者: 海东青
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 海东青 !
  目录