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 1jsSb7-0001iz-HC for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2020 14:59:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jsSb6-0002SR-Dl for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2020 14:59:56 +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 1jsSb6-0002SK-3Y for pgsql-hackers@lists.postgresql.org; Mon, 06 Jul 2020 14:59:56 +0000 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jsSb3-0007F5-BQ for pgsql-hackers@lists.postgresql.org; Mon, 06 Jul 2020 14:59:55 +0000 Received: by mail-io1-xd2f.google.com with SMTP id v8so39562151iox.2 for ; Mon, 06 Jul 2020 07:59:53 -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=WzsEKfuaoPGxQgTWdX8AvBpI9XwW7vMi34qGYieY+Hk=; b=tpW3g9E8QjhXHxnxHmVlb9Rv0iNuexZA+XH+KEo5ljo0QhUZIBYcjAYjfT51rHzvqn ZOnOqvAaHeZ2oMatkc/2rhruRt2NZcSxaVYTnfyiwFr6vjC2VJuU6wLDxURPmSGk3BC/ 7kOttfo34xbHlPPmD1qu23eEwP0A1YSuuJgxwF45OupYSioKkkNl971RLpFGpPluOZFb 7tIEPVkIgIScFQ5MGpC7MMvPiHSFUMkNyTKHnvp1gFLzNo2Qsf/+JI4QAa7yuLloJEDP EBbTFxByd6tvEzppcklGh+mZtutfi+YKijokbkWBHMs2J6VtHx4ezklVF9CaOWRrWxmJ w67g== 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=WzsEKfuaoPGxQgTWdX8AvBpI9XwW7vMi34qGYieY+Hk=; b=T9H+csOTXZosDVBX4y5hVgCMWkbZPqXehq+MnQhcg1xp4se78/zPWnaQiF75zQSHKN TqX8maugAFx6JxS9v59yneb2aOJKEu45fLKNEDrcnUkVzUFWX2800amKgBYdfseSFtlV nTJ3I99mQ+04cOfwBszNGBh7RtEZanEbgujnqDrXgMfHYtSfExP+jjdJX1wAmsfucw9J 6OffUrvdLJS/bUjUxuDCfFxPS/pqNknuSOw23JRr5Shm9hVTBH6Y9n4in1aT5GwK50eB +NzSCgQqIA3/N4yHsWf7/MsVWlIxtv3iYYzaIMX9mNWj2arkmjClzQzpwwzzg6r0+55s 93iQ== X-Gm-Message-State: AOAM5308HK7e/1i+E844DyfBVZlVrh1v41YdRwoGKbAR1nX5ZeD/dJwE d5PYqPXTBk52RaKDNkEHhU2cI3wllWI= X-Google-Smtp-Source: ABdhPJy6GVGj7VQ+7oBXsCLq0KnTJXhDIEQSoLHHvd9WgU7e8YglFSzNQ4nhyhG6xIVuwxK2RHO0lg== X-Received: by 2002:a05:6602:140b:: with SMTP id t11mr25646519iov.198.1594047591579; Mon, 06 Jul 2020 07:59:51 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id y20sm10355550ioc.30.2020.07.06.07.59.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jul 2020 07:59:50 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 45DA380064E; Mon, 6 Jul 2020 09:59:47 -0500 (CDT) Date: Mon, 6 Jul 2020 09:59:47 -0500 From: Justin Pryzby To: Anastasia Lubennikova Cc: PostgreSQL Hackers Subject: Re: Proposal: Automatic partition creation Message-ID: <20200706145947.GX4107@telsasoft.com> References: <7fec3abb-c663-c0d2-8452-a46141be6d4a@postgrespro.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7fec3abb-c663-c0d2-8452-a46141be6d4a@postgrespro.ru> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Jul 06, 2020 at 01:45:52PM +0300, Anastasia Lubennikova wrote: > The previous discussion of automatic partition creation [1] has addressed > static and dynamic creation of partitions and ended up with several syntax > proposals. ... > where partition_auto_create_clause is > > CONFIGURATION [IMMEDIATE| DEFERRED] USING partition_bound_spec > - IMMEDIATE| DEFERRED is optional, DEFERRED is not implemented yet > I wonder, is it worth placing a stub for dynamic partitioning, or we can > rather add these keywords later. I understand by "deferred" you mean that the partition isn't created at the time CREATE TABLE is run but rather deferred until needed by INSERT. For deferred, range partitioned tables, I think maybe what you'd want to specify (and store) is the INTERVAL. If the table is partitioned by day, then we'd date_trunc('day', time) and dynamically create that day. But if it was partitioned by month, we'd create the month. I think you'd want to have an ALTER command for that (we would use that to change tables between daily/monthly based on their current size). That should also support setting the MODULUS of a HASH partitioned table, to allow changing the size of its partitions (currently, the user would have to more or less recreate the table and move all its data into different partitions, but that's not ideal). I don't know if it's important for anyone, but it would be interesting to think about supporting sub-partitioning: partitions which are themselvese partitioned. Like something => something_YYYY => something_YYYY_MM => something_YYYY_MM_DD. You'd need to specify how to partition each layer of the heirarchy. In the most general case, it could be different partition strategy. If you have a callback function for partition renaming, I think you'd want to pass it not just the current name of the partition, but also the "VALUES" used in partition creation. Like (2020-04-05)TO(2020-05-06). Maybe instead, we'd allow setting a "format" to use to construct the partition name. Like "child.foo_bar_%Y_%m_%d". Ideally, the formats would be fixed-length (zero-padded, etc), so failures with length can happen at "parse" time of the statement and not at "run" time of the creation. You'd still have to handle the case that the name already exists but isn't a partition (or is a partition by doesn't handle the incoming tuple for some reason). Also, maybe your "configuration" syntax would allow specifying other values. Maybe including a retention period (as an INTERVAL for RANGE tables). That's useful if you had a command to PRUNE the oldest partitions, like ALTER..PRUNE. -- Justin