I am looking for a solution that lists all the range partition information. Tried the below query.
SELECT c.relname as partition_list,p.relname as parent_tbl FROM pg_inherits i JOIN pg_class p ON i.inhparent = p.oid
JOIN pg_class c ON i.inhrelid = c.oid WHERE p.relkind IN ('r', 'p');
output
"testpartpartition_1" "parentpartiontbl"
"testpartpartition_2" "parentpartiontbl"
But since I created a range partition, want to know the range values for eg:
CREATE TABLE testpartpartition_1 PARTITION OF parentpartiontbl FOR VALUES FROM (1) TO (5)
CREATE TABLE testpartpartition_2 PARTITION OF parentpartiontbl FOR VALUES FROM (6) TO (10)
Want the output also which states startvalue
and endvalue
for each partition like below
child_partition parent_tbl min_rangeval max_rangeval
---------------------------------------------------------------------------------
"testpartpartition_1" "parentpartiontbl" 1 5
"testpartpartition_2" "parentpartiontbl" 6 10
3
Answers
Since the partition boundaries are stored in binary parsed form, all you can do is deparse them:
Analyzing the boundary string is left as exercise to the reader.
Here’s the query that gets generated by
d+
:Looks like you need to use
pg_get_expr()
to decode the stuff inpg_class.relpartbound
to reconstruct the range partition parameters.You can also replace
i.inhparent = '33245'
with a subquery to query by parent table name:You can find the information in the
relpartbound
column of the system catalogpg_class
. Use the functionpg_get_expr()
to get the data readable:Use
regexp_matches()
to extract the numbers in parentheses