基于湖库一体架构,统一管理结构化、半结构化与非结构化等多模态数据,一个系统承载事务处理、实时分析与 AI 工作负载。
查询每张表的大小及其索引大小
更新时间:2026-08-17 03:26
统计一下 OceanBase 数据库每张表的大小及其索引大小,通过如下 SQL 语句查询获取每张表的大小及其索引大小。
注意
SQL 语句需要根据实际情况替换租户名、数据库名、表名以及索引名。
-- 以下两个语句都可以查询
select /*+ READ_CONSISTENCY(WEAK) */
dotl.database_name,
dotl2.table_name,
dotl.index_name,
concat(round(sum(dotr.data_size/1024/1024/1024), 2),'G') datasize_primary_replica ,
concat(round(sum(dotr.required_size)/1024/1024/1024, 2), 'G') requiredsize_primary_replica
from oceanbase.dba_ob_table_locations dotl,oceanbase.dba_ob_tablet_replicas dotr,oceanbase.dba_ob_table_locations dotl2
where dotl.ls_id = dotl2.ls_id
and dotl.svr_ip = dotl2.svr_ip
and dotl.role = dotl2.role
and dotl.data_table_id = dotl2.table_id
and dotl.ls_id = dotr.ls_id
and dotl.svr_ip = dotr.svr_ip
and dotl.tablet_id = dotr.tablet_id
and dotl.table_type = 'INDEX'
and dotl.index_name = 'idx_xxx'
and dotl.database_name = 'db_xxx'
and dotl2.table_name = 'tab_xxx'
and dotl.role = 'leader' -- 是否只查询主副本
group by dotl.index_name;
select /*+ READ_CONSISTENCY(WEAK) */ t1.table_name,
round(sum(t2.data_size)/1024/1024/1024,2) as data_size_gb,
round(sum(t2.required_size)/1024/1024/1024,2) as required_size_gb
from oceanbase.dba_ob_tenants t,oceanbase.cdb_ob_table_locations t1,oceanbase.cdb_ob_tablet_replicas t2
where t.tenant_id=t1.tenant_id
and t1.svr_ip=t2.svr_ip
and t1.tenant_id=t2.tenant_id
and t1.ls_id=t2.ls_id
and t1.tablet_id=t2.tablet_id
-- and t1.role='leader' -- 是否只查询主副本
and t.tenant_name='test1'
and t1.database_name='sbtest'
and t1.table_name='sbtest1'
group by t1.table_name
order by 3 desc;
适用版本
OceanBase 数据库 V4.x 版本。