【发布时间】:2021-02-10 16:59:49
【问题描述】:
首先,感谢您以后的帮助!
关于我的问题:我正在尝试获取我的 Greenplum 数据库中所有表的大小 - 很简单。但是,有很多分区表,我想要它们的总大小,而不是独立子大小。所以我使用以下查询来执行此操作:
select * from (
select schemaname as "Schema Name"
,tablename as "Table Name"
,cast(pg_relation_size(schemaname||'.'||tablename) as bigint ) / 1024 / 1024 as "Table Size (MB)"
from pg_tables
where schemaname||'.'||tablename not in (select schemaname||'.'||partitiontablename from pg_partitions)
and schemaname||'.'||tablename not in (select distinct schemaname||'.'||tablename from pg_partitions )
union all
select schemaname as "Schema Name"
,tablename as "Table Name"
,cast(sum(pg_relation_size(schemaname||'.'||partitiontablename)) as bigint ) / 1024 / 1024 as "Table Size (MB)"
from pg_partitions
group by 1, 2
) as union_join
where "Table Size (MB)" > '50'
order by 3 desc
;
但是,它不断抛出错误,提示“schema xyz 不存在”。而且……是的,它没有……所以我拿出下面的代码,在 where 子句中添加,然后让它运行:
select schemaname
,tablename
,cast(sum(pg_relation_size(schemaname||'.'||partitiontablename)) as bigint ) / 1024 / 1024 as "Table Size (MB)"
from pg_partitions
where schemaname != 'XYZ'
group by 1, 2
limit 1
;
这行得通!如果我将代码更改为仅包含“XYZ”,则会引发与以前相同的错误,说“模式 xyz 不存在”。然后我们就走了......
现在我希望它适用于所有模式,所以我不能只排除 XYZ(遗憾的是,还有大写的倍数)。我假设错误与以下部分有关:
pg_relation_size(schemaname||'.'||partitiontablename)
但老实说,我不知道为什么,或者即使是这一点。除了使用大写字母(双引号,yada yada)之外,谷歌搜索没有任何收获,我现在正用头撞墙慢慢失去理智......
非常感谢任何和所有帮助。
【问题讨论】:
标签: sql greenplum quoted-identifier