Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5vBZ-0006br-Mi for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jul 2021 19:13:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m5vBY-0006D7-6v for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jul 2021 19:13:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5vBX-0006Cz-Qo for pgsql-hackers@lists.postgresql.org; Tue, 20 Jul 2021 19:13:43 +0000 Received: from mail-io1-xd2b.google.com ([2607:f8b0:4864:20::d2b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m5vBR-0007LP-2d for pgsql-hackers@lists.postgresql.org; Tue, 20 Jul 2021 19:13:42 +0000 Received: by mail-io1-xd2b.google.com with SMTP id d9so25157380ioo.2 for ; Tue, 20 Jul 2021 12:13:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=wkcBmneZzRQ8vVB9XS2cEKYw4vhOPgK1Im4zNGeDzi4=; b=eWRtoBrzkEu2NacHYySHMomWdIbHyKP6zXq1u4Ktryyt+miWHfwGLQm9rsgC7XcU1a 0BBZPN7NPVjwFxvA+N8FEELxVVU2sPgM1w31W9NNwMZsO2euLlIRXuGbOH10mes1O7d3 NW03GG98gVfXOA8QgfWjAlUk6xw81LPBRe4u1LKUpgLLlnkfpdESWgxtcyodt10ofywx Yt3iz0c4OgsQgdE8h7S8gHn1LvPIthUQmCCDJQs8A+YV2Xyk+u+KqtSScYbfYer3PimW uuDWc0IDbOADP029xuyc255qHbmWA+OELurLaN4IMQItIHiSBenSxQfLyvIDjBRiBh7P aenA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=wkcBmneZzRQ8vVB9XS2cEKYw4vhOPgK1Im4zNGeDzi4=; b=ddEa7YUJMqc1+n5cjUt1T+IBrgwCAirnPP21Mo6XCsFXRyW7B0VthTVx/BrIJhL4HN xAtl53RwWyrPNmmDKU59c3NJUF8GfXLVlTuW55v/vxZkApA2wlC6k0ZC+WFHAJimrw1L L5NK/rxri24V/MIO4tvm2Br0yNWB2ZlapOx3AQ5i/TGsvvDCUPrUQgLu125A/xOofwef fFhGqbbj8IdaKe0a1WPiv0PPRIBUfNoChgQtKewKNbVGMHKLlsuOygakq17Rko9lbC96 1jecHZByLgNXb5lM/CnTEzE8f/JO6IJYf5GgtT6tGB6HtIq9zxhWxooL3JnZp7Y0JGkx zRyA== X-Gm-Message-State: AOAM533/+zrG1aIXiVEA0Acg0rgyXLyRt6ZA71fsLFL1GnwgwdcTRklm 4SwNshn0MNE4PNI3bG/VYlpONA== X-Google-Smtp-Source: ABdhPJyLamKZbYfo949/FJ8fxnDNcZcgTeYY0sdh7YV2LjSJPMqlZH4iv0Fk4QPFGl0XIY5Pis2YPw== X-Received: by 2002:a5d:87cc:: with SMTP id q12mr23854477ios.131.1626808416161; Tue, 20 Jul 2021 12:13:36 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id e17sm11388778ilr.51.2021.07.20.12.13.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jul 2021 12:13:35 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 822008015F3; Tue, 20 Jul 2021 14:13:34 -0500 (CDT) Date: Tue, 20 Jul 2021 14:13:34 -0500 From: Justin Pryzby To: Robert Haas Cc: Pavel Borisov , Thomas Munro , Anastasia Lubennikova , Rahila Syed , Michael Paquier , PostgreSQL Hackers , Fabien COELHO , Amul Sul Subject: Re: [PATCH] Automatic HASH and LIST partition creation Message-ID: <20210720191334.GH19498@telsasoft.com> References: <6ad2294a-cedc-2f3c-13bd-1ceceb56e4f7@postgrespro.ru> <20210302202617.GD29832@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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