您的位置:宽带测速网 > 网络知识 > postgresql怎么查表的分区信息

postgresql怎么查表的分区信息

2025-06-20 13:17来源:互联网 [ ]

要查看表的分区信息,可以使用以下两个 PostgreSQL 系统表:

    pg_partitioned_table:此表存储了所有被分区的表的信息。pg_partitioned_table:此表存储了每个分区的详细信息。

以下是一个示例查询,用于查看表的分区信息:

SELECTparent.relname AS parent_table,child.relname AS child_table,pg_get_expr(partition_def, parent.oid) AS partition_expressionFROMpg_partitioned_table AS pJOINpg_class AS parent ON p.partrelid = parent.oidJOINpg_class AS child ON p.partid = child.oidJOINpg_partitioned_table AS pp ON pp.partrelid = child.oidORDER BYparent.relname,child.relname;

该查询将返回被分区的表的名称、每个分区的名称以及分区表达式。

请注意,您需要有足够的权限才能查询这些系统表。