On Tue, Jul 20, 2021 at 02:42:16PM -0400, Robert Haas wrote: > The bigger issue IMHO with on-the-fly > partition creation is avoiding deadlocks in the presence of current > inserters; I submit that without at least some kind of attempt to > avoid deadlocks and spurious errors there, it's not really a usable > scheme, and that seems hard.
I was thinking that for dynamic creation, there would be a DDL command to create the necessary partitions: -- Creates 2021-01-02, unless the month already exists: ALTER TABLE bydate SET GRANULARITY='1day'; ALTER TABLE bydate CREATE PARTITION FOR VALUE ('2021-01-02'); I'd want it to support changing the granularity of the range partitions: -- Creates 2021-01 unless the month already exists. -- Errors if a day partition already exists which would overlap? ALTER TABLE bydate SET granularity='1month'; ALTER TABLE bydate CREATE PARTITION FOR VALUE ('2021-01-03'); It could support creating ranges, which might create multiple partitions, depending on the granularity: ALTER TABLE bydate CREATE PARTITION FOR VALUES ('2021-01-01') TO ('2021-02-01') Or the catalog could include not only granularity, but also endpoints: ALTER TABLE bydate SET ENDPOINTS ('2012-01-01') ('2022-01-01') ALTER TABLE bydate CREATE PARTITIONS; --create anything needed to fill from a->b ALTER TABLE bydate PRUNE PARTITIONS; --drop anything outside of [a,b] I would use this to set "fine" granularity for large tables, and "course" granularity for tables that were previously set to "fine" granularity, but its partitions are no longer large enough to justify it. This logic currently exists in our application - we create partitions dynamically immediately before inserting. But it'd be nicer if it were created asynchronously. It may create tables which were never inserted into, which is fine - they'd be course granularity tables (one per month). I think this might elegantly allow both 1) subpartitioning; 2) repartitioning to a different granularity (for which I currently have my own tool). -- Justin