首批通过分布式安全可靠测评,为关键业务系统打造
如何查看表和索引的大小和磁盘空间使用
更新时间:2026-06-16 09:21
本文总结如何在 OceanBase 数据库中计算各个租户的单表占用磁盘空间大小以及真实的表大小。这里用 MySQL 租户下的表 t1 来举例如何计算,Oracle 租户使用同样的计算方式。
适用版本
OceanBase 数据库 V2.x 和 V3.x 版本。
操作步骤
注意
以下 SQL 均在系统租户下执行。
可以从以下 3 张系统表来查询表或索引的分区大小和磁盘空间使用。
__all_virtual_meta_table:包含了表分区和全局索引的副本位置信息,以及合并时 major sstable 的大小统计。该表不包含本地索引的信息。## 查看表 select concat(round(data_size/1024/1024,2),' MB') data_size,row_count from __all_virtual_meta_table where role=1 and table_id=xxx and partition_id=xxx;__all_virtual_table_mgr:包含了表分区和索引分区的 SSTable、MEMTable 的相关属性,比如 size、版本号、事务等。当 index_id=table_id 时,表示的是基表。
该表中 table_type 的定义如下。
enum TableType { MEMTABLE = 0, MAJOR_SSTABLE = 1, MINOR_SSTABLE = 2, // obsoleted type after 2.2 TRANS_SSTABLE = 3, // new table type from 3.1 MULTI_VERSION_MINOR_SSTABLE = 4, COMPLEMENT_MINOR_SSTABLE = 5, // new table type from 3.1 MULTI_VERSION_SPARSE_MINOR_SSTABLE = 6, // reserved table type MINI_MINOR_SSTABLE = 7, BUF_MINOR_SSTABLE = 8, MAX_TABLE_TYPE };
查询示例。
select m.svr_ip,t.table_name,m.table_id,m.index_id,m.partition_id, m.table_type, m.size,m.compact_row from __all_virtual_table_mgr m, __all_virtual_table t where m.table_id=t.table_id and m.svr_ip='11.xxx.xx.xxx' and t.table_name='BMSQL_OORDER' and m.partition_id=118;+---------------+--------------+------------------+------------------+--------------+------------+----------+-------------+ | svr_ip | table_name | table_id | index_id | partition_id | table_type | size | compact_row | +---------------+--------------+------------------+------------------+--------------+------------+----------+-------------+ | 11.xxx.xx.xxx | BMSQL_OORDER | 1105009185965277 | 1105009185965277 | 118 | 1 | 22579718 | 1 | | 11.xxx.xx.xxx | BMSQL_OORDER | 1105009185965277 | 1105009185965277 | 118 | 7 | 0 | 1 | | 11.xxx.xx.xxx | BMSQL_OORDER | 1105009185965277 | 1105009185965277 | 118 | 5 | 0 | 1 | | 11.xxx.xx.xxx | BMSQL_OORDER | 1105009185965277 | 1105009185965278 | 118 | 1 | 3291129 | 1 | | 11.xxx.xx.xxx | BMSQL_OORDER | 1105009185965277 | 1105009185965278 | 118 | 7 | 0 | 1 | | 11.xxx.xx.xxx | BMSQL_OORDER | 1105009185965277 | 1105009185965278 | 118 | 5 | 0 | 1 | +---------------+--------------+------------------+------------------+--------------+------------+----------+-------------+__all_virtual_storage_stat:包含了存储层统计的表分区、索引分区的 SSTable 的统计信息。- 当 sstable_id<>table_id 时,sstable_id 是 index_id。
- store_type 的定义与 __all_virtual_table_mgr 表中 table_type 的定义一致。
select t.table_name,m.table_id,m.sstable_id,m.partition_id, m.store_type, m.occupy_size,m.used_size,m.row_count from __all_virtual_storage_stat m, __all_virtual_table t where m.role=1 and m.table_id=t.table_id and t.table_name='BMSQL_OORDER' and m.partition_id=118;+--------------+------------------+------------------+--------------+------------+-------------+-----------+-----------+ | table_name | table_id | sstable_id | partition_id | store_type | occupy_size | used_size | row_count | +--------------+------------------+------------------+--------------+------------+-------------+-----------+-----------+ | BMSQL_OORDER | 1105009185965277 | 1105009185965277 | 118 | 1 | 22579718 | 23068672 | 2731051 | | BMSQL_OORDER | 1105009185965277 | 1105009185965277 | 118 | 7 | 0 | 0 | 0 | | BMSQL_OORDER | 1105009185965277 | 1105009185965277 | 118 | 5 | 0 | 0 | 0 | | BMSQL_OORDER | 1105009185965277 | 1105009185965278 | 118 | 1 | 3291129 | 4194304 | 2731051 | | BMSQL_OORDER | 1105009185965277 | 1105009185965278 | 118 | 7 | 0 | 0 | 0 | | BMSQL_OORDER | 1105009185965277 | 1105009185965278 | 118 | 5 | 0 | 0 | 0 | +--------------+------------------+------------------+--------------+------------+-------------+-----------+-----------+
通常,使用 __all_virtual_table_mgr、__all_virtual_storage_stat 查询出来的 table size 会比 __all_virtual_meta_table 大,因为 __all_virtual_meta_table 只包含 major sstable 的统计。