---
title: 查询每张表的大小及其索引大小-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于查询每张表的大小及其索引大小相关的常见问题和使用技巧，帮助您快速解决查询每张表的大小及其索引大小的难题。
image: https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*OSPzQ6GUQF4AAAAAQHAAAAgAeiGDAQ/original
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

划线反馈

# 查询每张表的大小及其索引大小

更新时间：2026-08-17 03:26

适用版本： V4.0.x、V4.1.x、V4.2.x、V4.3.x 内容类型：TechNote  

统计一下 OceanBase 数据库每张表的大小及其索引大小，通过如下 SQL 语句查询获取每张表的大小及其索引大小。

#### 注意

SQL 语句需要根据实际情况替换租户名、数据库名、表名以及索引名。

```shell
-- 以下两个语句都可以查询
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 版本。

Previous

[为什么创建的 global index（全局索引）会自动变成 local index（本地索引）？](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000001487456)

Next

[创建索引空间不足](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000003170692) ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
