Skip to content

Instantly share code, notes, and snippets.

@amitlan
Last active November 14, 2018 10:31
Show Gist options
  • Save amitlan/97dbed8c7c3f49be7579782ba22c9ced to your computer and use it in GitHub Desktop.
Save amitlan/97dbed8c7c3f49be7579782ba22c9ced to your computer and use it in GitHub Desktop.
Viewing partitions in PG 12 with pg_partition_tree and friends
create table p (a int unique, b int) partition by hash (a);
create table p1 partition of p for values with (modulus 2, remainder 0) partition by hash (a);
create table p11 (b int, a int);
alter table p1 attach partition p11 for values with (modulus 1, remainder 0);
create table p2 partition of p for values with (modulus 2, remainder 1);

select  p.*,
        pg_get_expr(relpartbound, relid) as partbound,
        pg_get_partkeydef(relid) as partkey
from    pg_partition_tree('p') p join
        pg_class c on (p.relid = c.oid);

 relid │ parentrelid │ isleaf │ level │                partbound                 │ partkey  
───────┼─────────────┼────────┼───────┼──────────────────────────────────────────┼──────────
 p     │             │ f      │     0 │                                          │ HASH (a)
 p1    │ p           │ f      │     1 │ FOR VALUES WITH (modulus 2, remainder 0) │ HASH (a)
 p2    │ p           │ t      │     1 │ FOR VALUES WITH (modulus 2, remainder 1) │ 
 p11   │ p1          │ t      │     2 │ FOR VALUES WITH (modulus 1, remainder 0) │ 
(4 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment