如何知道 pg_partition 中 postgresql 分区的 table 名称
how to know the table name of a partition in pg_partition for postgresql
我检查来自 pg_partition、
的分区信息
select
relname,
parttype,
parentid,
rangenum,
interval,
boundaries
from pg_partition where parttype='p';
问题是:如何知道这些分区来自哪里,
如果您使用 greenplum,pg_partitions
有一个 tablename
列。参见
对于 Postgres,存储分区信息的 table 的名称是 pg_partitioned_table
对于包含分区的table详情,您可以简单查询pg_class
如this answer
select c.relnamespace::regnamespace::text as schema,
c.relname as table_name,
pg_get_partkeydef(c.oid) as partition_key
from pg_class c
where c.relkind = 'p';
这是一个demo
如果您想要分区的所有信息及其 tables,您可以将 2 tables 合并为 this answer
我检查来自 pg_partition、
的分区信息select
relname,
parttype,
parentid,
rangenum,
interval,
boundaries
from pg_partition where parttype='p';
问题是:如何知道这些分区来自哪里,
如果您使用 greenplum,pg_partitions
有一个 tablename
列。参见
对于 Postgres,存储分区信息的 table 的名称是 pg_partitioned_table
对于包含分区的table详情,您可以简单查询pg_class
如this answer
select c.relnamespace::regnamespace::text as schema,
c.relname as table_name,
pg_get_partkeydef(c.oid) as partition_key
from pg_class c
where c.relkind = 'p';
这是一个demo
如果您想要分区的所有信息及其 tables,您可以将 2 tables 合并为 this answer