select t1.database_name,t.tenant_name,
round(t2.data_size/1024/1024,4) as data_size_gb,
round(t2.required_size/1024/1024,4) as required_size_gb,t1.svr_ip,t1.TABLE_NAME
from dba_ob_tenants t,cdb_ob_table_locations t1,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=‘sys’
group by t1.database_name
order by 4 desc, 3 desc;
报错:
SELECT t.database_name AS db_name, SUM(p.data_size) AS total_data_size FROM oceanbase.CDB_OB_TABLE_LOCATIONS tl JOIN oceanbase.GV$OB_PARTITIONS p ON tl.table_id = p.table_id AND tl.partition_id = p.partition_id JOIN oceanbase.DBA_TABLES t ON tl.table_id = t.table_id WHERE tl.tenant_id = 1002 AND tl.role = ‘LEADER’ GROUP BY t.database_name ORDER BY total_data_size DESC
失败原因:
ErrorCode = 1146, SQLState = 42S02, Details = Table ‘oceanbase.GV$OB_PARTITIONS’ doesn’t exist
为了准确统计租户 A 下每个数据库(A1、A2、A3)的大小,可以使用 CDB_OB_TABLE_LOCATIONS 和 __all_virtual_table_mgr 视图来计算表占用的磁盘空间,并按数据库进行汇总。以下是修正后的 SQL 查询:
统计租户下每个数据库的大小(Leader)
SELECT
a.DATABASE_NAME,
SUM(
CASE
WHEN b.nested_offset = 0 THEN IFNULL(b.data_block_count + b.index_block_count + b.linked_block_count, 0) * 2 * 1024 * 1024
ELSE IFNULL(b.size, 0)
END
) / 1024.0 / 1024 / 1024 AS data_size_in_GB
FROM
oceanbase.CDB_OB_TABLE_LOCATIONS a
JOIN
oceanbase.__all_virtual_table_mgr b
ON a.svr_ip = b.svr_ip
AND a.svr_port = b.svr_port
AND a.tenant_id = b.tenant_id
AND a.LS_ID = b.LS_ID
AND a.TABLET_ID = b.TABLET_ID
AND a.role = 'LEADER'
AND a.tenant_id = 1002 -- 替换为您的租户ID
AND b.table_type >= 10
AND b.size > 0
GROUP BY
a.DATABASE_NAME
ORDER BY
data_size_in_GB DESC;
select t1.database_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 dba_ob_tenants t,cdb_ob_table_locations t1,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=‘sys’
group by t1.database_name
order by 3 desc;
##方法1
sql可以统计当前某个租户的对应的每个数据库大小(leader)
select /*+ LEADING(t t2) */ t1.database_name,t.tenant_name,
round(t2.data_size/1024/1024,4) as data_size_gb,
round(t2.required_size/1024/1024,4) as required_size_gb,t1.svr_ip,t1.TABLE_NAME
from dba_ob_tenants t,cdb_ob_table_locations t1,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=‘AA’
group by t1.database_name
用SQL 统计才 2.0000 G
dps core 0.0045 2.0000 G
###查看集群下的A租户的数据库大小 方法2白屏查看 dps 数据库大概 375.23GiB
白屏查看 dps 数据库大概 375.23GiB
dps utf8mb4 utf8mb4_bin
与租户一致 375.23GiB
##方法3;
###SQL .SYS租户下 统计 A租户下每个数据库的大小(Leader)
SELECT
a.DATABASE_NAME,
SUM(
CASE
WHEN b.nested_offset = 0 THEN IFNULL(b.data_block_count + b.index_block_count + b.linked_block_count, 0) * 2 * 1024 * 1024
ELSE IFNULL(b.size, 0)
END
) / 1024.0 / 1024 / 1024 AS data_size_in_GB
FROM
oceanbase.CDB_OB_TABLE_LOCATIONS a
JOIN
oceanbase.__all_virtual_table_mgr b
ON a.svr_ip = b.svr_ip
AND a.svr_port = b.svr_port
AND a.tenant_id = b.tenant_id
AND a.LS_ID = b.LS_ID
AND a.TABLET_ID = b.TABLET_ID
AND a.role = ‘LEADER’
AND a.tenant_id = 1080 – 替换为您的租户ID
AND b.table_type >= 10
AND b.size > 0
GROUP BY
a.DATABASE_NAME
ORDER BY
data_size_in_GB DESC;