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 1oVGVD-00071A-BW for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Sep 2022 18:07:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oVGVC-00005k-8G for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Sep 2022 18:07:18 +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 1oVGS9-0005B5-3c for pgsql-hackers@lists.postgresql.org; Mon, 05 Sep 2022 18:04:09 +0000 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oVGS5-0006or-PQ for pgsql-hackers@lists.postgresql.org; Mon, 05 Sep 2022 18:04:08 +0000 Received: by mail-il1-x12f.google.com with SMTP id a9so4951024ilh.1 for ; Mon, 05 Sep 2022 11:04:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date; bh=iG3GNiPDbrBzAP8AxQK+GfRY0JsQXLfwCwMv8eeIX9c=; b=WQfbacVgkk3c9+y+/YxmAmb/zkr6iw4VfVtKFRP3ZzPWk3shlXtQUkwRbO72UGOe1l 2vhqPBdk6Ak3aKKDas64LBfoBMxpUIuS0EonVD6PLiLPi4Zc5zvnDSdeei9oplxYShs5 Dw/Ye0d0e5j9iweX9EenK9LvGfNMXQ8zyJWjZQhU8lrzBBsPdu8ZVSkk4G08OOkG0rYj tnQSt65/eJL46ipvO4WmpoNa6lXw9bfUiky0rFUl/RLP5BiSH3u2YdQiiP4YkVrJnyEp dThDyC4W+VP7Aqgr80rRC13loS5PIwAadE2fyMpQY43GeoKX68l/h2FI80kHodKbbcjm Z8bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date; bh=iG3GNiPDbrBzAP8AxQK+GfRY0JsQXLfwCwMv8eeIX9c=; b=v+/RfWtHHQtKOzTvYcP7U/rPvzNAeTxRuuQgXmtt5jhX2M5ssbqIxElgyC6ExhkAmk vEtoBP+T0AXLOrEVZa3FXO5l+KNk7skTN4jzkLRXZ6ldc7LTyLLG2zAcTqRd9FrMB7Y5 5qyVWpLCnWX8dzSbnFjh0nu+Ot5ysh62kpR5EBZfTZaAG5A1vV5ogG41SBNaZvdl/dy/ w/WWXrD9fGRFqyn5btY6thC+zjDNrWHLBfR39F7DilcpFQ4ftm3Afx07GoeFZXk2281a O6pOeIfR3xfxqzZ4XitBxK/ehxKHQ9+bCOho1urQQXlJq3EjJpjqZc4OuhZP0olaYzcr NXIA== X-Gm-Message-State: ACgBeo3vGIkDNCMYv0BJjbXa6qDF6G3T942P4B/pucj5JQaepkeBw/mH bozC1TxRIRpcdpkL7axQOpXSxw== X-Google-Smtp-Source: AA6agR4ktTnMwE/GL7tZD0bIoyTNk7xCzeNf9xaLL0pjbOjZul/r9jdcxxsA4Hj2PeZxRVwqSbM0dA== X-Received: by 2002:a05:6e02:12a8:b0:2ea:f53a:2d06 with SMTP id f8-20020a056e0212a800b002eaf53a2d06mr18938200ilr.223.1662401044808; Mon, 05 Sep 2022 11:04:04 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id i19-20020a056e021d1300b002e58adc323fsm4109856ila.32.2022.09.05.11.04.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Sep 2022 11:04:04 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 6FF79800DE8; Mon, 5 Sep 2022 13:04:03 -0500 (CDT) Date: Mon, 5 Sep 2022 13:04:03 -0500 From: Justin Pryzby To: Robert Treat Cc: Andrew Dunstan , Robert Haas , pgsql-hackers@lists.postgresql.org, David Rowley , Alvaro Herrera Subject: Re: doc: mentioned CREATE+ATTACH PARTITION as an alternative to CREATE TABLE..PARTITION OF Message-ID: <20220905180403.GN31833@telsasoft.com> References: <20220718143304.GC18011@telsasoft.com> <1e91af94-2bea-5b35-49f3-ea14859c2a0d@dunslane.net> 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 Thu, Aug 04, 2022 at 01:45:49AM -0400, Robert Treat wrote: > After reading this again, it isn't clear to me that this advice would > be more appropriately placed into Section 5.11, aka > https://www.postgresql.org/docs/current/ddl-partitioning.html, but in > lieu of a specific suggestion for where to place it there (I haven't > settled on one yet), IMHO, I think the first sentence of the suggested > change should be rewritten as: > > > Note that creating a partition using PARTITION OF > requires taking an ACCESS EXCLUSIVE lock on the parent table. > It may be preferable to first CREATE a separate table... Thanks for looking. I used your language. There is some relevant information in ddl.sgml, but not a lot, and it's not easily referred to, so I removed the part of the patch that tried to cross-reference. @Robert: I wonder why shouldn't CREATE..PARTITION OF *also* be patched to first create a table, and then attach the partition, transparently doing what everyone would want, without having to re-read the updated docs or know to issue two commands? I wrote a patch for this which "doesn't fail tests", but I still wonder if I'm missing something.. commit 723fa7df82f39aed5d58e5e52ba80caa8cb13515 Author: Justin Pryzby Date: Mon Jul 18 09:24:55 2022 -0500 doc: mention CREATE+ATTACH PARTITION as an alternative to CREATE TABLE..PARTITION OF In v12, 898e5e329 (Allow ATTACH PARTITION with only ShareUpdateExclusiveLock) allows attaching a partition with a weaker lock than in CREATE..PARTITION OF, but it does that silently. On the one hand, things that are automatically better, without having to enable the option are the best kind of feature. OTOH, I doubt many people know to do that, because the docs don't say so, because it was implemented as an transparent improvement. This patch adds a bit of documentations to make that more visible. See also: 898e5e3290a72d288923260143930fb32036c00c Should backpatch to v12 diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml index 360284e37d6..66138b9299d 100644 --- a/doc/src/sgml/ddl.sgml +++ b/doc/src/sgml/ddl.sgml @@ -4092,7 +4092,9 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02 The ATTACH PARTITION command requires taking a - SHARE UPDATE EXCLUSIVE lock on the partitioned table. + SHARE UPDATE EXCLUSIVE lock on the partitioned table, + as opposed to the Access Exclusive lock which is + required by CREATE TABLE .. PARTITION OF. diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index c14b2010d81..54dbfa72e4c 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -619,6 +619,16 @@ WITH ( MODULUS numeric_literal, REM with DROP TABLE requires taking an ACCESS EXCLUSIVE lock on the parent table. + + + Note that creating a partition using PARTITION OF + requires taking an ACCESS EXCLUSIVE lock on the parent + table. It may be preferable to first create a separate table and then + attach it, which does not require as strong a lock. + See ATTACH PARTITION + for more information. + +