开发者社区> 问答> 正文

由于分区表中的数据量非常大,怎么用SQL查询准确的统计出分区所占用数据库空间大小?

由于分区表中的数据量非常大,怎么用SQL查询准确的统计出分区所占用数据库空间大小?

展开
收起
晓风瑟瑟 2021-10-14 23:16:40 1073 0
2 条回答
写回答
取消 提交回答
  • 分区可包含其自身,其自身也有子分区,可以用以下SQL进行统计: select t1.table_name,t2.bytes,t2.owner,t2.tablespace_name from dba_tab_partitions t1 left join dba_segments t2 on t1.table_owner = t2.owner and t1.tablespace_name = t2.tablespace_name and t1.partition_name

    = t2.partition_name and t1.table_name = t2.segment_name where t1.table_owner = 'TEST' and t1.tablespace_name = 'TEST' union all -- 返回子分区占用空间大小 select t3.table_name,t2.bytes,t2.owner,t2.tablespace_name from dba_tab_subpartitions t1 left join dba_tab_partitions t3

    on t1.table_owner = t3.table_owner and t1.partition_name = t3.partition_name and t1.tablespace_name

    = t3.tablespace_name and t1.table_name = t3.table_name left join dba_segments t2 on t1.subpartition_name = t2.partition_name and t1.table_name = t2.segment_name -- and

    t1.table_owner = t2.owner and t1.tablespace_name = t2.tablespace_name
    where t1.table_owner = 'TEST' and t1.tablespace_name = 'TEST' )t4 group by t4.segment_name,t4.owner,t4.tablespace_name )t5, dba_data_files t6 where t6.tablespace_name = 'TEST' group by t5.table_name,t5.bytes,t5.owner,t5.tablespace_name )t7 where t7.table_name not like '%$%' group by table_name,bytes,total_bytes,owner,tablespace_name; select owner,table_name,tablespace_name,bytes,(round((round(sum(bytes)/(1024*1024),2))/(round

    (total_bytes/(1024*1024),2)),4)100) " used(%)" ,round(sum(bytes)/(10241024),2) from ( select t5.table_name,t5.bytes as bytes,t5.owner,t5.tablespace_name,sum(t6.bytes) as total_bytes

    from ( select t4.segment_name as table_name,sum(t4.bytes) as bytes,t4.owner,t4.tablespace_name from ( -- 返回表数据 占用空间量 select t1.segment_name,t1.bytes,t1.owner,t1.tablespace_name from dba_segments t1,dba_tables t2 where t1.tablespace_name = t2.tablespace_name and t1.owner = t2.owner and t1.segment_name = t2.table_name and t1.tablespace_name = 'TEST' and t1.owner = 'TEST'

    2021-10-15 23:49:14
    赞同 展开评论 打赏
  • select segment_name, sum(bytes)/1024/1024 Mbytese from user_segments group by segment_name;
    
    2021-10-15 17:32:44
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
2022 DTCC-阿里云一站式数据库上云最佳实践 立即下载
云时代的数据库技术趋势 立即下载
超大型金融机构国产数据库全面迁移成功实践 立即下载