为什么用下面脚本统计数据库使用空间出来的结果是空的?
SELECT
table_schema,
SUM(data_length + index_length) / 1024 / 1024 / 1024 AS total_size_gb
FROM
information_schema.tables
WHERE
table_schema = ‘test’
GROUP BY
table_schema;
建议使用ob自己的系统表,information_schema中的表仅仅是为兼容mysql创建的
查询database大小可以使用CDB_OB_tablet_replicas 和 CDB_OB_table_locations两张表进行关联查询
这个表只能root@sys查,如果是非sys查询DBA_OB_xxxxxx
SELECT SUM(CAST(tr.data_size AS DECIMAL(18, 2)) / 1024 / 1024 / 1024) AS database_size_gb
FROM oceanbase.DBA_OB_TABLET_REPLICAS tr
JOIN oceanbase.DBA_OB_TABLE_LOCATIONS trl ON tr.tablet_id = trl.tablet_id;
是这样查吗
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;
这个sql需要使用root@sys
好吧 我没有root权限
我也去统计下试试