数据库中如何查询表空间大小

这篇文章主要为大家展示了“数据库中如何查询表空间大小”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“数据库中如何查询表空间大小”这篇文章吧。

1、查询某个表空间上对象的大小
select owner,segment_name,segment_type,sum(bytes)/1024/1024 as segment_size
  from dba_segments
where tablespace_name='xxx'
group by owner,segment_name,segment_type
order by 4;

2、查询某个用户下所有表的记录总数数量的语句生成语句
select 'select '''||table_name||''' as table_name,count(*) as cnt from '||table_name||' union all ' from all_tables where owner='xxx';

3、查询表空间的大小及使用大小
SELECT a.tablespace_name,
total / (1024 * 1024 * 1024) "大小(G)", 
free / (1024 * 1024 * 1024) "剩余大小(G)", 
(total - free) / (1024 * 1024 * 1024) "使用大小(G)", 
round((total - free) / total, 4) * 100 "使用率 %" 
FROM (SELECT tablespace_name, SUM(bytes) free 
FROM dba_free_space 
GROUP BY tablespace_name) a, 
(SELECT tablespace_name, SUM(bytes) total 
FROM dba_data_files 
GROUP BY tablespace_name) b 
WHERE a.tablespace_name = b.tablespace_name;

以上是“数据库中如何查询表空间大小”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!