要查看表的分區信息,可以使用以下兩個 PostgreSQL 系統表:
pg_partitioned_table
:此表存儲了所有被分區的表的信息。pg_partitioned_table
:此表存儲了每個分區的詳細信息。以下是一個示例查詢,用于查看表的分區信息:
SELECT
parent.relname AS parent_table,
child.relname AS child_table,
pg_get_expr(partition_def, parent.oid) AS partition_expression
FROM
pg_partitioned_table AS p
JOIN
pg_class AS parent ON p.partrelid = parent.oid
JOIN
pg_class AS child ON p.partid = child.oid
JOIN
pg_partitioned_table AS pp ON pp.partrelid = child.oid
ORDER BY
parent.relname,
child.relname;
該查詢將返回被分區的表的名稱、每個分區的名稱以及分區表達式。
請注意,您需要有足夠的權限才能查詢這些系統表。