图式资本在 Pg_Relation_Size 中造成混乱
Schema Capitals Causing Mayhem in Pg_Relation_Size
首先,感谢您以后的帮助!
关于我的问题:我正在尝试获取我的 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
;
但是,它一直抛出错误消息“架构 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),我现在正在用头撞墙慢慢失去理智......
非常感谢任何帮助。
尝试正确转义标识符:
pg_relation_size(format('%I.%I, schemaname, tablename)::regclass)
首先,感谢您以后的帮助!
关于我的问题:我正在尝试获取我的 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
;
但是,它一直抛出错误消息“架构 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),我现在正在用头撞墙慢慢失去理智......
非常感谢任何帮助。
尝试正确转义标识符:
pg_relation_size(format('%I.%I, schemaname, tablename)::regclass)